Skip to content

Commit

Permalink
chore: engine integration tests refactoring (#777)
Browse files Browse the repository at this point in the history
<!--
Thanks for submitting a pull request! Here are some helpful tips:

* Always create branches on and target the `develop` branch.
* Run all the tests locally and ensure that they are passing.
* Run `make format` to ensure that the code is formatted.
* Run `make check` to ensure that all checks passed successfully.
* Small commits and contributions that attempt one single goal is
preferable.
* If the idea changes or adds anything functional which will affect
users, an
AIP discussion is required first on the Aurora forum:

https://forum.aurora.dev/discussions/AIPs%20(Aurora%20Improvement%20Proposals).
* Avoid breaking the public API (namely in engine/src/lib.rs) unless
required.
* If your PR is a WIP, ensure that you enable "draft" mode.
* Your first PRs won't use the CI automatically unless a maintainer
starts.
If this is not your first PR, please do NOT abuse the CI resources.

Checklist:
- [ ] I have performed a self-review of my code
- [ ] I have documented my code, particularly in the hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests to prove my fix or new feature is effective and
works
- [ ] Any dependent changes have been merged
- [ ] The PR is targeting the `develop` branch and not `master`
- [ ] I have pre-squashed my commits into a single commit and rebased.
-->

The main goal of the PR is to replace the deprecated `near-sdk-sim`
crate with the `aurora-engine-workspace` crate, which is based on
[workspaces](https://github.com/near/workspaces-rs). Also, some test
files have been restructured.

No changes in gas costs.
  • Loading branch information
joshuajbouw committed Jul 21, 2023
1 parent fa1be8e commit 96a7d61
Show file tree
Hide file tree
Showing 82 changed files with 5,763 additions and 4,318 deletions.
2,482 changes: 1,435 additions & 1,047 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ aurora-engine-transactions = { path = "engine-transactions", default-features =
aurora-engine-types = { path = "engine-types", default-features = false }
aurora-engine-modexp = { path = "engine-modexp", default-features = false }
aurora-engine-test-doubles = { path = "engine-test-doubles" }
aurora-engine-workspace = { path = "engine-workspace" }
engine-standalone-storage = { path = "engine-standalone-storage" }
engine-standalone-tracing = { path = "engine-standalone-tracing", default-features = false, features = ["impl-serde"] }

anyhow = "1"
base64 = { version = "0.21", default-features = false, features = ["alloc"] }
bitflags = { version = "1", default-features = false }
bn = { version = "0.5", package = "zeropool-bn", default-features = false }
Expand All @@ -35,14 +37,16 @@ evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "
git2 = "0.17"
hex = { version = "0.4", default-features = false, features = ["alloc"] }
ibig = { version = "0.3", default-features = false, features = ["num-traits"] }
lazy_static = "1"
libsecp256k1 = { version = "0.7", default-features = false }
near-crypto = "0.16"
near-primitives = "0.16"
near-primitives-core = "0.16"
near-sdk-sim = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "cc4d4aaf2e1f7297aa060b342ca3ef3ff8e67003" }
near-vm-errors = "0.16"
near-vm-logic = "0.16"
near-vm-runner = { version = "0.16", default-features = false, features = [ "wasmer2_vm", "wasmtime_vm" ] }
near-crypto = "0.17"
near-primitives = "0.17"
near-primitives-core = "0.17"
near-sdk = "4"
near-vm-errors = "0.17"
near-vm-logic = "0.17"
near-vm-runner = { version = "0.17", default-features = false, features = [ "wasmer2_vm", "wasmtime_vm" ] }
near-units = "0.2"
num = { version = "0.4", default-features = false, features = ["alloc"] }
postgres = "0.19"
primitive-types = { version = "0.12", default-features = false, features = ["rlp", "serde_no_std"] }
Expand All @@ -55,10 +59,11 @@ serde_json = { version = "1", default-features = false, features = ["alloc"] }
sha2 = { version = "0.10", default-features = false }
sha3 = { version = "0.10", default-features = false }
tempfile = "3"
tokio = { version = "1", default-features = false, features = ["macros"] }
test-case = "3.1"
walrus = "0.20"
wee_alloc = { version = "0.4", default-features = false }

workspaces = "0.7"

[workspace]
resolver = "2"
Expand All @@ -73,6 +78,7 @@ members = [
"engine-tests",
"engine-transactions",
"engine-types",
"engine-workspace",
]

exclude = [
Expand Down
24 changes: 1 addition & 23 deletions engine-precompiles/src/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub mod state {

use aurora_engine_sdk::error::ReadU32Error;
use aurora_engine_sdk::io::{StorageIntermediate, IO};
use aurora_engine_types::borsh::{self, BorshDeserialize, BorshSerialize};
use aurora_engine_types::parameters::xcc::CodeVersion;
use aurora_engine_types::storage::{self, KeyPrefix};
use aurora_engine_types::types::{Address, Yocto};

Expand All @@ -251,28 +251,6 @@ pub mod state {
/// Amount of NEAR needed to cover storage for a router contract.
pub const STORAGE_AMOUNT: Yocto = Yocto::new(2_000_000_000_000_000_000_000_000);

/// Type wrapper for version of router contracts.
#[derive(
Debug,
Clone,
Copy,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
BorshDeserialize,
BorshSerialize,
)]
pub struct CodeVersion(pub u32);

impl CodeVersion {
#[must_use]
pub const fn increment(self) -> Self {
Self(self.0 + 1)
}
}

/// Get the address of the `wNEAR` ERC-20 contract
///
/// # Panics
Expand Down
5 changes: 4 additions & 1 deletion engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ aurora-engine-sdk = { workspace = true, features = ["std"] }
aurora-engine-test-doubles.workspace = true
aurora-engine-transactions = { workspace = true, features = ["std", "impl-serde"] }
aurora-engine-types = { workspace = true, features = ["std", "impl-serde"] }
aurora-engine-workspace.workspace = true

anyhow.workspace = true
borsh.workspace = true
bstr.workspace = true
byte-slice-cast.workspace = true
Expand All @@ -34,7 +37,6 @@ libsecp256k1.workspace = true
near-crypto.workspace = true
near-primitives-core.workspace = true
near-primitives.workspace = true
near-sdk-sim.workspace = true
near-vm-errors.workspace = true
near-vm-logic.workspace = true
near-vm-runner.workspace = true
Expand All @@ -44,6 +46,7 @@ serde.workspace = true
serde_json.workspace = true
sha3.workspace = true
tempfile.workspace = true
tokio.workspace = true
walrus.workspace = true

[features]
Expand Down
9 changes: 5 additions & 4 deletions engine-tests/src/benches/eth_deploy_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use criterion::{BatchSize, BenchmarkId, Criterion, Throughput};
use libsecp256k1::SecretKey;

use crate::prelude::Wei;
use crate::test_utils::{
address_from_secret_key, create_deploy_transaction, deploy_evm, sign_transaction, SUBMIT,
use crate::utils::{
address_from_secret_key, create_deploy_transaction, deploy_runner, parse_eth_gas,
sign_transaction, SUBMIT,
};

const INITIAL_BALANCE: Wei = Wei::new_u64(1000);
const INITIAL_NONCE: u64 = 0;

pub fn eth_deploy_code_benchmark(c: &mut Criterion) {
let mut runner = deploy_evm();
let mut runner = deploy_runner();
let mut rng = rand::thread_rng();
let source_account = SecretKey::random(&mut rng);
runner.create_address(
Expand Down Expand Up @@ -40,7 +41,7 @@ pub fn eth_deploy_code_benchmark(c: &mut Criterion) {
.call(SUBMIT, calling_account_id, input.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
let eth_gas = parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("ETH_DEPLOY_CODE_{input_size:?} NEAR GAS: {gas:?}");
println!("ETH_DEPLOY_CODE_{input_size:?} ETH GAS: {eth_gas:?}");
Expand Down
12 changes: 7 additions & 5 deletions engine-tests/src/benches/eth_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use crate::prelude::U256;
use criterion::{BatchSize, BenchmarkId, Criterion};
use libsecp256k1::SecretKey;

use crate::test_utils::erc20::{ERC20Constructor, ERC20};
use crate::test_utils::{address_from_secret_key, deploy_evm, sign_transaction, SUBMIT};
use crate::utils::solidity::erc20::{ERC20Constructor, ERC20};
use crate::utils::{
address_from_secret_key, deploy_runner, parse_eth_gas, sign_transaction, SUBMIT,
};

const INITIAL_BALANCE: u64 = 1000;
const INITIAL_NONCE: u64 = 0;
const TRANSFER_AMOUNT: u64 = 67;

pub fn eth_erc20_benchmark(c: &mut Criterion) {
let mut runner = deploy_evm();
let mut runner = deploy_runner();
let mut rng = rand::thread_rng();
let source_account = SecretKey::random(&mut rng);
runner.create_address(
Expand Down Expand Up @@ -66,7 +68,7 @@ pub fn eth_erc20_benchmark(c: &mut Criterion) {
.call(SUBMIT, calling_account_id, mint_tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
let eth_gas = parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("ETH_ERC20_MINT NEAR GAS: {gas:?}");
println!("ETH_ERC20_MINT ETH GAS: {eth_gas:?}");
Expand All @@ -77,7 +79,7 @@ pub fn eth_erc20_benchmark(c: &mut Criterion) {
.call(SUBMIT, calling_account_id, transfer_tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
let eth_gas = parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("ETH_ERC20_TRANSFER NEAR GAS: {gas:?}");
println!("ETH_ERC20_TRANSFER ETH GAS: {eth_gas:?}");
Expand Down
10 changes: 6 additions & 4 deletions engine-tests/src/benches/eth_standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use criterion::{BatchSize, BenchmarkId, Criterion};
use libsecp256k1::SecretKey;

use crate::prelude::Wei;
use crate::test_utils::standard_precompiles::{PrecompilesConstructor, PrecompilesContract};
use crate::test_utils::{address_from_secret_key, deploy_evm, sign_transaction, SUBMIT};
use crate::utils::solidity::standard_precompiles::{PrecompilesConstructor, PrecompilesContract};
use crate::utils::{
address_from_secret_key, deploy_runner, parse_eth_gas, sign_transaction, SUBMIT,
};

const INITIAL_BALANCE: Wei = Wei::new_u64(1000);
const INITIAL_NONCE: u64 = 0;

pub fn eth_standard_precompiles_benchmark(c: &mut Criterion) {
let mut runner = deploy_evm();
let mut runner = deploy_runner();
let mut rng = rand::thread_rng();
let source_account = SecretKey::random(&mut rng);
runner.create_address(
Expand Down Expand Up @@ -48,7 +50,7 @@ pub fn eth_standard_precompiles_benchmark(c: &mut Criterion) {
.call(SUBMIT, calling_account_id, tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = crate::test_utils::parse_eth_gas(&output);
let eth_gas = parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("ETH_STANDARD_PRECOMPILES_{name} NEAR GAS: {gas:?}");
println!("ETH_STANDARD_PRECOMPILES_{name} ETH GAS: {eth_gas:?}");
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/benches/eth_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use criterion::{BatchSize, Criterion};
use libsecp256k1::SecretKey;

use crate::prelude::Wei;
use crate::test_utils::{address_from_secret_key, create_eth_transaction, deploy_evm, SUBMIT};
use crate::utils::{address_from_secret_key, create_eth_transaction, deploy_runner, SUBMIT};

const INITIAL_BALANCE: Wei = Wei::new_u64(1000);
const INITIAL_NONCE: u64 = 0;
const TRANSFER_AMOUNT: Wei = Wei::new_u64(123);

pub fn eth_transfer_benchmark(c: &mut Criterion) {
let mut runner = deploy_evm();
let mut runner = deploy_runner();
let mut rng = rand::thread_rng();
let source_account = SecretKey::random(&mut rng);
runner.create_address(
Expand Down
14 changes: 7 additions & 7 deletions engine-tests/src/benches/nft_pagination.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::{Address, Wei, U256};
use crate::test_utils::{self, solidity};
use crate::utils::{self, solidity};
use aurora_engine_transactions::legacy::TransactionLegacy;
use aurora_engine_types::parameters::engine::TransactionStatus;
use libsecp256k1::SecretKey;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn measure_gas_usage(total_tokens: usize, data_size: usize, tokens_per_page:
let nonce = source_account.nonce;
let tx = marketplace.get_page(tokens_per_page, 0, nonce.into());
let (status, profile) = runner
.profiled_view_call(&test_utils::as_view_call(tx, dest_address))
.profiled_view_call(&utils::as_view_call(tx, dest_address))
.unwrap();

assert!(matches!(status, TransactionStatus::Succeed(_)));
Expand Down Expand Up @@ -157,15 +157,15 @@ impl MarketPlace {
}
}

fn initialize_evm() -> (test_utils::AuroraRunner, test_utils::Signer, Address) {
fn initialize_evm() -> (utils::AuroraRunner, utils::Signer, Address) {
// set up Aurora runner and accounts
let mut runner = test_utils::deploy_evm();
let mut runner = utils::deploy_runner();
let mut rng = rand::thread_rng();
let source_account = SecretKey::random(&mut rng);
let source_address = test_utils::address_from_secret_key(&source_account);
let source_address = utils::address_from_secret_key(&source_account);
runner.create_address(source_address, INITIAL_BALANCE, INITIAL_NONCE.into());
let dest_address = test_utils::address_from_secret_key(&SecretKey::random(&mut rng));
let mut signer = test_utils::Signer::new(source_account);
let dest_address = utils::address_from_secret_key(&SecretKey::random(&mut rng));
let mut signer = utils::Signer::new(source_account);
signer.nonce = INITIAL_NONCE;

runner.wasm_config.limit_config.max_gas_burnt = u64::MAX;
Expand Down
10 changes: 5 additions & 5 deletions engine-tests/src/benches/uniswap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use criterion::{BatchSize, BenchmarkId, Criterion};

use crate::prelude::U256;
use crate::test_utils::{self, SUBMIT};
use crate::tests::uniswap::UniswapTestContext;
use crate::utils::{self, SUBMIT};

const MINT_AMOUNT: u64 = 1_000_000_000;
const LIQUIDITY_AMOUNT: u64 = MINT_AMOUNT / 2;
Expand All @@ -24,7 +24,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) {
let nonce = context.signer.use_nonce();
let liquidity_params = context.mint_params(LIQUIDITY_AMOUNT.into(), &token_a, &token_b);
let tx = context.manager.mint(&liquidity_params, nonce.into());
let signed_tx = test_utils::sign_transaction(tx, chain_id, &context.signer.secret_key);
let signed_tx = utils::sign_transaction(tx, chain_id, &context.signer.secret_key);
let liquidity_tx_bytes = rlp::encode(&signed_tx).to_vec();

// create transaction for swapping
Expand All @@ -34,7 +34,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) {
let tx = context
.swap_router
.exact_output_single(&swap_params, nonce.into());
let signed_tx = test_utils::sign_transaction(tx, chain_id, &context.signer.secret_key);
let signed_tx = utils::sign_transaction(tx, chain_id, &context.signer.secret_key);
let swap_tx_bytes = rlp::encode(&signed_tx).to_vec();

let mut group = c.benchmark_group(&context.name);
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) {
.call(SUBMIT, calling_account_id, liquidity_tx_bytes.clone());
let output = result.unwrap();
let gas = output.burnt_gas;
let eth_gas = test_utils::parse_eth_gas(&output);
let eth_gas = utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("UNISWAP_ADD_LIQUIDITY NEAR GAS: {gas:?}");
println!("UNISWAP_ADD_LIQUIDITY ETH GAS: {eth_gas:?}");
Expand All @@ -75,7 +75,7 @@ pub fn uniswap_benchmark(c: &mut Criterion, context: &mut UniswapTestContext) {
.call(SUBMIT, calling_account_id, swap_tx_bytes.clone())
.unwrap();
let gas = output.burnt_gas;
let eth_gas = test_utils::parse_eth_gas(&output);
let eth_gas = utils::parse_eth_gas(&output);
// TODO(#45): capture this in a file
println!("UNISWAP_SWAP NEAR GAS: {gas:?}");
println!("UNISWAP_SWAP ETH GAS: {eth_gas:?}");
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod benches;
#[cfg(test)]
mod prelude;
#[cfg(test)]
mod test_utils;
#[cfg(test)]
mod tests;
#[cfg(test)]
mod utils;
1 change: 0 additions & 1 deletion engine-tests/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod v0 {
pub use aurora_engine_types::storage;
pub use aurora_engine_types::types::*;
pub use aurora_engine_types::*;
pub use borsh::{BorshDeserialize, BorshSerialize};
}

pub use v0::*;
Loading

0 comments on commit 96a7d61

Please sign in to comment.