Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
  • Loading branch information
Gabriel-Trintinalia committed Sep 3, 2023
1 parent 8594933 commit b453cf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder;
import org.hyperledger.besu.ethereum.mainnet.BodyValidation;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;

import java.math.BigInteger;
Expand Down Expand Up @@ -215,7 +214,13 @@ public void shouldValidateExcessBlobGasCorrectly() {

@Test
public void shouldRejectTransactionsWithFullBlob() {
List<String> transactions = List.of(createBlobTransactionEncodedForNetwork());

Bytes transactionWithBlobsBytes =
TransactionEncoder.encodeOpaqueBytes(
createTransactionWithBlobs(), EncodingContext.POOLED_TRANSACTION);

List<String> transactions = List.of(transactionWithBlobsBytes.toString());

BlockHeader mockHeader =
setupValidPayload(
new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))),
Expand All @@ -229,24 +234,19 @@ public void shouldRejectTransactionsWithFullBlob() {
verify(engineCallListener, times(1)).executionEngineCalled();
}

private String createBlobTransactionEncodedForNetwork() {
private Transaction createTransactionWithBlobs() {
BlobTestFixture blobTestFixture = new BlobTestFixture();
BlobsWithCommitments bwc = blobTestFixture.createBlobsWithCommitments(1);
Transaction blobTx =
new TransactionTestFixture()
.to(Optional.of(Address.fromHexString("0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")))
.type(TransactionType.BLOB)
.chainId(Optional.of(BigInteger.ONE))
.maxFeePerGas(Optional.of(Wei.of(15)))
.maxFeePerBlobGas(Optional.of(Wei.of(128)))
.maxPriorityFeePerGas(Optional.of(Wei.of(1)))
.blobsWithCommitments(Optional.of(bwc))
.versionedHashes(Optional.of(bwc.getVersionedHashes()))
.createTransaction(senderKeys);

final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
TransactionEncoder.encodeOpaqueBytes(blobTx, EncodingContext.POOLED_TRANSACTION);
Bytes encodedRLP = bytesValueRLPOutput.encoded();
return encodedRLP.toString();

return new TransactionTestFixture()
.to(Optional.of(Address.fromHexString("0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")))
.type(TransactionType.BLOB)
.chainId(Optional.of(BigInteger.ONE))
.maxFeePerGas(Optional.of(Wei.of(15)))
.maxFeePerBlobGas(Optional.of(Wei.of(128)))
.maxPriorityFeePerGas(Optional.of(Wei.of(1)))
.blobsWithCommitments(Optional.of(bwc))
.versionedHashes(Optional.of(bwc.getVersionedHashes()))
.createTransaction(senderKeys);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ public void blobTransactionEncodingDecodingForNetWorkTest(
final Transaction transaction =
TransactionDecoder.decodeOpaqueBytes(bytes, EncodingContext.POOLED_TRANSACTION);

final BytesValueRLPOutput output = new BytesValueRLPOutput();
TransactionEncoder.encodeRLP(transaction.getType(), bytes, output);

final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
TransactionEncoder.encodeRLP(
transaction, bytesValueRLPOutput, EncodingContext.POOLED_TRANSACTION);
assertThat(transaction.getSize()).isEqualTo(bytes.size());
assertThat(transaction.getSize()).isEqualTo(output.encodedSize());
}

@ParameterizedTest(name = "{index} {0}")
Expand All @@ -72,8 +75,7 @@ public void blobTransactionEncodingDecodingTest(final TypedTransactionBytesArgum
TransactionDecoder.decodeOpaqueBytes(bytes, EncodingContext.BLOCK_BODY);

// Encode the transaction for wire using the TransactionEncoder.
Bytes encoded =
TransactionEncoder.encodeOpaqueBytes(transaction, EncodingContext.POOLED_TRANSACTION);
Bytes encoded = TransactionEncoder.encodeOpaqueBytes(transaction, EncodingContext.BLOCK_BODY);
// Assert that the encoded transaction matches the original bytes.
assertThat(encoded.toHexString()).isEqualTo(bytes.toHexString());

Expand Down

0 comments on commit b453cf7

Please sign in to comment.