use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class ResponseBlocks method encode.
@Override
public byte[] encode() {
byte[][] toEncode = new byte[this.blocks.size()][];
int i = 0;
for (Block block : blocks) {
toEncode[i] = block.getEncoded();
i++;
}
return RLP.encodeList(toEncode);
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class StatefulnessTest method sendTransactions.
private AionTxReceipt sendTransactions(AionTransaction... transactions) {
Block parentBlock = this.blockchain.getBestBlock();
MiningBlock block = this.blockchain.createBlock(parentBlock, Arrays.asList(transactions), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
return connectResult.getRight().getReceipts().get(0);
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class FvmBulkTransactionTest method sendTransactionsInBulkInSingleBlock.
private AionBlockSummary sendTransactionsInBulkInSingleBlock(List<AionTransaction> transactions) {
Block parentBlock = this.blockchain.getBestBlock();
MiningBlock block = this.blockchain.createBlock(parentBlock, transactions, false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
return connectResult.getRight();
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class InternalTransactionTest method testNestedCreateWithExistedAccount.
@Test
public void testNestedCreateWithExistedAccount() throws Exception {
String contractA = "0x60506040523415600f5760006000fd5b5b60166048565b604051809103906000f0801582151615602f5760006000fd5b60006000508282909180600101839055555050505b6057565b604051605a8061009f83390190565b603a806100656000396000f30060506040526008565b60006000fd00a165627a7a72305820c0eea40d4778b01848164e58898e9e8c8ab068ed5ee36ed6f0582d119ecbbede002960506040523415600f5760006000fd5b6013565b603a8060206000396000f30060506040526008565b60006000fd00a165627a7a723058208c13bc92baf844f8574632dca44c49776516cb6cd537b10ed700bf61392b6ae80029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
AionAddress firstContractAddr = TxUtil.calculateContractAddress(deployerAccount.getAddress(), BigInteger.ONE);
AionAddress internalContractAddress = TxUtil.calculateContractAddress(firstContractAddr.toByteArray(), BigInteger.ZERO);
BigInteger nonce = BigInteger.ZERO;
// ======================
// Transfer balance to the internal contract address
// ======================
AionTransaction tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), internalContractAddress, BigInteger.ONE.toByteArray(), new byte[0], 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
Block parentBlock = bc.getBestBlock();
MiningBlock newBlock = bc.createBlock(parentBlock, Collections.singletonList(tx), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> result = bc.tryToConnectAndFetchSummary(newBlock);
assertTrue(result.getLeft().isSuccessful());
nonce = nonce.add(BigInteger.ONE);
bc.forkUtility.enable040Fork(1000);
// ======================
// DEPLOY Failed
// ======================
tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
parentBlock = bc.getBestBlock();
newBlock = bc.createBlock(parentBlock, Collections.singletonList(tx), false, parentBlock.getTimestamp());
result = bc.tryToConnectAndFetchSummary(newBlock);
assertTrue(result.getLeft().isSuccessful());
assertEquals("reverted", result.getRight().getReceipts().get(0).getError());
nonce = nonce.add(BigInteger.ONE);
bc.forkUtility.enable040Fork(0);
// ======================
// DEPLOY
// ======================
tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
System.out.println("contractaddr: " + TxUtil.calculateContractAddress(tx));
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx), false);
AionTxExecSummary summary = executeTransaction(bc, context, tx);
System.out.println(summary.getReceipt());
boolean firstItx = true;
for (InternalTransaction itx : summary.getInternalTransactions()) {
System.out.println(itx);
if (firstItx) {
AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
assertNotNull(contractAddress);
assertTrue(bc.getRepository().hasAccountState(contractAddress));
assertTrue(bc.getRepository().hasAccountState(TxUtil.calculateContractAddress(contractAddress.toByteArray(), BigInteger.ZERO)));
firstItx = false;
}
}
}
use of org.aion.zero.impl.types.Block 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());
}
Aggregations