Commit 8d127251 authored by Maurelian's avatar Maurelian

op-node: clean up FuzzParseL1InfoDepositTxDataValid

parent c3af0455
package derive package derive
import ( import (
"math/big"
"math/rand"
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/testutils" "github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum-optimism/optimism/op-node/testutils/fuzzerutils" "github.com/ethereum-optimism/optimism/op-node/testutils/fuzzerutils"
"github.com/ethereum/go-ethereum/common"
fuzz "github.com/google/gofuzz" fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -17,37 +14,20 @@ import ( ...@@ -17,37 +14,20 @@ import (
// L1 deposit tx info and derives a tx from it, then derives the info back from the tx, to ensure round-trip // L1 deposit tx info and derives a tx from it, then derives the info back from the tx, to ensure round-trip
// derivation is upheld. This generates "valid" data and ensures it is always derived back to original values. // derivation is upheld. This generates "valid" data and ensures it is always derived back to original values.
func FuzzParseL1InfoDepositTxDataValid(f *testing.F) { func FuzzParseL1InfoDepositTxDataValid(f *testing.F) {
f.Fuzz(func(t *testing.T, fuzzedData []byte, seqNr uint64, rngSeed int64) { f.Fuzz(func(t *testing.T, fuzzedData []byte) {
// Create our fuzzer wrapper to generate complex values // Create our fuzzer wrapper to generate complex values
typeProvider := fuzz.NewFromGoFuzz(fuzzedData).NilChance(0).MaxDepth(10000).NumElements(0, 0x100) typeProvider := fuzz.NewFromGoFuzz(fuzzedData).NilChance(0).MaxDepth(10000).NumElements(0, 0x100)
fuzzerutils.AddFuzzerFunctions(typeProvider) fuzzerutils.AddFuzzerFunctions(typeProvider)
// Generate our fuzzed value types to construct our L1 info var l1Info testutils.MockBlockInfo
var fuzzVars struct { typeProvider.Fuzz(&l1Info)
InfoBaseFee *big.Int var seqNr uint64
InfoTime uint64 typeProvider.Fuzz(&seqNr)
InfoNum uint64 var sysCfg eth.SystemConfig
// InfoSequenceNumber uint64 typeProvider.Fuzz(&sysCfg)
}
typeProvider.Fuzz(&fuzzVars)
// Create an rng provider and construct an L1 info from random + fuzzed data.
rng := rand.New(rand.NewSource(rngSeed))
// just go instantiate the struct instead of calling MakeL1Info
// see what has become of it.
l1Info := testutils.MakeBlockInfo(func(l *testutils.MockBlockInfo) {
l.InfoBaseFee = fuzzVars.InfoBaseFee
l.InfoTime = fuzzVars.InfoTime
l.InfoNum = fuzzVars.InfoNum
})(rng)
// Create our deposit tx from our info // Create our deposit tx from our info
testSysCfg := eth.SystemConfig{ depTx, err := L1InfoDeposit(seqNr, &l1Info, sysCfg)
BatcherAddr: common.Address{42},
Overhead: [32]byte{},
Scalar: [32]byte{},
}
depTx, err := L1InfoDeposit(seqNr, l1Info, testSysCfg)
require.NoError(t, err) require.NoError(t, err)
// Get our info from out deposit tx // Get our info from out deposit tx
...@@ -61,8 +41,10 @@ func FuzzParseL1InfoDepositTxDataValid(f *testing.F) { ...@@ -61,8 +41,10 @@ func FuzzParseL1InfoDepositTxDataValid(f *testing.F) {
require.Equal(t, res.BaseFee.Bytes(), l1Info.BaseFee().Bytes()) require.Equal(t, res.BaseFee.Bytes(), l1Info.BaseFee().Bytes())
require.Equal(t, res.BlockHash, l1Info.Hash()) require.Equal(t, res.BlockHash, l1Info.Hash())
require.Equal(t, res.SequenceNumber, seqNr) require.Equal(t, res.SequenceNumber, seqNr)
l1CfgFetcher := &testutils.MockL2Client{} require.Equal(t, res.BatcherAddr, sysCfg.BatcherAddr)
l1CfgFetcher.ExpectSystemConfigByL2Hash(res.BlockHash, testSysCfg, nil)
require.Equal(t, res.L1FeeOverhead, sysCfg.Overhead)
require.Equal(t, res.L1FeeScalar, sysCfg.Scalar)
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment