use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method testGetMissingNodes_wCompleteTrie.
@Test
public void testGetMissingNodes_wCompleteTrie() {
MockDB mockDB = new MockDB("temp", log);
mockDB.open();
TrieImpl trie = new TrieImpl(mockDB);
for (Map.Entry<ByteArrayWrapper, byte[]> e : getSampleTrieUpdates().entrySet()) {
trie.update(e.getKey().toBytes(), e.getValue());
}
trie.getCache().commitForTest();
byte[] root = trie.getRootHash();
trie = new TrieImpl(mockDB);
assertThat(trie.getMissingNodes(root)).isEmpty();
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method testGetReferencedTrieNodes.
@Test
public void testGetReferencedTrieNodes() {
MockDB mockDB = new MockDB("temp", log);
mockDB.open();
TrieImpl trie = new TrieImpl(mockDB);
for (Map.Entry<ByteArrayWrapper, byte[]> e : getSampleTrieUpdates().entrySet()) {
trie.update(e.getKey().toBytes(), e.getValue());
}
trie.getCache().commitForTest();
byte[] root = trie.getRootHash();
byte[] value = mockDB.get(root).get();
trie = new TrieImpl(mockDB);
// empty for limit <= 0
assertThat(trie.getReferencedTrieNodes(value, -2)).isEmpty();
assertThat(trie.getReferencedTrieNodes(value, 0)).isEmpty();
// partial size
assertThat(trie.getReferencedTrieNodes(value, 3).size()).isEqualTo(3);
assertThat(trie.getReferencedTrieNodes(value, 4).size()).isEqualTo(4);
// full size except for initial root
int full = trie.getTrieSize(root) - 1;
assertThat(trie.getReferencedTrieNodes(value, full).size()).isEqualTo(full);
assertThat(trie.getReferencedTrieNodes(value, 2 * full).size()).isEqualTo(full);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method testGetReferencedTrieNodes_withStartFromAllNodes.
@Test
public void testGetReferencedTrieNodes_withStartFromAllNodes() {
MockDB mockDB = new MockDB("temp", log);
mockDB.open();
TrieImpl trie = new TrieImpl(mockDB);
for (Map.Entry<ByteArrayWrapper, byte[]> e : getSampleTrieUpdates().entrySet()) {
trie.update(e.getKey().toBytes(), e.getValue());
}
trie.getCache().commitForTest();
byte[] value, root = trie.getRootHash();
Set<ByteArrayWrapper> allKeys = trie.getTrieKeys(root);
trie = new TrieImpl(mockDB);
Value v;
for (ByteArrayWrapper key : allKeys) {
value = mockDB.get(key.toBytes()).get();
v = Value.fromRlpEncoded(value);
// empty for limit <= 0
assertThat(trie.getReferencedTrieNodes(key.toBytes(), -2)).isEmpty();
assertThat(trie.getReferencedTrieNodes(value, -2)).isEmpty();
assertThat(trie.getReferencedTrieNodes(key.toBytes(), 0)).isEmpty();
assertThat(trie.getReferencedTrieNodes(value, 0)).isEmpty();
// partial size = 1 for non-leafs and 0 for leafs
assertThat(trie.getReferencedTrieNodes(value, 1).size()).isAtMost(1);
assertThat(trie.getReferencedTrieNodes(key.toBytes(), 1).size()).isAtMost(1);
if (v.isList() && v.asList().size() > 2) {
// partial size = 4 for branch node
assertThat(trie.getReferencedTrieNodes(value, 100).size()).isEqualTo(4);
assertThat(trie.getReferencedTrieNodes(key.toBytes(), 100).size()).isEqualTo(5);
} else if (v.isList()) {
// at most whole list
assertThat(trie.getReferencedTrieNodes(value, 100).size()).isAtMost(5);
assertThat(trie.getReferencedTrieNodes(key.toBytes(), 100).size()).isAtMost(6);
} else {
// partial size = 0 for leafs
assertThat(trie.getReferencedTrieNodes(value, 100).size()).isAtMost(0);
assertThat(trie.getReferencedTrieNodes(key.toBytes(), 100).size()).isAtMost(0);
}
}
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ExternalStateForAvm method getStorage.
@Override
public byte[] getStorage(AionAddress address, byte[] key) {
ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key);
ByteArrayWrapper value = this.repositoryCache.getStorageValue(address, storageKey);
return (value == null) ? null : value.toBytes();
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ExternalStateForAvm method putStorage.
@Override
public void putStorage(AionAddress address, byte[] key, byte[] value) {
ByteArrayWrapper storageKey = ByteArrayWrapper.wrap(key);
ByteArrayWrapper storageValue = ByteArrayWrapper.wrap(value);
this.repositoryCache.addStorageRow(address, storageKey, storageValue);
setVmType(address);
}
Aggregations