use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.
the class GraphQLHttpServiceTest method query_untypedPost.
@Test
public void query_untypedPost() throws Exception {
final RequestBody body = RequestBody.create("{gasPrice}", null);
final Wei price = Wei.of(16);
Mockito.when(miningCoordinatorMock.getMinTransactionGasPrice()).thenReturn(price);
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
// Check general format of result
Assertions.assertThat(resp.code()).isEqualTo(200);
final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidGraphQLResult(json);
final String result = json.getJsonObject("data").getString("gasPrice");
Assertions.assertThat(result).isEqualTo("0x10");
}
}
use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.
the class FixedKeySigningPrivateMarkerTransactionFactoryTest method createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce.
@Test
public void createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce() {
final PrivateTransaction privTransaction = mock(PrivateTransaction.class);
final Wei gasPrice = Wei.of(100);
final long gasLimit = 500;
final long providedNonce = 100;
final String enclaveKey = "pmtLookupKey";
final KeyPair signingKeys = SignatureAlgorithmFactory.getInstance().generateKeyPair();
final Address precompiledAddress = Address.fromHexString("1");
final FixedKeySigningPrivateMarkerTransactionFactory factory = new FixedKeySigningPrivateMarkerTransactionFactory(signingKeys);
final Transaction unsignedPrivateMarkerTransaction = new Transaction.Builder().type(TransactionType.FRONTIER).nonce(providedNonce).gasPrice(gasPrice).gasLimit(gasLimit).to(precompiledAddress).value(Wei.ZERO).payload(Bytes.fromBase64String(enclaveKey)).build();
final Transaction transaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
assertThat(transaction.getNonce()).isEqualTo(providedNonce);
assertThat(transaction.getGasLimit()).isEqualTo(gasLimit);
assertThat(transaction.getGasPrice().get()).isEqualTo(gasPrice);
assertThat(transaction.getValue()).isEqualTo(Wei.ZERO);
assertThat(transaction.getSender()).isEqualTo(Util.publicKeyToAddress(signingKeys.getPublicKey()));
assertThat(transaction.getTo()).isEqualTo(Optional.of(precompiledAddress));
assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey));
final Transaction nextTransaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
assertThat(nextTransaction.getSender()).isEqualTo(transaction.getSender());
}
use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.
the class RandomSigningPrivateMarkerTransactionFactoryTest method producedTransactionHasZeroNonceAndDifferentSendThanPrior.
@Test
public void producedTransactionHasZeroNonceAndDifferentSendThanPrior() {
final PrivateTransaction privTransaction = mock(PrivateTransaction.class);
final Wei gasPrice = Wei.of(100);
final long gasLimit = 500;
final String enclaveKey = "enclaveKey";
final long providedNonce = 0;
final Address precompiledAddress = Address.fromHexString("1");
final Transaction unsignedPrivateMarkerTransaction = new Transaction.Builder().type(TransactionType.FRONTIER).nonce(providedNonce).gasPrice(gasPrice).gasLimit(gasLimit).to(precompiledAddress).value(Wei.ZERO).payload(Bytes.fromBase64String(enclaveKey)).build();
final RandomSigningPrivateMarkerTransactionFactory factory = new RandomSigningPrivateMarkerTransactionFactory();
final Transaction transaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
assertThat(transaction.getNonce()).isEqualTo(0);
assertThat(transaction.getGasLimit()).isEqualTo(gasLimit);
assertThat(transaction.getGasPrice().get()).isEqualTo(gasPrice);
assertThat(transaction.getValue()).isEqualTo(Wei.ZERO);
assertThat(transaction.getTo()).isEqualTo(Optional.of(precompiledAddress));
assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey));
final Transaction nextTransaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
assertThat(nextTransaction.getSender()).isNotEqualTo(transaction.getSender());
}
use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.
the class StateTestVersionedTransaction method get.
public Transaction get(final GeneralStateTestCaseSpec.Indexes indexes) {
Long gasLimit = gasLimits.get(indexes.gas);
Wei value = values.get(indexes.value);
Bytes data = payloads.get(indexes.data);
if (value == null || gasLimit == null) {
// this means one of the params is an out-of-bounds value. Don't generate the transaction.
return null;
}
final Transaction.Builder transactionBuilder = Transaction.builder().nonce(nonce).gasLimit(gasLimit).to(to).value(value).payload(data);
Optional.ofNullable(gasPrice).ifPresent(transactionBuilder::gasPrice);
Optional.ofNullable(maxFeePerGas).ifPresent(transactionBuilder::maxFeePerGas);
Optional.ofNullable(maxPriorityFeePerGas).ifPresent(transactionBuilder::maxPriorityFeePerGas);
maybeAccessLists.ifPresent(accessLists -> transactionBuilder.accessList(accessLists.get(indexes.data)));
transactionBuilder.guessType();
if (transactionBuilder.getTransactionType().requiresChainId()) {
transactionBuilder.chainId(BigInteger.ONE);
}
return transactionBuilder.signAndBuild(keys);
}
use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.
the class EthGetMinerDataByBlockHash method createMinerDataResult.
public static MinerDataResult createMinerDataResult(final BlockWithMetadata<TransactionWithMetadata, Hash> block, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries) {
final BlockHeader blockHeader = block.getHeader();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final Wei staticBlockReward = protocolSpec.getBlockReward();
final Wei transactionFee = block.getTransactions().stream().map(t -> blockchainQueries.transactionReceiptByTransactionHash(t.getTransaction().getHash()).map(receipt -> receipt.getTransaction().getEffectiveGasPrice(receipt.getBaseFee()).multiply(receipt.getGasUsed())).orElse(Wei.ZERO)).reduce(Wei.ZERO, BaseUInt256Value::add);
final Wei uncleInclusionReward = staticBlockReward.multiply(block.getOmmers().size()).divide(32);
final Wei netBlockReward = staticBlockReward.add(transactionFee).add(uncleInclusionReward);
final List<UncleRewardResult> uncleRewards = new ArrayList<>();
blockchainQueries.getBlockchain().getBlockByNumber(block.getHeader().getNumber()).ifPresent(blockBody -> blockBody.getBody().getOmmers().forEach(header -> uncleRewards.add(ImmutableUncleRewardResult.builder().hash(header.getHash().toHexString()).coinbase(header.getCoinbase().toHexString()).build())));
return ImmutableMinerDataResult.builder().netBlockReward(netBlockReward.toHexString()).staticBlockReward(staticBlockReward.toHexString()).transactionFee(transactionFee.toHexString()).uncleInclusionReward(uncleInclusionReward.toHexString()).uncleRewards(uncleRewards).coinbase(blockHeader.getCoinbase().toHexString()).extraData(blockHeader.getExtraData().toHexString()).difficulty(blockHeader.getDifficulty().toHexString()).totalDifficulty(block.getTotalDifficulty().toHexString()).build();
}
Aggregations