Skip to content

feat(gas-keys): 4/n add gas key tests for Add/DeleteKey#14892

Merged
darioush merged 4 commits into
masterfrom
darioush/gaskeys-updated/0.4-new-tests-alt
Jan 19, 2026
Merged

feat(gas-keys): 4/n add gas key tests for Add/DeleteKey#14892
darioush merged 4 commits into
masterfrom
darioush/gaskeys-updated/0.4-new-tests-alt

Conversation

@darioush

@darioush darioush commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

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.

@codecov

codecov Bot commented Jan 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.66310% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.72%. Comparing base (cb47e22) to head (e10648d).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
runtime/runtime/src/access_keys.rs 98.26% 3 Missing and 2 partials ⚠️
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     
Flag Coverage Δ
pytests-nightly 1.31% <ø> (ø)
unittests 68.45% <98.66%> (?)
unittests-nightly 68.24% <98.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@darioush darioush marked this pull request as ready for review January 16, 2026 02:19
@darioush darioush requested a review from a team as a code owner January 16, 2026 02:19
@darioush darioush requested review from walnut-the-cat and removed request for a team January 16, 2026 02:19
@pugachAG pugachAG requested review from attila0x2A and pugachAG and removed request for walnut-the-cat January 16, 2026 19:47
Comment thread runtime/runtime/src/access_keys.rs Outdated
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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use unwrap, it will give pretty much this message

Comment thread runtime/runtime/src/access_keys.rs Outdated
};
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Result -> result, please update across all tests

Comment thread runtime/runtime/src/access_keys.rs Outdated
);

let AccessKeyPermission::GasKeyFullAccess(gas_key_info) = &gas_key.permission else {
panic!("expected GasKeyFullAccess permission");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since you are not logging any additional data here just use unreachable

Comment thread runtime/runtime/src/access_keys.rs Outdated
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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here: do not capitalize messages

}

#[test]
fn test_view_gas_key_nonces() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this test probably belongs as part of state_viewer module

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@darioush darioush force-pushed the darioush/gaskeys-updated/0.3-actions-query-alt branch from 9ff2975 to f81a8f7 Compare January 17, 2026 01:20
@darioush darioush force-pushed the darioush/gaskeys-updated/0.4-new-tests-alt branch from 1eef728 to 61450be Compare January 17, 2026 01:41
@darioush darioush force-pushed the darioush/gaskeys-updated/0.3-actions-query-alt branch from 4865576 to e5a9172 Compare January 19, 2026 14:19
@darioush darioush requested a review from frol as a code owner January 19, 2026 14:19
Base automatically changed from darioush/gaskeys-updated/0.3-actions-query-alt to master January 19, 2026 15:05
@darioush darioush force-pushed the darioush/gaskeys-updated/0.4-new-tests-alt branch from d5abb64 to e10648d Compare January 19, 2026 15:06
@darioush darioush enabled auto-merge January 19, 2026 15:12
@darioush darioush added this pull request to the merge queue Jan 19, 2026
Merged via the queue into master with commit de36d2e Jan 19, 2026
31 checks passed
@darioush darioush deleted the darioush/gaskeys-updated/0.4-new-tests-alt branch January 19, 2026 15:41
pull Bot pushed a commit to See887777/nearcore that referenced this pull request Jun 3, 2026
# 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants