Skip to content

Commit

Permalink
Prepare loadtest to work with custom token
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Jul 29, 2020
1 parent da245ea commit e58b94e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
9 changes: 5 additions & 4 deletions core/loadtest/src/configs/reddit.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"genesis_account": {
"address": "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049",
"private_key": "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"
"address": "0x4F9133D1d3F50011A6859807C837bdCB31Aaab13",
"private_key": "0xe667e57a9b8aaa6709e51ff7d093f1c5b73b63f9987e4ab4aa9a5c699e024ee8"
},
"genesis_account_zksync_sk": "00b0819f44ec11bd863037bf4155f0a14a0cf8415855e977ef31cdddc6351fbc",
"block_timeout": 36000,
"token_id": 0,
"token_name": "ETH"
"token_id": 4,
"token_name": "MLTT"
}
2 changes: 2 additions & 0 deletions core/loadtest/src/scenarios/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ impl RealLifeConfig {
pub struct RedditConfig {
/// Main account to mint tokens from.
pub genesis_account: AccountInfo,
/// zkSync private key of genesis account.
pub genesis_account_zksync_sk: String,
/// Timeout for awaiting a block to be verified.
pub block_timeout: u64,
/// Used token ID.
Expand Down
39 changes: 25 additions & 14 deletions core/loadtest/src/scenarios/reddit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,19 @@ impl ScenarioExecutor {
Http::new(&ctx.options.web3_url).expect("http transport start");

// Create genesis account to mint tokens from.
let genesis_account =
TestAccount::from_info(&config.genesis_account, &transport, &ctx.options);
let private_key_bytes: Vec<_> = hex::decode(config.genesis_account_zksync_sk)
.unwrap()
.into_iter()
.rev()
.collect();
let zk_private_key =
PrivateKey::read(&private_key_bytes[..]).expect("Can't read private key [zk]");
let genesis_account = TestAccount::from_info_and_private_key(
&config.genesis_account,
zk_private_key,
&transport,
&ctx.options,
);

// Create a burn account to burn tokens.
// TODO: Burn account should be deterministic, not random.
Expand Down Expand Up @@ -241,21 +252,19 @@ impl ScenarioExecutor {

/// Initializes the test, preparing the both main account and all the intermediate accounts for the interaction.
async fn initialize(&mut self) -> Result<(), failure::Error> {
// 1. Update the account nonce.
self.genesis_account
.update_nonce_values(&self.rpc_client)
.await?;

if self.token.0 == 0 {
log::info!("Token ID is 0 (ETH). Assuming that genesis account has to be initialized");

// 1. Update the account nonce.
self.genesis_account
.update_nonce_values(&self.rpc_client)
.await?;

// 2. Perform a deposit
deposit_single(
&self.genesis_account,
BigUint::from(1_000_000_000_000_000_000u64),
&self.rpc_client,
)
.await?;
let one_token = BigUint::from(1_000_000_000_000_000_000u64);
let deposit_amount =
one_token * BigUint::from(1_000u64) * BigUint::from(N_ACCOUNTS as u64);
deposit_single(&self.genesis_account, deposit_amount, &self.rpc_client).await?;

// 3. Set the account ID.
let resp = self
Expand Down Expand Up @@ -322,7 +331,9 @@ impl ScenarioExecutor {
let to_acc = account;

// A big transfer amount to cover the fees in transfers.
let transfer_amount = 1_000_000_000_000u64;
// Transfer amount is 100 MLTT (assuming that precision is 18 decimals).
let one_token = BigUint::from(1_000_000_000_000_000_000u64);
let transfer_amount = one_token * BigUint::from(100u64);

let fee = self.transfer_fee(&to_acc).await;
let (transfer_tx, eth_sign) =
Expand Down
25 changes: 24 additions & 1 deletion core/loadtest/src/test_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use web3::transports::Http;
// Workspace uses
use models::{
config_options::ConfigurationOptions,
node::{tx::PackedEthSignature, FranklinTx},
node::{tx::PackedEthSignature, FranklinTx, PrivateKey},
};
use testkit::{eth_account::EthereumAccount, zksync_account::ZksyncAccount};
// Local uses
Expand Down Expand Up @@ -49,6 +49,29 @@ impl TestAccount {
}
}

pub fn from_info_and_private_key(
acc_info: &AccountInfo,
zksync_private_key: PrivateKey,
transport: &Http,
config: &ConfigurationOptions,
) -> Self {
let addr = acc_info.address;
let pk = acc_info.private_key;
let eth_acc = EthereumAccount::new(
pk,
addr,
transport.clone(),
config.contract_eth_addr,
config.chain_id,
config.gas_price_factor,
);
Self {
zk_acc: ZksyncAccount::new(zksync_private_key, 0, eth_acc.address, eth_acc.private_key),
eth_acc,
eth_nonce: Mutex::new(0),
}
}

// Parses and builds a new accounts list.
pub fn construct_test_accounts(
input_accs: &[AccountInfo],
Expand Down

0 comments on commit e58b94e

Please sign in to comment.