use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AvmBulkTransactionTest method deployEmptyContract.
/**
* Ensures that contracts with empty jars cannot be deployed on the AVM.
*/
@Test
public void deployEmptyContract() {
AionTransaction deployEmptyContractTx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), null, BigInteger.ZERO.toByteArray(), new byte[0], 5_000_000L, 10_123_456_789L, TransactionTypes.AVM_CREATE_CODE, null);
Block parentBlock = blockchain.getBestBlock();
MiningBlock block = blockchain.createBlock(parentBlock, List.of(deployEmptyContractTx), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
// ensure block was imported
assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
// ensure the tx failed
AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
System.out.println(receipt);
assertEquals(receipt.isSuccessful(), false);
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class Benchmark method validateTransactions.
private static List<AionTxReceipt> validateTransactions(List<AionTransaction> txs) {
long t1 = System.currentTimeMillis();
List<AionTxReceipt> list = new ArrayList<>();
for (AionTransaction tx : txs) {
assertNotNull(tx.getTransactionHash());
assertEquals(32, tx.getTransactionHash().length);
assertNotNull(tx.getValue());
assertEquals(16, tx.getValue().length);
assertNotNull(tx.getData());
assertNotNull(tx.getSenderAddress());
assertNotNull(tx.getDestinationAddress());
assertNotNull(tx.getNonce());
assertEquals(16, tx.getNonce().length);
assertTrue(tx.getEnergyLimit() > 0);
assertTrue(tx.getEnergyPrice() > 0);
assertTrue(SignatureFac.verify(tx.getTransactionHashWithoutSignature(), tx.getSignature()));
}
long t2 = System.currentTimeMillis();
timeValidateTransactions = t2 - t1;
return list;
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AvmBulkTransactionTest method importBlockWithContractAndCallsForBothVMs.
/**
* Ensures that a block containing the transactions described below is processed correctly:
*
* <ol>
* <li>an FVM contract deployment,
* <li>an AVM contract deployment,
* <li>an FVM call to the first contract,
* <li>an AVM call to the second contract.
* </ol>
*/
@Test
public void importBlockWithContractAndCallsForBothVMs() {
BigInteger expectedNonce = getNonce(deployerKey);
BigInteger initialBalance = getBalance(deployerKey);
List<AionTransaction> transactions = new ArrayList<>();
// Deploy FVM contract with code.
String contractCode = "0x605060405234156100105760006000fd5b5b600a600060005081909090555060006000505460016000506000600060005054815260100190815260100160002090506000508190909055506064600260005060000160005081909090555060c8600260005060010160005081909090555060026000506001016000505460016000506000600260005060000160005054815260100190815260100160002090506000508190909055505b6100ae565b610184806100bd6000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680631677b0ff14610049578063209652551461007657806362eb702a146100a057610043565b60006000fd5b34156100555760006000fd5b61007460048080359060100190919080359060100190919050506100c4565b005b34156100825760006000fd5b61008a610111565b6040518082815260100191505060405180910390f35b34156100ac5760006000fd5b6100c26004808035906010019091905050610123565b005b8160026000506000016000508190909055508060026000506001016000508190909055508082016001600050600084815260100190815260100160002090506000508190909055505b5050565b60006000600050549050610120565b90565b806000600050819090905550600181016001600050600083815260100190815260100160002090506000508190909055505b505600a165627a7a723058205b6e690d70d3703337452467437dc7c4e863ee4ad34b24cc516e2afa71e334700029";
AionTransaction deployTxFVM = AionTransaction.create(deployerKey, expectedNonce.toByteArray(), null, BigInteger.ZERO.toByteArray(), ByteUtil.hexStringToBytes(contractCode), 5_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
AionAddress fvmContract = TxUtil.calculateContractAddress(deployTxFVM);
transactions.add(deployTxFVM);
expectedNonce = expectedNonce.add(BigInteger.ONE);
// Deploy AVM contract.
AionTransaction deployTxAVM = makeAvmContractCreateTransaction(deployerKey, expectedNonce);
AionAddress avmContract = TxUtil.calculateContractAddress(deployTxAVM);
transactions.add(deployTxAVM);
expectedNonce = expectedNonce.add(BigInteger.ONE);
// Call FVM contract with code.
AionTransaction contractCallTx = AionTransaction.create(deployerKey, expectedNonce.toByteArray(), fvmContract, BigInteger.ZERO.toByteArray(), Hex.decode("62eb702a00000000000000000000000000000006"), 2_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
transactions.add(contractCallTx);
expectedNonce = expectedNonce.add(BigInteger.ONE);
// Call AVM contract.
transactions.add(makeAvmContractCallTransaction(deployerKey, expectedNonce, avmContract));
expectedNonce = expectedNonce.add(BigInteger.ONE);
// Process the 4 transactions in a single block.
AionBlockSummary blockSummary = sendTransactionsInBulkInSingleBlock(transactions);
// Verify that all transactions were successful.
assertThat(blockSummary.getSummaries().size()).isEqualTo(4);
BigInteger expectedBalance = initialBalance;
for (AionTxExecSummary transactionSummary : blockSummary.getSummaries()) {
AionTxReceipt receipt = transactionSummary.getReceipt();
assertThat(receipt.isSuccessful()).isTrue();
// Compute the expected balance.
expectedBalance = expectedBalance.subtract(BigInteger.valueOf(receipt.getEnergyUsed()).multiply(BigInteger.valueOf(energyPrice)));
}
// Verify that the code and storage of the FVM contract have changed.
AccountState fvm = (AccountState) blockchain.getRepository().startTracking().getAccountState(fvmContract);
assertThat(fvm.getStateRoot()).isNotEqualTo(EMPTY_TRIE_HASH);
assertThat(fvm.getCodeHash()).isNotEqualTo(EMPTY_DATA_HASH);
assertEquals(expectedBalance, getBalance(deployerKey));
assertEquals(expectedNonce, getNonce(deployerKey));
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AvmBulkTransactionTest method importBlockWithContractAndCallsForFvmOnTopOfAddressWithBalanceBeforeFork040.
@Test
public void importBlockWithContractAndCallsForFvmOnTopOfAddressWithBalanceBeforeFork040() {
// Disable Fork040.
blockchain.forkUtility.disable040Fork();
BigInteger initialNonce = getNonce(deployerKey);
// One transaction will be made to add balance to the expected contract address before the contract deployment.
BigInteger expectedNonce = initialNonce.add(BigInteger.ONE);
BigInteger initialBalance = getBalance(deployerKey);
// Deploy FVM contract.
String contractCode = "0x605060405234156100105760006000fd5b5b600a600060005081909090555060006000505460016000506000600060005054815260100190815260100160002090506000508190909055506064600260005060000160005081909090555060c8600260005060010160005081909090555060026000506001016000505460016000506000600260005060000160005054815260100190815260100160002090506000508190909055505b6100ae565b610184806100bd6000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680631677b0ff14610049578063209652551461007657806362eb702a146100a057610043565b60006000fd5b34156100555760006000fd5b61007460048080359060100190919080359060100190919050506100c4565b005b34156100825760006000fd5b61008a610111565b6040518082815260100191505060405180910390f35b34156100ac5760006000fd5b6100c26004808035906010019091905050610123565b005b8160026000506000016000508190909055508060026000506001016000508190909055508082016001600050600084815260100190815260100160002090506000508190909055505b5050565b60006000600050549050610120565b90565b806000600050819090905550600181016001600050600083815260100190815260100160002090506000508190909055505b505600a165627a7a723058205b6e690d70d3703337452467437dc7c4e863ee4ad34b24cc516e2afa71e334700029";
AionTransaction deployTxFVM = AionTransaction.create(deployerKey, expectedNonce.toByteArray(), null, BigInteger.ZERO.toByteArray(), ByteUtil.hexStringToBytes(contractCode), 5_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
AionAddress fvmContract = TxUtil.calculateContractAddress(deployTxFVM);
expectedNonce = expectedNonce.add(BigInteger.ONE);
// First send balance to the future contract.
AionTransaction balanceTransferToFVM = AionTransaction.create(deployerKey, initialNonce.toByteArray(), fvmContract, BigInteger.TEN.toByteArray(), new byte[0], 2_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
AionBlockSummary blockSummary = sendTransactionsInBulkInSingleBlock(List.of(balanceTransferToFVM));
// Verify that the transaction was successful.
assertThat(blockSummary.getSummaries().size()).isEqualTo(1);
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertThat(receipt.isSuccessful()).isTrue();
BigInteger expectedBalance = initialBalance.subtract(BigInteger.TEN).subtract(BigInteger.valueOf(receipt.getEnergyUsed()).multiply(BigInteger.valueOf(energyPrice)));
AccountState contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(fvmContract);
assertThat(contractState.getBalance()).isEqualTo(BigInteger.TEN);
assertThat(contractState.getStateRoot()).isEqualTo(EMPTY_TRIE_HASH);
assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
// Next, process the deploy transaction.
blockSummary = sendTransactionsInBulkInSingleBlock(List.of(deployTxFVM));
// Verify that the transaction fails when fork 040 is not enabled.
assertThat(blockSummary.getSummaries().size()).isEqualTo(1);
receipt = blockSummary.getSummaries().get(0).getReceipt();
assertThat(receipt.isSuccessful()).isFalse();
assertThat(receipt.getEnergyUsed()).isEqualTo(deployTxFVM.getEnergyLimit());
contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(fvmContract);
assertThat(contractState.getBalance()).isEqualTo(BigInteger.TEN);
assertThat(contractState.getStateRoot()).isEqualTo(EMPTY_TRIE_HASH);
assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
expectedBalance = expectedBalance.subtract(BigInteger.valueOf(receipt.getEnergyUsed()).multiply(BigInteger.valueOf(energyPrice)));
assertThat(getBalance(deployerKey)).isEqualTo(expectedBalance);
assertThat(getNonce(deployerKey)).isEqualTo(expectedNonce);
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class AvmInternalTxTest method testDeployAndCallContract.
@Test
public void testDeployAndCallContract() {
AvmVersion version = AvmVersion.VERSION_1;
TransactionTypeRule.allowAVMContractTransaction();
// Deploy the contract.
byte[] jar = getJarBytes(version);
AionTransaction transaction = AionTransaction.create(deployerKey, new byte[0], null, new byte[0], jar, 5_000_000, minEnergyPrice, TransactionTypes.AVM_CREATE_CODE, null);
MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), Collections.singletonList(transaction), false);
Pair<ImportResult, AionBlockSummary> connectResult = this.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);
assertThat(receipt.getTransactionOutput()[0]).isEqualTo(AddressSpecs.A0_IDENTIFIER);
assertThat(receipt.isSuccessful()).isTrue();
AionAddress contract = new AionAddress(receipt.getTransactionOutput());
// verify that the output is indeed the contract address
assertThat(TxUtil.calculateContractAddress(transaction)).isEqualTo(contract);
IAvmResourceFactory factory = (version == AvmVersion.VERSION_1) ? resourceProvider.factoryForVersion1 : resourceProvider.factoryForVersion2;
byte[] call = factory.newStreamingEncoder().encodeOneString("recursivelyGetValue").getEncoding();
makeCall(BigInteger.ONE, contract, call);
}
Aggregations