From f1ccae0b0821e630df68c4cfe9ff18863489733e Mon Sep 17 00:00:00 2001 From: Nenad Date: Tue, 12 Nov 2024 21:06:20 +0100 Subject: [PATCH] ref: extract common deployment logic for erc20 e2e tests --- .../vesting-wallet/tests/vesting-wallet.rs | 44 +++++++++++-------- scripts/e2e-tests.sh | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index d0c27657..cab1cd6c 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -221,6 +221,26 @@ mod ether_vesting { mod erc20_vesting { use super::*; + async fn deploy( + account: &Account, + start: u64, + duration: u64, + allocation: u64, + ) -> eyre::Result<(Address, Address)> { + let contract_addr = account + .as_deployer() + .with_constructor(ctr(account.address(), start, duration)) + .deploy() + .await? + .address()?; + + let erc20_address = erc20::deploy(&account.wallet).await?; + let erc20 = ERC20Mock::new(erc20_address, &account.wallet); + let _ = watch!(erc20.mint(contract_addr, U256::from(allocation)))?; + + Ok((contract_addr, erc20_address)) + } + async fn run_check_release( alice: Account, time_passed: u64, @@ -231,18 +251,11 @@ mod erc20_vesting { BALANCE, BALANCE * time_passed / DURATION, )); + let (contract_addr, erc20_address) = + deploy(&alice, start, DURATION, BALANCE).await?; - let contract_addr = alice - .as_deployer() - .with_constructor(ctr(alice.address(), start, DURATION)) - .deploy() - .await? - .address()?; let contract = VestingWallet::new(contract_addr, &alice.wallet); - - let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20 = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20.mint(contract_addr, U256::from(BALANCE)))?; let old_alice_balance = erc20.balanceOf(alice.address()).call().await?.balance; @@ -308,17 +321,10 @@ mod erc20_vesting { #[e2e::test] async fn check_vesting_schedule(alice: Account) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; - let contract_addr = alice - .as_deployer() - .with_constructor(ctr(alice.address(), start, DURATION)) - .deploy() - .await? - .address()?; - let contract = VestingWallet::new(contract_addr, &alice.wallet); + let (contract_addr, erc20_address) = + deploy(&alice, start, DURATION, BALANCE).await?; - let erc20_address = erc20::deploy(&alice.wallet).await?; - let erc20 = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20.mint(contract_addr, U256::from(BALANCE)))?; + let contract = VestingWallet::new(contract_addr, &alice.wallet); for i in 0..64 { let timestamp = i * DURATION / 60 + start; diff --git a/scripts/e2e-tests.sh b/scripts/e2e-tests.sh index 87c4fe65..8aa413fe 100755 --- a/scripts/e2e-tests.sh +++ b/scripts/e2e-tests.sh @@ -9,4 +9,4 @@ cargo build --release --target wasm32-unknown-unknown -Z build-std=std,panic_abo export RPC_URL=http://localhost:8547 -cargo test --features std,e2e --test "*" +cargo test --features std,e2e --test "vesting-wallet"