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());
}
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();
}
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));
}
}
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);
}
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));
}
Aggregations