Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion crates/core/src/rpc/surfnet_cheatcodes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::BTreeMap;

use base64::{Engine as _, engine::general_purpose::STANDARD};
use jsonrpc_core::{BoxFuture, Error, Result, futures::future};
use jsonrpc_derive::rpc;
use solana_account::Account;
use solana_account_decoder::UiAccountEncoding;
use solana_client::rpc_response::{RpcLogsResponse, RpcResponseContext};
use solana_clock::Slot;
use solana_commitment_config::CommitmentConfig;
Expand All @@ -24,7 +27,7 @@ use crate::{
State,
utils::{verify_pubkey, verify_pubkeys},
},
surfnet::{GetAccountResult, locker::SvmAccessContext},
surfnet::{GetAccountResult, locker::SvmAccessContext, svm::AccountFixture},
types::{TimeTravelConfig, TokenAccount},
};

Expand Down Expand Up @@ -756,6 +759,53 @@ pub trait SurfnetCheatcodes {
config: Option<ResetAccountConfig>,
) -> Result<RpcResponse<()>>;

/// A cheat code to export all accounts as fixtures for testing.
///
/// ## Parameters
/// - `encoding` (optional): The encoding to use for account data. Defaults to `"base64"`.
/// - `"base64"`: Returns raw account data as base64 encoded strings
/// - `"jsonParsed"`: Attempts to parse known account types (tokens, programs with IDLs, etc.)
///
/// ## Returns
/// A `HashMap<String, AccountFixture>` where:
/// - Key: The account's public key as a base-58 string
/// - Value: An `AccountFixture` containing the account's full state
///
/// ## Example Request
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "id": 1,
/// "method": "surfnet_exportSnapshot",
/// "params": ["base64"]
/// }
/// ```
///
/// ## Example Response
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "result": {
/// "4EXSeLGxVBpAZwq7vm6evLdewpcvE2H56fpqL2pPiLFa": {
/// "pubkey": "4EXSeLGxVBpAZwq7vm6evLdewpcvE2H56fpqL2pPiLFa",
/// "lamports": 1000000,
/// "owner": "11111111111111111111111111111111",
/// "executable": false,
/// "rentEpoch": 0,
/// "data": ["...", "base64"]
/// }
/// },
/// "id": 1
/// }
/// ```
///
#[rpc(meta, name = "surfnet_exportSnapshot")]
fn export_account_fixtures(
&self,
meta: Self::Metadata,
encoding: Option<UiAccountEncoding>,
) -> Result<BTreeMap<String, AccountFixture>>;

/// A cheat code to get Surfnet network information.
///
/// ## Parameters
Expand Down Expand Up @@ -1338,6 +1388,16 @@ impl SurfnetCheatcodes for SurfnetCheatcodesRpc {
value: GetSurfnetInfoResponse::new(runbook_executions),
})
}

fn export_account_fixtures(
&self,
meta: Self::Metadata,
encoding: Option<UiAccountEncoding>,
) -> Result<BTreeMap<String, AccountFixture>> {
let encoding = encoding.unwrap_or(UiAccountEncoding::Base64);
meta.with_svm_reader(|svm_reader| svm_reader.export_accounts_as_fixtures(encoding))
.map_err(Into::into)
}
}

#[cfg(test)]
Expand Down
Loading