-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Conversation
d39f462
to
a5e0443
Compare
Codecov Report
@@ Coverage Diff @@
## master #21812 +/- ##
========================================
Coverage 81.3% 81.3%
========================================
Files 516 516
Lines 144307 144064 -243
========================================
- Hits 117323 117150 -173
+ Misses 26984 26914 -70 |
a5e0443
to
3b0212f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR. We've wanted this feature for a while!
test-validator/src/lib.rs
Outdated
@@ -203,6 +206,37 @@ impl TestValidatorGenesis { | |||
self | |||
} | |||
|
|||
pub fn add_accounts_with_path(&mut self, filenames: Vec<&str>) -> &mut Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
pub fn add_accounts_with_path(&mut self, filenames: Vec<&str>) -> &mut Self { | |
pub fn add_accounts_from_json_files(&mut self, filename: &[Pubkey]) -> &mut Self { |
Pubkey
as the type for filename, and we don't need to assume a Vec
when any slice will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slice instead of Vec makes sense, will do.
However can you elaborate about the suggestion to enforce that the file name be the account address string? I fear it might be unnecessarily constraining, particularly when the pubkey is naturally part of the file content (coming from solana account
), and that the deserialization operation would already validate that this address string makes for a valid Pubkey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just feels like better typing to require the filename to be a Pubkey
here to me, we don't actually accept any other value right? So we can push the validation out to the --account-from-json-file
clap.rs argument handling, and know that internally the filename will always be a valid pubkey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue that we don't really care about the name of the file, actually. A standard flow would look like:
- dump mainnet account to file
solana account -u m \
--output json-compact \
--output-file SRM_token.json \
SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt
- start test validator with this account, and another one dumped beforehand for instance:
solana-test-validator --clone-from-file SRM_token USD_token
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was thinking we'd just use the filename as the address:
$ solana-test-validator --account-from-json-file SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt.json
but yeah maybe that's not so great, and it doesn't match what --bpf-program
already does.
So I take it all back, something like this seems great (also looking to drop the "clone" naming from this argument):
$ solana-test-validator --account SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt SRM_token.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
As a minor tweak, we could change the address to be an optional second argument to --account
will simplify the arg parsing code. Slightly inconsistent with the --bpf-program
argument though, but feels more natural if the address is also now embedded in SRM_token.json.
$ solana-test-validator --account SRM_token.json
or
$ solana-test-validator --account SRM_token.json SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- My bad, I was not clear enough. I was actually proposing to implement one, or the other. I just looked into implementing an optional pubkey arg like you suggest, and unless I am missing something it makes the parsing quite tricky, because option values are collected "flat", even across separate occurrences of a particular option.
Example:
solana-test-validator --account serum SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt uscd --account raydium
would be collected by clap
as the following String
array: [serum, SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt, usdc, raydium]
, not [[serum, SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt], [usdc], [raydium]]
.
The grouping would then need to be inferred from a is_pubkey
check succeeding or not, or something similar.
Do you think this is worth it? Or would 1 of the options above sound good enough?
- A detail I'd rather clarify, since I mislead you a bit in the examples above: the file argument is currently without the file extension, which is automatically appended to the argument provided. I went that way because only a json file is valid, but I'm open to challenge if you think that's weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. This seems best then
$ solana-test-validator --account SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt SRM_token.json
Consistent with --bpf-program
and allows the same SRM_token.json
account data to be reused at different addresses without editing the file contents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments addressed. CI under way. I actually changed the parsing so that the whole filename (including extension) is required. Didn't make much sense to not allow the user to add it (if they're using autocompletion for instance).
The only thing a bit annoying right now is that if you specify a file that does not exist in CWD or tests/fixtures (the paths explored by solana_program_test::find_file
), the error log is in test-ledger/validator.log
, and not in the CLI output like it is for a wrong pubkey.
I left it that way as it is a tradeoff to be able to get the files automatically found in tests/fixtures
without having to supply the whole path. Not sure if it is worth it though, or if I should just require a straight valid path which could be validated before starting the validator, and would display the error in the command output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks. I pushed a tiny commit to update the arg name
281838a
to
15903e8
Compare
This commit introduces the ability to dump the complete content of an account to a JSON file (compact or not depending on the provided format option). Example: ```sh solana account -u m \ --output json-compact \ --output-file SRM_token.json \ SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt ``` Note: Behavior remains untouched if format option `--output` is not provided (only account data gets written to file).
This introduces the `--clone-from-file` option for solana-test-validator. It allows specifying any number of files (without extension) containing account info and data, which will be loaded at genesis. This is similar to `--bpf-program` for programs loading. The files will be searched for in the CWD or in `tests/fixtures`. Example: `solana-test-validator --clone-from-file SRM_token USD_token`
15903e8
to
4b77dcc
Compare
Problem
Programs can be dumped to file, and seamlessly loaded from file at genesis into the test validator. There is no similar feature for accounts (only dumping data of an account is supported, and no loading). This would ease testing on localnet when several accounts are necessary to run tests (manual and automated both), and for repeatability purposes (cloning leads to changing states per test run).
Summary of Changes
solana-test-validator
option to load accounts from fileNotes
--output
option ofsolana-test-validator
, i.e.json
andjson-compact
--output
option (only data gets written)Fixes #20279