Search in sources :

Example 96 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class BlockDetailsValidatorTest method validateBlockHasRejectedTransaction.

@Test
public void validateBlockHasRejectedTransaction() {
    byte[] receiptTrieEncoded = new byte[32];
    Arrays.fill(receiptTrieEncoded, (byte) 1);
    // The block initially has rejected transaction
    when(mockBlock.getNumber()).thenReturn(1L);
    when(mockBlock.getHeader()).thenReturn(mockBlockHeader);
    when(mockBlock.getLogBloom()).thenReturn(new byte[Bloom.SIZE]);
    when(mockBlockHeader.getEnergyConsumed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxExecSummary.isRejected()).thenReturn(true);
    when(mockTxExecSummary.getReceipt()).thenReturn(mockTxReceipt);
    when(mockTxReceipt.getEnergyUsed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxReceipt.getReceiptTrieEncoded()).thenReturn(receiptTrieEncoded);
    when(mockTxReceipt.getBloomFilter()).thenReturn(new Bloom());
    List<AionTxExecSummary> summaryList = new ArrayList<>();
    summaryList.add(mockTxExecSummary);
    List<AionTxReceipt> receiptList = new ArrayList<>();
    receiptList.add(mockTxReceipt);
    byte[] calculatedTrieroot = BlockUtil.calcReceiptsTrie(receiptList);
    when(mockBlock.getReceiptsRoot()).thenReturn(calculatedTrieroot);
    Truth.assertThat(isValidBlock(mockBlock, summaryList, receiptList, true, AionLoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))).isTrue();
    // The block has rejected transaction after nonce hard fork active
    when(mockBlock.getNumber()).thenReturn(2L);
    Truth.assertThat(isValidBlock(mockBlock, summaryList, receiptList, false, AionLoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))).isFalse();
}
Also used : Bloom(org.aion.base.Bloom) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 97 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class BlockDetailsValidatorTest method validateBlockHasInvalidEnergyUsed.

@Test
public void validateBlockHasInvalidEnergyUsed() {
    byte[] receiptTrieEncoded = new byte[32];
    Arrays.fill(receiptTrieEncoded, (byte) 1);
    // The block has invalid total energy use in the block header
    when(mockBlock.getNumber()).thenReturn(2L);
    when(mockBlock.getHeader()).thenReturn(mockBlockHeader);
    when(mockBlock.getLogBloom()).thenReturn(new byte[Bloom.SIZE]);
    when(mockBlockHeader.getEnergyConsumed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT + 1);
    when(mockTxExecSummary.isRejected()).thenReturn(false);
    when(mockTxExecSummary.getReceipt()).thenReturn(mockTxReceipt);
    when(mockTxExecSummary.getTransaction()).thenReturn(mockTransaction);
    when(mockTxReceipt.getEnergyUsed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxReceipt.getReceiptTrieEncoded()).thenReturn(receiptTrieEncoded);
    when(mockTxReceipt.getBloomFilter()).thenReturn(new Bloom());
    List<AionTxExecSummary> summaryList = new ArrayList<>();
    summaryList.add(mockTxExecSummary);
    List<AionTxReceipt> receiptList = new ArrayList<>();
    receiptList.add(mockTxReceipt);
    byte[] calculatedTrieroot = BlockUtil.calcReceiptsTrie(receiptList);
    when(mockBlock.getReceiptsRoot()).thenReturn(calculatedTrieroot);
    Truth.assertThat(isValidBlock(mockBlock, summaryList, receiptList, false, AionLoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))).isFalse();
}
Also used : Bloom(org.aion.base.Bloom) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 98 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class BlockDetailsValidatorTest method validateBlockHasInvalidReceiptRoot.

@Test
public void validateBlockHasInvalidReceiptRoot() {
    byte[] receiptTrieEncoded = new byte[32];
    Arrays.fill(receiptTrieEncoded, (byte) 1);
    // The block has invalid receipt root in the block header
    when(mockBlock.getNumber()).thenReturn(2L);
    when(mockBlock.getHeader()).thenReturn(mockBlockHeader);
    when(mockBlock.getLogBloom()).thenReturn(new byte[Bloom.SIZE]);
    when(mockBlockHeader.getEnergyConsumed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxExecSummary.isRejected()).thenReturn(false);
    when(mockTxExecSummary.getReceipt()).thenReturn(mockTxReceipt);
    when(mockTxExecSummary.getTransaction()).thenReturn(mockTransaction);
    when(mockTxReceipt.getEnergyUsed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxReceipt.getReceiptTrieEncoded()).thenReturn(receiptTrieEncoded);
    when(mockTxReceipt.getBloomFilter()).thenReturn(new Bloom());
    when(mockTxReceipt.getTransaction()).thenReturn(mockTransaction);
    List<AionTxExecSummary> summaryList = new ArrayList<>();
    summaryList.add(mockTxExecSummary);
    List<AionTxReceipt> receiptList = new ArrayList<>();
    receiptList.add(mockTxReceipt);
    when(mockBlock.getReceiptsRoot()).thenReturn(ConstantUtil.EMPTY_TRIE_HASH);
    Truth.assertThat(isValidBlock(mockBlock, summaryList, receiptList, false, AionLoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))).isFalse();
}
Also used : Bloom(org.aion.base.Bloom) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 99 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class BlockDetailsValidatorTest method validateBlockHasInvalidLogBloom.

@Test
public void validateBlockHasInvalidLogBloom() {
    byte[] receiptTrieEncoded = new byte[32];
    Arrays.fill(receiptTrieEncoded, (byte) 1);
    byte[] txBloom = new byte[Bloom.SIZE];
    Arrays.fill(txBloom, (byte) 1);
    // The block has invalid receipt root in the block header
    when(mockBlock.getNumber()).thenReturn(2L);
    when(mockBlock.getHeader()).thenReturn(mockBlockHeader);
    when(mockBlock.getLogBloom()).thenReturn(new byte[Bloom.SIZE]);
    when(mockBlockHeader.getEnergyConsumed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxExecSummary.isRejected()).thenReturn(false);
    when(mockTxExecSummary.getReceipt()).thenReturn(mockTxReceipt);
    when(mockTxExecSummary.getTransaction()).thenReturn(mockTransaction);
    when(mockTxReceipt.getEnergyUsed()).thenReturn((long) Constants.NRG_TRANSACTION_DEFAULT);
    when(mockTxReceipt.getReceiptTrieEncoded()).thenReturn(receiptTrieEncoded);
    when(mockTxReceipt.getBloomFilter()).thenReturn(new Bloom(txBloom));
    when(mockTxReceipt.getTransaction()).thenReturn(mockTransaction);
    List<AionTxExecSummary> summaryList = new ArrayList<>();
    summaryList.add(mockTxExecSummary);
    List<AionTxReceipt> receiptList = new ArrayList<>();
    receiptList.add(mockTxReceipt);
    byte[] calculatedTrieroot = BlockUtil.calcReceiptsTrie(receiptList);
    when(mockBlock.getReceiptsRoot()).thenReturn(calculatedTrieroot);
    Truth.assertThat(isValidBlock(mockBlock, summaryList, receiptList, false, AionLoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))).isFalse();
}
Also used : Bloom(org.aion.base.Bloom) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 100 with AionTxReceipt

use of org.aion.base.AionTxReceipt in project aion by aionnetwork.

the class RPCMethods method ops_getTransaction.

@Override
public OpsTransaction ops_getTransaction(ByteArray hash) {
    final AionTxInfo transactionInfo = chainHolder.getTransactionInfo(hash.toBytes());
    if (transactionInfo == null) {
        return null;
    } else {
        final Block block = chainHolder.getBlockByHash(transactionInfo.blockHash.toBytes());
        if (block == null) {
            // We cannot create the response if the block is null
            return null;
        // Consider creating a new error class for this
        }
        AionTxReceipt txReceipt = transactionInfo.getReceipt();
        if (txReceipt == null) {
            // We cannot create a response if there is not transaction receipt
            return null;
        }
        AionTransaction aionTransaction = transactionInfo.getReceipt().getTransaction();
        return serializeOpsTransaction(transactionInfo, block, aionTransaction, txReceipt);
    }
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) StakingBlock(org.aion.zero.impl.types.StakingBlock) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Aggregations

AionTxReceipt (org.aion.base.AionTxReceipt)111 Test (org.junit.Test)76 AionTransaction (org.aion.base.AionTransaction)74 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)61 AionAddress (org.aion.types.AionAddress)56 BigInteger (java.math.BigInteger)53 ImportResult (org.aion.zero.impl.core.ImportResult)50 MiningBlock (org.aion.zero.impl.types.MiningBlock)43 ArrayList (java.util.ArrayList)24 Block (org.aion.zero.impl.types.Block)24 AionTxExecSummary (org.aion.base.AionTxExecSummary)17 RepositoryCache (org.aion.base.db.RepositoryCache)17 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)15 Builder (org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder)14 ECKey (org.aion.crypto.ECKey)12 SolidityType (org.aion.solidity.SolidityType)10 AccountState (org.aion.base.AccountState)9 Log (org.aion.types.Log)9 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)7 StakingBlock (org.aion.zero.impl.types.StakingBlock)7