Fix tests for AccountState empty hashes

This commit is contained in:
nicksavers 2014-10-31 23:01:45 +01:00
parent bb52b1c492
commit 95fda6ada4
5 changed files with 13 additions and 12 deletions

View File

@ -53,10 +53,10 @@ public class AccountState {
this.rlpEncoded = rlpData; this.rlpEncoded = rlpData;
RLPList items = (RLPList) RLP.decode2(rlpEncoded).get(0); RLPList items = (RLPList) RLP.decode2(rlpEncoded).get(0);
this.nonce = new BigInteger(1, ((items.get(0).getRLPData()) == null ? new byte[]{0} : this.nonce = items.get(0).getRLPData() == null ? BigInteger.ZERO
items.get(0).getRLPData())); : new BigInteger(1, items.get(0).getRLPData());
this.balance = new BigInteger(1, ((items.get(1).getRLPData()) == null ? new byte[]{0} : this.balance = items.get(1).getRLPData() == null ? BigInteger.ZERO
items.get(1).getRLPData())); : new BigInteger(1, items.get(1).getRLPData());
this.stateRoot = items.get(2).getRLPData(); this.stateRoot = items.get(2).getRLPData();
this.codeHash = items.get(3).getRLPData(); this.codeHash = items.get(3).getRLPData();
} }

View File

@ -69,8 +69,7 @@ public class Genesis extends Block {
// The proof-of-concept series include a development pre-mine, making the state root hash // The proof-of-concept series include a development pre-mine, making the state root hash
// some value stateRoot. The latest documentation should be consulted for the value of the state root. // some value stateRoot. The latest documentation should be consulted for the value of the state root.
for (String address : premine) { for (String address : premine) {
AccountState acctState = new AccountState(); AccountState acctState = new AccountState(BigInteger.ZERO, PREMINE_AMOUNT);
acctState.addToBalance(PREMINE_AMOUNT);
state.update(Hex.decode(address), acctState.getEncoded()); state.update(Hex.decode(address), acctState.getEncoded());
} }

View File

@ -11,7 +11,10 @@ public class AccountStateTest {
@Test @Test
public void testGetEncoded() { public void testGetEncoded() {
String expected = "de809a01000000000000000000000000000000000000000000000000008080"; String expected = "f85e809"
+ "a0100000000000000000000000000000000000000000000000000"
+ "a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
+ "a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200)); AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200));
assertEquals(expected, Hex.toHexString(acct.getEncoded())); assertEquals(expected, Hex.toHexString(acct.getEncoded()));
} }

View File

@ -14,7 +14,7 @@ import org.spongycastle.util.encoders.Hex;
public class StateTest { public class StateTest {
private static final String GENESIS_STATE_ROOT = "c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718c"; private static final String GENESIS_STATE_ROOT = "477fd4d3a3bae60913bbb0cbffbc1aae5c57a60f6351f9ed702d97378f851fc6";
@Test @Test
public void testGenesisAccounts() { public void testGenesisAccounts() {
@ -94,7 +94,7 @@ public class StateTest {
// 4) calc the root // 4) calc the root
Trie trie = generateGenesisState(); Trie trie = generateGenesisState();
String expected = "73d725637d76b140720cc75500cfb5ce17bf4c6089798b69a7db1a7e4d97d617"; String expected = "e9d7cff80ac451f10a5212b0e8bb6070d0c2214b9d4943794269be78b13d1fb4";
// Get and update sender in world state // Get and update sender in world state
byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"); byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");

View File

@ -1,8 +1,8 @@
package org.ethereum.db; package org.ethereum.db;
import org.ethereum.core.AccountState; import org.ethereum.core.AccountState;
import org.ethereum.crypto.HashUtil;
import org.ethereum.facade.Repository; import org.ethereum.facade.Repository;
import org.ethereum.util.ByteUtil;
import org.ethereum.vm.DataWord; import org.ethereum.vm.DataWord;
import org.junit.*; import org.junit.*;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
@ -10,7 +10,6 @@ import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger; import java.math.BigInteger;
import static org.ethereum.util.ByteUtil.EMTPY_SHA3_RLP_ELEMENT_HASH;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
@ -184,7 +183,7 @@ public class RepositoryTest {
AccountState accountState = repository.getAccountState(addr); AccountState accountState = repository.getAccountState(addr);
assertTrue(code0 == null); assertTrue(code0 == null);
assertNull(code1); assertNull(code1);
assertEquals(EMTPY_SHA3_RLP_ELEMENT_HASH, accountState.getCodeHash()); assertArrayEquals(HashUtil.EMPTY_DATA_HASH, accountState.getCodeHash());
} finally { } finally {
repository.close(); repository.close();
} }