Search in sources :

Example 56 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class AionBlock method toString.

@Override
public String toString() {
    StringBuilder toStringBuff = new StringBuilder();
    parseRLP();
    toStringBuff.setLength(0);
    toStringBuff.append(Hex.toHexString(this.getEncoded())).append("\n");
    toStringBuff.append("BlockData [ ");
    toStringBuff.append("hash=").append(ByteUtil.toHexString(this.getHash())).append("\n");
    toStringBuff.append(header.toString());
    if (!getTransactionsList().isEmpty()) {
        toStringBuff.append("Txs [\n");
        for (AionTransaction tx : getTransactionsList()) {
            toStringBuff.append(tx);
            toStringBuff.append("\n");
        }
        toStringBuff.append("]\n");
    } else {
        toStringBuff.append("Txs []\n");
    }
    toStringBuff.append("]");
    return toStringBuff.toString();
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction)

Example 57 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class AionBlock method toFlatString.

public String toFlatString() {
    StringBuilder toStringBuff = new StringBuilder();
    parseRLP();
    toStringBuff.setLength(0);
    toStringBuff.append("BlockData [");
    toStringBuff.append("hash=").append(ByteUtil.toHexString(this.getHash()));
    toStringBuff.append(header.toFlatString());
    for (AionTransaction tx : getTransactionsList()) {
        toStringBuff.append("\n");
        toStringBuff.append(tx.toString());
    }
    toStringBuff.append("]");
    return toStringBuff.toString();
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction)

Example 58 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class BlockchainConcurrencyTest method testPublishBestBlockSafely.

@Test
public void testPublishBestBlockSafely() {
    ExecutorService blockCreationService = Executors.newSingleThreadExecutor();
    ExecutorService getBlockService = Executors.newSingleThreadExecutor();
    StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withDefaultAccounts().withValidatorConfiguration("simple").build();
    StandaloneBlockchain bc = bundle.bc;
    final int MAX_COUNT = 100000;
    final CountDownLatch endLatch = new CountDownLatch(2);
    // this will not definitively prove
    try {
        blockCreationService.submit(() -> {
            int count = 0;
            List<AionTransaction> txList = Collections.emptyList();
            AionBlock block = bc.createNewBlock(bc.genesis, Collections.emptyList(), false);
            while (!Thread.currentThread().isInterrupted() && count < MAX_COUNT) {
                block = bc.createNewBlock(block, txList, false);
                count++;
            }
            System.out.println("completed block creation");
            endLatch.countDown();
        });
        getBlockService.submit(() -> {
            int count = 0;
            long prevNumber = bc.getBestBlock().getNumber();
            while (!Thread.currentThread().isInterrupted() && count < MAX_COUNT) {
                // all three of these methods use {@link AionBlockchainImpl#pubBestBlock}
                assertThat(bc.getBestBlockHash()).isNotNull();
                bc.getSize();
                AionBlock block = bc.getBestBlock();
                assertThat(block).isNotNull();
                assertThat(block.getNumber()).isAtLeast(prevNumber);
                prevNumber = block.getNumber();
                count++;
            }
            endLatch.countDown();
        });
    } finally {
        blockCreationService.shutdown();
        getBlockService.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) AionTransaction(org.aion.zero.types.AionTransaction) CountDownLatch(java.util.concurrent.CountDownLatch) AionBlock(org.aion.zero.impl.types.AionBlock) Test(org.junit.Test)

Example 59 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class BlockchainIntegrationTest method testSimpleFailedTransactionInsufficientBalance.

@Test
public void testSimpleFailedTransactionInsufficientBalance() {
    // generate a recipient
    final Address receiverAddress = Address.wrap(ByteUtil.hexStringToBytes("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"));
    StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
    StandaloneBlockchain bc = bundle.bc;
    // (byte[] nonce, byte[] from, byte[] to, byte[] value, byte[] data)
    AionTransaction tx = new AionTransaction(BigInteger.valueOf(1).toByteArray(), receiverAddress, BigInteger.valueOf(100).toByteArray(), ByteUtil.EMPTY_BYTE_ARRAY, 1L, 1L);
    tx.sign(bundle.privateKeys.get(0));
    AionBlock block = bc.createNewBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
    assertThat(block.getTransactionsList()).isEmpty();
    assertThat(block.getTxTrieRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
    ImportResult connection = bc.tryToConnect(block);
    assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
}
Also used : ImportResult(org.aion.mcf.core.ImportResult) Address(org.aion.base.type.Address) AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock) Test(org.junit.Test)

Example 60 with AionTransaction

use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.

the class AionTxExecSummaryTest method testRLPEncoding.

@Test
public void testRLPEncoding() {
    AionTransaction mockTx = new AionTransaction(BigInteger.ONE.toByteArray(), defaultAddress, defaultAddress, BigInteger.ONE.toByteArray(), HashUtil.EMPTY_DATA_HASH, 1L, 1L);
    AionTxReceipt txReceipt = new AionTxReceipt(HashUtil.EMPTY_TRIE_HASH, new Bloom(), Collections.EMPTY_LIST);
    txReceipt.setNrgUsed(1);
    txReceipt.setTransaction(mockTx);
    AionTxExecSummary.Builder builder = AionTxExecSummary.builderFor(txReceipt);
    builder.markAsFailed().result(new byte[0]);
    AionTxExecSummary summary = builder.build();
    byte[] encodedSummary = summary.getEncoded();
    AionTxExecSummary newSummary = new AionTxExecSummary(encodedSummary);
    newSummary.getReceipt().setTransaction(mockTx);
    assertThat(newSummary.getFee()).isEqualTo(BigInteger.ONE);
}
Also used : Bloom(org.aion.mcf.vm.types.Bloom) AionTxExecSummary(org.aion.zero.types.AionTxExecSummary) AionTransaction(org.aion.zero.types.AionTransaction) AionTxReceipt(org.aion.zero.types.AionTxReceipt) Test(org.junit.Test)

Aggregations

AionTransaction (org.aion.zero.types.AionTransaction)75 Test (org.junit.Test)44 BigInteger (java.math.BigInteger)30 ITransaction (org.aion.base.type.ITransaction)26 Address (org.aion.base.type.Address)23 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionBlock (org.aion.zero.impl.types.AionBlock)17 ArrayList (java.util.ArrayList)16 ECKey (org.aion.crypto.ECKey)12 AionTxReceipt (org.aion.zero.types.AionTxReceipt)7 TxRecpt (org.aion.api.server.types.TxRecpt)4 ImportResult (org.aion.mcf.core.ImportResult)4 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)4 ByteString (com.google.protobuf.ByteString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBuffer (java.nio.ByteBuffer)2 java.util (java.util)2 Entry (java.util.Map.Entry)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Collectors (java.util.stream.Collectors)2