Updated tests
This commit is contained in:
@@ -120,6 +120,8 @@ pub struct ExportState {
|
||||
pub at: BlockID,
|
||||
pub storage: bool,
|
||||
pub code: bool,
|
||||
pub min_balance: Option<U256>,
|
||||
pub max_balance: Option<U256>,
|
||||
}
|
||||
|
||||
pub fn execute(cmd: BlockchainCmd) -> Result<String, String> {
|
||||
@@ -402,10 +404,17 @@ fn execute_export_state(cmd: ExportState) -> Result<String, String> {
|
||||
}
|
||||
|
||||
for account in accounts.into_iter() {
|
||||
|
||||
let balance = client.balance(&account, at).unwrap_or_else(U256::zero);
|
||||
|
||||
if cmd.min_balance.map_or(false, |m| balance < m) || cmd.max_balance.map_or(false, |m| balance > m) {
|
||||
continue; //filtered out
|
||||
}
|
||||
|
||||
if i != 0 {
|
||||
out.write(b",").expect("Write error");
|
||||
}
|
||||
out.write_fmt(format_args!("\n\"0x{}\": {{\"balance\": \"{:x}\", \"nonce\": \"{:x}\"", account.hex(), client.balance(&account, at).unwrap_or_else(U256::zero), client.nonce(&account, at).unwrap_or_else(U256::zero))).expect("Write error");
|
||||
out.write_fmt(format_args!("\n\"0x{}\": {{\"balance\": \"{:x}\", \"nonce\": \"{:x}\"", account.hex(), balance, client.nonce(&account, at).unwrap_or_else(U256::zero))).expect("Write error");
|
||||
let code = client.code(&account, at).unwrap_or(None).unwrap_or_else(Vec::new);
|
||||
if !code.is_empty() {
|
||||
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", code.sha3().hex())).expect("Write error");
|
||||
@@ -441,7 +450,7 @@ fn execute_export_state(cmd: ExportState) -> Result<String, String> {
|
||||
out.write(b"}").expect("Write error");
|
||||
i += 1;
|
||||
if i % 10000 == 0 {
|
||||
info!("#{}", i);
|
||||
info!("Account #{}", i);
|
||||
}
|
||||
last = Some(account);
|
||||
}
|
||||
|
||||
@@ -250,6 +250,8 @@ usage! {
|
||||
flag_no_seal_check: bool = false, or |_| None,
|
||||
flag_no_storage: bool = false, or |_| None,
|
||||
flag_no_code: bool = false, or |_| None,
|
||||
flag_min_balance: Option<String> = None, or |_| None,
|
||||
flag_max_balance: Option<String> = None, or |_| None,
|
||||
|
||||
// -- Snapshot Optons
|
||||
flag_at: String = "latest", or |_| None,
|
||||
@@ -606,6 +608,10 @@ mod tests {
|
||||
flag_to: "latest".into(),
|
||||
flag_format: None,
|
||||
flag_no_seal_check: false,
|
||||
flag_no_code: false,
|
||||
flag_no_storage: false,
|
||||
flag_min_balance: None,
|
||||
flag_max_balance: None,
|
||||
|
||||
// -- Snapshot Optons
|
||||
flag_at: "latest".into(),
|
||||
|
||||
@@ -277,6 +277,10 @@ Import/Export Options:
|
||||
(default: {flag_at})
|
||||
--no-storage Don't export account storge. (default: {flag_no_storage})
|
||||
--no-code Don't export account code. (default: {flag_no_code})
|
||||
--min-balance WEI Don't export accounts with balance less than specified.
|
||||
(default: {flag_min_balance:?})
|
||||
--max-balance WEI Don't export accounts with balance greater than specified.
|
||||
(default: {flag_max_balance:?})
|
||||
|
||||
Snapshot Options:
|
||||
--at BLOCK Take a snapshot at the given block, which may be an
|
||||
|
||||
@@ -195,6 +195,8 @@ impl Configuration {
|
||||
at: try!(to_block_id(&self.args.flag_at)),
|
||||
storage: !self.args.flag_no_storage,
|
||||
code: !self.args.flag_no_code,
|
||||
min_balance: self.args.flag_min_balance.and_then(|s| to_u256(&s).ok()),
|
||||
max_balance: self.args.flag_max_balance.and_then(|s| to_u256(&s).ok()),
|
||||
};
|
||||
Cmd::Blockchain(BlockchainCmd::ExportState(export_cmd))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user