use of org.aion.types.Transaction 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();
}
use of org.aion.types.Transaction 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();
}
use of org.aion.types.Transaction in project aion by aionnetwork.
the class InvokableTransactionTest method encodeDecodeTest.
@Test
public void encodeDecodeTest() {
Transaction tx = Transaction.contractCallTransaction(new AionAddress(key.getAddress()), AddressUtils.ZERO_ADDRESS, new byte[0], BigInteger.ZERO, BigInteger.ZERO, new byte[0], 1L, 1L);
AionAddress executor = AddressUtils.ZERO_ADDRESS;
byte[] invokable = InvokableTxUtil.encodeInvokableTransaction(key, tx.nonce, tx.destinationAddress, tx.value, tx.copyOfTransactionData(), executor);
InternalTransaction tx2 = InvokableTxUtil.decode(invokable, AddressUtils.ZERO_ADDRESS, 21000, 1);
assertNotNull(tx2);
assertEquals(tx.destinationAddress, tx2.destination);
assertEquals(tx.nonce, tx2.senderNonce);
assertEquals(tx.value, tx2.value);
assertArrayEquals(tx.copyOfTransactionData(), tx2.copyOfData());
}
use of org.aion.types.Transaction in project aion by aionnetwork.
the class InvokableTransactionTest method nullExecutorTest.
@Test
public void nullExecutorTest() {
Transaction tx = Transaction.contractCallTransaction(new AionAddress(key.getAddress()), AddressUtils.ZERO_ADDRESS, new byte[0], BigInteger.ZERO, BigInteger.ZERO, new byte[0], 1L, 1L);
byte[] invokable = InvokableTxUtil.encodeInvokableTransaction(key, tx.nonce, tx.destinationAddress, tx.value, tx.copyOfTransactionData(), null);
InternalTransaction tx2 = InvokableTxUtil.decode(invokable, getRandomAddress(), 21000, 1);
assertNotNull(tx2);
assertEquals(tx.destinationAddress, tx2.destination);
assertEquals(tx.nonce, tx2.senderNonce);
assertEquals(tx.value, tx2.value);
assertArrayEquals(tx.copyOfTransactionData(), tx2.copyOfData());
}
use of org.aion.types.Transaction 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();
}
Aggregations