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

Commit 7dd1e70

Browse files
Ruteriavalonche
authored andcommitted
Refactor block validation test to be less flaky (#10) (#31)
1 parent 6bd0d57 commit 7dd1e70

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
@@ -107,14 +107,13 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
107107

108108
blockRequest.Message.GasLimit += 1
109109
blockRequest.ExecutionPayload.GasLimit += 1
110+
updatePayloadHash(t, blockRequest)
110111

111-
oldHash := blockRequest.Message.BlockHash
112-
copy(blockRequest.Message.BlockHash[:], hexutil.MustDecode("0x56cbdd508966f89cfb6ba16535e3676b59ae3ac3774478b631466bc99c1033c9")[:32])
113112
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "incorrect gas limit set")
114113

115114
blockRequest.Message.GasLimit -= 1
116115
blockRequest.ExecutionPayload.GasLimit -= 1
117-
blockRequest.Message.BlockHash = oldHash
116+
updatePayloadHash(t, blockRequest)
118117

119118
// TODO: test with contract calling blacklisted address
120119
// Test tx from blacklisted address
@@ -153,10 +152,16 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
153152
invalidPayload.LogsBloom = boostTypes.Bloom{}
154153
copy(invalidPayload.ReceiptsRoot[:], hexutil.MustDecode("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")[:32])
155154
blockRequest.ExecutionPayload = invalidPayload
156-
copy(blockRequest.Message.BlockHash[:], hexutil.MustDecode("0x595cba7ab70a18b7e11ae7541661cb6692909a0acd3eba3f1cf6ae694f85a8bd")[:32])
155+
updatePayloadHash(t, blockRequest)
157156
require.ErrorContains(t, api.ValidateBuilderSubmissionV1(blockRequest), "could not apply tx 4", "insufficient funds for gas * price + value")
158157
}
159158

159+
func updatePayloadHash(t *testing.T, blockRequest *BuilderBlockValidationRequest) {
160+
updatedBlock, err := beacon.ExecutionPayloadToBlock(blockRequest.ExecutionPayload)
161+
require.NoError(t, err)
162+
copy(blockRequest.Message.BlockHash[:], updatedBlock.Hash().Bytes()[:32])
163+
}
164+
160165
func generatePreMergeChain(n int) (*core.Genesis, []*types.Block) {
161166
db := rawdb.NewMemoryDatabase()
162167
config := params.AllEthashProtocolChanges

0 commit comments

Comments
 (0)