Search in sources :

Example 11 with Block

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);
}
Also used : Block(org.aion.zero.impl.types.Block)

Example 12 with Block

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);
}
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) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 13 with Block

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();
}
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) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 14 with Block

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;
        }
    }
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) StandaloneBlockchain(org.aion.zero.impl.blockchain.StandaloneBlockchain) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) InternalTransaction(org.aion.types.InternalTransaction) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) BigInteger(java.math.BigInteger) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Example 15 with Block

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());
}
Also used : AionAddress(org.aion.types.AionAddress) 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)

Aggregations

Block (org.aion.zero.impl.types.Block)283 MiningBlock (org.aion.zero.impl.types.MiningBlock)155 Test (org.junit.Test)148 AionTransaction (org.aion.base.AionTransaction)106 ImportResult (org.aion.zero.impl.core.ImportResult)86 ArrayList (java.util.ArrayList)63 AionAddress (org.aion.types.AionAddress)61 StakingBlock (org.aion.zero.impl.types.StakingBlock)58 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)57 BigInteger (java.math.BigInteger)55 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)34 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)30 AionTxReceipt (org.aion.base.AionTxReceipt)29 Hex.toHexString (org.aion.util.conversions.Hex.toHexString)28 AccountState (org.aion.base.AccountState)26 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)26 JSONArray (org.json.JSONArray)26 JSONObject (org.json.JSONObject)26 MiningBlockHeader (org.aion.zero.impl.types.MiningBlockHeader)22 AionTxExecSummary (org.aion.base.AionTxExecSummary)20