Search in sources :

Example 1 with IAionVirtualMachine

use of org.aion.avm.stub.IAionVirtualMachine in project aion by aionnetwork.

the class AvmProviderTest method testBalanceTransferTransactionVersion2.

@Test
public void testBalanceTransferTransactionVersion2() throws Exception {
    Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
    AvmProvider.enableAvmVersion(AvmVersion.VERSION_2, this.projectRootDir);
    AvmProvider.startAvm(AvmVersion.VERSION_2);
    // Set up the repo and give the sender account some balance.
    RepositoryCache repository = newRepository();
    AionAddress sender = randomAddress();
    AionAddress recipient = randomAddress();
    addBalance(repository, sender, BigInteger.valueOf(1_000_000));
    // Run the transaction.
    RepositoryCache repositoryChild = repository.startTracking();
    IAvmExternalState externalState = newExternalState(AvmVersion.VERSION_2, repositoryChild, newEnergyRules());
    Transaction transaction = newBalanceTransferTransaction(sender, recipient, BigInteger.TEN);
    IAionVirtualMachine avm = AvmProvider.getAvm(AvmVersion.VERSION_2);
    IAvmFutureResult[] futures = avm.run(externalState, new Transaction[] { transaction }, AvmExecutionType.MINING, 0);
    // Assert the result and state changes we expect.
    Assert.assertEquals(1, futures.length);
    TransactionResult result = futures[0].getResult();
    Assert.assertTrue(result.transactionStatus.isSuccess());
    Assert.assertEquals(BigInteger.TEN, repositoryChild.getBalance(recipient));
    AvmProvider.shutdownAvm(AvmVersion.VERSION_2);
    AvmProvider.disableAvmVersion(AvmVersion.VERSION_2);
    AvmProvider.releaseLock();
}
Also used : IAvmExternalState(org.aion.avm.stub.IAvmExternalState) TransactionResult(org.aion.types.TransactionResult) AionAddress(org.aion.types.AionAddress) Transaction(org.aion.types.Transaction) IAvmFutureResult(org.aion.avm.stub.IAvmFutureResult) RepositoryCache(org.aion.base.db.RepositoryCache) IAionVirtualMachine(org.aion.avm.stub.IAionVirtualMachine) Test(org.junit.Test)

Example 2 with IAionVirtualMachine

use of org.aion.avm.stub.IAionVirtualMachine in project aion by aionnetwork.

the class AvmProviderTest method testBalanceTransferTransactionVersion2WithCoinbaseLock.

@Test
public void testBalanceTransferTransactionVersion2WithCoinbaseLock() throws Exception {
    Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
    AvmProvider.enableAvmVersion(AvmVersion.VERSION_2, this.projectRootDir);
    AvmProvider.startAvm(AvmVersion.VERSION_2, true);
    // Set up the repo and give the sender account some balance.
    RepositoryCache repository = newRepository();
    AionAddress sender = randomAddress();
    AionAddress recipient = randomAddress();
    addBalance(repository, sender, BigInteger.valueOf(1_000_000));
    // Run the transaction.
    RepositoryCache repositoryChild = repository.startTracking();
    IAvmExternalState externalState = newExternalState(AvmVersion.VERSION_2, repositoryChild, newEnergyRules());
    Transaction transaction = newBalanceTransferTransaction(sender, recipient, BigInteger.TEN);
    IAionVirtualMachine avm = AvmProvider.getAvm(AvmVersion.VERSION_2);
    IAvmFutureResult[] futures = avm.run(externalState, new Transaction[] { transaction }, AvmExecutionType.MINING, 0);
    // Assert the result and state changes we expect.
    Assert.assertEquals(1, futures.length);
    TransactionResult result = futures[0].getResult();
    Assert.assertTrue(result.transactionStatus.isSuccess());
    Assert.assertEquals(BigInteger.TEN, repositoryChild.getBalance(recipient));
    AvmProvider.shutdownAvm(AvmVersion.VERSION_2);
    AvmProvider.disableAvmVersion(AvmVersion.VERSION_2);
    AvmProvider.releaseLock();
}
Also used : IAvmExternalState(org.aion.avm.stub.IAvmExternalState) TransactionResult(org.aion.types.TransactionResult) AionAddress(org.aion.types.AionAddress) Transaction(org.aion.types.Transaction) IAvmFutureResult(org.aion.avm.stub.IAvmFutureResult) RepositoryCache(org.aion.base.db.RepositoryCache) IAionVirtualMachine(org.aion.avm.stub.IAionVirtualMachine) Test(org.junit.Test)

Example 3 with IAionVirtualMachine

use of org.aion.avm.stub.IAionVirtualMachine in project aion by aionnetwork.

the class AvmProviderTest method testBalanceTransferTransactionVersion1.

@Test
public void testBalanceTransferTransactionVersion1() throws Exception {
    Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
    AvmProvider.enableAvmVersion(AvmVersion.VERSION_1, this.projectRootDir);
    AvmProvider.startAvm(AvmVersion.VERSION_1);
    // Set up the repo and give the sender account some balance.
    RepositoryCache repository = newRepository();
    AionAddress sender = randomAddress();
    AionAddress recipient = randomAddress();
    addBalance(repository, sender, BigInteger.valueOf(1_000_000));
    // Run the transaction.
    RepositoryCache repositoryChild = repository.startTracking();
    IAvmExternalState externalState = newExternalState(AvmVersion.VERSION_1, repositoryChild, newEnergyRules());
    Transaction transaction = newBalanceTransferTransaction(sender, recipient, BigInteger.TEN);
    IAionVirtualMachine avm = AvmProvider.getAvm(AvmVersion.VERSION_1);
    IAvmFutureResult[] futures = avm.run(externalState, new Transaction[] { transaction }, AvmExecutionType.MINING, 0);
    // Assert the result and state changes we expect.
    Assert.assertEquals(1, futures.length);
    TransactionResult result = futures[0].getResult();
    Assert.assertTrue(result.transactionStatus.isSuccess());
    Assert.assertEquals(BigInteger.TEN, repositoryChild.getBalance(recipient));
    AvmProvider.shutdownAvm(AvmVersion.VERSION_1);
    AvmProvider.disableAvmVersion(AvmVersion.VERSION_1);
    AvmProvider.releaseLock();
}
Also used : IAvmExternalState(org.aion.avm.stub.IAvmExternalState) TransactionResult(org.aion.types.TransactionResult) AionAddress(org.aion.types.AionAddress) Transaction(org.aion.types.Transaction) IAvmFutureResult(org.aion.avm.stub.IAvmFutureResult) RepositoryCache(org.aion.base.db.RepositoryCache) IAionVirtualMachine(org.aion.avm.stub.IAionVirtualMachine) Test(org.junit.Test)

Example 4 with IAionVirtualMachine

use of org.aion.avm.stub.IAionVirtualMachine in project aion by aionnetwork.

the class AvmTransactionExecutor method invokeAvm.

/**
 * Invokes the avm, whichever is the specified versionToUse, to run the given transactions under
 * the given circumstances. Returns a list of future results pertaining to the transactions.
 *
 * @param versionToUse The version of the avm to use.
 * @param repository The current world state.
 * @param blockDifficulty The block difficulty.
 * @param blockNumber The current block number.
 * @param blockTimestamp The block timestamp.
 * @param blockEnergyLimit The energy limit of the block.
 * @param miner The miner address.
 * @param transactions The transactions to execute.
 * @param allowNonceIncrement Whether to increment the sender's nonce or not.
 * @param isLocalCall Whether this is a local call (ie. is to cause no state changes).
 * @param executionType The avm execution type.
 * @param cachedBlockNumber The cached block number.
 * @param unityForkEnabled The unityFork feature enabled/disabled.
 * @return the future execution results.
 */
private static IAvmFutureResult[] invokeAvm(AvmVersion versionToUse, RepositoryCache repository, BigInteger blockDifficulty, long blockNumber, long blockTimestamp, long blockEnergyLimit, AionAddress miner, AionTransaction[] transactions, boolean allowNonceIncrement, boolean isLocalCall, AvmExecutionType executionType, long cachedBlockNumber, boolean unityForkEnabled) {
    IAvmExternalState externalState = AvmProvider.newExternalStateBuilder(versionToUse).withRepository(repository.startTracking()).withMiner(miner).withDifficulty(blockDifficulty).withBlockNumber(blockNumber).withBlockTimestamp(blockTimestamp).withBlockEnergyLimit(blockEnergyLimit).withEnergyRules(unityForkEnabled ? AvmConfigurations.getEnergyLimitRulesAfterUnityFork() : AvmConfigurations.getEnergyLimitRules()).allowNonceIncrement(allowNonceIncrement).isLocalCall(isLocalCall).build();
    IAionVirtualMachine avm = AvmProvider.getAvm(versionToUse);
    return avm.run(externalState, toAionTypesTransactions(transactions), executionType, cachedBlockNumber);
}
Also used : IAvmExternalState(org.aion.avm.stub.IAvmExternalState) IAionVirtualMachine(org.aion.avm.stub.IAionVirtualMachine)

Aggregations

IAionVirtualMachine (org.aion.avm.stub.IAionVirtualMachine)4 IAvmExternalState (org.aion.avm.stub.IAvmExternalState)4 IAvmFutureResult (org.aion.avm.stub.IAvmFutureResult)3 RepositoryCache (org.aion.base.db.RepositoryCache)3 AionAddress (org.aion.types.AionAddress)3 Transaction (org.aion.types.Transaction)3 TransactionResult (org.aion.types.TransactionResult)3 Test (org.junit.Test)3