Search in sources :

Example 51 with AionTransaction

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

the class AlternatingVmBlockTest method testOverflowBlockWithAlternatingVms2.

/**
 * Tests a special case of the alternating transactions: the first 14 don't overflow the limit,
 * the 15th does overflow it, but the 16th can fit into it.
 *
 * <p>The problem: the nonce no longer makes any sense because the 15th transaction is kicked
 * out.
 */
@Test
public void testOverflowBlockWithAlternatingVms2() throws Exception {
    List<AionTransaction> alternatingTransactions = makeAlternatingAvmFvmContractCreateTransactions(AvmVersion.VERSION_1, 16, BigInteger.ZERO);
    Block parentBlock = blockchain.getBestBlock();
    MiningBlock block = blockchain.createBlock(parentBlock, alternatingTransactions, false, parentBlock.getTimestamp());
    Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
    // A correct block is produced but it does not contain all of the transactions. The second
    // last transaction is rejected
    // because it would cause the block energy limit to be exceeded, and the last transaction
    // now has an invalid nonce since
    // the previous transaction was rejected, so neither of these are included in the block.
    assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
    assertEquals(14, connectResult.getRight().getReceipts().size());
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 52 with AionTransaction

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

the class AvmHelloWorldTest method testDeployAndCallContractInTheSameBlock.

@Test
public void testDeployAndCallContractInTheSameBlock() {
    TransactionTypeRule.allowAVMContractTransaction();
    // Deploy the contract.
    byte[] jar = getJarBytes(AvmVersion.VERSION_1);
    AionTransaction transaction = AionTransaction.create(deployerKey, new byte[0], null, new byte[0], jar, 5_000_000, energyPrice, TransactionTypes.AVM_CREATE_CODE, null);
    List<AionTransaction> ls = new ArrayList<>();
    ls.add(transaction);
    byte[] call = getCallArguments(AvmVersion.VERSION_1);
    AionTransaction transaction2 = AionTransaction.create(deployerKey, BigInteger.ONE.toByteArray(), TxUtil.calculateContractAddress(transaction), new byte[0], call, 2_000_000, energyPrice, TransactionTypes.DEFAULT, null);
    ls.add(transaction2);
    MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), ls, false);
    Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
    assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
    assertThat(connectResult.getRight().getReceipts().size() == 2);
    // Check the block was imported, the contract has the Avm prefix, and deployment succeeded.
    AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
    assertThat(receipt.getTransactionOutput()[0]).isEqualTo(AddressSpecs.A0_IDENTIFIER);
    assertThat(receipt.isSuccessful()).isTrue();
    // Check the call success
    receipt = connectResult.getRight().getReceipts().get(1);
    assertThat(receipt.isSuccessful()).isTrue();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 53 with AionTransaction

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

the class SolidityTypeTest method testStaticArray2.

@Test
public void testStaticArray2() throws Exception {
    List<byte[]> x = new ArrayList<>();
    x.add(Hex.decode("1122334455667788112233445566778811223344"));
    x.add(Hex.decode("2122334455667788112233445566778811223344"));
    x.add(Hex.decode("3122334455667788112233445566778811223344"));
    SolidityType type = new StaticArrayType("bytes20[3]");
    byte[] params = type.encode(x);
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("e4bef5c9"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    Object[] decoded = (Object[]) type.decode(receipt.getTransactionOutput());
    for (Object d : decoded) {
        System.out.println(Hex.toHexString((byte[]) d));
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryCache(org.aion.base.db.RepositoryCache) StaticArrayType(org.aion.solidity.SolidityType.StaticArrayType) AionTransaction(org.aion.base.AionTransaction) SolidityType(org.aion.solidity.SolidityType) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 54 with AionTransaction

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

the class SolidityTypeTest method createDummyBlock.

private static MiningBlock createDummyBlock() {
    byte[] parentHash = new byte[32];
    byte[] coinbase = RandomUtils.nextBytes(AionAddress.LENGTH);
    byte[] logsBloom = new byte[256];
    byte[] difficulty = new DataWord(0x1000000L).getData();
    long number = 1;
    long timestamp = System.currentTimeMillis() / 1000;
    byte[] extraData = new byte[0];
    byte[] nonce = new byte[32];
    byte[] receiptsRoot = new byte[32];
    byte[] transactionsRoot = new byte[32];
    byte[] stateRoot = new byte[32];
    List<AionTransaction> transactionsList = Collections.emptyList();
    byte[] solutions = new byte[1408];
    // TODO: set a dummy limit of 5000000 for now
    return new MiningBlock(parentHash, new AionAddress(coinbase), logsBloom, difficulty, number, timestamp, extraData, nonce, receiptsRoot, transactionsRoot, stateRoot, transactionsList, solutions, 0, 5000000);
}
Also used : AionAddress(org.aion.types.AionAddress) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 55 with AionTransaction

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

the class SolidityTypeTest method testBytes1.

@Test
public void testBytes1() throws Exception {
    byte[] x = Hex.decode("1122334455667788");
    SolidityType type = new BytesType();
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("61cb5a01"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    assertArrayEquals(x, (byte[]) type.decode(receipt.getTransactionOutput(), 16));
}
Also used : RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) SolidityType(org.aion.solidity.SolidityType) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) BytesType(org.aion.solidity.SolidityType.BytesType) Test(org.junit.Test)

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