diff --git a/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java b/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java index bd26f336..8570ed52 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java @@ -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(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java b/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java index 6ca12cc2..cbcabe90 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java @@ -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()); } diff --git a/ethereumj-core/src/test/java/org/ethereum/core/AccountStateTest.java b/ethereumj-core/src/test/java/org/ethereum/core/AccountStateTest.java index cfc14615..96cb081b 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/AccountStateTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/AccountStateTest.java @@ -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())); } diff --git a/ethereumj-core/src/test/java/org/ethereum/core/StateTest.java b/ethereumj-core/src/test/java/org/ethereum/core/StateTest.java index 20526c25..db7269a6 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/StateTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/StateTest.java @@ -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"); diff --git a/ethereumj-core/src/test/java/org/ethereum/db/RepositoryTest.java b/ethereumj-core/src/test/java/org/ethereum/db/RepositoryTest.java index d321742b..438a0088 100644 --- a/ethereumj-core/src/test/java/org/ethereum/db/RepositoryTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/db/RepositoryTest.java @@ -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(); }