Fix stCallCreateCallCodeTest

Closes #268
This commit is contained in:
Gav Wood 2016-01-29 18:33:47 +01:00
parent 36b92210e1
commit c19339e799
3 changed files with 9 additions and 9 deletions

View File

@ -251,12 +251,13 @@ impl<'a> Executive<'a> {
// part of substate that may be reverted
let mut unconfirmed_substate = Substate::new();
// at first create new contract
self.state.new_contract(&params.address);
// then transfer value to it
// create contract and transfer value to it if necessary
let prev_bal = self.state.balance(&params.address);
if let ActionValue::Transfer(val) = params.value {
self.state.transfer_balance(&params.sender, &params.address, &val);
self.state.sub_balance(&params.sender, &val);
self.state.new_contract(&params.address, val + prev_bal);
} else {
self.state.new_contract(&params.address, prev_bal);
}
let res = {

View File

@ -72,8 +72,8 @@ impl State {
/// Create a new contract at address `contract`. If there is already an account at the address
/// it will have its code reset, ready for `init_code()`.
pub fn new_contract(&mut self, contract: &Address) {
self.require_or_from(contract, false, || Account::new_contract(U256::from(0u8)), |r| r.reset_code());
pub fn new_contract(&mut self, contract: &Address, balance: U256) {
self.cache.borrow_mut().insert(contract.clone(), Some(Account::new_contract(balance)));
}
/// Remove an existing account.

View File

@ -182,8 +182,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
let code = xjson!(&s["code"]);
let _nonce: U256 = xjson!(&s["nonce"]);
state.new_contract(&address);
state.add_balance(&address, &balance);
state.new_contract(&address, balance);
state.init_code(&address, code);
BTreeMap::from_json(&s["storage"]).into_iter().foreach(|(k, v)| state.set_storage(&address, k, v));
});