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;
RLPList items = (RLPList) RLP.decode2(rlpEncoded).get(0);
this.nonce = new BigInteger(1, ((items.get(0).getRLPData()) == null ? new byte[]{0} :
items.get(0).getRLPData()));
this.balance = new BigInteger(1, ((items.get(1).getRLPData()) == null ? new byte[]{0} :
items.get(1).getRLPData()));
this.nonce = items.get(0).getRLPData() == null ? BigInteger.ZERO
: new BigInteger(1, items.get(0).getRLPData());
this.balance = items.get(1).getRLPData() == null ? BigInteger.ZERO
: new BigInteger(1, items.get(1).getRLPData());
this.stateRoot = items.get(2).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
// some value stateRoot. The latest documentation should be consulted for the value of the state root.
for (String address : premine) {
AccountState acctState = new AccountState();
acctState.addToBalance(PREMINE_AMOUNT);
AccountState acctState = new AccountState(BigInteger.ZERO, PREMINE_AMOUNT);
state.update(Hex.decode(address), acctState.getEncoded());
}

View File

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

View File

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

View File

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