Skip to content

Commit

Permalink
deps: bump near dependencies in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss committed Sep 4, 2024
1 parent 00948af commit f4d0b5e
Show file tree
Hide file tree
Showing 15 changed files with 537 additions and 591 deletions.
908 changes: 406 additions & 502 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ ibig = { version = "0.3", default-features = false, features = ["num-traits"] }
impl-serde = { version = "0.4", default-features = false }
lazy_static = "1"
libsecp256k1 = { version = "0.7", default-features = false }
near-crypto = "0.20"
near-crypto = "0.25"
near-gas = "0.3"
near-parameters = "0.20"
near-primitives = "0.20"
near-primitives-core = "0.20"
near-parameters = "0.25"
near-primitives = "0.25"
near-primitives-core = "0.25"
near-sdk = "5"
near-vm-runner = { version = "0.20", features = ["wasmtime_vm", "wasmer2_vm"] }
near-vm-runner = { version = "0.25", features = ["wasmtime_vm", "wasmer2_vm", "near_vm"] }
near-workspaces = "0.12"
num = { version = "0.4", default-features = false, features = ["alloc"] }
postgres = "0.19"
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/benches/nft_pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ fn initialize_evm() -> (utils::AuroraRunner, utils::Signer, Address) {
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;
runner.max_gas_burnt(u64::MAX);

(runner, signer, dest_address)
}
10 changes: 5 additions & 5 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ fn profile_erc20_get_balance() {
.unwrap();
assert!(status.is_ok());

// call costs less than 2 Tgas
utils::assert_gas_bound(profile.all_gas(), 2);
// at least 70% of the cost is spent on wasm computation (as opposed to host functions)
// call costs less than 3 Tgas
utils::assert_gas_bound(profile.all_gas(), 3);
// at least 80% of the cost is spent on wasm computation (as opposed to host functions)
let wasm_fraction = (100 * profile.wasm_gas()) / profile.all_gas();
assert!(
(20..=30).contains(&wasm_fraction),
"{wasm_fraction}% is not between 20% and 30%",
(10..=20).contains(&wasm_fraction),
"{wasm_fraction}% is not between 10% and 20%",
);
}

Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/modexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ impl Default for ModExpBenchContext {

// Standalone not relevant here because this is not an Aurora Engine instance
inner.standalone_runner = None;
inner.wasm_config.limit_config.max_gas_burnt = u64::MAX;
inner.code = ContractCode::new(bench_contract_bytes, None);
inner.max_gas_burnt(u64::MAX);
inner.set_code(ContractCode::new(bench_contract_bytes, None));

Self { inner }
}
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/multisender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn send_eth_data(amounts: &[(Address, U256)]) -> Vec<u8> {

fn initialize() -> (utils::AuroraRunner, utils::Signer, Address) {
let mut runner = utils::deploy_runner();
runner.wasm_config.limit_config.max_gas_burnt = u64::MAX;
runner.max_gas_burnt(u64::MAX);

let mut rng = rand::thread_rng();
let source_account = SecretKey::random(&mut rng);
Expand Down
10 changes: 5 additions & 5 deletions engine-tests/src/tests/one_inch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_1inch_liquidity_protocol() {

let (result, profile, pool_factory) = helper.create_pool_factory(&deployer_address);
assert!(result.gas_used >= 2_800_000); // more than 2.8M EVM gas used
assert_gas_bound(profile.all_gas(), 10); // less than 9 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 11); // less than 11 NEAR Tgas used

// create some ERC-20 tokens to have a liquidity pool for
let signer_address = utils::address_from_secret_key(&helper.signer.secret_key);
Expand All @@ -38,7 +38,7 @@ fn test_1inch_liquidity_protocol() {
let (result, profile, pool) =
helper.create_pool(&pool_factory, token_a.0.address, token_b.0.address);
assert!(result.gas_used >= 4_500_000); // more than 4.5M EVM gas used
assert_gas_bound(profile.all_gas(), 20);
assert_gas_bound(profile.all_gas(), 21);

// Approve giving ERC-20 tokens to the pool
helper.approve_erc20_tokens(&token_a, pool.address());
Expand Down Expand Up @@ -72,7 +72,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 210_000); // more than 210k EVM gas used
assert_gas_bound(profile.all_gas(), 24);
assert_gas_bound(profile.all_gas(), 25);

let (result, profile) = helper.pool_withdraw(
&pool,
Expand All @@ -83,7 +83,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 150_000); // more than 150k EVM gas used
assert_gas_bound(profile.all_gas(), 20);
assert_gas_bound(profile.all_gas(), 21);
}

#[test]
Expand All @@ -104,7 +104,7 @@ fn test_1_inch_limit_order_deploy() {
// at least 45% of which is from wasm execution
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(45..=55).contains(&wasm_fraction),
(40..=50).contains(&wasm_fraction),
"{wasm_fraction}% is not between 45% and 55%",
);
}
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/promise_results_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ fn test_promise_result_gas_cost() {
let total_gas2 = y2 + baseline.all_gas();

assert!(
utils::within_x_percent(21, evm1, total_gas1 / NEAR_GAS_PER_EVM),
utils::within_x_percent(36, evm1, total_gas1 / NEAR_GAS_PER_EVM),
"Incorrect EVM gas used. Expected: {} Actual: {}",
evm1,
total_gas1 / NEAR_GAS_PER_EVM
);
assert!(
utils::within_x_percent(21, evm2, total_gas2 / NEAR_GAS_PER_EVM),
utils::within_x_percent(36, evm2, total_gas2 / NEAR_GAS_PER_EVM),
"Incorrect EVM gas used. Expected: {} Actual: {}",
evm2,
total_gas2 / NEAR_GAS_PER_EVM
Expand Down
14 changes: 7 additions & 7 deletions engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn repro_GdASJ3KESs() {
block_timestamp: 1_645_717_564_644_206_730,
input_path: "src/tests/res/input_GdASJ3KESs.hex",
evm_gas_used: 706_713,
near_gas_used: 114,
near_gas_used: 115,
});
}

Expand All @@ -51,7 +51,7 @@ fn repro_8ru7VEA() {
block_timestamp: 1_648_829_935_343_349_589,
input_path: "src/tests/res/input_8ru7VEA.hex",
evm_gas_used: 1_732_181,
near_gas_used: 205,
near_gas_used: 206,
});
}

Expand All @@ -71,7 +71,7 @@ fn repro_FRcorNv() {
block_timestamp: 1_650_960_438_774_745_116,
input_path: "src/tests/res/input_FRcorNv.hex",
evm_gas_used: 1_239_721,
near_gas_used: 167,
near_gas_used: 168,
});
}

Expand All @@ -88,7 +88,7 @@ fn repro_5bEgfRQ() {
block_timestamp: 1_651_073_772_931_594_646,
input_path: "src/tests/res/input_5bEgfRQ.hex",
evm_gas_used: 6_414_105,
near_gas_used: 649,
near_gas_used: 650,
});
}

Expand All @@ -106,7 +106,7 @@ fn repro_D98vwmi() {
block_timestamp: 1_651_753_443_421_003_245,
input_path: "src/tests/res/input_D98vwmi.hex",
evm_gas_used: 1_035_348,
near_gas_used: 168,
near_gas_used: 169,
});
}

Expand All @@ -125,7 +125,7 @@ fn repro_Emufid2() {
block_timestamp: 1_662_118_048_636_713_538,
input_path: "src/tests/res/input_Emufid2.hex",
evm_gas_used: 1_156_364,
near_gas_used: 293,
near_gas_used: 294,
});
}

Expand All @@ -145,7 +145,7 @@ fn repro_common(context: &ReproContext) {
standalone_runner: None, // Turn off standalone here, validated separately below
..Default::default()
};
runner.wasm_config.limit_config.max_gas_burnt = 3_000_000_000_000_000;
runner.max_gas_burnt(3_000_000_000_000_000);
runner.context.storage_usage = 1_000_000_000;
runner.consume_json_snapshot(snapshot.clone());
runner.context.block_height = *block_height;
Expand Down
25 changes: 15 additions & 10 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn test_is_contract() {
#[test]
fn test_solidity_pure_bench() {
let (mut runner, mut signer, _) = initialize_transfer();
runner.wasm_config.limit_config.max_gas_burnt = u64::MAX;
runner.max_gas_burnt(u64::MAX);

let constructor = utils::solidity::ContractConstructor::force_compile(
"src/tests/res",
Expand Down Expand Up @@ -454,18 +454,23 @@ fn test_solidity_pure_bench() {
base_path.join("target/wasm32-unknown-unknown/release/benchmark_contract.wasm");
utils::rust::compile(base_path);
let contract_bytes = std::fs::read(output_path).unwrap();
let code = ContractCode::new(contract_bytes, None);
runner.set_code(ContractCode::new(contract_bytes, None));
let mut context = runner.context.clone();
context.input = loop_limit.to_le_bytes().to_vec();
let outcome = near_vm_runner::run(
&code,

let contract = near_vm_runner::prepare(
&runner.ext.underlying,
runner.wasm_config.clone(),
Some(&runner.cache),
context.make_gas_counter(runner.wasm_config.as_ref()),
"cpu_ram_soak_test",
);

let outcome = near_vm_runner::run(
contract,
&mut runner.ext,
context,
&runner.wasm_config,
&runner.fees_config,
&[],
Some(&runner.cache),
&context,
runner.fees_config.clone(),
)
.unwrap();
let profile = utils::ExecutionProfile::new(&outcome);
Expand Down Expand Up @@ -685,7 +690,7 @@ fn test_num_wasm_functions() {
// See https://github.com/near/nearcore/issues/4814 for context
let runner = utils::deploy_runner();
let module = walrus::ModuleConfig::default()
.parse(runner.code.code())
.parse(runner.ext.underlying.code.unwrap().code())
.unwrap();
let expected_number = 1600;
let actual_number = module.funcs.iter().count();
Expand Down
18 changes: 9 additions & 9 deletions engine-tests/src/tests/standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,55 @@ fn test_standard_precompiles() {
#[test]
fn profile_ecrecover() {
let profile = precompile_execution_profile("test_ecrecover");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 7);
}

#[test]
fn profile_sha256() {
let profile = precompile_execution_profile("test_sha256");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 6);
}

#[test]
fn profile_ripemd160() {
let profile = precompile_execution_profile("test_ripemd160");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 6);
}

#[test]
fn profile_identity() {
let profile = precompile_execution_profile("test_identity");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 6);
}

#[test]
fn profile_modexp() {
let profile = precompile_execution_profile("test_modexp");
utils::assert_gas_bound(profile.all_gas(), 7);
utils::assert_gas_bound(profile.all_gas(), 8);
}

#[test]
fn profile_ecadd() {
let profile = precompile_execution_profile("test_ecadd");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 6);
}

#[test]
fn profile_ecmul() {
let profile = precompile_execution_profile("test_ecmul");
utils::assert_gas_bound(profile.all_gas(), 6);
utils::assert_gas_bound(profile.all_gas(), 7);
}

#[test]
fn profile_ecpair() {
let profile = precompile_execution_profile("test_ecpair");
utils::assert_gas_bound(profile.all_gas(), 115);
utils::assert_gas_bound(profile.all_gas(), 116);
}

#[test]
fn profile_blake2f() {
let profile = precompile_execution_profile("test_blake2f");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 6);
}

fn initialize() -> (AuroraRunner, Signer, PrecompilesContract) {
Expand Down
9 changes: 6 additions & 3 deletions engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use aurora_engine_types::types::Wei;
use aurora_engine_types::H160;
use libsecp256k1::SecretKey;
use rand::SeedableRng;
use std::sync::Arc;

const INITIAL_BALANCE: u64 = 1000;
const INITIAL_NONCE: u64 = 0;
Expand All @@ -38,7 +39,7 @@ fn test_uniswap_input_multihop() {

let (_amount_out, _evm_gas, profile) = context.exact_input(&tokens, INPUT_AMOUNT.into());

assert_eq!(107, profile.all_gas() / 1_000_000_000_000);
assert_eq!(108, profile.all_gas() / 1_000_000_000_000);
}

#[test]
Expand All @@ -49,7 +50,7 @@ fn test_uniswap_exact_output() {

let (_result, profile) =
context.add_equal_liquidity(LIQUIDITY_AMOUNT.into(), &token_a, &token_b);
utils::assert_gas_bound(profile.all_gas(), 31);
utils::assert_gas_bound(profile.all_gas(), 32);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(40..=50).contains(&wasm_fraction),
Expand Down Expand Up @@ -148,7 +149,9 @@ impl UniswapTestContext {
}

pub fn no_gas(&mut self) {
self.runner.wasm_config.regular_op_cost = 0;
Arc::get_mut(&mut self.runner.wasm_config)
.unwrap()
.regular_op_cost = 0;
}

pub fn create_tokens(&mut self, n: usize, mint_amount: U256) -> Vec<ERC20> {
Expand Down
6 changes: 2 additions & 4 deletions engine-tests/src/tests/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,8 @@ fn test_xcc_exec_gas() {
}

fn deploy_router() -> AuroraRunner {
let mut router = AuroraRunner {
code: ContractCode::new(contract_bytes(), None),
..Default::default()
};
let mut router = AuroraRunner::default();
router.set_code(ContractCode::new(contract_bytes(), None));

// Standalone not relevant here because this is not an Aurora Engine instance
router.standalone_runner = None;
Expand Down
24 changes: 22 additions & 2 deletions engine-tests/src/utils/mocked_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ impl near_vm_runner::logic::External for MockedExternalWithTrie {
}
}

fn get_recorded_storage_size(&self) -> usize {
self.underlying.get_recorded_storage_size()
}

fn validator_stake(&self, account_id: &AccountId) -> Result<Option<Balance>, VMLogicError> {
self.underlying.validator_stake(account_id)
}
Expand All @@ -101,12 +105,28 @@ impl near_vm_runner::logic::External for MockedExternalWithTrie {
self.underlying.validator_total_stake()
}

fn create_receipt(
fn create_action_receipt(
&mut self,
receipt_indices: Vec<ReceiptIndex>,
receiver_id: AccountId,
) -> Result<ReceiptIndex, VMLogicError> {
self.underlying.create_receipt(receipt_indices, receiver_id)
self.underlying
.create_action_receipt(receipt_indices, receiver_id)
}

fn create_promise_yield_receipt(
&mut self,
receiver_id: AccountId,
) -> Result<(ReceiptIndex, CryptoHash), VMLogicError> {
self.underlying.create_promise_yield_receipt(receiver_id)
}

fn submit_promise_resume_data(
&mut self,
data_id: CryptoHash,
data: Vec<u8>,
) -> Result<bool, VMLogicError> {
self.underlying.submit_promise_resume_data(data_id, data)
}

fn append_action_create_account(
Expand Down
Loading

0 comments on commit f4d0b5e

Please sign in to comment.