fn apply_many_ops() -> FranklinCircuit<'static, Bn256> {
    const ETH_TOKEN: u16 = 0;
    const NNM_TOKEN: u16 = 2;

    // Create two accounts: we will perform all the operations with the first one,
    // while the second one will be used as "target" account for transfers.
    let accounts = vec![
        WitnessTestAccount::new_empty(1),
        WitnessTestAccount::new_empty(2),
    ];
    let (account, account_to) = (&accounts[0], &accounts[1]);

    // Deposit two types of tokens on the account.
    let deposit_data = [
        (ETH_TOKEN, 1000u32), // 1000 of ETH
        (NNM_TOKEN, 2000u32), // 2000 of token with ID 2
    ];
    let deposit_ops = deposit_data
        .iter()
        .map(|(token_id, token_amount)| DepositOp {
            priority_op: Deposit {
                from: account.account.address,
                token: *token_id,
                amount: BigUint::from(*token_amount),
                to: account.account.address,
            },
            account_id: account.id,
        });

    // Transfer ETH to an existing account.
    let transfer_op = TransferOp {
        tx: account
            .zksync_account
            .sign_transfer(
                ETH_TOKEN,
                "",
                BigUint::from(97u32),
                BigUint::from(3u32),
                &account_to.account.address,
                None,
                true,
            )
            .0,
        from: account.id,
        to: account_to.id,
    };
    let transfer_input =
        SigDataInput::from_transfer_op(&transfer_op).expect("SigDataInput creation failed");

    // Transfer token to a new account.
    let new_account = WitnessTestAccount::new_empty(3);
    let transfer_to_new_op = TransferToNewOp {
        tx: account
            .zksync_account
            .sign_transfer(
                NNM_TOKEN,
                "",
                BigUint::from(1900u32),
                BigUint::from(90u32),
                &account_to.account.address,
                None,
                true,
            )
            .0,
        from: account.id,
        to: new_account.id,
    };
    let transfer_to_new_input = SigDataInput::from_transfer_to_new_op(&transfer_to_new_op)
        .expect("SigDataInput creation failed");

    // Withdraw token from account.
    // We've transferred 1990 tokens above, so we have 10 left.
    let withdraw_op = WithdrawOp {
        tx: account
            .zksync_account
            .sign_withdraw(
                NNM_TOKEN,
                "",
                BigUint::from(5u32),
                BigUint::from(5u32),
                &Address::zero(),
                None,
                true,
            )
            .0,
        account_id: account.id,
    };
    let withdraw_input =
        SigDataInput::from_withdraw_op(&withdraw_op).expect("SigDataInput creation failed");

    // Perform full exit.
    // We've transferred 100 tokens above, so we have 900 left.
    let full_exit_op = FullExitOp {
        priority_op: FullExit {
            account_id: account.id,
            eth_address: account.account.address,
            token: 0,
        },
        withdraw_amount: Some(BigUint::from(900u32).into()),
    };
    let full_exit_success = true;

    // Initialize Plasma and WitnessBuilder.
    let (mut plasma_state, mut circuit_account_tree) = PlasmaStateGenerator::generate(&accounts);
    let mut witness_accum = WitnessBuilder::new(&mut circuit_account_tree, FEE_ACCOUNT_ID, 1);

    // Fees to be collected.
    let mut fees = vec![];

    // Apply deposit ops.
    for deposit_op in deposit_ops {
        plasma_state.apply_deposit_op(&deposit_op);

        let witness = DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
        let circuit_operations = witness.calculate_operations(());
        let pub_data_from_witness = witness.get_pubdata();

        witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);
    }

    // Apply transfer op.
    let (fee, _) = plasma_state
        .apply_transfer_op(&transfer_op)
        .expect("Transfer failed");
    fees.push(fee);

    let witness = TransferWitness::apply_tx(&mut witness_accum.account_tree, &transfer_op);
    let circuit_operations = witness.calculate_operations(transfer_input);
    let pub_data_from_witness = witness.get_pubdata();

    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);

    // Apply transfer to new op.
    let (fee, _) = plasma_state
        .apply_transfer_to_new_op(&transfer_to_new_op)
        .expect("Transfer to new failed");
    fees.push(fee);

    let witness =
        TransferToNewWitness::apply_tx(&mut witness_accum.account_tree, &transfer_to_new_op);
    let circuit_operations = witness.calculate_operations(transfer_to_new_input);
    let pub_data_from_witness = witness.get_pubdata();

    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);

    // Apply withdraw op.
    let (fee, _) = plasma_state
        .apply_withdraw_op(&withdraw_op)
        .expect("Withdraw failed");
    fees.push(fee);

    let witness = WithdrawWitness::apply_tx(&mut witness_accum.account_tree, &withdraw_op);
    let circuit_operations = witness.calculate_operations(withdraw_input);
    let pub_data_from_witness = witness.get_pubdata();

    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);

    // Apply full exit op.
    plasma_state.apply_full_exit_op(&full_exit_op);

    let witness = FullExitWitness::apply_tx(
        &mut witness_accum.account_tree,
        &(full_exit_op, full_exit_success),
    );
    let circuit_operations = witness.calculate_operations(());
    let pub_data_from_witness = witness.get_pubdata();

    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);

    // Collect fees.
    plasma_state.collect_fee(&fees, FEE_ACCOUNT_ID);
    witness_accum.collect_fees(&fees);
    witness_accum.calculate_pubdata_commitment();

    // Check that root hashes match
    assert_eq!(
        plasma_state.root_hash(),
        witness_accum
            .root_after_fees
            .expect("witness accum after root hash empty"),
        "root hash in state keeper and witness generation code mismatch"
    );

    witness_accum.into_circuit_instance()
}
/// Executes the following operations:
///
/// - Deposit several types of token on the account.
/// - Transfer some funds to different accounts, both existing and new.
/// - Change the public key of account.
/// - Withdraw some funds.
///
/// Returns the resulting `WitnessBuilder` and the hash obtained
/// from `PlasmaState` for further correctness checks.
Executes the following operations:
Deposit several types of token on the account.
Transfer some funds to different accounts, both existing and new.
Change the public key of account.
Withdraw some funds.

Returns the resulting `WitnessBuilder` and the hash obtained
from `PlasmaState` for further correctness checks.
Executes the following operations : Deposit several types of token on the account . Transfer some funds to different accounts both existing and new . Change the public key of account . Withdraw some funds . Returns the resulting ` WitnessBuilder ` and the hash obtained from ` PlasmaState ` for further correctness checks .
fn apply_many_ops() -> FranklinCircuit<'static, Bn256> {
    const ETH_TOKEN: u16 = 0;
    const NNM_TOKEN: u16 = 2;
    // Create two accounts: we will perform all the operations with the first one,
    // while the second one will be used as "target" account for transfers.
    let accounts = vec![
        WitnessTestAccount::new_empty(1),
        WitnessTestAccount::new_empty(2),
    ];
    let (account, account_to) = (&accounts[0], &accounts[1]);
    // Deposit two types of tokens on the account.
    let deposit_data = [
        (ETH_TOKEN, 1000u32), // 1000 of ETH
        (NNM_TOKEN, 2000u32), // 2000 of token with ID 2
    ];
    let deposit_ops = deposit_data
        .iter()
        .map(|(token_id, token_amount)| DepositOp {
            priority_op: Deposit {
                from: account.account.address,
                token: *token_id,
                amount: BigUint::from(*token_amount),
                to: account.account.address,
            },
            account_id: account.id,
        });
    // Transfer ETH to an existing account.
    let transfer_op = TransferOp {
        tx: account
            .zksync_account
            .sign_transfer(
                ETH_TOKEN,
                "",
                BigUint::from(97u32),
                BigUint::from(3u32),
                &account_to.account.address,
                None,
                true,
            )
            .0,
        from: account.id,
        to: account_to.id,
    };
    let transfer_input =
        SigDataInput::from_transfer_op(&transfer_op).expect("SigDataInput creation failed");
    // Transfer token to a new account.
    let new_account = WitnessTestAccount::new_empty(3);
    let transfer_to_new_op = TransferToNewOp {
        tx: account
            .zksync_account
            .sign_transfer(
                NNM_TOKEN,
                "",
                BigUint::from(1900u32),
                BigUint::from(90u32),
                &account_to.account.address,
                None,
                true,
            )
            .0,
        from: account.id,
        to: new_account.id,
    };
    let transfer_to_new_input = SigDataInput::from_transfer_to_new_op(&transfer_to_new_op)
        .expect("SigDataInput creation failed");
    // Withdraw token from account.
    // We've transferred 1990 tokens above, so we have 10 left.
    let withdraw_op = WithdrawOp {
        tx: account
            .zksync_account
            .sign_withdraw(
                NNM_TOKEN,
                "",
                BigUint::from(5u32),
                BigUint::from(5u32),
                &Address::zero(),
                None,
                true,
            )
            .0,
        account_id: account.id,
    };
    let withdraw_input =
        SigDataInput::from_withdraw_op(&withdraw_op).expect("SigDataInput creation failed");
    // Perform full exit.
    // We've transferred 100 tokens above, so we have 900 left.
    let full_exit_op = FullExitOp {
        priority_op: FullExit {
            account_id: account.id,
            eth_address: account.account.address,
            token: 0,
        },
        withdraw_amount: Some(BigUint::from(900u32).into()),
    };
    let full_exit_success = true;
    // Initialize Plasma and WitnessBuilder.
    let (mut plasma_state, mut circuit_account_tree) = PlasmaStateGenerator::generate(&accounts);
    let mut witness_accum = WitnessBuilder::new(&mut circuit_account_tree, FEE_ACCOUNT_ID, 1);
    // Fees to be collected.
    let mut fees = vec![];
    // Apply deposit ops.
    for deposit_op in deposit_ops {
        plasma_state.apply_deposit_op(&deposit_op);
        let witness = DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
        let circuit_operations = witness.calculate_operations(());
        let pub_data_from_witness = witness.get_pubdata();
        witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);
    }
    // Apply transfer op.
    let (fee, _) = plasma_state
        .apply_transfer_op(&transfer_op)
        .expect("Transfer failed");
    fees.push(fee);
    let witness = TransferWitness::apply_tx(&mut witness_accum.account_tree, &transfer_op);
    let circuit_operations = witness.calculate_operations(transfer_input);
    let pub_data_from_witness = witness.get_pubdata();
    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);
    // Apply transfer to new op.
    let (fee, _) = plasma_state
        .apply_transfer_to_new_op(&transfer_to_new_op)
        .expect("Transfer to new failed");
    fees.push(fee);
    let witness =
        TransferToNewWitness::apply_tx(&mut witness_accum.account_tree, &transfer_to_new_op);
    let circuit_operations = witness.calculate_operations(transfer_to_new_input);
    let pub_data_from_witness = witness.get_pubdata();
    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);
    // Apply withdraw op.
    let (fee, _) = plasma_state
        .apply_withdraw_op(&withdraw_op)
        .expect("Withdraw failed");
    fees.push(fee);
    let witness = WithdrawWitness::apply_tx(&mut witness_accum.account_tree, &withdraw_op);
    let circuit_operations = witness.calculate_operations(withdraw_input);
    let pub_data_from_witness = witness.get_pubdata();
    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);
    // Apply full exit op.
    plasma_state.apply_full_exit_op(&full_exit_op);
    let witness = FullExitWitness::apply_tx(
        &mut witness_accum.account_tree,
        &(full_exit_op, full_exit_success),
    );
    let circuit_operations = witness.calculate_operations(());
    let pub_data_from_witness = witness.get_pubdata();
    witness_accum.add_operation_with_pubdata(circuit_operations, pub_data_from_witness);
    // Collect fees.
    plasma_state.collect_fee(&fees, FEE_ACCOUNT_ID);
    witness_accum.collect_fees(&fees);
    witness_accum.calculate_pubdata_commitment();
    // Check that root hashes match
    assert_eq!(
        plasma_state.root_hash(),
        witness_accum
            .root_after_fees
            .expect("witness accum after root hash empty"),
        "root hash in state keeper and witness generation code mismatch"
    );
    witness_accum.into_circuit_instance()
}
fn apply_many_ops ( ) -> FranklinCircuit < ' static , Bn256 > { const ETH_TOKEN : u16 = 0 ; const NNM_TOKEN : u16 = 2 ; // Create two accounts: we will perform all the operations with the first one, // while the second one will be used as "target" account for transfers. let accounts = vec ! [ WitnessTestAccount new_empty ( 1 ) WitnessTestAccount new_empty ( 2 ) ] ; let ( account , account_to ) = ( & accounts [ 0 ] , & accounts [ 1 ] ) ; // Deposit two types of tokens on the account. let deposit_data = [ ( ETH_TOKEN , 1000u32 ) , // 1000 of ETH ( NNM_TOKEN , 2000u32 ) , // 2000 of token with ID 2 ] ; let deposit_ops = deposit_data . iter ( ) . map ( | ( token_id , token_amount ) | DepositOp { priority_op : Deposit { from : account . account . address , token : * token_id , amount : BigUint :: from ( * token_amount ) , to : account . account . address , } , account_id : account . id , } ) ; // Transfer ETH to an existing account. let transfer_op = TransferOp { tx : account . zksync_account . sign_transfer ( ETH_TOKEN , " " , BigUint :: from ( 97u32 ) , BigUint :: from ( 3u32 ) , & account_to . account . address , None , true , ) . 0 , from : account . id , to : account_to . id , } ; let transfer_input = SigDataInput :: from_transfer_op ( & transfer_op ) . expect ( " " ) ; // Transfer token to a new account. let new_account = WitnessTestAccount :: new_empty ( 3 ) ; let transfer_to_new_op = TransferToNewOp { tx : account . zksync_account . sign_transfer ( NNM_TOKEN , " " , BigUint :: from ( 1900u32 ) , BigUint :: from ( 90u32 ) , & account_to . account . address , None , true , ) . 0 , from : account . id , to : new_account . id , } ; let transfer_to_new_input = SigDataInput :: from_transfer_to_new_op ( & transfer_to_new_op ) . expect ( " " ) ; // Withdraw token from account. // We've transferred 1990 tokens above, so we have 10 left. let withdraw_op = WithdrawOp { tx : account . zksync_account . sign_withdraw ( NNM_TOKEN , " " , BigUint :: from ( 5u32 ) , BigUint :: from ( 5u32 ) , & Address :: zero ( ) , None , true , ) . 0 , account_id : account . id , } ; let withdraw_input = SigDataInput :: from_withdraw_op ( & withdraw_op ) . expect ( " " ) ; // Perform full exit. // We've transferred 100 tokens above, so we have 900 left. let full_exit_op = FullExitOp { priority_op : FullExit { account_id : account . id , eth_address : account . account . address , token : 0 , } , withdraw_amount : Some ( BigUint :: from ( 900u32 ) . into ( ) ) , } ; let full_exit_success = true ; // Initialize Plasma and WitnessBuilder. let ( mut plasma_state , mut circuit_account_tree ) = PlasmaStateGenerator :: generate ( & accounts ) ; let mut witness_accum = WitnessBuilder :: new ( & mut circuit_account_tree , FEE_ACCOUNT_ID , 1 ) ; // Fees to be collected. let mut fees = vec ! [ ] ; // Apply deposit ops. for deposit_op in deposit_ops { plasma_state . apply_deposit_op ( & deposit_op ) ; let witness = DepositWitness :: apply_tx ( & mut witness_accum . account_tree , & deposit_op ) ; let circuit_operations = witness . calculate_operations ( ( ) ) ; let pub_data_from_witness = witness . get_pubdata ( ) ; witness_accum . add_operation_with_pubdata ( circuit_operations , pub_data_from_witness ) ; } // Apply transfer op. let ( fee , _ ) = plasma_state . apply_transfer_op ( & transfer_op ) . expect ( " " ) ; fees . push ( fee ) ; let witness = TransferWitness :: apply_tx ( & mut witness_accum . account_tree , & transfer_op ) ; let circuit_operations = witness . calculate_operations ( transfer_input ) ; let pub_data_from_witness = witness . get_pubdata ( ) ; witness_accum . add_operation_with_pubdata ( circuit_operations , pub_data_from_witness ) ; // Apply transfer to new op. let ( fee , _ ) = plasma_state . apply_transfer_to_new_op ( & transfer_to_new_op ) . expect ( " " ) ; fees . push ( fee ) ; let witness = TransferToNewWitness :: apply_tx ( & mut witness_accum . account_tree , & transfer_to_new_op ) ; let circuit_operations = witness . calculate_operations ( transfer_to_new_input ) ; let pub_data_from_witness = witness . get_pubdata ( ) ; witness_accum . add_operation_with_pubdata ( circuit_operations , pub_data_from_witness ) ; // Apply withdraw op. let ( fee , _ ) = plasma_state . apply_withdraw_op ( & withdraw_op ) . expect ( " " ) ; fees . push ( fee ) ; let witness = WithdrawWitness :: apply_tx ( & mut witness_accum . account_tree , & withdraw_op ) ; let circuit_operations = witness . calculate_operations ( withdraw_input ) ; let pub_data_from_witness = witness . get_pubdata ( ) ; witness_accum . add_operation_with_pubdata ( circuit_operations , pub_data_from_witness ) ; // Apply full exit op. plasma_state . apply_full_exit_op ( & full_exit_op ) ; let witness = FullExitWitness :: apply_tx ( & mut witness_accum . account_tree , & ( full_exit_op , full_exit_success ) , ) ; let circuit_operations = witness . calculate_operations ( ( ) ) ; let pub_data_from_witness = witness . get_pubdata ( ) ; witness_accum . add_operation_with_pubdata ( circuit_operations , pub_data_from_witness ) ; // Collect fees. plasma_state . collect_fee ( & fees , FEE_ACCOUNT_ID ) ; witness_accum . collect_fees ( & fees ) ; witness_accum . calculate_pubdata_commitment ( ) ; // Check that root hashes match assert_eq ! ( plasma_state root_hash ( ) witness_accum root_after_fees expect ( " " ) " " ) ; witness_accum . into_circuit_instance ( ) }
Executes the following operations:
 Deposit several types of token on the account.
Executes the following operations : Deposit several types of token on the account .