use of org.aion.avm.stub.IAvmResourceFactory in project aion by aionnetwork.
the class AvmLogAndInternalTransactionTest method callFireLogs.
public Pair<ImportResult, AionBlockSummary> callFireLogs(AvmVersion version, BigInteger nonce, AionAddress address, AionAddress addressToCall, String methodName) {
IAvmResourceFactory factory = (version == AvmVersion.VERSION_1) ? resourceProvider.factoryForVersion1 : resourceProvider.factoryForVersion2;
byte[] data = factory.newStreamingEncoder().encodeOneString(methodName).encodeOneAddress(addressToCall).getEncoding();
AionTransaction transaction = AionTransaction.create(deployerKey, nonce.toByteArray(), address, new byte[0], data, 2_000_000, minEnergyPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = this.blockchain.createBlock(this.blockchain.getBestBlock(), Collections.singletonList(transaction), false, this.blockchain.getBestBlock().getTimestamp());
return this.blockchain.tryToConnectAndFetchSummary(block);
}
use of org.aion.avm.stub.IAvmResourceFactory in project aion by aionnetwork.
the class AvmBulkTransactionTest method getDeployedStatefulnessCountValue.
private int getDeployedStatefulnessCountValue(AvmVersion version, ECKey sender, BigInteger nonce, AionAddress contract) {
AionTransaction transaction = AionTransaction.create(sender, nonce.toByteArray(), contract, new byte[0], abiEncodeMethodCall(AvmVersion.VERSION_1, "getCount"), 2_000_000, this.energyPrice, TransactionTypes.DEFAULT, null);
AionBlockSummary summary = sendTransactionsInBulkInSingleBlock(Collections.singletonList(transaction));
IAvmResourceFactory factory = (version == AvmVersion.VERSION_1) ? resourceProvider.factoryForVersion1 : resourceProvider.factoryForVersion2;
return factory.newDecoder(summary.getReceipts().get(0).getTransactionOutput()).decodeOneInteger();
}
use of org.aion.avm.stub.IAvmResourceFactory in project aion by aionnetwork.
the class AvmInternalTxTest method testDeployAndCallContract.
@Test
public void testDeployAndCallContract() {
AvmVersion version = AvmVersion.VERSION_1;
TransactionTypeRule.allowAVMContractTransaction();
// Deploy the contract.
byte[] jar = getJarBytes(version);
AionTransaction transaction = AionTransaction.create(deployerKey, new byte[0], null, new byte[0], jar, 5_000_000, minEnergyPrice, TransactionTypes.AVM_CREATE_CODE, null);
MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), Collections.singletonList(transaction), false);
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
// Check the block was imported, the contract has the Avm prefix, and deployment succeeded.
assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
assertThat(receipt.getTransactionOutput()[0]).isEqualTo(AddressSpecs.A0_IDENTIFIER);
assertThat(receipt.isSuccessful()).isTrue();
AionAddress contract = new AionAddress(receipt.getTransactionOutput());
// verify that the output is indeed the contract address
assertThat(TxUtil.calculateContractAddress(transaction)).isEqualTo(contract);
IAvmResourceFactory factory = (version == AvmVersion.VERSION_1) ? resourceProvider.factoryForVersion1 : resourceProvider.factoryForVersion2;
byte[] call = factory.newStreamingEncoder().encodeOneString("recursivelyGetValue").getEncoding();
makeCall(BigInteger.ONE, contract, call);
}
use of org.aion.avm.stub.IAvmResourceFactory in project aion by aionnetwork.
the class TestResourceProvider method initializeAndCreateNewProvider.
/**
* Initializes the test resources for the two avm versions and creates a new provider with
* those loaded resources.
*
* @return a new test provider.
*/
public static TestResourceProvider initializeAndCreateNewProvider(String projectRootDirectory) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
URLClassLoader version1 = newClassLoaderForAvmVersion(projectRootDirectory, AvmVersion.VERSION_1);
URLClassLoader version2 = newClassLoaderForAvmVersion(projectRootDirectory, AvmVersion.VERSION_2);
IAvmResourceFactory factory1 = loadAvmResourceFactory(version1, AvmVersion.VERSION_1);
IAvmResourceFactory factory2 = loadAvmResourceFactory(version2, AvmVersion.VERSION_2);
return new TestResourceProvider(version1, factory1, version2, factory2);
}
use of org.aion.avm.stub.IAvmResourceFactory in project aion by aionnetwork.
the class TestResourceProvider method loadAvmResourceFactory.
/**
* Uses the provided classloader to load a new instance of {@link IAvmResourceFactory} defined
* in the avm version 1 module.
*/
private static IAvmResourceFactory loadAvmResourceFactory(URLClassLoader classLoader, AvmVersion version) throws IllegalAccessException, InstantiationException, ClassNotFoundException, IOException {
Class<?> factory = classLoader.loadClass(version == AvmVersion.VERSION_1 ? AvmDependencyInfo.avmResourceFactoryClassNameVersion1 : AvmDependencyInfo.avmResourceFactoryClassNameVersion2);
IAvmResourceFactory resourceFactory = (IAvmResourceFactory) factory.newInstance();
// Verify that the resources were loaded by the correct classloader.
ClassLoader resourceClassloader = resourceFactory.verifyAndReturnClassloader();
if (resourceClassloader != classLoader) {
classLoader.close();
throw new IllegalStateException("The avm resources were loaded using the wrong classloader: " + resourceClassloader);
}
return resourceFactory;
}
Aggregations