Skip to content

Conversation

Shradhesh71
Copy link

Changes

Flat Key/Value Dump with Slot Tracking

  • Added account_update_slots: HashMap<Pubkey, Slot> field to SurfnetSvm to track when each account was last modified.
  • Updated set_account() method to record the modification slot for each account update.
  • Implemented export_accounts_as_fixtures() method that exports all accounts as a flat map with slot information.
  • Added AccountFixture struct with the following fields:
    • pubkey: Account public key
    • lamports: Account balance
    • owner: Program owner
    • executable: Executable flag
    • rent_epoch: Rent epoch
    • data: Account data (encoded based on specified encoding)
    • parsed_data: Optional parsed data (when using JsonParsed encoding)
    • slot: Absolute slot index when the account was last updated

RPC Method

  • Added surfnet_exportSnapshot RPC method to SurfnetCheatcodes trait.
  • Accepts optional encoding parameter (defaults to Base64).
  • Returns HashMap<String, AccountFixture> with all accounts.

Test Coverage

  • test_export_accounts_as_fixtures — Basic export with Base64 encoding
  • test_export_accounts_as_fixtures_with_json_parsed — Export with JsonParsed encoding for token accounts
  • test_export_accounts_at_different_slots — Verify slot tracking across multiple slot updates

/// A cheat code to export all accounts as fixtures for testing.
///
/// ## Parameters
/// - `meta`: Metadata passed with the request, such as the client's request context.
Copy link
Member

Choose a reason for hiding this comment

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

Apologies, this param meta being here is a copy-pasta in the first place, could you please get rid of it?
This docstring is meant to be documenting the RPC endpoint, not the rust method.

Copy link
Member

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

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

Love it, thank you @Shradhesh71 !
Some small feedback!

@Shradhesh71
Copy link
Author

@lgalabru Pushed updates addressing all feedback

@lgalabru
Copy link
Member

Thanks @Shradhesh71 ! Could you run the command

cargo +nightly fmt --all

on your machine? that should fix the CI!

I just added this button in the studio, looking forward to get this new cheat code in the next release :)

Screenshot 2025-10-15 at 06 39 35

Copy link
Member

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

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

Thanks so much for your contribution @Shradhesh71, the code looks good to me!

@lgalabru
Copy link
Member

hey @Shradhesh71! I talked with @MicaiahReid and it looks like your approach could be missing something. If a transaction is updating the state of an account, it looks like the current approach would not capture that.
Do you think you could look into this issue?

@Shradhesh71
Copy link
Author

hey @Shradhesh71! I talked with @MicaiahReid and it looks like your approach could be missing something. If a transaction is updating the state of an account, it looks like the current approach would not capture that. Do you think you could look into this issue?

yep, I’ll look into why transactions that update account state aren’t being captured, reproduce the case, and push a follow up here

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