async fn send_transactions_from_acc(
    test_acc: TestAccount,
    ctx: LoadTestConfig,
    rpc_client: RpcClient,
    tps_counter: Arc<TPSCounter>,
) -> Result<SentTransactions, failure::Error> {
    let mut sent_txs = SentTransactions::new();
    let addr_hex = hex::encode(test_acc.eth_acc.address);
    let wei_in_gwei = BigUint::from(1_000_000_000u32);

    // First of all, we have to update both the Ethereum and ZKSync accounts nonce values.
    test_acc.update_nonce_values(&rpc_client).await?;

    // Perform the deposit operation.
    let deposit_amount = BigUint::from(ctx.deposit_initial_gwei).mul(&wei_in_gwei);
    let op_id = deposit_single(&test_acc, deposit_amount.clone(), &rpc_client).await?;

    log::info!(
        "Account {}: initial deposit completed (amount: {})",
        addr_hex,
        deposit_amount
    );
    sent_txs.add_op_id(op_id);

    log::info!(
        "Account {}: performing {} deposit operations",
        addr_hex,
        ctx.n_deposits,
    );

    // Add the deposit operations.
    for _ in 0..ctx.n_deposits {
        let amount = rand_amount(ctx.deposit_from_amount_gwei, ctx.deposit_to_amount_gwei);
        let op_id = deposit_single(&test_acc, amount.mul(&wei_in_gwei), &rpc_client).await?;
        sent_txs.add_op_id(op_id);
    }

    // Now when deposits are done it is time to update account id.
    test_acc.update_account_id(&rpc_client).await?;

    // Create a queue for all the transactions to send.
    // First, we will create and sign all the transactions, and then we will send all the
    // prepared transactions.
    let n_change_pubkeys = 1;
    let txs_amount = (n_change_pubkeys + ctx.n_transfers + ctx.n_withdraws) as usize;
    let mut tx_queue = Vec::with_capacity(txs_amount);

    log::info!(
        "Account {}: preparing {} transactions to send",
        addr_hex,
        txs_amount,
    );

    // Add the `ChangePubKey` operation.
    tx_queue.push((test_acc.sign_change_pubkey(), None));

    // Add the transfer operations.
    for _ in 0..ctx.n_transfers {
        let amount = rand_amount(ctx.transfer_from_amount_gwei, ctx.transfer_to_amount_gwei);
        let signed_transfer =
            test_acc.sign_transfer_to_random(&ctx.input_accounts, amount.mul(&wei_in_gwei));
        tx_queue.push(signed_transfer);
    }
    // Add the withdraw operations.
    for _ in 0..ctx.n_withdraws {
        let amount = rand_amount(ctx.withdraw_from_amount_gwei, ctx.withdraw_to_amount_gwei);
        let signed_withdraw = test_acc.sign_withdraw_single(amount.mul(&wei_in_gwei));
        tx_queue.push(signed_withdraw)
    }

    log::info!(
        "Account {}: preparing transactions completed, sending...",
        addr_hex
    );

    for (tx, eth_sign) in tx_queue {
        let tx_hash = rpc_client.send_tx(tx, eth_sign).await?;
        tps_counter.increment();
        sent_txs.add_tx_hash(tx_hash);
    }

    log::info!("Account: {}: all the transactions are sent", addr_hex);

    Ok(sent_txs)
}
// Sends the configured deposits, withdraws and transfer from a single account concurrently.
Sends the configured deposits, withdraws and transfer from a single account concurrently.
Sends the configured deposits withdraws and transfer from a single account concurrently .
async fn send_transactions_from_acc(
    test_acc: TestAccount,
    ctx: LoadTestConfig,
    rpc_client: RpcClient,
    tps_counter: Arc<TPSCounter>,
) -> Result<SentTransactions, failure::Error> {
    let mut sent_txs = SentTransactions::new();
    let addr_hex = hex::encode(test_acc.eth_acc.address);
    let wei_in_gwei = BigUint::from(1_000_000_000u32);
    // First of all, we have to update both the Ethereum and ZKSync accounts nonce values.
    test_acc.update_nonce_values(&rpc_client).await?;
    // Perform the deposit operation.
    let deposit_amount = BigUint::from(ctx.deposit_initial_gwei).mul(&wei_in_gwei);
    let op_id = deposit_single(&test_acc, deposit_amount.clone(), &rpc_client).await?;
    log::info!(
        "Account {}: initial deposit completed (amount: {})",
        addr_hex,
        deposit_amount
    );
    sent_txs.add_op_id(op_id);
    log::info!(
        "Account {}: performing {} deposit operations",
        addr_hex,
        ctx.n_deposits,
    );
    // Add the deposit operations.
    for _ in 0..ctx.n_deposits {
        let amount = rand_amount(ctx.deposit_from_amount_gwei, ctx.deposit_to_amount_gwei);
        let op_id = deposit_single(&test_acc, amount.mul(&wei_in_gwei), &rpc_client).await?;
        sent_txs.add_op_id(op_id);
    }
    // Now when deposits are done it is time to update account id.
    test_acc.update_account_id(&rpc_client).await?;
    // Create a queue for all the transactions to send.
    // First, we will create and sign all the transactions, and then we will send all the
    // prepared transactions.
    let n_change_pubkeys = 1;
    let txs_amount = (n_change_pubkeys + ctx.n_transfers + ctx.n_withdraws) as usize;
    let mut tx_queue = Vec::with_capacity(txs_amount);
    log::info!(
        "Account {}: preparing {} transactions to send",
        addr_hex,
        txs_amount,
    );
    // Add the `ChangePubKey` operation.
    tx_queue.push((test_acc.sign_change_pubkey(), None));
    // Add the transfer operations.
    for _ in 0..ctx.n_transfers {
        let amount = rand_amount(ctx.transfer_from_amount_gwei, ctx.transfer_to_amount_gwei);
        let signed_transfer =
            test_acc.sign_transfer_to_random(&ctx.input_accounts, amount.mul(&wei_in_gwei));
        tx_queue.push(signed_transfer);
    }
    // Add the withdraw operations.
    for _ in 0..ctx.n_withdraws {
        let amount = rand_amount(ctx.withdraw_from_amount_gwei, ctx.withdraw_to_amount_gwei);
        let signed_withdraw = test_acc.sign_withdraw_single(amount.mul(&wei_in_gwei));
        tx_queue.push(signed_withdraw)
    }
    log::info!(
        "Account {}: preparing transactions completed, sending...",
        addr_hex
    );
    for (tx, eth_sign) in tx_queue {
        let tx_hash = rpc_client.send_tx(tx, eth_sign).await?;
        tps_counter.increment();
        sent_txs.add_tx_hash(tx_hash);
    }
    log::info!("Account: {}: all the transactions are sent", addr_hex);
    Ok(sent_txs)
}
async fn send_transactions_from_acc ( test_acc : TestAccount , ctx : LoadTestConfig , rpc_client : RpcClient , tps_counter : Arc < TPSCounter > , ) -> Result < SentTransactions , failure :: Error > { let mut sent_txs = SentTransactions :: new ( ) ; let addr_hex = hex :: encode ( test_acc . eth_acc . address ) ; let wei_in_gwei = BigUint :: from ( 1_000_000_000u32 ) ; // First of all, we have to update both the Ethereum and ZKSync accounts nonce values. test_acc . update_nonce_values ( & rpc_client ) . await ? ; // Perform the deposit operation. let deposit_amount = BigUint :: from ( ctx . deposit_initial_gwei ) . mul ( & wei_in_gwei ) ; let op_id = deposit_single ( & test_acc , deposit_amount . clone ( ) , & rpc_client ) . await ? ; log :: info ! ( " " addr_hex deposit_amount ) ; sent_txs . add_op_id ( op_id ) ; log :: info ! ( " " addr_hex ctx n_deposits ) ; // Add the deposit operations. for _ in 0 .. ctx . n_deposits { let amount = rand_amount ( ctx . deposit_from_amount_gwei , ctx . deposit_to_amount_gwei ) ; let op_id = deposit_single ( & test_acc , amount . mul ( & wei_in_gwei ) , & rpc_client ) . await ? ; sent_txs . add_op_id ( op_id ) ; } // Now when deposits are done it is time to update account id. test_acc . update_account_id ( & rpc_client ) . await ? ; // Create a queue for all the transactions to send. // First, we will create and sign all the transactions, and then we will send all the // prepared transactions. let n_change_pubkeys = 1 ; let txs_amount = ( n_change_pubkeys + ctx . n_transfers + ctx . n_withdraws ) as usize ; let mut tx_queue = Vec :: with_capacity ( txs_amount ) ; log :: info ! ( " " addr_hex txs_amount ) ; // Add the `ChangePubKey` operation. tx_queue . push ( ( test_acc . sign_change_pubkey ( ) , None ) ) ; // Add the transfer operations. for _ in 0 .. ctx . n_transfers { let amount = rand_amount ( ctx . transfer_from_amount_gwei , ctx . transfer_to_amount_gwei ) ; let signed_transfer = test_acc . sign_transfer_to_random ( & ctx . input_accounts , amount . mul ( & wei_in_gwei ) ) ; tx_queue . push ( signed_transfer ) ; } // Add the withdraw operations. for _ in 0 .. ctx . n_withdraws { let amount = rand_amount ( ctx . withdraw_from_amount_gwei , ctx . withdraw_to_amount_gwei ) ; let signed_withdraw = test_acc . sign_withdraw_single ( amount . mul ( & wei_in_gwei ) ) ; tx_queue . push ( signed_withdraw ) } log :: info ! ( " " addr_hex ) ; for ( tx , eth_sign ) in tx_queue { let tx_hash = rpc_client . send_tx ( tx , eth_sign ) . await ? ; tps_counter . increment ( ) ; sent_txs . add_tx_hash ( tx_hash ) ; } log :: info ! ( " " addr_hex ) ; Ok ( sent_txs ) }
Sends the configured deposits, withdraws and transfer from a single account concurrently.
Sends the configured deposits withdraws and transfer from a single account concurrently .
test_acc
TestAccount
ctx
LoadTestConfig
rpc_client
RpcClient
tps_counter
Arc<TPSCounter>