use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class InnerContractDetailsTest method testCommitToStored_withStorageOnFvm.
@Test
public void testCommitToStored_withStorageOnFvm() {
AionAddress address = mock(AionAddress.class);
ByteArrayKeyValueStore db = mock(XorDataSource.class);
FvmContractDetails parent = new FvmContractDetails(address, db);
InnerContractDetails child = new InnerContractDetails(null);
Map<ByteArrayWrapper, ByteArrayWrapper> storage = new HashMap<>();
for (int i = 0; i < 3; i++) {
ByteArrayWrapper key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(32));
ByteArrayWrapper value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(100));
child.put(key, value);
storage.put(key, value);
}
ByteArrayWrapper deletedKey = ByteArrayWrapper.wrap(RandomUtils.nextBytes(32));
child.delete(deletedKey);
storage.put(deletedKey, null);
assertThat(child.isDirty()).isTrue();
assertThat(parent.getVmType()).isEqualTo(InternalVmType.FVM);
child.commitTo(parent);
assertThat(parent.getVmType()).isEqualTo(InternalVmType.FVM);
for (ByteArrayWrapper key : storage.keySet()) {
assertThat(parent.get(key)).isEqualTo(storage.get(key));
}
assertThat(parent.isDirty()).isTrue();
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class InnerContractDetailsTest method testCommitToInner_withStorage.
@Test
public void testCommitToInner_withStorage() {
InnerContractDetails parent = new InnerContractDetails(null);
InnerContractDetails child = new InnerContractDetails(null);
Map<ByteArrayWrapper, ByteArrayWrapper> storage = new HashMap<>();
for (int i = 0; i < 3; i++) {
ByteArrayWrapper key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(32));
ByteArrayWrapper value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(100));
child.put(key, value);
storage.put(key, value);
}
ByteArrayWrapper deletedKey = ByteArrayWrapper.wrap(RandomUtils.nextBytes(32));
child.delete(deletedKey);
storage.put(deletedKey, null);
assertThat(child.isDirty()).isTrue();
assertThat(parent.getVmType()).isEqualTo(InternalVmType.EITHER);
child.commitTo(parent);
assertThat(parent.getVmType()).isEqualTo(InternalVmType.EITHER);
for (ByteArrayWrapper key : storage.keySet()) {
assertThat(parent.get(key)).isEqualTo(storage.get(key));
}
assertThat(parent.isDirty()).isTrue();
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class PendingBlockStoreTest method testDropPendingQueues_wException.
@Test
public void testDropPendingQueues_wException() {
Properties props = new Properties();
props.setProperty(Props.DB_TYPE, DBVendor.MOCKDB.toValue());
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (IOException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
// add first queue
List<Block> blocks = TestResources.consecutiveBlocks(6);
Block first = blocks.get(0);
pb.addBlockRange(blocks);
// add second queue
MiningBlock altBlock = (MiningBlock) BlockUtil.newBlockFromRlp(first.getEncoded());
MiningBlockHeader newHeader = MiningBlockHeader.Builder.newInstance().withHeader(altBlock.getHeader()).withExtraData("random".getBytes()).build();
altBlock.updateHeader(newHeader);
List<Block> sideChain = new ArrayList<>();
sideChain.add(altBlock);
pb.addBlockRange(sideChain);
// check storage updates
assertThat(pb.getIndexSize()).isEqualTo(7);
assertThat(pb.getLevelSize()).isEqualTo(1);
assertThat(pb.getQueueSize()).isEqualTo(2);
// closing the pending block store to cause exception
pb.close();
// test drop functionality
Map<ByteArrayWrapper, List<Block>> actual = pb.loadBlockRange(first.getNumber());
pb.dropPendingQueues(first.getNumber(), actual.keySet(), actual);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class AionRepositoryCacheTest method testGetStorageValueIsSingleZero.
@Test
public void testGetStorageValueIsSingleZero() {
AionAddress address = getNewAddress();
ByteArrayWrapper key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(SINGLE_BYTES));
cache.removeStorageRow(address, key);
assertNull(cache.getStorageValue(address, key));
key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
cache.removeStorageRow(address, key);
assertNull(cache.getStorageValue(address, key));
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ContractInformationTest method testDecodeEncode_correctMultiInstance.
@Test
public void testDecodeEncode_correctMultiInstance() {
byte[] encoding = // contract info
RLP.encodeList(// hash map entry 1
RLP.encodeList(encodedHash1, RLP.encodeList(RLP.encodeList(RLP.encodeList(encodedHash2, flag1)), avm)), // hash map entry 2
RLP.encodeList(encodedHash2, RLP.encodeList(RLP.encodeList(RLP.encodeList(encodedHash1, flag1), RLP.encodeList(encodedHash2, flag0)), fvm)));
ContractInformation ci = ContractInformation.RLP_SERIALIZER.deserialize(encoding);
System.out.println(ci);
assertThat(ci).isNotNull();
assertThat(ci.getVmUsed(hash1)).isEqualTo(InternalVmType.AVM);
assertThat(ci.getVmUsed(hash2)).isEqualTo(InternalVmType.FVM);
assertThat(ci.getVmUsed(new byte[] { 1, 2 })).isEqualTo(InternalVmType.UNKNOWN);
assertThat(ci.getInceptionBlocks(hash1)).isEqualTo(Set.of(ByteArrayWrapper.wrap(hash2)));
assertThat(ci.getInceptionBlocks(hash2)).isEqualTo(Set.of(ByteArrayWrapper.wrap(hash1), ByteArrayWrapper.wrap(hash2)));
assertThat(ci.getInceptionBlocks(new byte[HASH_SIZE]).isEmpty()).isTrue();
assertThat(ci.isComplete(hash1, hash2)).isTrue();
assertThat(ci.isComplete(hash1, hash1)).isFalse();
assertThat(ci.isComplete(hash2, hash1)).isTrue();
assertThat(ci.isComplete(hash2, hash2)).isFalse();
assertThat(ci.isComplete(new byte[HASH_SIZE], hash2)).isFalse();
// check that the encoding matches
// note that this might differ if the hash1 would not be less than hash2
assertThat(ContractInformation.RLP_SERIALIZER.serialize(ci)).isEqualTo(encoding);
// constructor version
ByteArrayWrapper key1 = ByteArrayWrapper.wrap(hash1);
ByteArrayWrapper key2 = ByteArrayWrapper.wrap(hash2);
ci = new ContractInformation(key1, InternalVmType.AVM, key2, true);
ci.append(key2, InternalVmType.FVM, key1, true);
ci.append(key2, InternalVmType.FVM, key2, false);
assertThat(ContractInformation.RLP_SERIALIZER.serialize(ci)).isEqualTo(encoding);
}
Aggregations