Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

solana-test-validator could expose add_account_with_file_data #20279

Closed
Arrowana opened this issue Sep 28, 2021 · 1 comment · Fixed by #21812
Closed

solana-test-validator could expose add_account_with_file_data #20279

Arrowana opened this issue Sep 28, 2021 · 1 comment · Fixed by #21812

Comments

@Arrowana
Copy link
Contributor

Problem

We want to simplify testing of program B, by relying on binary of program A + relevant accounts when using solana-test-validator

This is also useful to test a dApp with a realistic state E2E.

Not reading directly from a live cluster is necessary since we might want to alter data a little bit, or don't want to rely on ever changing states, or don't want the setup to rely on http requests.

https://discordapp.com/channels/428295358100013066/517163444747894795/892205222951260170

The burden of dumping the relevant accounts and providing them at genesis is the job of the developer. However, we can enhance things a lot to make that not a total pain.

Proposed Solution

solana account --output-file dumps account data only => dump the entire Account instead (lamports, data, owner, executable).
Provide a serialized format, maybe even human readable, likely we would want address to also exist in this serialized data so the address/account pair can be used easily.

This is to allow calling of solana-test-validator --clone-account-from-file USDC-mint.json super-amm.json ... with a sound Account format for each file

then the cli arguments are parsed and call:

/// Add an account to the test environment with the account data in the provided `filename`
pub fn add_account_with_file_data(
&mut self,
address: Pubkey,
lamports: u64,
owner: Pubkey,
filename: &str,
) -> &mut Self {
self.add_account(
address,
AccountSharedData::from(Account {
lamports,
data: solana_program_test::read_file(
solana_program_test::find_file(filename).unwrap_or_else(|| {
panic!("Unable to locate {}", filename);
}),
),
owner,
executable: false,
rent_epoch: 0,
}),
)
}

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any activity in past 7 days after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant