Skip to content

test(mirror): add gas key test case to offline mirror test#15207

Merged
darioush merged 3 commits into
near:masterfrom
darioush:gaskeys-mirror-test
Jun 10, 2026
Merged

test(mirror): add gas key test case to offline mirror test#15207
darioush merged 3 commits into
near:masterfrom
darioush:gaskeys-mirror-test

Conversation

@darioush

Copy link
Copy Markdown
Contributor
  • Add GasKeyTest to offline_test.py covering gas key add, fund, withdraw, and V1 transfers across fork boundary
  • Add borsh schema entries for gas key types (GasKeyInfo, GasKeyFullAccessPermission, TransactionV1, TransferToGasKey, etc.)
  • Add transaction helpers for gas key operations in transaction.py
  • Add mirror_utils helpers for gas key RPC queries and tx submission

@codecov

codecov Bot commented Feb 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.83%. Comparing base (6e7c670) to head (cae546f).
⚠️ Report is 32 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15207      +/-   ##
==========================================
- Coverage   69.86%   69.83%   -0.03%     
==========================================
  Files         944      945       +1     
  Lines      201933   202848     +915     
  Branches   201933   202848     +915     
==========================================
+ Hits       141082   141661     +579     
- Misses      56101    56422     +321     
- Partials     4750     4765      +15     
Flag Coverage Δ
pytests-nightly 1.11% <ø> (-0.01%) ⬇️
unittests 69.56% <ø> (+0.09%) ⬆️
unittests-nightly 69.55% <ø> (-0.03%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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 requested a review from VanBarbascu February 25, 2026 17:23
@darioush darioush marked this pull request as ready for review February 25, 2026 17:23
@darioush darioush requested a review from a team as a code owner February 25, 2026 17:23
Copilot AI review requested due to automatic review settings February 25, 2026 17:23

Copilot AI left a comment

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.

Pull request overview

This PR adds comprehensive test coverage for gas key functionality to the mirror offline test suite. Gas keys are a new access key type that allows for V1 transactions with multiple nonce indexes per key. The changes add support for serializing gas key-related transactions and actions, as well as RPC query helpers for gas key state.

Changes:

  • Added GasKeyTest to validate gas key operations (add, fund, withdraw) and V1 transaction replay across fork boundaries
  • Implemented Borsh schema definitions for gas key types including GasKeyInfo, GasKeyFullAccessPermission, TransactionV1, and TransactionNonce
  • Added transaction helper functions for gas key operations and V1 transaction signing with nonce indexes

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pytest/tools/mirror/offline_test.py Adds GasKeyTest class with comprehensive test coverage for gas key lifecycle and V1 transfers
pytest/tools/mirror/mirror_utils.py Adds helper functions for sending gas key transactions and querying gas key state via RPC
pytest/lib/transaction.py Adds action creators for gas key operations and V1 transaction serialization with gas key nonces
pytest/lib/messages/tx.py Adds Borsh schema entries for TransactionV1, TransactionNonce, GasKeyNonceData, and gas key actions
pytest/lib/messages/crypto.py Adds Borsh schema entries for GasKeyInfo and gas key permission types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pytest/lib/messages/tx.py Outdated
Comment thread pytest/tools/mirror/offline_test.py
Comment thread pytest/tools/mirror/offline_test.py

@VanBarbascu VanBarbascu left a comment

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.

Looks good!

ctx.next_nonce(), ctx.bhash)
return []

def on_post_fork_block(self, ctx):

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. I know that this is testing the integration between mirror and gas key transactions, but do you think that we get extra value if we add negative tests to this? Such as invalid transactions.

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.

I think we can leave negative tests to a future PR.

@darioush darioush force-pushed the gaskeys-mirror-test branch 4 times, most recently from d21230a to dcd40f4 Compare June 2, 2026 22:53
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.
@darioush darioush marked this pull request as draft June 3, 2026 19:57
@darioush darioush force-pushed the gaskeys-mirror-test branch 2 times, most recently from ba1da22 to bae81f0 Compare June 3, 2026 22:27
mirror: defer txs whose target nonce is unknown instead of dropping them,
resolve them by re-querying the live target (robust across restarts), and
finish on height_popped >= --stop-height. fork-network: force static shard
layout. Adds the fork-network offline test + gas-key pytest borsh schemas.
@darioush darioush marked this pull request as ready for review June 10, 2026 20:42
@darioush darioush enabled auto-merge June 10, 2026 20:43
@darioush darioush added this pull request to the merge queue Jun 10, 2026
Merged via the queue into near:master with commit 02af1a3 Jun 10, 2026
32 checks passed
@darioush darioush deleted the gaskeys-mirror-test branch June 10, 2026 21:15
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.

3 participants