use of co.rsk.trie.Trie in project rskj by rsksmart.
the class BlockTest method testPremineFromJSON.
@Test
public void testPremineFromJSON() throws ParseException {
JSONParser parser = new JSONParser();
JSONObject genesisMap = (JSONObject) parser.parse(TEST_GENESIS);
Set keys = genesisMap.keySet();
Trie state = new TrieImpl(null, true);
for (Object key : keys) {
JSONObject val = (JSONObject) genesisMap.get(key);
String denom = (String) val.keySet().toArray()[0];
String value = (String) val.values().toArray()[0];
BigInteger wei = Denomination.valueOf(denom.toUpperCase()).value().multiply(new BigInteger(value));
AccountState accountState = new AccountState(BigInteger.ZERO, new Coin(wei));
byte[] encodedAccountState = accountState.getEncoded();
byte[] accountKey = Hex.decode(key.toString());
state = state.put(accountKey, encodedAccountState);
Assert.assertArrayEquals(encodedAccountState, state.get(accountKey));
}
logger.info("root: {}", state.getHash());
assertEquals(GENESIS_STATE_ROOT, state.getHash());
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class StateTest method generateGenesisState.
private Trie generateGenesisState() {
Trie trie = new TrieImpl();
Genesis genesis = (Genesis) Genesis.getInstance(new RskSystemProperties());
for (RskAddress addr : genesis.getPremine().keySet()) {
trie = trie.put(addr.getBytes(), genesis.getPremine().get(addr).getAccountState().getEncoded());
}
return trie;
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class SecureTrieImplHashTest method removeOrNeverInsertShouldBringSameHashWithSecureTrie.
@Test
public void removeOrNeverInsertShouldBringSameHashWithSecureTrie() {
Trie trie1 = new TrieImpl(true).put("roosevalt", "So, first of all, let me assert my firm belief that".getBytes()).put("roosevelt", "the only thing we have to fear is... fear itself ".getBytes()).put("roosevilt", "42".getBytes()).delete("roosevelt");
Trie trie2 = new TrieImpl(true).put("roosevalt", "So, first of all, let me assert my firm belief that".getBytes()).put("roosevilt", "42".getBytes());
Assert.assertTrue(Arrays.equals(trie1.get("roosevalt"), "So, first of all, let me assert my firm belief that".getBytes()));
Assert.assertTrue(Arrays.equals(trie1.get("roosevilt"), "42".getBytes()));
Assert.assertNull(trie1.get("roosevelt"));
Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class SecureTrieImplKeyValueTest method zeroKeyWhenTwoKeysHasNoSharedPath.
@Test
public void zeroKeyWhenTwoKeysHasNoSharedPath() {
byte[] zeroKey = "0".getBytes();
byte[] oneKey = "1".getBytes();
Trie trie = new TrieImpl(true).put(zeroKey, "So, first of all, let me assert my firm belief that".getBytes()).put(oneKey, "the only thing we have to fear is... fear itself ".getBytes());
trie = trie.delete(oneKey);
Assert.assertTrue(Arrays.equals(trie.get(zeroKey), "So, first of all, let me assert my firm belief that".getBytes()));
Assert.assertNull(trie.get(oneKey));
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class SecureTrieImplKeyValueTest method zeroKeyWhenTwoKeysHasSharedPathAndOneIsPrefixOfTheOther.
@Test
public void zeroKeyWhenTwoKeysHasSharedPathAndOneIsPrefixOfTheOther() {
byte[] zeroKey = "0".getBytes();
byte[] oneKey = "012345678910".getBytes();
Trie trie = new TrieImpl(true).put(zeroKey, "So, first of all, let me assert my firm belief that".getBytes()).put(oneKey, "the only thing we have to fear is... fear itself ".getBytes());
trie = trie.delete(zeroKey);
Assert.assertTrue(Arrays.equals(trie.get(oneKey), "the only thing we have to fear is... fear itself ".getBytes()));
Assert.assertNull(trie.get(zeroKey));
}
Aggregations