private Transaction transaction(final Hash hash) { final Transaction tx = mock(Transaction.class); when(tx.hash()).thenReturn(hash); return tx; }
@Before public void setUp() { when(transaction.hash()).thenReturn(transactionHash); }
private List<Hash> transactionsWithHashOnly() { final List<Hash> hashes = new ArrayList<>(); for (final TransactionWithMetadata transactionWithMetadata : transactionsWithMetadata()) { hashes.add(transactionWithMetadata.getTransaction().hash()); } return hashes; }
private void assertTransactionPending(final Transaction t) { assertThat(transactions.getTransactionByHash(t.hash())).contains(t); }
private void assertTransactionNotPending(final Transaction t) { assertThat(transactions.getTransactionByHash(t.hash())).isEmpty(); }
private void assertTransactionPending(final Transaction t) { assertThat(transactions.getTransactionByHash(t.hash())).contains(t); }
private void assertTransactionNotPending(final Transaction transaction) { assertThat(transactions.getTransactionByHash(transaction.hash())).isEmpty(); }
private Hash recordPendingTransaction(final int blockNumber, final int transactionIndex) { final Block block = BLOCKS.get(1); final Transaction transaction = block.getBody().getTransactions().get(0); filterManager.recordPendingTransactionEvent(transaction); return transaction.hash(); }
private Hash receivePendingTransaction() { final Transaction transaction = blockGenerator.transaction(); filterManager.recordPendingTransactionEvent(transaction); return transaction.hash(); } }
@Before public void setUp() throws Exception { transactionTracer = new TransactionTracer(new BlockReplay(protocolSchedule, blockchain, worldStateArchive)); when(transaction.hash()).thenReturn(transactionHash); when(otherTransaction.hash()).thenReturn(otherTransactionHash); when(blockHeader.getNumber()).thenReturn(12L); when(blockHeader.getHash()).thenReturn(blockHash); when(blockHeader.getParentHash()).thenReturn(previousBlockHash); when(previousBlockHeader.getStateRoot()).thenReturn(Hash.ZERO); when(worldStateArchive.getMutable(Hash.ZERO)).thenReturn(mutableWorldState); when(protocolSchedule.getByBlockNumber(12)).thenReturn(protocolSpec); when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor); when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(BlockHeader::getCoinbase); }
private TransactionReceiptWithMetadata createTransactionWithLog( final Transaction transaction, final Log log) { final BlockHeader blockHeader = blockHeaderTestFixture.buildHeader(); final TransactionReceipt transactionReceipt = new TransactionReceipt(Hash.ZERO, 1L, Lists.newArrayList(log)); final TransactionReceiptWithMetadata transactionReceiptWithMetadata = TransactionReceiptWithMetadata.create( transactionReceipt, transaction, transaction.hash(), 0, 1L, blockHeader.getHash(), blockHeader.getNumber()); when(blockchainQueries.transactionReceiptByTransactionHash(eq(transaction.hash()))) .thenReturn(Optional.of(transactionReceiptWithMetadata)); return transactionReceiptWithMetadata; }
final Hash blockHash, final Long blockNumber) { assertThat(Hash.fromHexString(result.getString("hash"))).isEqualTo(transaction.hash()); assertThat(Long.decode(result.getString("nonce"))).isEqualByComparingTo(transaction.getNonce()); if (blockHash != null) {
private void assertBlockMatchesResultWithTxHashes( final Block targetBlock, final BlockWithMetadata<Hash, Hash> result) { assertEquals(targetBlock.getHeader(), result.getHeader()); final List<Hash> expectedOmmers = targetBlock .getBody() .getOmmers() .stream() .map(BlockHeader::getHash) .collect(Collectors.toList()); assertEquals(expectedOmmers, result.getOmmers()); for (int i = 0; i < result.getTransactions().size(); i++) { final Hash txResult = result.getTransactions().get(i); final Transaction actualTx = targetBlock.getBody().getTransactions().get(i); assertEquals(actualTx.hash(), txResult); } }
assertThat(blockchain.getTransactionByHash(tx.hash())).isNotPresent();
final Optional<Transaction> actualTransaction = blockchain.getTransactionByHash(tx.hash()); if (tx.equals(overlappingTx)) { assertThat(actualTransaction).isPresent();
private void assertBlockDataIsStored( final Blockchain blockchain, final Block block, final List<TransactionReceipt> receipts) { final Hash hash = block.getHash(); assertEquals(hash, blockchain.getBlockHashByNumber(block.getHeader().getNumber()).get()); assertEquals(block.getHeader(), blockchain.getBlockHeader(block.getHeader().getNumber()).get()); assertEquals(block.getHeader(), blockchain.getBlockHeader(hash).get()); assertEquals(block.getBody(), blockchain.getBlockBody(hash).get()); assertThat(blockchain.blockIsOnCanonicalChain(block.getHash())).isTrue(); final List<Transaction> txs = block.getBody().getTransactions(); for (int i = 0; i < txs.size(); i++) { final Transaction expected = txs.get(i); final Transaction actual = blockchain.getTransactionByHash(expected.hash()).get(); assertEquals(expected, actual); } final List<TransactionReceipt> actualReceipts = blockchain.getTxReceipts(hash).get(); assertEquals(receipts, actualReceipts); }
if (shouldTransactionsBeHashed) { assertThat(Hash.fromHexString(transactionsResult.getString(i))) .isEqualTo(transaction.hash()); } else { final JsonObject transactionResult = transactionsResult.getJsonObject(i);
assertThat(blockchain.getTransactionByHash(tx.hash())).isNotPresent();
public void milestone(final String milestone) { final TransactionTestCaseSpec.Expectation expected = spec.expectation(milestone); try { final BytesValue rlp = spec.getRlp(); // Test transaction deserialization (will throw an exception if it fails). final Transaction transaction = Transaction.readFrom(RLP.input(rlp)); if (!transactionValidator(milestone).validate(transaction).isValid()) { throw new RuntimeException(String.format("Transaction is invalid %s", transaction)); } // Test rlp encoding final BytesValue actualRlp = RLP.encode(transaction::writeTo); Assert.assertTrue(expected.isSucceeds()); Assert.assertEquals(rlp, actualRlp); Assert.assertEquals(expected.getSender(), transaction.getSender()); Assert.assertEquals(expected.getHash(), transaction.hash()); } catch (final Exception e) { Assert.assertFalse(expected.isSucceeds()); } } }