Search in sources :

Example 86 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method energyLimitMinimum.

@Test
public void energyLimitMinimum() {
    AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), ByteUtils.fromHexString("1"), 21_000L, energyPrice, TransactionTypes.DEFAULT, null);
    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.DROPPED);
    MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), pendingState.getPendingTransactions(), false);
    Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 87 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method testAddPendingTransaction_AVMContractCall_Success.

@Test
public void testAddPendingTransaction_AVMContractCall_Success() throws Exception {
    TestResourceProvider resourceProvider = TestResourceProvider.initializeAndCreateNewProvider(AvmPathManager.getPathOfProjectRootDirectory());
    IAvmResourceFactory resourceFactory = resourceProvider.factoryForVersion1;
    // Successful transaction
    byte[] jar = resourceFactory.newContractFactory().getDeploymentBytes(AvmContract.HELLO_WORLD);
    AionTransaction createTransaction = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), null, BigInteger.ZERO.toByteArray(), jar, 5_000_000, energyPrice, TransactionTypes.AVM_CREATE_CODE, null);
    assertEquals(pendingState.addTransactionFromApiServer(createTransaction), TxResponse.SUCCESS);
    MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), pendingState.getPendingTransactions(), false);
    Pair<ImportResult, AionBlockSummary> connectResult = 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);
    // verify that the output is indeed the contract address
    AionAddress contractAddress = TxUtil.calculateContractAddress(createTransaction);
    assertThat(contractAddress.toByteArray()).isEqualTo(receipt.getTransactionOutput());
    AionAddress contract = new AionAddress(receipt.getTransactionOutput());
    byte[] call = resourceFactory.newStreamingEncoder().encodeOneString("sayHello").getEncoding();
    AionTransaction callTransaction = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), contract, BigInteger.ZERO.toByteArray(), call, 2_000_000, energyPrice, TransactionTypes.DEFAULT, null);
    assertEquals(pendingState.addTransactionFromApiServer(callTransaction), TxResponse.SUCCESS);
}
Also used : IAvmResourceFactory(org.aion.avm.stub.IAvmResourceFactory) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) TestResourceProvider(org.aion.zero.impl.vm.TestResourceProvider) Test(org.junit.Test)

Example 88 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method addLargeNonce.

@Test
public void addLargeNonce() {
    AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.TEN.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 1000_000L, energyPrice, TransactionTypes.DEFAULT, null);
    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.CACHED_NONCE);
    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.ALREADY_CACHED);
}
Also used : AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 89 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method alreadySealed.

@Test
public void alreadySealed() {
    AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 1000_000L, energyPrice, TransactionTypes.DEFAULT, null);
    AionTransaction tx2 = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("2"), ByteUtils.fromHexString("2"), 1000_000L, energyPrice * 2, TransactionTypes.DEFAULT, null);
    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.SUCCESS);
    MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), pendingState.getPendingTransactions(), false);
    Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.ALREADY_SEALED);
    assertEquals(pendingState.addTransactionFromApiServer(tx2), TxResponse.ALREADY_SEALED);
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 90 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method getMockTransaction.

private List<AionTransaction> getMockTransaction(int startNonce, int num, int keyIndex) {
    List<AionTransaction> txn = new ArrayList<>();
    for (int i = startNonce; i < startNonce + num; i++) {
        AionTransaction tx = AionTransaction.create(bundle.privateKeys.get(keyIndex), BigInteger.valueOf(i).toByteArray(), new AionAddress(bundle.privateKeys.get(keyIndex + 1).getAddress()), ByteUtil.hexStringToBytes("1"), ByteUtil.hexStringToBytes("1"), Constant.MIN_ENERGY_CONSUME * 10, energyPrice, TransactionTypes.DEFAULT, null);
        txn.add(tx);
    }
    return txn;
}
Also used : AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction)

Aggregations

AionTransaction (org.aion.base.AionTransaction)437 Test (org.junit.Test)308 AionAddress (org.aion.types.AionAddress)273 BigInteger (java.math.BigInteger)174 MiningBlock (org.aion.zero.impl.types.MiningBlock)149 ArrayList (java.util.ArrayList)127 ImportResult (org.aion.zero.impl.core.ImportResult)115 AionTxExecSummary (org.aion.base.AionTxExecSummary)103 Block (org.aion.zero.impl.types.Block)102 RepositoryCache (org.aion.base.db.RepositoryCache)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)87 AionTxReceipt (org.aion.base.AionTxReceipt)75 ECKey (org.aion.crypto.ECKey)52 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)46 BlockContext (org.aion.zero.impl.types.BlockContext)43 PooledTransaction (org.aion.base.PooledTransaction)40 AccountState (org.aion.base.AccountState)39 Properties (java.util.Properties)35 HashMap (java.util.HashMap)33 DataWord (org.aion.util.types.DataWord)29