@Before public void setUp() { when(blockchainQueries.headBlockNumber()).thenReturn(1L); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getBlockHeader(eq(1L))).thenReturn(Optional.of(blockHeader)); when(blockHeader.getGasLimit()).thenReturn(Long.MAX_VALUE); when(blockHeader.getNumber()).thenReturn(1L); method = new EthEstimateGas( blockchainQueries, transientTransactionProcessor, new JsonRpcParameter()); }
private void assertBlockResultMatchesBlock(final JsonObject result, final Block block) { final BlockHeader header = block.getHeader(); assertThat(Hash.fromHexString(result.getString("parentHash"))) .isEqualTo(header.getParentHash()); assertThat(Hash.fromHexString(result.getString("sha3Uncles"))) .isEqualTo(header.getOmmersHash()); assertThat(Hash.fromHexString(result.getString("transactionsRoot"))) .isEqualTo(header.getTransactionsRoot()); assertThat(Hash.fromHexString(result.getString("stateRoot"))).isEqualTo(header.getStateRoot()); assertThat(Hash.fromHexString(result.getString("receiptsRoot"))) .isEqualTo(header.getReceiptsRoot()); assertThat(Address.fromHexString(result.getString("miner"))).isEqualTo(header.getCoinbase()); assertThat(UInt256.fromHexString(result.getString("difficulty"))) .isEqualTo(header.getDifficulty()); assertThat(BytesValue.fromHexString(result.getString("extraData"))) .isEqualTo(header.getExtraData()); assertThat(hexStringToInt(result.getString("size"))).isEqualTo(block.calculateSize()); assertThat(Long.decode(result.getString("gasLimit"))).isEqualTo(header.getGasLimit()); assertThat(Long.decode(result.getString("gasUsed"))).isEqualTo(header.getGasUsed()); assertThat(Long.decode(result.getString("timestamp"))).isEqualTo(header.getTimestamp()); assertThat(Long.decode(result.getString("number"))).isEqualTo(header.getNumber()); // Nonce is a data field and should represent 8 bytes exactly final String nonceResult = result.getString("nonce").toLowerCase(); assertThat(nonceResult.length() == 18 && nonceResult.startsWith("0x")).isTrue(); assertThat(Long.parseUnsignedLong(nonceResult.substring(2), 16)).isEqualTo(header.getNonce()); assertThat(Hash.fromHexString(result.getString("hash"))).isEqualTo(header.getHash()); assertThat(LogsBloomFilter.fromHexString(result.getString("logsBloom"))) .isEqualTo(header.getLogsBloom()); }
@Before public void setUp() { final ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.create(); blockchain = executionContext.getBlockchain(); final ProtocolContext<Void> protocolContext = executionContext.getProtocolContext(); when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec); when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator); genesisBlockGasLimit = executionContext.getGenesis().getHeader().getGasLimit(); transactionPool = new TransactionPool(transactions, protocolSchedule, protocolContext, batchAddedListener); blockchain.observeBlockAdded(transactionPool); }
if (transaction.getGasLimit() > blockHeader.getGasLimit() - blockHeader.getGasUsed()) { return;