Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix for morden consensus. #556

Merged
merged 1 commit into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ethcore/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ impl Account {

/// Create a new contract account.
/// NOTE: make sure you use `init_code` on this before `commit`ing.
pub fn new_contract(balance: U256) -> Account {
pub fn new_contract(balance: U256, nonce: U256) -> Account {
Account {
balance: balance,
nonce: U256::from(0u8),
nonce: nonce,
storage_root: SHA3_NULL_RLP,
storage_overlay: RefCell::new(HashMap::new()),
code_hash: None,
Expand Down Expand Up @@ -261,7 +261,7 @@ mod tests {
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
let rlp = {
let mut a = Account::new_contract(U256::from(69u8));
let mut a = Account::new_contract(x!(69), x!(0));
a.set_storage(H256::from(&U256::from(0x00u64)), H256::from(&U256::from(0x1234u64)));
a.commit_storage(&mut db);
a.init_code(vec![]);
Expand All @@ -281,7 +281,7 @@ mod tests {
let mut db = AccountDBMut::new(&mut db, &Address::new());

let rlp = {
let mut a = Account::new_contract(U256::from(69u8));
let mut a = Account::new_contract(x!(69), x!(0));
a.init_code(vec![0x55, 0x44, 0xffu8]);
a.commit_code(&mut db);
a.rlp()
Expand All @@ -296,7 +296,7 @@ mod tests {

#[test]
fn commit_storage() {
let mut a = Account::new_contract(U256::from(69u8));
let mut a = Account::new_contract(x!(69), x!(0));
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.set_storage(x!(0), x!(0x1234));
Expand All @@ -307,7 +307,7 @@ mod tests {

#[test]
fn commit_remove_commit_storage() {
let mut a = Account::new_contract(U256::from(69u8));
let mut a = Account::new_contract(x!(69), x!(0));
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.set_storage(x!(0), x!(0x1234));
Expand All @@ -321,7 +321,7 @@ mod tests {

#[test]
fn commit_code() {
let mut a = Account::new_contract(U256::from(69u8));
let mut a = Account::new_contract(x!(69), x!(0));
let mut db = MemoryDB::new();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.init_code(vec![0x55, 0x44, 0xffu8]);
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ 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, balance: U256) {
self.insert_cache(&contract, Some(Account::new_contract(balance)));
self.insert_cache(&contract, Some(Account::new_contract(balance, self.account_start_nonce)));
}

/// Remove an existing account.
Expand Down Expand Up @@ -204,7 +204,7 @@ impl State {
/// Initialise the code of account `a` so that it is `value` for `key`.
/// NOTE: Account should have been created with `new_contract`.
pub fn init_code(&mut self, a: &Address, code: Bytes) {
self.require_or_from(a, true, || Account::new_contract(U256::from(0u8)), |_|{}).init_code(code);
self.require_or_from(a, true, || Account::new_contract(x!(0), self.account_start_nonce), |_|{}).init_code(code);
}

/// Execute a given transaction.
Expand Down Expand Up @@ -349,7 +349,7 @@ fn code_from_database() {
let temp = RandomTempPath::new();
let (root, db) = {
let mut state = get_temp_state_in(temp.as_path());
state.require_or_from(&a, false, ||Account::new_contract(U256::from(42u32)), |_|{});
state.require_or_from(&a, false, ||Account::new_contract(x!(42), x!(0)), |_|{});
state.init_code(&a, vec![1, 2, 3]);
assert_eq!(state.code(&a), Some([1u8, 2, 3].to_vec()));
state.commit();
Expand Down