private Transaction transactionWithNonceSenderAndGasPrice( final int nonce, final KeyPair keyPair, final long gasPrice) { return new TransactionTestFixture() .nonce(nonce) .gasPrice(Wei.of(gasPrice)) .createTransaction(keyPair); }
private BlockHeader createHeader(final int blockNumber, final BlockHeader parentHeader) { return new BlockHeaderTestFixture() .number(blockNumber) .parentHash(parentHeader != null ? parentHeader.getHash() : Hash.EMPTY) .buildHeader(); } }
private MessageFrameTestFixture validMessageFrameBuilder() { final BlockHeader blockHeader = new BlockHeaderTestFixture().number(1).buildHeader(); final TestBlockchain blockchain = new TestBlockchain(blockHeader.getNumber()); return new MessageFrameTestFixture() .initialGas(INITIAL_GAS) .worldState(worldUpdater) .gasPrice(Wei.of(25)) .blockHeader(blockHeader) .blockchain(blockchain) .depth(DEPTH); }
private Block createEmptyBlock(final long blockNumber, final Hash parentHash) { headerBuilder.number(blockNumber).parentHash(parentHash).coinbase(AddressHelpers.ofValue(0)); return new Block( headerBuilder.buildHeader(), new BlockBody(Lists.emptyList(), Lists.emptyList())); }
@Test public void replaceAccountBalance() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setBalance(Wei.of(200000)); updater.commit(); assertEquals(Wei.of(200000), worldState.get(ADDRESS).getBalance()); assertEquals( Hash.fromHexString("0xbfa4e0598cc2b810a8ccc4a2d9a4c575574d05c9c4a7f915e6b8545953a5051e"), worldState.rootHash()); }
private Block createEmptyBlock( final long blockNumber, final Hash parentHash, final KeyPair signer) { headerTestFixture.number(blockNumber).parentHash(parentHash); final BlockHeader header = TestHelpers.createCliqueSignedBlockHeader(headerTestFixture, signer, validators); return new Block(header, new BlockBody(Lists.emptyList(), Lists.emptyList())); } }
@Test public void getAccountNonce_AccountExists() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setNonce(1L); updater.commit(); assertEquals(1L, worldState.get(ADDRESS).getNonce()); assertEquals( Hash.fromHexString("0x9648b05cc2eef5513ae2edfe16bfcedb3d1c60ffb5dff3fc501bd3e4ae39f536"), worldState.rootHash()); }
@Test public void getAccountBalance_AccountExists() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.commit(); assertEquals(Wei.of(100000), worldState.get(ADDRESS).getBalance()); }
private Transaction createTransaction(final int transactionNumber) { return new TransactionTestFixture() .value(Wei.of(transactionNumber)) .nonce(transactionNumber) .createTransaction(KEYS1); } }
Expectation( @JsonProperty("hash") final String hash, @JsonProperty("sender") final String sender) { this.succeeds = hash != null && sender != null; if (succeeds) { this.hash = Hash.fromHexString(hash); this.sender = Address.fromHexString(sender); } else { this.hash = null; this.sender = null; } }
private static MutableBlockchain buildBlockchain(final BlockHeader genesisBlockHeader) { final Block genesisBlock = new Block(genesisBlockHeader, BlockBody.empty()); return createInMemoryBlockchain(genesisBlock); }
private Transaction createTransaction(final int transactionNumber) { return new TransactionTestFixture() .nonce(transactionNumber) .gasLimit(0) .createTransaction(KEY_PAIR1); }
public int getPendingTransactionCount() { return transactionPool.getPendingTransactions().size(); } }
private Hash receivePendingTransaction() { final Transaction transaction = blockGenerator.transaction(); filterManager.recordPendingTransactionEvent(transaction); return transaction.hash(); } }
@Test public void shouldRemoveTransactionsFromPendingListWhenIncludedInBlockOnChain() { transactions.addRemoteTransaction(transaction1); assertTransactionPending(transaction1); appendBlock(transaction1); assertTransactionNotPending(transaction1); }
@Test public void shouldTrackMaximumNonceForEachSender() { transactions.addRemoteTransaction(transactionWithNonceAndSender(0, KEYS1)); assertMaximumNonceForSender(SENDER1, 1); transactions.addRemoteTransaction(transactionWithNonceAndSender(1, KEYS1)); assertMaximumNonceForSender(SENDER1, 2); transactions.addRemoteTransaction(transactionWithNonceAndSender(2, KEYS1)); assertMaximumNonceForSender(SENDER1, 3); transactions.addRemoteTransaction(transactionWithNonceAndSender(20, KEYS2)); assertMaximumNonceForSender(SENDER2, 21); assertMaximumNonceForSender(SENDER1, 3); }
@Test public void setStorageValue_ZeroValue() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setStorageValue(UInt256.ZERO, UInt256.ZERO); updater.commit(); assertEquals(UInt256.ZERO, worldState.get(ADDRESS).getStorageValue(UInt256.ZERO)); assertEquals( Hash.fromHexString("0xa3e1c133a5a51b03399ed9ad0380f3182e9e18322f232b816dd4b9094f871e1b"), worldState.rootHash()); }
@Test public void containsAccount_AccountExists() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.commit(); assertNotNull(worldState.get(ADDRESS)); assertEquals( Hash.fromHexString("0xa3e1c133a5a51b03399ed9ad0380f3182e9e18322f232b816dd4b9094f871e1b"), worldState.rootHash()); }