Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit edb750b

Browse files
authored
Refactor block validation test to be less flaky (#10)
1 parent 89c30e3 commit edb750b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

eth/block-validation/api_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
9898

9999
blockRequest.Message.GasLimit += 1
100100
blockRequest.ExecutionPayload.GasLimit += 1
101+
updatePayloadHash(t, blockRequest)
101102

102-
oldHash := blockRequest.Message.BlockHash
103-
copy(blockRequest.Message.BlockHash[:], hexutil.MustDecode("0xa6592f67b46f9567ff417defcc2e5ef40b7e3eafb04be990395ef3807d6c57e9")[:32])
104103
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "incorrect gas limit set")
105104

106105
blockRequest.Message.GasLimit -= 1
107106
blockRequest.ExecutionPayload.GasLimit -= 1
108-
blockRequest.Message.BlockHash = oldHash
107+
updatePayloadHash(t, blockRequest)
109108

110109
// TODO: test with contract calling blacklisted address
111110
// Test tx from blacklisted address
@@ -144,10 +143,16 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
144143
invalidPayload.LogsBloom = boostTypes.Bloom{}
145144
copy(invalidPayload.ReceiptsRoot[:], hexutil.MustDecode("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")[:32])
146145
blockRequest.ExecutionPayload = invalidPayload
147-
copy(blockRequest.Message.BlockHash[:], hexutil.MustDecode("0xb91a7a79407584a835d814de77808a25e72d5025bc7691630e57c40d8c47ee33")[:32])
146+
updatePayloadHash(t, blockRequest)
148147
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "could not apply tx 3", "insufficient funds for gas * price + value")
149148
}
150149

150+
func updatePayloadHash(t *testing.T, blockRequest *BuilderBlockValidationRequest) {
151+
updatedBlock, err := beacon.ExecutionPayloadToBlock(blockRequest.ExecutionPayload)
152+
require.NoError(t, err)
153+
copy(blockRequest.Message.BlockHash[:], updatedBlock.Hash().Bytes()[:32])
154+
}
155+
151156
func generatePreMergeChain(n int) (*core.Genesis, []*types.Block) {
152157
db := rawdb.NewMemoryDatabase()
153158
config := params.AllEthashProtocolChanges

0 commit comments

Comments
 (0)