private static WorldStateArchive buildWorldStateArchive( final Map<String, WorldStateMock.AccountMock> accounts) { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final MutableWorldState worldState = worldStateArchive.getMutable(); final WorldUpdater updater = worldState.updater(); for (final Map.Entry<String, WorldStateMock.AccountMock> entry : accounts.entrySet()) { insertAccount(updater, Address.fromHexString(entry.getKey()), entry.getValue()); } updater.commit(); worldState.persist(); return worldStateArchive; }
assertThat(account.getStorageValue(storageKey)).isEqualTo(originalStorageValue); updater.commit(); worldState.persist();
@Test public void rootHash_Empty() { final MutableWorldState worldState = createEmpty(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); worldState.persist(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); }
account.setStorageValue(storageKey, storageValue); updater.commit(); worldState.persist(); assertNotNull(worldState.get(ADDRESS)); assertNotEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash());
@Test public void removeAccount_AccountDoesNotExist() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.deleteAccount(ADDRESS); updater.commit(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); worldState.persist(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); }
@Test public void removeAccount_UpdatedAccount() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.deleteAccount(ADDRESS); updater.commit(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); worldState.persist(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); }
@Test public void removeAccount_AccountExistsAndIsPersisted() { // Create a world state with one account final MutableWorldState worldState = createEmpty(); WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.commit(); worldState.persist(); assertNotNull(worldState.get(ADDRESS)); assertNotEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); // Delete account updater = worldState.updater(); updater.deleteAccount(ADDRESS); assertNull(updater.get(ADDRESS)); assertNull(updater.getMutable(ADDRESS)); // Check account is gone after committing updater.commit(); assertNull(updater.get(ADDRESS)); // And after persisting worldState.persist(); assertNull(updater.get(ADDRESS)); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); }
worldState.persist(); assertNotEquals(0, storage.entries().count()); assertEquals(expectedRootHash, worldState.rootHash());