Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pallet::call to hotfix sufficients for non-zero nonce accounts #619

Merged
merged 12 commits into from
Jun 2, 2022
Prev Previous commit
Next Next commit
Merge branch 'master' into nish-upstream-hotfix
  • Loading branch information
nbaztec authored May 4, 2022
commit ab3b9024ff212f8588105d204a21be42992bde71
124 changes: 121 additions & 3 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn test_hotfix_inc_account_sufficients_returns_error_if_max_addresses_exceeded()
EVM::hotfix_inc_account_sufficients(Origin::signed(H160::default()), addresses);

assert!(result.is_err(), "expected error");
});
});
}

#[test]
Expand All @@ -429,7 +429,7 @@ fn test_hotfix_inc_account_sufficients_requires_signed_origin() {
let result = EVM::hotfix_inc_account_sufficients(unsigned_origin, vec![addr]);

assert!(result.is_err(), "expected error");
});
});
}

#[test]
Expand Down Expand Up @@ -461,7 +461,7 @@ fn test_hotfix_inc_account_sufficients_increments_if_nonce_nonzero() {
assert_eq!(account_1.sufficients, 1);
assert_eq!(account_2.nonce, 0);
assert_eq!(account_2.sufficients, 0);
});
});
}

#[test]
Expand All @@ -486,5 +486,123 @@ fn test_hotfix_inc_account_sufficients_increments_with_saturation_if_nonce_nonze
let account = frame_system::Account::<Test>::get(substrate_addr);
assert_eq!(account.sufficients, u32::MAX);
assert_eq!(account.nonce, 1);
});
}

#[test]
fn runner_non_transactional_calls_with_non_balance_accounts_is_ok_without_gas_price() {
// Expect to skip checks for gas price and account balance when both:
// - The call is non transactional (`is_transactional == false`).
// - The `max_fee_per_gas` is None.
new_test_ext().execute_with(|| {
let non_balance_account =
H160::from_str("7700000000000000000000000000000000000001").unwrap();
assert_eq!(
EVM::account_basic(&non_balance_account).balance,
U256::zero()
);
let _ = <Test as Config>::Runner::call(
non_balance_account,
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
Vec::new(),
U256::from(1u32),
1000000,
None,
None,
None,
Vec::new(),
false,
&<Test as Config>::config().clone(),
)
.expect("Non transactional call succeeds");
assert_eq!(
EVM::account_basic(&non_balance_account).balance,
U256::zero()
);
});
}

#[test]
fn runner_non_transactional_calls_with_non_balance_accounts_is_err_with_gas_price() {
// In non transactional calls where `Some(gas_price)` is defined, expect it to be
// checked against the `BaseFee`, and expect the account to have enough balance
// to pay for the call.
new_test_ext().execute_with(|| {
let non_balance_account =
H160::from_str("7700000000000000000000000000000000000001").unwrap();
assert_eq!(
EVM::account_basic(&non_balance_account).balance,
U256::zero()
);
let res = <Test as Config>::Runner::call(
non_balance_account,
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
Vec::new(),
U256::from(1u32),
1000000,
Some(U256::from(1_000_000_000)),
None,
None,
Vec::new(),
false,
&<Test as Config>::config().clone(),
);
assert!(res.is_err());
});
}

#[test]
fn runner_transactional_call_with_zero_gas_price_fails() {
// Transactional calls are rejected when `max_fee_per_gas == None`.
new_test_ext().execute_with(|| {
let res = <Test as Config>::Runner::call(
H160::default(),
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
Vec::new(),
U256::from(1u32),
1000000,
None,
None,
None,
Vec::new(),
true,
&<Test as Config>::config().clone(),
);
assert!(res.is_err());
});
}

#[test]
fn runner_max_fee_per_gas_gte_max_priority_fee_per_gas() {
// Transactional and non transactional calls enforce `max_fee_per_gas >= max_priority_fee_per_gas`.
new_test_ext().execute_with(|| {
let res = <Test as Config>::Runner::call(
H160::default(),
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
Vec::new(),
U256::from(1u32),
1000000,
Some(U256::from(1_000_000_000)),
Some(U256::from(2_000_000_000)),
None,
Vec::new(),
true,
&<Test as Config>::config().clone(),
);
assert!(res.is_err());
let res = <Test as Config>::Runner::call(
H160::default(),
H160::from_str("1000000000000000000000000000000000000001").unwrap(),
Vec::new(),
U256::from(1u32),
1000000,
Some(U256::from(1_000_000_000)),
Some(U256::from(2_000_000_000)),
None,
Vec::new(),
false,
&<Test as Config>::config().clone(),
);
assert!(res.is_err());
});
}
You are viewing a condensed version of this merge commit. You can view the full changes here.