Search in sources :

Example 1 with Bundle

use of org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle in project aion by aionnetwork.

the class ConsensusTest method testConsensus.

@Test
public void testConsensus() {
    Bundle bundle = new Builder().withDefaultAccounts(Collections.singletonList(ECKeyFac.inst().fromPrivate(PRIVATE_KEY))).withValidatorConfiguration("simple").build();
    StandaloneBlockchain blockchain = bundle.bc;
    AionTransaction deployTransaction = getDeployTransaction();
    assertEquals(CONTRACT, TxUtil.calculateContractAddress(deployTransaction));
    // Place the transaction in a block alone.
    Block parentBlock = blockchain.getRepository().getBestBlock();
    List<AionTransaction> transactions = Collections.singletonList(deployTransaction);
    // Run the transaction.
    MiningBlock block = blockchain.createNewMiningBlock(parentBlock, transactions, false);
    Pair<ImportResult, AionBlockSummary> results = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(ImportResult.IMPORTED_BEST, results.getLeft());
    assertEquals(1, results.getRight().getSummaries().size());
    // Extract the results.
    AionBlockSummary blockSummary = results.getRight();
    AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
    byte[] stateRoot = blockSummary.getBlock().getStateRoot();
    byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
    byte[] receiptPostTransactionState = receipt.getPostTxState();
    byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
    parentBlock = blockchain.getRepository().getBestBlock();
    // Place the transactions all in a block.
    transactions = new ArrayList<>();
    // success
    transactions.add(getTransactionThatCallsAddOwner());
    // success
    transactions.add(getTransactionThatCallsIsOwner(OWNER, 2));
    // success
    transactions.add(getTransactionThatCallsIsOwner(OTHER, 3));
    // rejected: invalid nonce
    transactions.add(getTransactionThatCallsIsOwner(OWNER, 3));
    transactions.add(// failed: out of energy
    getTransactionThatCallsIsOwnerAndRunOutOfEnergy());
    transactions.add(getTransactionThatCallsNumOwners());
    // success
    transactions.add(getTransactionThatCallsIsOwner(OWNER, 6));
    transactions.add(// success
    getTransactionThatOnlyTransfersValue(BigInteger.valueOf(1_000_000_000)));
    // Runs the block of transactions.
    block = blockchain.createNewMiningBlock(parentBlock, transactions, false);
    results = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(ImportResult.IMPORTED_BEST, results.getLeft());
    assertEquals(7, results.getRight().getSummaries().size());
    // Extract results.
    blockSummary = results.getRight();
    AionTxReceipt receipt1 = blockSummary.getSummaries().get(0).getReceipt();
    AionTxReceipt receipt2 = blockSummary.getSummaries().get(1).getReceipt();
    AionTxReceipt receipt3 = blockSummary.getSummaries().get(2).getReceipt();
    AionTxReceipt receipt4 = blockSummary.getSummaries().get(3).getReceipt();
    AionTxReceipt receipt5 = blockSummary.getSummaries().get(4).getReceipt();
    AionTxReceipt receipt6 = blockSummary.getSummaries().get(5).getReceipt();
    AionTxReceipt receipt7 = blockSummary.getSummaries().get(6).getReceipt();
    byte[] stateRoot2 = blockSummary.getBlock().getStateRoot();
    byte[] blockReceiptsRoot2 = blockSummary.getBlock().getReceiptsRoot();
    byte[] receiptPostTransactionState1 = receipt1.getPostTxState();
    byte[] receiptPostTransactionState2 = receipt2.getPostTxState();
    byte[] receiptPostTransactionState3 = receipt3.getPostTxState();
    byte[] receiptPostTransactionState4 = receipt4.getPostTxState();
    byte[] receiptPostTransactionState5 = receipt5.getPostTxState();
    byte[] receiptPostTransactionState6 = receipt6.getPostTxState();
    byte[] receiptPostTransactionState7 = receipt7.getPostTxState();
    byte[] receiptTrieEncoded1 = receipt1.getReceiptTrieEncoded();
    byte[] receiptTrieEncoded2 = receipt2.getReceiptTrieEncoded();
    byte[] receiptTrieEncoded3 = receipt3.getReceiptTrieEncoded();
    byte[] receiptTrieEncoded4 = receipt4.getReceiptTrieEncoded();
    byte[] receiptTrieEncoded5 = receipt5.getReceiptTrieEncoded();
    byte[] receiptTrieEncoded6 = receipt6.getReceiptTrieEncoded();
    byte[] receiptTrieEncoded7 = receipt7.getReceiptTrieEncoded();
    System.out.println("Transaction: " + receipt.getTransaction());
    System.out.println();
    System.out.println("BLOCK RECEIPT ROOT: " + Hex.toHexString(blockReceiptsRoot));
    System.out.println("RECEIPT TRIE ENCODING: " + Hex.toHexString(receiptTrieEncoded));
    System.out.println("RECEIPT POST-TRANSACTION STATE: " + Hex.toHexString(receiptPostTransactionState));
    System.out.println("Receipt: " + receipt);
    System.out.println();
    System.out.println("STATE ROOT: " + Hex.toHexString(stateRoot));
    System.out.println("----------------------------------------------------------------------");
    System.out.println("Transaction (CALL #1): " + receipt1.getTransaction());
    System.out.println("Transaction (CALL #2): " + receipt2.getTransaction());
    System.out.println();
    System.out.println("BLOCK RECEIPT ROOT: " + Hex.toHexString(blockReceiptsRoot2));
    System.out.println("RECEIPT TRIE ENCODING (CALL #1): " + Hex.toHexString(receiptTrieEncoded1));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #1): " + Hex.toHexString(receiptPostTransactionState1));
    System.out.println("Receipt (CALL #1): " + receipt1);
    System.out.println();
    System.out.println("RECEIPT TRIE ENCODING (CALL #2): " + Hex.toHexString(receiptTrieEncoded2));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #2): " + Hex.toHexString(receiptPostTransactionState2));
    System.out.println("Receipt (CALL #2): " + receipt2);
    System.out.println();
    System.out.println("RECEIPT TRIE ENCODING (CALL #3): " + Hex.toHexString(receiptTrieEncoded3));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #3): " + Hex.toHexString(receiptPostTransactionState3));
    System.out.println("Receipt (CALL #3): " + receipt3);
    System.out.println();
    System.out.println("RECEIPT TRIE ENCODING (CALL #4): " + Hex.toHexString(receiptTrieEncoded4));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #4): " + Hex.toHexString(receiptPostTransactionState4));
    System.out.println("Receipt (CALL #4): " + receipt4);
    System.out.println();
    System.out.println("RECEIPT TRIE ENCODING (CALL #5): " + Hex.toHexString(receiptTrieEncoded5));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #5): " + Hex.toHexString(receiptPostTransactionState5));
    System.out.println("Receipt (CALL #5): " + receipt5);
    System.out.println();
    System.out.println("RECEIPT TRIE ENCODING (CALL #6): " + Hex.toHexString(receiptTrieEncoded6));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #6): " + Hex.toHexString(receiptPostTransactionState6));
    System.out.println("Receipt (CALL #6): " + receipt6);
    System.out.println();
    System.out.println("RECEIPT TRIE ENCODING (CALL #7): " + Hex.toHexString(receiptTrieEncoded7));
    System.out.println("RECEIPT POST-TRANSACTION STATE (CALL #7): " + Hex.toHexString(receiptPostTransactionState7));
    System.out.println("Receipt (CALL #7): " + receipt7);
    System.out.println();
    System.out.println("STATE ROOT: " + Hex.toHexString(stateRoot2));
    // Check first block.
    assertEquals(RECEIPT, receipt.toString());
    assertArrayEquals(RECEIPT_TRIE_ENCODING, receiptTrieEncoded);
    assertArrayEquals(RECEIPT_POST_TX_STATE, receiptPostTransactionState);
    assertArrayEquals(BLOCK_RECEIPT_ROOT1, blockReceiptsRoot);
    assertArrayEquals(STATE_ROOT1, stateRoot);
    // Check second block.
    assertEquals(RECEIPT1, receipt1.toString());
    assertEquals(RECEIPT2, receipt2.toString());
    assertEquals(RECEIPT3, receipt3.toString());
    assertEquals(RECEIPT4, receipt4.toString());
    assertEquals(RECEIPT5, receipt5.toString());
    assertEquals(RECEIPT6, receipt6.toString());
    assertEquals(RECEIPT7, receipt7.toString());
    assertArrayEquals(RECEIPT_TRIE_ENCODING1, receiptTrieEncoded1);
    assertArrayEquals(RECEIPT_POST_TX_STATE1, receiptPostTransactionState1);
    assertArrayEquals(RECEIPT_TRIE_ENCODING2, receiptTrieEncoded2);
    assertArrayEquals(RECEIPT_POST_TX_STATE2, receiptPostTransactionState2);
    assertArrayEquals(RECEIPT_TRIE_ENCODING3, receiptTrieEncoded3);
    assertArrayEquals(RECEIPT_POST_TX_STATE3, receiptPostTransactionState3);
    assertArrayEquals(RECEIPT_TRIE_ENCODING4, receiptTrieEncoded4);
    assertArrayEquals(RECEIPT_POST_TX_STATE4, receiptPostTransactionState4);
    assertArrayEquals(RECEIPT_TRIE_ENCODING5, receiptTrieEncoded5);
    assertArrayEquals(RECEIPT_POST_TX_STATE5, receiptPostTransactionState5);
    assertArrayEquals(RECEIPT_TRIE_ENCODING6, receiptTrieEncoded6);
    assertArrayEquals(RECEIPT_POST_TX_STATE6, receiptPostTransactionState6);
    assertArrayEquals(RECEIPT_TRIE_ENCODING7, receiptTrieEncoded7);
    assertArrayEquals(RECEIPT_POST_TX_STATE7, receiptPostTransactionState7);
    assertArrayEquals(BLOCK_RECEIPT_ROOT2, blockReceiptsRoot2);
    assertArrayEquals(STATE_ROOT2, stateRoot2);
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) Bundle(org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle) Builder(org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder) StandaloneBlockchain(org.aion.zero.impl.blockchain.StandaloneBlockchain) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 2 with Bundle

use of org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle in project aion by aionnetwork.

the class BalanceTransferConsensusTest method setup.

@Before
public void setup() {
    Bundle bundle = new Builder().withDefaultAccounts(Collections.singletonList(org.aion.crypto.ECKeyFac.inst().fromPrivate(SENDER_KEY))).withValidatorConfiguration("simple").withAvmEnabled().build();
    this.blockchain = bundle.bc;
    AvmTestConfig.supportOnlyAvmVersion1();
}
Also used : Bundle(org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle) Builder(org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder) Before(org.junit.Before)

Example 3 with Bundle

use of org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle in project aion by aionnetwork.

the class FvmBalanceTransferConsensusTest method setup.

@Before
public void setup() {
    Bundle bundle = new Builder().withDefaultAccounts(Collections.singletonList(org.aion.crypto.ECKeyFac.inst().fromPrivate(SENDER_KEY))).withValidatorConfiguration("simple").withAvmEnabled().build();
    this.blockchain = bundle.bc;
    AvmTestConfig.supportOnlyAvmVersion1();
}
Also used : Bundle(org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle) Builder(org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder) Before(org.junit.Before)

Aggregations

Builder (org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder)3 Bundle (org.aion.zero.impl.blockchain.StandaloneBlockchain.Bundle)3 Before (org.junit.Before)2 AionTransaction (org.aion.base.AionTransaction)1 AionTxReceipt (org.aion.base.AionTxReceipt)1 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)1 ImportResult (org.aion.zero.impl.core.ImportResult)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 Block (org.aion.zero.impl.types.Block)1 MiningBlock (org.aion.zero.impl.types.MiningBlock)1 Test (org.junit.Test)1