Skip to content

Commit

Permalink
Update gas bounds on regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed Feb 10, 2022
1 parent 65c8daa commit c453840
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ fn profile_erc20_get_balance() {
runner.profiled_view_call(test_utils::as_view_call(balance_tx, source_address));
assert!(result.is_ok());

// call costs less than 4 Tgas
test_utils::assert_gas_bound(profile.all_gas(), 4);
// call costs less than 3 Tgas
test_utils::assert_gas_bound(profile.all_gas(), 3);
// at least 70% of the cost is spent on wasm computation (as opposed to host functions)
let wasm_fraction = (100 * profile.wasm_gas()) / profile.all_gas();
assert!(
Expand Down
16 changes: 8 additions & 8 deletions engine-tests/src/tests/one_inch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ fn test_1inch_liquidity_protocol() {

let (result, profile, deployer_address) = helper.create_mooniswap_deployer();
assert!(result.gas_used >= 5_100_000); // more than 5.1M EVM gas used
assert_gas_bound(profile.all_gas(), 20); // less than 20 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 18); // less than 18 NEAR Tgas used

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(), 19); // less than 19 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 18); // less than 18 NEAR Tgas used

// create some ERC-20 tokens to have a liquidity pool for
let signer_address = test_utils::address_from_secret_key(&helper.signer.secret_key);
Expand All @@ -39,7 +39,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(), 59); // less than 59 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 48); // less than 48 NEAR Tgas used

// Approve giving ERC-20 tokens to the pool
helper.approve_erc20_tokens(&token_a, pool.address());
Expand All @@ -58,7 +58,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 302_000); // more than 302k EVM gas used
assert_gas_bound(profile.all_gas(), 89); // less than 89 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 64); // less than 64 NEAR Tgas used

// Same here
helper.runner.context.block_timestamp += 10_000_000 * 1_000_000_000;
Expand All @@ -73,7 +73,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 210_000); // more than 210k EVM gas used
assert_gas_bound(profile.all_gas(), 91); // less than 91 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 66); // less than 66 NEAR Tgas used

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

#[test]
Expand All @@ -100,8 +100,8 @@ fn test_1_inch_limit_order_deploy() {

// more than 3.5 million Ethereum gas used
assert!(result.gas_used > 3_500_000);
// less than 20 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 20);
// less than 17 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 17);
// at least 45% of which is from wasm execution
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ fn test_deploy_largest_contract() {
result.gas_used,
);

// Less than 20 NEAR Tgas
test_utils::assert_gas_bound(profile.all_gas(), 20);
// Less than 18 NEAR Tgas
test_utils::assert_gas_bound(profile.all_gas(), 18);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn test_uniswap_exact_output() {

let (_result, profile) =
context.add_equal_liquidity(LIQUIDITY_AMOUNT.into(), &token_a, &token_b);
test_utils::assert_gas_bound(profile.all_gas(), 126);
test_utils::assert_gas_bound(profile.all_gas(), 88);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
20 <= wasm_fraction && wasm_fraction <= 30,
Expand All @@ -63,7 +63,7 @@ fn test_uniswap_exact_output() {

let (_amount_in, profile) =
context.exact_output_single(&token_a, &token_b, OUTPUT_AMOUNT.into());
test_utils::assert_gas_bound(profile.all_gas(), 61);
test_utils::assert_gas_bound(profile.all_gas(), 48);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
20 <= wasm_fraction && wasm_fraction <= 30,
Expand Down

0 comments on commit c453840

Please sign in to comment.