fix tests, json tests
This commit is contained in:
parent
3655601693
commit
91753c53cd
@ -250,10 +250,12 @@ impl Engine for AuthorityRound {
|
|||||||
fn on_close_block(&self, block: &mut ExecutedBlock) {
|
fn on_close_block(&self, block: &mut ExecutedBlock) {
|
||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
// Bestow block reward
|
// Bestow block reward
|
||||||
fields.state.add_balance(fields.header.author(), &self.block_reward, CleanupMode::NoEmpty);
|
let res = fields.state.add_balance(fields.header.author(), &self.block_reward, CleanupMode::NoEmpty)
|
||||||
|
.map_err(::error::Error::from)
|
||||||
|
.and_then(|_| fields.state.commit());
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
if let Err(e) = fields.state.commit() {
|
if let Err(e) = res {
|
||||||
warn!("Encountered error on state commit: {}", e);
|
warn!("Encountered error on closing block: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,10 +467,12 @@ impl Engine for Tendermint {
|
|||||||
fn on_close_block(&self, block: &mut ExecutedBlock) {
|
fn on_close_block(&self, block: &mut ExecutedBlock) {
|
||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
// Bestow block reward
|
// Bestow block reward
|
||||||
fields.state.add_balance(fields.header.author(), &self.block_reward, CleanupMode::NoEmpty);
|
let res = fields.state.add_balance(fields.header.author(), &self.block_reward, CleanupMode::NoEmpty)
|
||||||
|
.map_err(::error::Error::from)
|
||||||
|
.and_then(|_| fields.state.commit());
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
if let Err(e) = fields.state.commit() {
|
if let Err(e) = res {
|
||||||
warn!("Encountered error on state commit: {}", e);
|
warn!("Encountered error on closing block: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,13 +213,13 @@ impl Engine for Ethash {
|
|||||||
if block.fields().header.number() == self.ethash_params.dao_hardfork_transition {
|
if block.fields().header.number() == self.ethash_params.dao_hardfork_transition {
|
||||||
// TODO: enable trigger function maybe?
|
// TODO: enable trigger function maybe?
|
||||||
// if block.fields().header.gas_limit() <= 4_000_000.into() {
|
// if block.fields().header.gas_limit() <= 4_000_000.into() {
|
||||||
let mut state = block.fields_mut().state;
|
let state = block.fields_mut().state;
|
||||||
for child in &self.ethash_params.dao_hardfork_accounts {
|
for child in &self.ethash_params.dao_hardfork_accounts {
|
||||||
let beneficiary = &self.ethash_params.dao_hardfork_beneficiary;
|
let beneficiary = &self.ethash_params.dao_hardfork_beneficiary;
|
||||||
let res = state.balance(child)
|
let res = state.balance(child)
|
||||||
.and_then(|b| state.transfer_balance(child, beneficiary, &b, CleanupMode::NoEmpty));
|
.and_then(|b| state.transfer_balance(child, beneficiary, &b, CleanupMode::NoEmpty));
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(_) = res {
|
||||||
warn!("Unable to apply DAO hardfork due to database corruption.");
|
warn!("Unable to apply DAO hardfork due to database corruption.");
|
||||||
warn!("Your node is now likely out of consensus.");
|
warn!("Your node is now likely out of consensus.");
|
||||||
}
|
}
|
||||||
@ -235,12 +235,28 @@ impl Engine for Ethash {
|
|||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
|
|
||||||
// Bestow block reward
|
// Bestow block reward
|
||||||
fields.state.add_balance(fields.header.author(), &(reward + reward / U256::from(32) * U256::from(fields.uncles.len())), CleanupMode::NoEmpty);
|
let res = fields.state.add_balance(
|
||||||
|
fields.header.author(),
|
||||||
|
&(reward + reward / U256::from(32) * U256::from(fields.uncles.len())),
|
||||||
|
CleanupMode::NoEmpty
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
warn!("Failed to give block reward: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
// Bestow uncle rewards
|
// Bestow uncle rewards
|
||||||
let current_number = fields.header.number();
|
let current_number = fields.header.number();
|
||||||
for u in fields.uncles.iter() {
|
for u in fields.uncles.iter() {
|
||||||
fields.state.add_balance(u.author(), &(reward * U256::from(8 + u.number() - current_number) / U256::from(8)), CleanupMode::NoEmpty);
|
let res = fields.state.add_balance(
|
||||||
|
u.author(),
|
||||||
|
&(reward * U256::from(8 + u.number() - current_number) / U256::from(8)),
|
||||||
|
CleanupMode::NoEmpty
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
warn!("Failed to give uncle reward: {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
@ -473,7 +489,7 @@ mod tests {
|
|||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let b = b.close();
|
let b = b.close();
|
||||||
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
assert_eq!(b.state().balance(&Address::zero()).unwrap(), U256::from_str("4563918244f40000").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -491,8 +507,8 @@ mod tests {
|
|||||||
b.push_uncle(uncle).unwrap();
|
b.push_uncle(uncle).unwrap();
|
||||||
|
|
||||||
let b = b.close();
|
let b = b.close();
|
||||||
assert_eq!(b.state().balance(&Address::zero()), "478eae0e571ba000".into());
|
assert_eq!(b.state().balance(&Address::zero()).unwrap(), "478eae0e571ba000".into());
|
||||||
assert_eq!(b.state().balance(&uncle_author), "3cb71f51fc558000".into());
|
assert_eq!(b.state().balance(&uncle_author).unwrap(), "3cb71f51fc558000".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -91,12 +91,12 @@ mod tests {
|
|||||||
let mut db_result = get_temp_state_db();
|
let mut db_result = get_temp_state_db();
|
||||||
let db = spec.ensure_db_good(db_result.take(), &Default::default()).unwrap();
|
let db = spec.ensure_db_good(db_result.take(), &Default::default()).unwrap();
|
||||||
let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(), Default::default()).unwrap();
|
let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(), Default::default()).unwrap();
|
||||||
assert_eq!(s.balance(&"0000000000000000000000000000000000000001".into()), 1u64.into());
|
assert_eq!(s.balance(&"0000000000000000000000000000000000000001".into()).unwrap(), 1u64.into());
|
||||||
assert_eq!(s.balance(&"0000000000000000000000000000000000000002".into()), 1u64.into());
|
assert_eq!(s.balance(&"0000000000000000000000000000000000000002".into()).unwrap(), 1u64.into());
|
||||||
assert_eq!(s.balance(&"0000000000000000000000000000000000000003".into()), 1u64.into());
|
assert_eq!(s.balance(&"0000000000000000000000000000000000000003".into()).unwrap(), 1u64.into());
|
||||||
assert_eq!(s.balance(&"0000000000000000000000000000000000000004".into()), 1u64.into());
|
assert_eq!(s.balance(&"0000000000000000000000000000000000000004".into()).unwrap(), 1u64.into());
|
||||||
assert_eq!(s.balance(&"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c".into()), U256::from(1u64) << 200);
|
assert_eq!(s.balance(&"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c".into()).unwrap(), U256::from(1u64) << 200);
|
||||||
assert_eq!(s.balance(&"0000000000000000000000000000000000000000".into()), 0u64.into());
|
assert_eq!(s.balance(&"0000000000000000000000000000000000000000".into()).unwrap(), 0u64.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -82,28 +82,29 @@ impl Default for Schedule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Ext for FakeExt {
|
impl Ext for FakeExt {
|
||||||
fn storage_at(&self, key: &H256) -> H256 {
|
fn storage_at(&self, key: &H256) -> trie::Result<H256> {
|
||||||
self.store.get(key).unwrap_or(&H256::new()).clone()
|
Ok(self.store.get(key).unwrap_or(&H256::new()).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_storage(&mut self, key: H256, value: H256) {
|
fn set_storage(&mut self, key: H256, value: H256) -> trie::Result<()> {
|
||||||
self.store.insert(key, value);
|
self.store.insert(key, value);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exists(&self, address: &Address) -> bool {
|
fn exists(&self, address: &Address) -> trie::Result<bool> {
|
||||||
self.balances.contains_key(address)
|
Ok(self.balances.contains_key(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exists_and_not_null(&self, address: &Address) -> bool {
|
fn exists_and_not_null(&self, address: &Address) -> trie::Result<bool> {
|
||||||
self.balances.get(address).map_or(false, |b| !b.is_zero())
|
Ok(self.balances.get(address).map_or(false, |b| !b.is_zero()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn origin_balance(&self) -> U256 {
|
fn origin_balance(&self) -> trie::Result<U256> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, address: &Address) -> U256 {
|
fn balance(&self, address: &Address) -> trie::Result<U256> {
|
||||||
self.balances[address]
|
Ok(self.balances[address])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blockhash(&self, number: &U256) -> H256 {
|
fn blockhash(&self, number: &U256) -> H256 {
|
||||||
@ -146,12 +147,12 @@ impl Ext for FakeExt {
|
|||||||
MessageCallResult::Success(*gas)
|
MessageCallResult::Success(*gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extcode(&self, address: &Address) -> Arc<Bytes> {
|
fn extcode(&self, address: &Address) -> trie::Result<Arc<Bytes>> {
|
||||||
self.codes.get(address).unwrap_or(&Arc::new(Bytes::new())).clone()
|
Ok(self.codes.get(address).unwrap_or(&Arc::new(Bytes::new())).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extcodesize(&self, address: &Address) -> usize {
|
fn extcodesize(&self, address: &Address) -> trie::Result<usize> {
|
||||||
self.codes.get(address).map_or(0, |c| c.len())
|
Ok(self.codes.get(address).map_or(0, |c| c.len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(&mut self, topics: Vec<H256>, data: &[u8]) {
|
fn log(&mut self, topics: Vec<H256>, data: &[u8]) {
|
||||||
@ -165,7 +166,7 @@ impl Ext for FakeExt {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suicide(&mut self, _refund_address: &Address) {
|
fn suicide(&mut self, _refund_address: &Address) -> trie::Result<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +544,7 @@ mod tests {
|
|||||||
params.value = ActionValue::Transfer(U256::from(0x7));
|
params.value = ActionValue::Transfer(U256::from(0x7));
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(0x100u64), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(0x100u64), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -555,9 +555,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(gas_left, U256::from(79_975));
|
assert_eq!(gas_left, U256::from(79_975));
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0xf9u64)));
|
assert_eq!(state.storage_at(&address, &H256::new()).unwrap(), H256::from(&U256::from(0xf9u64)));
|
||||||
assert_eq!(state.balance(&sender), U256::from(0xf9));
|
assert_eq!(state.balance(&sender).unwrap(), U256::from(0xf9));
|
||||||
assert_eq!(state.balance(&address), U256::from(0x7));
|
assert_eq!(state.balance(&address).unwrap(), U256::from(0x7));
|
||||||
// 0 cause contract hasn't returned
|
// 0 cause contract hasn't returned
|
||||||
assert_eq!(substate.contracts_created.len(), 0);
|
assert_eq!(substate.contracts_created.len(), 0);
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ mod tests {
|
|||||||
params.value = ActionValue::Transfer(U256::from(100));
|
params.value = ActionValue::Transfer(U256::from(100));
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -662,7 +662,7 @@ mod tests {
|
|||||||
params.call_type = CallType::Call;
|
params.call_type = CallType::Call;
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(5);
|
let engine = TestEngine::new(5);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -773,7 +773,7 @@ mod tests {
|
|||||||
params.value = ActionValue::Transfer(100.into());
|
params.value = ActionValue::Transfer(100.into());
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(5);
|
let engine = TestEngine::new(5);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -861,7 +861,7 @@ mod tests {
|
|||||||
params.value = ActionValue::Transfer(U256::from(100));
|
params.value = ActionValue::Transfer(U256::from(100));
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -913,7 +913,7 @@ mod tests {
|
|||||||
params.value = ActionValue::Transfer(U256::from(100));
|
params.value = ActionValue::Transfer(U256::from(100));
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(1024);
|
let engine = TestEngine::new(1024);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -971,9 +971,9 @@ mod tests {
|
|||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.init_code(&address_a, code_a.clone());
|
state.init_code(&address_a, code_a.clone()).unwrap();
|
||||||
state.init_code(&address_b, code_b.clone());
|
state.init_code(&address_b, code_b.clone()).unwrap();
|
||||||
state.add_balance(&sender, &U256::from(100_000), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100_000), CleanupMode::NoEmpty).unwrap();
|
||||||
|
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
@ -985,7 +985,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(gas_left, U256::from(73_237));
|
assert_eq!(gas_left, U256::from(73_237));
|
||||||
assert_eq!(state.storage_at(&address_a, &H256::from(&U256::from(0x23))), H256::from(&U256::from(1)));
|
assert_eq!(state.storage_at(&address_a, &H256::from(&U256::from(0x23))).unwrap(), H256::from(&U256::from(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// test is incorrect, mk
|
// test is incorrect, mk
|
||||||
@ -1019,7 +1019,7 @@ mod tests {
|
|||||||
params.code = Some(Arc::new(code.clone()));
|
params.code = Some(Arc::new(code.clone()));
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.init_code(&address, code);
|
state.init_code(&address, code).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
@ -1030,8 +1030,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(gas_left, U256::from(59_870));
|
assert_eq!(gas_left, U256::from(59_870));
|
||||||
assert_eq!(state.storage_at(&address, &H256::from(&U256::zero())), H256::from(&U256::from(1)));
|
assert_eq!(state.storage_at(&address, &H256::from(&U256::zero())).unwrap(), H256::from(&U256::from(1)));
|
||||||
assert_eq!(state.storage_at(&address, &H256::from(&U256::one())), H256::from(&U256::from(1)));
|
assert_eq!(state.storage_at(&address, &H256::from(&U256::one())).unwrap(), H256::from(&U256::from(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// test is incorrect, mk
|
// test is incorrect, mk
|
||||||
@ -1052,7 +1052,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(18), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(18), CleanupMode::NoEmpty).unwrap();
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = U256::from(100_000);
|
info.gas_limit = U256::from(100_000);
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
@ -1069,10 +1069,10 @@ mod tests {
|
|||||||
assert_eq!(executed.cumulative_gas_used, U256::from(41_301));
|
assert_eq!(executed.cumulative_gas_used, U256::from(41_301));
|
||||||
assert_eq!(executed.logs.len(), 0);
|
assert_eq!(executed.logs.len(), 0);
|
||||||
assert_eq!(executed.contracts_created.len(), 0);
|
assert_eq!(executed.contracts_created.len(), 0);
|
||||||
assert_eq!(state.balance(&sender), U256::from(1));
|
assert_eq!(state.balance(&sender).unwrap(), U256::from(1));
|
||||||
assert_eq!(state.balance(&contract), U256::from(17));
|
assert_eq!(state.balance(&contract).unwrap(), U256::from(17));
|
||||||
assert_eq!(state.nonce(&sender), U256::from(1));
|
assert_eq!(state.nonce(&sender).unwrap(), U256::from(1));
|
||||||
assert_eq!(state.storage_at(&contract, &H256::new()), H256::from(&U256::from(1)));
|
assert_eq!(state.storage_at(&contract, &H256::new()).unwrap(), H256::from(&U256::from(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
evm_test!{test_transact_invalid_nonce: test_transact_invalid_nonce_jit, test_transact_invalid_nonce_int}
|
evm_test!{test_transact_invalid_nonce: test_transact_invalid_nonce_jit, test_transact_invalid_nonce_int}
|
||||||
@ -1090,7 +1090,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(17), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(17), CleanupMode::NoEmpty).unwrap();
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = U256::from(100_000);
|
info.gas_limit = U256::from(100_000);
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
@ -1123,7 +1123,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(17), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(17), CleanupMode::NoEmpty).unwrap();
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_used = U256::from(20_000);
|
info.gas_used = U256::from(20_000);
|
||||||
info.gas_limit = U256::from(100_000);
|
info.gas_limit = U256::from(100_000);
|
||||||
@ -1158,7 +1158,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from(100_017), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from(100_017), CleanupMode::NoEmpty).unwrap();
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = U256::from(100_000);
|
info.gas_limit = U256::from(100_000);
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
@ -1193,7 +1193,7 @@ mod tests {
|
|||||||
params.value = ActionValue::Transfer(U256::from_str("0de0b6b3a7640000").unwrap());
|
params.value = ActionValue::Transfer(U256::from_str("0de0b6b3a7640000").unwrap());
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
state.add_balance(&sender, &U256::from_str("152d02c7e14af6800000").unwrap(), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &U256::from_str("152d02c7e14af6800000").unwrap(), CleanupMode::NoEmpty).unwrap();
|
||||||
let info = EnvInfo::default();
|
let info = EnvInfo::default();
|
||||||
let engine = TestEngine::new(0);
|
let engine = TestEngine::new(0);
|
||||||
let mut substate = Substate::new();
|
let mut substate = Substate::new();
|
||||||
|
@ -506,7 +506,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let mut ext = Externalities::new(state, &setup.env_info, &*setup.engine, &vm_factory, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer);
|
let mut ext = Externalities::new(state, &setup.env_info, &*setup.engine, &vm_factory, 0, get_test_origin(), &mut setup.sub_state, OutputPolicy::InitContract(None), &mut tracer, &mut vm_tracer);
|
||||||
ext.suicide(refund_account);
|
ext.suicide(refund_account).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(setup.sub_state.suicides.len(), 1);
|
assert_eq!(setup.sub_state.suicides.len(), 1);
|
||||||
|
@ -74,39 +74,39 @@ impl<'a, T: 'a, V: 'a, B: 'a> TestExt<'a, T, V, B>
|
|||||||
address: Address,
|
address: Address,
|
||||||
tracer: &'a mut T,
|
tracer: &'a mut T,
|
||||||
vm_tracer: &'a mut V,
|
vm_tracer: &'a mut V,
|
||||||
) -> Self {
|
) -> trie::Result<Self> {
|
||||||
TestExt {
|
Ok(TestExt {
|
||||||
contract_address: contract_address(&address, &state.nonce(&address)),
|
contract_address: contract_address(&address, &state.nonce(&address)?),
|
||||||
ext: Externalities::new(state, info, engine, vm_factory, depth, origin_info, substate, output, tracer, vm_tracer),
|
ext: Externalities::new(state, info, engine, vm_factory, depth, origin_info, substate, output, tracer, vm_tracer),
|
||||||
callcreates: vec![]
|
callcreates: vec![]
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
|
impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
|
||||||
where T: Tracer, V: VMTracer, B: StateBackend
|
where T: Tracer, V: VMTracer, B: StateBackend
|
||||||
{
|
{
|
||||||
fn storage_at(&self, key: &H256) -> H256 {
|
fn storage_at(&self, key: &H256) -> trie::Result<H256> {
|
||||||
self.ext.storage_at(key)
|
self.ext.storage_at(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_storage(&mut self, key: H256, value: H256) {
|
fn set_storage(&mut self, key: H256, value: H256) -> trie::Result<()> {
|
||||||
self.ext.set_storage(key, value)
|
self.ext.set_storage(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exists(&self, address: &Address) -> bool {
|
fn exists(&self, address: &Address) -> trie::Result<bool> {
|
||||||
self.ext.exists(address)
|
self.ext.exists(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exists_and_not_null(&self, address: &Address) -> bool {
|
fn exists_and_not_null(&self, address: &Address) -> trie::Result<bool> {
|
||||||
self.ext.exists_and_not_null(address)
|
self.ext.exists_and_not_null(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, address: &Address) -> U256 {
|
fn balance(&self, address: &Address) -> trie::Result<U256> {
|
||||||
self.ext.balance(address)
|
self.ext.balance(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn origin_balance(&self) -> U256 {
|
fn origin_balance(&self) -> trie::Result<U256> {
|
||||||
self.ext.origin_balance()
|
self.ext.origin_balance()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,11 +143,11 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
|
|||||||
MessageCallResult::Success(*gas)
|
MessageCallResult::Success(*gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extcode(&self, address: &Address) -> Arc<Bytes> {
|
fn extcode(&self, address: &Address) -> trie::Result<Arc<Bytes>> {
|
||||||
self.ext.extcode(address)
|
self.ext.extcode(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extcodesize(&self, address: &Address) -> usize {
|
fn extcodesize(&self, address: &Address) -> trie::Result<usize> {
|
||||||
self.ext.extcodesize(address)
|
self.ext.extcodesize(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
|
|||||||
self.ext.ret(gas, data)
|
self.ext.ret(gas, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suicide(&mut self, refund_address: &Address) {
|
fn suicide(&mut self, refund_address: &Address) -> trie::Result<()> {
|
||||||
self.ext.suicide(refund_address)
|
self.ext.suicide(refund_address)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +201,19 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8]) -> Vec<String> {
|
|||||||
fail = true
|
fail = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
macro_rules! try_fail {
|
||||||
|
($e: expr) => {
|
||||||
|
match $e {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(e) => {
|
||||||
|
let msg = format!("Internal error: {}", e);
|
||||||
|
fail_unless(false, &msg);
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let out_of_gas = vm.out_of_gas();
|
let out_of_gas = vm.out_of_gas();
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
@ -217,7 +230,7 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8]) -> Vec<String> {
|
|||||||
|
|
||||||
// execute
|
// execute
|
||||||
let (res, callcreates) = {
|
let (res, callcreates) = {
|
||||||
let mut ex = TestExt::new(
|
let mut ex = try_fail!(TestExt::new(
|
||||||
&mut state,
|
&mut state,
|
||||||
&info,
|
&info,
|
||||||
&engine,
|
&engine,
|
||||||
@ -229,7 +242,7 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8]) -> Vec<String> {
|
|||||||
params.address.clone(),
|
params.address.clone(),
|
||||||
&mut tracer,
|
&mut tracer,
|
||||||
&mut vm_tracer,
|
&mut vm_tracer,
|
||||||
);
|
));
|
||||||
let mut evm = vm_factory.create(params.gas);
|
let mut evm = vm_factory.create(params.gas);
|
||||||
let res = evm.exec(params, &mut ex);
|
let res = evm.exec(params, &mut ex);
|
||||||
// a return in finalize will not alter callcreates
|
// a return in finalize will not alter callcreates
|
||||||
@ -248,14 +261,19 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8]) -> Vec<String> {
|
|||||||
for (address, account) in vm.post_state.unwrap().into_iter() {
|
for (address, account) in vm.post_state.unwrap().into_iter() {
|
||||||
let address = address.into();
|
let address = address.into();
|
||||||
let code: Vec<u8> = account.code.into();
|
let code: Vec<u8> = account.code.into();
|
||||||
fail_unless(state.code(&address).as_ref().map_or_else(|| code.is_empty(), |c| &**c == &code), "code is incorrect");
|
let found_code = try_fail!(state.code(&address));
|
||||||
fail_unless(state.balance(&address) == account.balance.into(), "balance is incorrect");
|
let found_balance = try_fail!(state.balance(&address));
|
||||||
fail_unless(state.nonce(&address) == account.nonce.into(), "nonce is incorrect");
|
let found_nonce = try_fail!(state.nonce(&address));
|
||||||
account.storage.into_iter().foreach(|(k, v)| {
|
|
||||||
|
fail_unless(found_code.as_ref().map_or_else(|| code.is_empty(), |c| &**c == &code), "code is incorrect");
|
||||||
|
fail_unless(found_balance == account.balance.into(), "balance is incorrect");
|
||||||
|
fail_unless(found_nonce == account.nonce.into(), "nonce is incorrect");
|
||||||
|
for (k, v) in account.storage {
|
||||||
let key: U256 = k.into();
|
let key: U256 = k.into();
|
||||||
let value: U256 = v.into();
|
let value: U256 = v.into();
|
||||||
fail_unless(state.storage_at(&address, &From::from(key)) == From::from(value), "storage is incorrect");
|
let found_storage = try_fail!(state.storage_at(&address, &From::from(key)));
|
||||||
});
|
fail_unless(found_storage == From::from(value), "storage is incorrect");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let calls: Option<Vec<CallCreate>> = vm.calls.map(|c| c.into_iter().map(From::from).collect());
|
let calls: Option<Vec<CallCreate>> = vm.calls.map(|c| c.into_iter().map(From::from).collect());
|
||||||
|
@ -715,7 +715,8 @@ impl MinerService for Miner {
|
|||||||
let needed_balance = t.value + t.gas * t.gas_price;
|
let needed_balance = t.value + t.gas * t.gas_price;
|
||||||
if balance < needed_balance {
|
if balance < needed_balance {
|
||||||
// give the sender a sufficient balance
|
// give the sender a sufficient balance
|
||||||
state.add_balance(&sender, &(needed_balance - balance), CleanupMode::NoEmpty);
|
state.add_balance(&sender, &(needed_balance - balance), CleanupMode::NoEmpty)
|
||||||
|
.map_err(ExecutionError::from)?;
|
||||||
}
|
}
|
||||||
let options = TransactOptions { tracing: analytics.transaction_tracing, vm_tracing: analytics.vm_tracing, check_nonce: false };
|
let options = TransactOptions { tracing: analytics.transaction_tracing, vm_tracing: analytics.vm_tracing, check_nonce: false };
|
||||||
let mut ret = Executive::new(&mut state, &env_info, &*self.engine, client.vm_factory()).transact(t, options)?;
|
let mut ret = Executive::new(&mut state, &env_info, &*self.engine, client.vm_factory()).transact(t, options)?;
|
||||||
|
@ -62,7 +62,7 @@ pub use self::work_notify::NotifyWork;
|
|||||||
pub use self::stratum::{Stratum, Error as StratumError, Options as StratumOptions};
|
pub use self::stratum::{Stratum, Error as StratumError, Options as StratumOptions};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use util::{H256, U256, Address, Bytes, trie};
|
use util::{H256, U256, Address, Bytes};
|
||||||
use client::{MiningBlockChainClient, Executed, CallAnalytics};
|
use client::{MiningBlockChainClient, Executed, CallAnalytics};
|
||||||
use block::ClosedBlock;
|
use block::ClosedBlock;
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
@ -389,6 +389,6 @@ mod tests {
|
|||||||
let db = spec.ensure_db_good(db_result.take(), &Default::default()).unwrap();
|
let db = spec.ensure_db_good(db_result.take(), &Default::default()).unwrap();
|
||||||
let state = State::from_existing(db.boxed_clone(), spec.state_root(), spec.engine.account_start_nonce(), Default::default()).unwrap();
|
let state = State::from_existing(db.boxed_clone(), spec.state_root(), spec.engine.account_start_nonce(), Default::default()).unwrap();
|
||||||
let expected = H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
|
let expected = H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
|
||||||
assert_eq!(state.storage_at(&Address::from_str("0000000000000000000000000000000000000005").unwrap(), &H256::zero()), expected);
|
assert_eq!(state.storage_at(&Address::from_str("0000000000000000000000000000000000000005").unwrap(), &H256::zero()).unwrap(), expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ mod tests {
|
|||||||
let rlp = {
|
let rlp = {
|
||||||
let mut a = Account::new_contract(69.into(), 0.into());
|
let mut a = Account::new_contract(69.into(), 0.into());
|
||||||
a.set_storage(H256::from(&U256::from(0x00u64)), H256::from(&U256::from(0x1234u64)));
|
a.set_storage(H256::from(&U256::from(0x00u64)), H256::from(&U256::from(0x1234u64)));
|
||||||
a.commit_storage(&Default::default(), &mut db);
|
a.commit_storage(&Default::default(), &mut db).unwrap();
|
||||||
a.init_code(vec![]);
|
a.init_code(vec![]);
|
||||||
a.commit_code(&mut db);
|
a.commit_code(&mut db);
|
||||||
a.rlp()
|
a.rlp()
|
||||||
@ -491,8 +491,8 @@ mod tests {
|
|||||||
|
|
||||||
let a = Account::from_rlp(&rlp);
|
let a = Account::from_rlp(&rlp);
|
||||||
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
||||||
assert_eq!(a.storage_at(&db.immutable(), &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64)));
|
assert_eq!(a.storage_at(&db.immutable(), &H256::from(&U256::from(0x00u64))).unwrap(), H256::from(&U256::from(0x1234u64)));
|
||||||
assert_eq!(a.storage_at(&db.immutable(), &H256::from(&U256::from(0x01u64))), H256::new());
|
assert_eq!(a.storage_at(&db.immutable(), &H256::from(&U256::from(0x01u64))).unwrap(), H256::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -521,7 +521,7 @@ mod tests {
|
|||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(0.into(), 0x1234.into());
|
a.set_storage(0.into(), 0x1234.into());
|
||||||
assert_eq!(a.storage_root(), None);
|
assert_eq!(a.storage_root(), None);
|
||||||
a.commit_storage(&Default::default(), &mut db);
|
a.commit_storage(&Default::default(), &mut db).unwrap();
|
||||||
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,11 +531,11 @@ mod tests {
|
|||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(0.into(), 0x1234.into());
|
a.set_storage(0.into(), 0x1234.into());
|
||||||
a.commit_storage(&Default::default(), &mut db);
|
a.commit_storage(&Default::default(), &mut db).unwrap();
|
||||||
a.set_storage(1.into(), 0x1234.into());
|
a.set_storage(1.into(), 0x1234.into());
|
||||||
a.commit_storage(&Default::default(), &mut db);
|
a.commit_storage(&Default::default(), &mut db).unwrap();
|
||||||
a.set_storage(1.into(), 0.into());
|
a.set_storage(1.into(), 0.into());
|
||||||
a.commit_storage(&Default::default(), &mut db);
|
a.commit_storage(&Default::default(), &mut db).unwrap();
|
||||||
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +573,7 @@ impl<B: Backend> State<B> {
|
|||||||
let addr_hash = account.address_hash(address);
|
let addr_hash = account.address_hash(address);
|
||||||
{
|
{
|
||||||
let mut account_db = factories.accountdb.create(db.as_hashdb_mut(), addr_hash);
|
let mut account_db = factories.accountdb.create(db.as_hashdb_mut(), addr_hash);
|
||||||
account.commit_storage(&factories.trie, account_db.as_hashdb_mut());
|
account.commit_storage(&factories.trie, account_db.as_hashdb_mut())?;
|
||||||
account.commit_code(account_db.as_hashdb_mut());
|
account.commit_code(account_db.as_hashdb_mut());
|
||||||
}
|
}
|
||||||
if !account.is_empty() {
|
if !account.is_empty() {
|
||||||
@ -911,7 +911,7 @@ mod tests {
|
|||||||
data: FromHex::from_hex("601080600c6000396000f3006000355415600957005b60203560003555").unwrap(),
|
data: FromHex::from_hex("601080600c6000396000f3006000355415600957005b60203560003555").unwrap(),
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -941,13 +941,13 @@ mod tests {
|
|||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
let mut state = {
|
let mut state = {
|
||||||
let mut state = get_temp_state_in(temp.as_path());
|
let mut state = get_temp_state_in(temp.as_path());
|
||||||
assert_eq!(state.exists(&a), false);
|
assert_eq!(state.exists(&a).unwrap(), false);
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
state.clone()
|
state.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,7 +971,7 @@ mod tests {
|
|||||||
data: FromHex::from_hex("5b600056").unwrap(),
|
data: FromHex::from_hex("5b600056").unwrap(),
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1008,8 +1008,8 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("6000").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1051,7 +1051,7 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1135,7 +1135,7 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap()).unwrap();
|
||||||
let result = state.apply(&info, engine, &t, true).unwrap();
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
@ -1178,8 +1178,8 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap()).unwrap();
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap();
|
||||||
let result = state.apply(&info, engine, &t, true).unwrap();
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
@ -1240,8 +1240,8 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap()).unwrap();
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap();
|
||||||
let result = state.apply(&info, engine, &t, true).unwrap();
|
let result = state.apply(&info, engine, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
@ -1299,8 +1299,8 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("5b600056").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("5b600056").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1339,9 +1339,9 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap();
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
@ -1399,8 +1399,8 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006045600b6000f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006045600b6000f1").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1454,8 +1454,8 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060ff600b6000f1").unwrap()); // not enough funds.
|
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060ff600b6000f1").unwrap()).unwrap(); // not enough funds.
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1497,9 +1497,9 @@ mod tests {
|
|||||||
data: vec![],//600480600b6000396000f35b600056
|
data: vec![],//600480600b6000396000f35b600056
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap();
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("5b600056").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("5b600056").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1553,10 +1553,10 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap();
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1").unwrap()).unwrap();
|
||||||
state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1628,10 +1628,10 @@ mod tests {
|
|||||||
data: vec![],//600480600b6000396000f35b600056
|
data: vec![],//600480600b6000396000f35b600056
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap();
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1505b601256").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1505b601256").unwrap()).unwrap();
|
||||||
state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap()).unwrap();
|
||||||
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
@ -1701,9 +1701,9 @@ mod tests {
|
|||||||
data: vec![],
|
data: vec![],
|
||||||
}.sign(&secret(), None);
|
}.sign(&secret(), None);
|
||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("73000000000000000000000000000000000000000bff").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("73000000000000000000000000000000000000000bff").unwrap()).unwrap();
|
||||||
state.add_balance(&0xa.into(), &50.into(), CleanupMode::NoEmpty);
|
state.add_balance(&0xa.into(), &50.into(), CleanupMode::NoEmpty).unwrap();
|
||||||
state.add_balance(&t.sender(), &100.into(), CleanupMode::NoEmpty);
|
state.add_balance(&t.sender(), &100.into(), CleanupMode::NoEmpty).unwrap();
|
||||||
let result = state.apply(&info, &engine, &t, true).unwrap();
|
let result = state.apply(&info, &engine, &t, true).unwrap();
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1740,16 +1740,16 @@ mod tests {
|
|||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = get_temp_state_in(temp.as_path());
|
let mut state = get_temp_state_in(temp.as_path());
|
||||||
state.require_or_from(&a, false, ||Account::new_contract(42.into(), 0.into()), |_|{});
|
state.require_or_from(&a, false, ||Account::new_contract(42.into(), 0.into()), |_|{}).unwrap();
|
||||||
state.init_code(&a, vec![1, 2, 3]);
|
state.init_code(&a, vec![1, 2, 3]).unwrap();
|
||||||
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
|
assert_eq!(state.code(&a).unwrap(), Some(Arc::new([1u8, 2, 3].to_vec())));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
|
assert_eq!(state.code(&a).unwrap(), Some(Arc::new([1u8, 2, 3].to_vec())));
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert_eq!(state.code(&a), Some(Arc::new([1u8, 2, 3].to_vec())));
|
assert_eq!(state.code(&a).unwrap(), Some(Arc::new([1u8, 2, 3].to_vec())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1758,13 +1758,13 @@ mod tests {
|
|||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = get_temp_state_in(temp.as_path());
|
let mut state = get_temp_state_in(temp.as_path());
|
||||||
state.set_storage(&a, H256::from(&U256::from(1u64)), H256::from(&U256::from(69u64)));
|
state.set_storage(&a, H256::from(&U256::from(1u64)), H256::from(&U256::from(69u64))).unwrap();
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
|
|
||||||
let s = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let s = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert_eq!(s.storage_at(&a, &H256::from(&U256::from(1u64))), H256::from(&U256::from(69u64)));
|
assert_eq!(s.storage_at(&a, &H256::from(&U256::from(1u64))).unwrap(), H256::from(&U256::from(69u64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1773,16 +1773,16 @@ mod tests {
|
|||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = get_temp_state_in(temp.as_path());
|
let mut state = get_temp_state_in(temp.as_path());
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty).unwrap();
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
assert_eq!(state.nonce(&a), U256::from(1u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(1u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1790,16 +1790,16 @@ mod tests {
|
|||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
assert_eq!(state.exists(&a), false);
|
assert_eq!(state.exists(&a).unwrap(), false);
|
||||||
assert_eq!(state.exists_and_not_null(&a), false);
|
assert_eq!(state.exists_and_not_null(&a).unwrap(), false);
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
assert_eq!(state.exists(&a), true);
|
assert_eq!(state.exists(&a).unwrap(), true);
|
||||||
assert_eq!(state.exists_and_not_null(&a), true);
|
assert_eq!(state.exists_and_not_null(&a).unwrap(), true);
|
||||||
assert_eq!(state.nonce(&a), U256::from(1u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(1u64));
|
||||||
state.kill_account(&a);
|
state.kill_account(&a);
|
||||||
assert_eq!(state.exists(&a), false);
|
assert_eq!(state.exists(&a).unwrap(), false);
|
||||||
assert_eq!(state.exists_and_not_null(&a), false);
|
assert_eq!(state.exists_and_not_null(&a).unwrap(), false);
|
||||||
assert_eq!(state.nonce(&a), U256::from(0u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(0u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1809,13 +1809,13 @@ mod tests {
|
|||||||
let db = get_temp_state_db_in(path.as_path());
|
let db = get_temp_state_db_in(path.as_path());
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = State::new(db, U256::from(0), Default::default());
|
let mut state = State::new(db, U256::from(0), Default::default());
|
||||||
state.add_balance(&a, &U256::default(), CleanupMode::NoEmpty); // create an empty account
|
state.add_balance(&a, &U256::default(), CleanupMode::NoEmpty).unwrap(); // create an empty account
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert!(!state.exists(&a));
|
assert!(!state.exists(&a).unwrap());
|
||||||
assert!(!state.exists_and_not_null(&a));
|
assert!(!state.exists_and_not_null(&a).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1825,13 +1825,13 @@ mod tests {
|
|||||||
let db = get_temp_state_db_in(path.as_path());
|
let db = get_temp_state_db_in(path.as_path());
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = State::new(db, U256::from(0), Default::default());
|
let mut state = State::new(db, U256::from(0), Default::default());
|
||||||
state.add_balance(&a, &U256::default(), CleanupMode::ForceCreate); // create an empty account
|
state.add_balance(&a, &U256::default(), CleanupMode::ForceCreate).unwrap(); // create an empty account
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert!(state.exists(&a));
|
assert!(state.exists(&a).unwrap());
|
||||||
assert!(!state.exists_and_not_null(&a));
|
assert!(!state.exists_and_not_null(&a).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1840,27 +1840,27 @@ mod tests {
|
|||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = get_temp_state_in(temp.as_path());
|
let mut state = get_temp_state_in(temp.as_path());
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.exists(&a), true);
|
assert_eq!(state.exists(&a).unwrap(), true);
|
||||||
assert_eq!(state.nonce(&a), U256::from(1u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(1u64));
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let mut state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert_eq!(state.exists(&a), true);
|
assert_eq!(state.exists(&a).unwrap(), true);
|
||||||
assert_eq!(state.nonce(&a), U256::from(1u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(1u64));
|
||||||
state.kill_account(&a);
|
state.kill_account(&a);
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.exists(&a), false);
|
assert_eq!(state.exists(&a).unwrap(), false);
|
||||||
assert_eq!(state.nonce(&a), U256::from(0u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(0u64));
|
||||||
state.drop()
|
state.drop()
|
||||||
};
|
};
|
||||||
|
|
||||||
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
let state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap();
|
||||||
assert_eq!(state.exists(&a), false);
|
assert_eq!(state.exists(&a).unwrap(), false);
|
||||||
assert_eq!(state.nonce(&a), U256::from(0u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(0u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1869,20 +1869,20 @@ mod tests {
|
|||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
let b = 1u64.into();
|
let b = 1u64.into();
|
||||||
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.sub_balance(&a, &U256::from(42u64));
|
state.sub_balance(&a, &U256::from(42u64)).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(27u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(27u64));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(27u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(27u64));
|
||||||
state.transfer_balance(&a, &b, &U256::from(18u64), CleanupMode::NoEmpty);
|
state.transfer_balance(&a, &b, &U256::from(18u64), CleanupMode::NoEmpty).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(9u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(9u64));
|
||||||
assert_eq!(state.balance(&b), U256::from(18u64));
|
assert_eq!(state.balance(&b).unwrap(), U256::from(18u64));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(9u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(9u64));
|
||||||
assert_eq!(state.balance(&b), U256::from(18u64));
|
assert_eq!(state.balance(&b).unwrap(), U256::from(18u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1890,16 +1890,16 @@ mod tests {
|
|||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
assert_eq!(state.nonce(&a), U256::from(1u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(1u64));
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
assert_eq!(state.nonce(&a), U256::from(2u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(2u64));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.nonce(&a), U256::from(2u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(2u64));
|
||||||
state.inc_nonce(&a);
|
state.inc_nonce(&a).unwrap();
|
||||||
assert_eq!(state.nonce(&a), U256::from(3u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(3u64));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.nonce(&a), U256::from(3u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(3u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1907,11 +1907,11 @@ mod tests {
|
|||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
assert_eq!(state.balance(&a), U256::from(0u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(0u64));
|
||||||
assert_eq!(state.nonce(&a), U256::from(0u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(0u64));
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(0u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(0u64));
|
||||||
assert_eq!(state.nonce(&a), U256::from(0u64));
|
assert_eq!(state.nonce(&a).unwrap(), U256::from(0u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1919,7 +1919,7 @@ mod tests {
|
|||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
state.require(&a, false);
|
state.require(&a, false).unwrap();
|
||||||
state.commit().unwrap();
|
state.commit().unwrap();
|
||||||
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
|
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
|
||||||
}
|
}
|
||||||
@ -1930,15 +1930,15 @@ mod tests {
|
|||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
state.checkpoint();
|
state.checkpoint();
|
||||||
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.discard_checkpoint();
|
state.discard_checkpoint();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.checkpoint();
|
state.checkpoint();
|
||||||
state.add_balance(&a, &U256::from(1u64), CleanupMode::NoEmpty);
|
state.add_balance(&a, &U256::from(1u64), CleanupMode::NoEmpty).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(70u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(70u64));
|
||||||
state.revert_to_checkpoint();
|
state.revert_to_checkpoint();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1948,12 +1948,12 @@ mod tests {
|
|||||||
let a = Address::zero();
|
let a = Address::zero();
|
||||||
state.checkpoint();
|
state.checkpoint();
|
||||||
state.checkpoint();
|
state.checkpoint();
|
||||||
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty);
|
state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty).unwrap();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.discard_checkpoint();
|
state.discard_checkpoint();
|
||||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(69u64));
|
||||||
state.revert_to_checkpoint();
|
state.revert_to_checkpoint();
|
||||||
assert_eq!(state.balance(&a), U256::from(0));
|
assert_eq!(state.balance(&a).unwrap(), U256::from(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1970,14 +1970,14 @@ mod tests {
|
|||||||
let mut state = state.reference().clone();
|
let mut state = state.reference().clone();
|
||||||
|
|
||||||
let a: Address = 0xa.into();
|
let a: Address = 0xa.into();
|
||||||
state.init_code(&a, b"abcdefg".to_vec());
|
state.init_code(&a, b"abcdefg".to_vec()).unwrap();;
|
||||||
state.add_balance(&a, &256.into(), CleanupMode::NoEmpty);
|
state.add_balance(&a, &256.into(), CleanupMode::NoEmpty).unwrap();
|
||||||
state.set_storage(&a, 0xb.into(), 0xc.into());
|
state.set_storage(&a, 0xb.into(), 0xc.into()).unwrap();
|
||||||
|
|
||||||
let mut new_state = state.clone();
|
let mut new_state = state.clone();
|
||||||
new_state.set_storage(&a, 0xb.into(), 0xd.into());
|
new_state.set_storage(&a, 0xb.into(), 0xd.into()).unwrap();
|
||||||
|
|
||||||
new_state.diff_from(state);
|
new_state.diff_from(state).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ fn change_history_size() {
|
|||||||
|
|
||||||
for _ in 0..20 {
|
for _ in 0..20 {
|
||||||
let mut b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]);
|
let mut b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]);
|
||||||
b.block_mut().fields_mut().state.add_balance(&address, &5.into(), CleanupMode::NoEmpty);
|
b.block_mut().fields_mut().state.add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap();
|
||||||
b.block_mut().fields_mut().state.commit().unwrap();
|
b.block_mut().fields_mut().state.commit().unwrap();
|
||||||
let b = b.close_and_lock().seal(&*test_spec.engine, vec![]).unwrap();
|
let b = b.close_and_lock().seal(&*test_spec.engine, vec![]).unwrap();
|
||||||
client.import_sealed_block(b).unwrap(); // account change is in the journal overlay
|
client.import_sealed_block(b).unwrap(); // account change is in the journal overlay
|
||||||
@ -307,7 +307,7 @@ fn change_history_size() {
|
|||||||
Arc::new(Miner::with_spec(&test_spec)),
|
Arc::new(Miner::with_spec(&test_spec)),
|
||||||
IoChannel::disconnected(),
|
IoChannel::disconnected(),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
assert_eq!(client.state().balance(&address), 100.into());
|
assert_eq!(client.state().balance(&address).unwrap(), 100.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user