use of org.aion.db.impl.ByteArrayKeyValueStore 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.db.impl.ByteArrayKeyValueStore in project aion by aionnetwork.
the class InnerContractDetailsTest method testCommitToStored_withCodeOnFvm.
@Test
public void testCommitToStored_withCodeOnFvm() {
AionAddress address = mock(AionAddress.class);
ByteArrayKeyValueStore db = mock(XorDataSource.class);
FvmContractDetails parent = new FvmContractDetails(address, db);
byte[] code = RandomUtils.nextBytes(100);
InnerContractDetails child = new InnerContractDetails(null);
child.setCode(code);
assertThat(child.isDirty()).isTrue();
assertThat(parent.getVmType()).isEqualTo(InternalVmType.FVM);
child.commitTo(parent);
assertThat(parent.getVmType()).isEqualTo(InternalVmType.FVM);
assertThat(parent.getCode(h256(code))).isEqualTo(code);
assertThat(parent.isDirty()).isTrue();
}
use of org.aion.db.impl.ByteArrayKeyValueStore in project aion by aionnetwork.
the class InnerContractDetailsTest method testCommitToStored_withCodeOnAvm.
@Test
public void testCommitToStored_withCodeOnAvm() {
AionAddress address = mock(AionAddress.class);
ByteArrayKeyValueStore db = mock(XorDataSource.class);
AvmContractDetails parent = new AvmContractDetails(address, db, db);
byte[] code = RandomUtils.nextBytes(100);
InnerContractDetails child = new InnerContractDetails(null);
child.setCode(code);
assertThat(child.isDirty()).isTrue();
assertThat(parent.getVmType()).isEqualTo(InternalVmType.AVM);
child.commitTo(parent);
assertThat(parent.getVmType()).isEqualTo(InternalVmType.AVM);
assertThat(parent.getCode(h256(code))).isEqualTo(code);
assertThat(parent.isDirty()).isTrue();
}
use of org.aion.db.impl.ByteArrayKeyValueStore in project aion by aionnetwork.
the class InnerContractDetailsTest method testCommitToStored_withObjectGraph.
@Test
public void testCommitToStored_withObjectGraph() {
AionAddress address = mock(AionAddress.class);
ByteArrayKeyValueStore db = mock(XorDataSource.class);
AvmContractDetails parent = new AvmContractDetails(address, db, db);
byte[] graph = RandomUtils.nextBytes(100);
InnerContractDetails child = new InnerContractDetails(null);
child.setObjectGraph(graph);
assertThat(child.isDirty()).isTrue();
child.commitTo(parent);
assertThat(parent.getVmType()).isEqualTo(InternalVmType.AVM);
assertThat(parent.getObjectGraph()).isEqualTo(graph);
assertThat(parent.isDirty()).isTrue();
}
use of org.aion.db.impl.ByteArrayKeyValueStore in project aion by aionnetwork.
the class DetailsDataStore method getSnapshot.
/**
* Fetches the ContractDetails with the given root.
*
* @param vm the virtual machine used at contract deployment
* @param key the contract address as bytes
* @param storageRoot the requested storage root
* @return a snapshot of the contract details with the requested root
*/
public synchronized StoredContractDetails getSnapshot(InternalVmType vm, byte[] key, byte[] storageRoot) {
Optional<byte[]> rawDetails = detailsSrc.get(key);
if (rawDetails.isPresent()) {
// decode raw details and return snapshot
RLPContractDetails rlpDetails = fromEncoding(rawDetails.get());
ByteArrayKeyValueStore storage = createStorageSource(rlpDetails.address);
if (vm == InternalVmType.AVM) {
ByteArrayKeyValueStore graph = createGraphSource(rlpDetails.address);
return AvmContractDetails.decodeAtRoot(rlpDetails, storage, graph, storageRoot);
} else if (vm == InternalVmType.FVM) {
return FvmContractDetails.decodeAtRoot(rlpDetails, storage, storageRoot);
} else {
// There is no need to instantiate a ContractDetails object.
return null;
}
} else {
return null;
}
}
Aggregations