-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add testnet account json #769
Conversation
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 left a couple of questions.
This will be nice so that people don't need to add accounts straight to the Rust code if they want to get some tokens.
testnet-accounts.json
Outdated
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.
Let's not litter the top level of the repo with this.
I'm tempted to say that we should put it in chains
, but that might be misleading. Maybe it can live in a res
directory in node/cli/src/chain_spec/
?
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.
Let's not litter the top level of the repo with this.
I'm tempted to say that we should put it in
chains
, but that might be misleading. Maybe it can live in ares
directory innode/cli/src/chain_spec/
?
Another option would be to not have this file - and if we fail to open this file, we make the list of accounts to add be an empty vector. So we only need this file if there is something to put in it.
testnet-accounts.json
Outdated
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.
Any reason why you went with JSON here instead instead of just a flat text file?
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.
ya I like json better, you can format it and it is usually colour coated and can enforce format better
node/cli/src/endowed_accounts.rs
Outdated
"{}/testnet-accounts.json", | ||
get_project_root().expect("Error getting project root").to_string_lossy() | ||
)) | ||
.expect("file should open read only"); |
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.
While the docs do say this, I'd make this error a bit more descriptive.
node/cli/src/endowed_accounts.rs
Outdated
|
||
for address in accounts { | ||
inital_accounts | ||
.push(AccountId::from_string(&address).expect("failed to convert a testnet_address")) |
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.
Could be useful to print out what address we failed to parse as part of the error message
node/cli/src/endowed_accounts.rs
Outdated
// handle user submitted file for tokens | ||
let mut file = File::open(format!( | ||
"{}/testnet-accounts.json", | ||
get_project_root().expect("Error getting project root").to_string_lossy() |
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.
Are you sure we want to_string_lossy()
here? From what I understand it would mean that we accept paths with �
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.
That would only happen if get_project_root
found a path which contained invalid utf8 which is very unlikely so i think this is fine.
Strictly speaking though its probably better to not convert to a string - as File::open
can take a PathBuf
:
let mut file = File::open(get_project_root().expect("Error getting project root").join("testnet-accounts.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.
Looks good to me. Although just to be clear, the use-case for this is the local docker-compose setup, right? If i remember rightly our deployed devnet doesn't use the pre-endowed accounts.
If so i guess the use case would be for trying things out with a lot of users, eg: benchmarking. For that this would be really useful. But its not so clear to me why this is useful for accomplices - why wouldn't they just use the existing endowed accounts?
node/cli/src/endowed_accounts.rs
Outdated
// handle user submitted file for tokens | ||
let mut file = File::open(format!( | ||
"{}/testnet-accounts.json", | ||
get_project_root().expect("Error getting project root").to_string_lossy() |
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.
That would only happen if get_project_root
found a path which contained invalid utf8 which is very unlikely so i think this is fine.
Strictly speaking though its probably better to not convert to a string - as File::open
can take a PathBuf
:
let mut file = File::open(get_project_root().expect("Error getting project root").join("testnet-accounts.json"))
So the use case that I understand here is that we would like accomplices to have endowed accounts which are persisted between testnet resets. In order to do that in such a way that doesn't require anybody to make a PR into the Rust code we can just keep a list of accomplice accounts instead. For other use cases, e.g benchmarking I would prefer to use a more Rust based approach. |
Ah ok makes sense - so testnet does use the endowed accounts. Yeah i can see that would be useful. |
Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This allows for a json file to be given endowed accounts, this way accomplices can add them to our network