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();
}
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();
}
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();
}
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();
}
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);
}
}
Aggregations