use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class InternalTransactionTest method testLogs.
@Test
public void testLogs() throws InterruptedException {
String contractA = "0x605060405234156100105760006000fd5b610015565b61013c806100246000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680632d7df21a146100335761002d565b60006000fd5b341561003f5760006000fd5b61006660048080806010013590359091602001909192908035906010019091905050610068565b005b7fc1599bd9a91e57420b9b93745d7475dc054736a3f2becd4f08b450b7012e125760405160405180910390a1828282600060405180806f662829000000000000000000000000008152601001506003019050604051809103902090506c01000000000000000000000000900491906040518363ffffffff166c01000000000000000000000000028152600401600060405180830381858a8a89f195505050505050505b5050505600a165627a7a723058205e51c42347e4353247e8419ef6cda02250d358868e2cb3782d0d5d74065f2ef70029";
String contractB = "0x605060405234156100105760006000fd5b610015565b60cb806100236000396000f30060506040526000356c01000000000000000000000000900463ffffffff16806326121ff014603157602b565b60006000fd5b3415603c5760006000fd5b60426044565b005b600060007f45b3fe4256d6d198dc4c34457a04e8c048ce54df933a93061f1a0e386b52f7a260405160405180910390a160009150600090505b6103e8811015609a57808201915081505b8080600101915050607d565b5b50505600a165627a7a72305820b2bf8aef36001079d347d250e50b098ad52629336644a841d19db288f30667470029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
// ======================
// DEPLOY
// ======================
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx1 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx2 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractB), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx1, tx2), false);
ImportResult result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress addressA = TxUtil.calculateContractAddress(tx1);
System.out.println("contract A = " + addressA);
AionAddress addressB = TxUtil.calculateContractAddress(tx2);
System.out.println("contract B = " + addressB);
Thread.sleep(1000);
// ======================
// CALL B
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx3 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressB, new byte[0], ByteUtil.hexStringToBytes("0x26121ff0"), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx3), false);
result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionTxInfo info = bc.getTransactionInfo(tx3.getTransactionHash());
System.out.println(info.getReceipt());
assertEquals(1, info.getReceipt().getLogInfoList().size());
Thread.sleep(1000);
// ======================
// CALL A (calls B, 80k)
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx4 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressA, new byte[0], ByteUtil.merge(ByteUtil.hexStringToBytes("0x2d7df21a"), addressB.toByteArray(), new DataWord(80_000).getData()), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx4), false);
result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
info = bc.getTransactionInfo(tx4.getTransactionHash());
System.out.println(info.getReceipt());
assertEquals(2, info.getReceipt().getLogInfoList().size());
Thread.sleep(1000);
// ======================
// CALL A (calls B, 20k)
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx6 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressA, new byte[0], ByteUtil.merge(ByteUtil.hexStringToBytes("0x2d7df21a"), addressB.toByteArray(), new DataWord(20_000).getData()), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx6), false);
result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
info = bc.getTransactionInfo(tx6.getTransactionHash());
System.out.println(info.getReceipt());
assertEquals(1, info.getReceipt().getLogInfoList().size());
Thread.sleep(1000);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class MultiVersionAvmTest method testCallInBothAvmVersions.
/**
* We test deploying & calling the same contract in version 1 and 2. We expect the same result
* each time.
*/
@Test
public void testCallInBothAvmVersions() {
Assert.assertEquals(0, this.blockchain.getBestBlock().getNumber());
// Ensure we are at a block height where avm version 1 is enabled, then deploy.
buildBlockchainToHeight(BLOCK_VERSION1_ENABLED);
AionAddress contractForVersion1 = deployHelloWorldContract(AvmVersion.VERSION_1, BigInteger.ZERO);
AionTransaction transactionForVersion1 = makeHelloWorldCallTransaction(AvmVersion.VERSION_1, BigInteger.ONE, contractForVersion1);
Block parentBlock = this.blockchain.getBestBlock();
MiningBlock block = this.blockchain.createBlock(parentBlock, Collections.singletonList(transactionForVersion1), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
Assert.assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
Assert.assertEquals(1, connectResult.getRight().getReceipts().size());
Assert.assertTrue(connectResult.getRight().getReceipts().get(0).isSuccessful());
// Now, climb to a block height where avm version 2 is enabled and deploy.
buildBlockchainToHeight(BLOCK_VERSION2_ENABLED);
AionAddress contractForVersion2 = deployHelloWorldContract(AvmVersion.VERSION_2, BigInteger.TWO);
AionTransaction transactionForVersion2 = makeHelloWorldCallTransaction(AvmVersion.VERSION_2, BigInteger.valueOf(3), contractForVersion2);
parentBlock = this.blockchain.getBestBlock();
block = this.blockchain.createBlock(parentBlock, Collections.singletonList(transactionForVersion2), false, parentBlock.getTimestamp());
connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
Assert.assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
Assert.assertEquals(1, connectResult.getRight().getReceipts().size());
Assert.assertTrue(connectResult.getRight().getReceipts().get(0).isSuccessful());
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class VMTxStateAlignTest method testDeployAndCallContractStatesAlign.
@Test
public void testDeployAndCallContractStatesAlign() throws IOException {
List<AionTransaction> txList = new ArrayList<>();
List<AionAddress> deployAddr = new ArrayList<>();
for (int i = 0; i < this.deployerKeys.size() && i < deployerNum; i++) {
ECKey senderKey = this.deployerKeys.get(i);
txList.add(makeFvmContractCreateTransaction(senderKey, BigInteger.ZERO));
deployAddr.add(TxUtil.calculateContractAddress(txList.get(i)));
}
MiningBlock deplayBlock = genNewBlock(txList, blockchainWoAVM);
tryImportNewBlock(blockchainWoAVM, deplayBlock);
txList.clear();
ECKey sender = this.deployerKeys.get(deployerKeys.size() - 1);
txList.add(makePrecompiledContractTransaction(sender, BigInteger.ZERO));
for (int i = 0; i < this.deployerKeys.size() && i < deployerNum; i++) {
ECKey senderKey = this.deployerKeys.get(i);
txList.add(makeFvmContractCallTransaction(senderKey, BigInteger.ONE, deployAddr.get(i)));
}
MiningBlock callBlock = genNewBlock(txList, blockchainWoAVM);
tryImportNewBlock(blockchainWoAVM, callBlock);
// Does not initial in the setup call due to the avmenable in the StandaloneBlockchain is a
// static variable.
StandaloneBlockchain.Bundle bundleAVM = new StandaloneBlockchain.Builder().withDefaultAccounts(deployerKeys).withAvmEnabled().withValidatorConfiguration("simple").build();
StandaloneBlockchain blockchainWithAVM = bundleAVM.bc;
tryImportNewBlock(blockchainWithAVM, deplayBlock);
tryImportNewBlock(blockchainWithAVM, callBlock);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class ApiAion method getTransactionByBlockNumberAndIndex.
protected TransactionWithBlockInfo getTransactionByBlockNumberAndIndex(long blkNr, long index) {
Block pBlk = this.getBlock(blkNr);
if (pBlk == null) {
if (LOG.isErrorEnabled()) {
LOG.error("ApiAion.getTransactionByBlockNumberAndIndex - can't find the block by the block number");
}
return null;
}
List<AionTransaction> txList = pBlk.getTransactionsList();
AionTransaction tx = txList.get((int) index);
if (tx == null) {
if (LOG.isErrorEnabled()) {
LOG.error("Can't find the transaction by the txIndex");
}
return null;
}
TxRecpt receipt = this.getTransactionReceipt(tx.getTransactionHash());
// The receipt shouldn't be null!
if (receipt == null) {
throw new NullPointerException();
}
return new TransactionWithBlockInfo(tx, pBlk.getHash(), pBlk.getNumber(), index, receipt.nrgUsed);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class ApiAion method doCall.
protected byte[] doCall(ArgTxCall _params) {
AionTransaction tx = AionTransaction.createWithoutKey(_params.getNonce().toByteArray(), _params.getFrom() == null ? AddressUtils.ZERO_ADDRESS : _params.getFrom(), _params.getTo(), _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice(), _params.getType(), null);
AionTxReceipt rec = this.ac.callConstant(tx, this.ac.getAionHub().getBlockchain().getBestBlock());
return rec.getTransactionOutput();
}
Aggregations