feat(gas-keys): 4/n add gas key tests for Add/DeleteKey#14892
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #14892 +/- ##
===========================================
+ Coverage 1.31% 68.72% +67.41%
===========================================
Files 722 916 +194
Lines 139818 199576 +59758
Branches 139818 199576 +59758
===========================================
+ Hits 1835 137155 +135320
+ Misses 137930 56501 -81429
- Partials 53 5920 +5867
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| access_key: AccessKey::gas_key_full_access(TEST_NUM_NONCES), | ||
| }; | ||
| action_add_key(&apply_state, state_update, account, &mut result, account_id, &action) | ||
| .expect("Expect ok"); |
There was a problem hiding this comment.
just use unwrap, it will give pretty much this message
| }; | ||
| action_add_key(&apply_state, state_update, account, &mut result, account_id, &action) | ||
| .expect("Expect ok"); | ||
| assert!(result.result.is_ok(), "Result error: {:?}", result.result); |
There was a problem hiding this comment.
nit: Result -> result, please update across all tests
| ); | ||
|
|
||
| let AccessKeyPermission::GasKeyFullAccess(gas_key_info) = &gas_key.permission else { | ||
| panic!("expected GasKeyFullAccess permission"); |
There was a problem hiding this comment.
nit: since you are not logging any additional data here just use unreachable
| for i in 0..gas_key_info.num_nonces { | ||
| let gas_key_nonce = | ||
| get_gas_key_nonce(&state_update, &account_id, &gas_key_public_key, i) | ||
| .expect("Failed to get gas key nonce") |
There was a problem hiding this comment.
same here: do not capitalize messages
| } | ||
|
|
||
| #[test] | ||
| fn test_view_gas_key_nonces() { |
There was a problem hiding this comment.
nit: this test probably belongs as part of state_viewer module
There was a problem hiding this comment.
It seems too difficult to use the functions like add_gas_key_to_account from integration-tests/src/tests/runtime/state_viewer.rs (not sure if you meant another place)
9ff2975 to
f81a8f7
Compare
1eef728 to
61450be
Compare
4865576 to
e5a9172
Compare
d5abb64 to
e10648d
Compare
# Gas Keys ([NEP-611](near/NEPs#611)) Gas keys are a new type of access key that carries a pre-funded NEAR balance and multiple independent nonce sequences. When a transaction is signed with a gas key, gas costs are deducted from the gas key's balance rather than the signer's account balance (deposits like NEAR transfers still come from the account). ## Why do we need gas keys? - Enabling SPICE without a DoS vector. The SPICE project (Separation of Execution from Consensus) decouples transaction execution from block production: transactions are included in blocks first, and executed asynchronously later. This means chunk producers can no longer verify account balances at inclusion time. An attacker could drain an account's balance in one transaction, then flood the chain with many transactions signed by that account. All would be accepted (since execution hasn't caught up), consuming block space for free when they inevitably fail. Gas keys close this gap by requiring gas to be pre-committed in the key itself, so chunk producers can verify gas availability without access to the latest state. - Parallel transaction submission. Today, programmatic users who submit many transactions in parallel must manage multiple access keys (each with its own nonce sequence). A gas key supports up to 1,024 independent nonce slots via a single key, removing that complexity. # Context - NEP (if exists): near/NEPs#611 - Implementation: - near#14868 - near#14869 - near#14883 - near#14891 - near#14892 - near#14911 - near#14924 - near#14925 - near#14930 - near#14933 - near#14969 - near#14985 - near#15033 - near#15034 - near#15067 - near#15068 - near#15100 - near#15101 - near#15186 # Testing and QA - unit tests - test-loop: https://github.com/near/nearcore/blob/master/test-loop-tests/src/tests/gas_keys.rs - forknet (automated): near#15207 - forknet (manual testing, planned) # Checklist - [x] Link to nightly nayduck run: https://nayduck.nearone.org/#/run/4756 - [x] Update CHANGELOG.md to include this protocol feature in the `Unreleased` section.
Added a suite of tests for gas keys covering add, storage usage, deletion, and listing. Tests verify rejection of duplicate gas keys, conflicts with existing access keys, correct storage and nonce cleanup on deletion, proper errors when deleting non-existent gas keys, and removal of all gas keys when an account is deleted.
Added tests enforcing gas key protocol rules: too many nonces are rejected; function-call permissions with an allowance are rejected; and method name length limits are enforced.