diff --git a/consensus/blake3pow/blake3pow_test.go b/consensus/blake3pow/blake3pow_test.go deleted file mode 100644 index 01bd0b6356..0000000000 --- a/consensus/blake3pow/blake3pow_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package blake3pow - -import ( - "io/ioutil" - "math/big" - "math/rand" - "os" - "sync" - "testing" - "time" - - "github.com/dominant-strategies/go-quai/common" - "github.com/dominant-strategies/go-quai/common/hexutil" - "github.com/dominant-strategies/go-quai/core/types" -) - -// Tests that blake3pow works correctly in test mode. -func TestTestMode(t *testing.T) { - header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)} - - blake3pow := NewTester(nil, false) - defer blake3pow.Close() - - results := make(chan *types.Block) - err := blake3pow.Seal(nil, types.NewBlockWithHeader(header), results, nil) - if err != nil { - t.Fatalf("failed to seal block: %v", err) - } - select { - case block := <-results: - header.Nonce() = types.EncodeNonce(block.Nonce()) - if err := blake3pow.verifySeal(header); err != nil { - t.Fatalf("unexpected verification error: %v", err) - } - case <-time.NewTimer(4 * time.Second).C: - t.Error("sealing result timeout") - } -} - -// This test checks that cache lru logic doesn't crash under load. -func TestCacheFileEvict(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "blake3pow-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - config := Config{ - CachesInMem: 3, - CachesOnDisk: 10, - CacheDir: tmpdir, - PowMode: ModeTest, - } - e := New(config, nil, false) - defer e.Close() - - workers := 8 - epochs := 100 - var wg sync.WaitGroup - wg.Add(workers) - for i := 0; i < workers; i++ { - go verifyTest(&wg, e, i, epochs) - } - wg.Wait() -} - -func verifyTest(wg *sync.WaitGroup, e *Blake3pow, workerIndex, epochs int) { - defer wg.Done() - - const wiggle = 4 * epochLength - r := rand.New(rand.NewSource(int64(workerIndex))) - for epoch := 0; epoch < epochs; epoch++ { - block := int64(epoch)*epochLength - wiggle/2 + r.Int63n(wiggle) - if block < 0 { - block = 0 - } - header := &types.Header{Number: big.NewInt(block), Difficulty: big.NewInt(100)} - e.verifySeal(header) - } -} - -func TestRemoteSealer(t *testing.T) { - blake3pow := NewTester(nil, false) - defer blake3pow.Close() - - api := &API{blake3pow} - if _, err := api.GetWork(); err != errNoMiningWork { - t.Error("expect to return an error indicate there is no mining work") - } - header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)} - block := types.NewBlockWithHeader(header) - sealhash := blake3pow.SealHash(header) - - // Push new work. - results := make(chan *types.Block) - blake3pow.Seal(nil, block, results, nil) - - var ( - work [4]string - err error - ) - if work, err = api.GetWork(); err != nil || work[0] != sealhash.Hex() { - t.Error("expect to return a mining work has same hash") - } - - if res := api.SubmitWork(types.BlockNonce{}, sealhash, common.Hash{}); res { - t.Error("expect to return false when submit a fake solution") - } - // Push new block with same block number to replace the original one. - header = &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(1000)} - block = types.NewBlockWithHeader(header) - sealhash = blake3pow.SealHash(header) - blake3pow.Seal(nil, block, results, nil) - - if work, err = api.GetWork(); err != nil || work[0] != sealhash.Hex() { - t.Error("expect to return the latest pushed work") - } -} - -func TestHashrate(t *testing.T) { - var ( - hashrate = []hexutil.Uint64{100, 200, 300} - expect uint64 - ids = []common.Hash{common.HexToHash("a"), common.HexToHash("b"), common.HexToHash("c")} - ) - blake3pow := NewTester(nil, false) - defer blake3pow.Close() - - if tot := blake3pow.Hashrate(); tot != 0 { - t.Error("expect the result should be zero") - } - - api := &API{blake3pow} - for i := 0; i < len(hashrate); i += 1 { - if res := api.SubmitHashrate(hashrate[i], ids[i]); !res { - t.Error("remote miner submit hashrate failed") - } - expect += uint64(hashrate[i]) - } - if tot := blake3pow.Hashrate(); tot != float64(expect) { - t.Error("expect total hashrate should be same") - } -} - -func TestClosedRemoteSealer(t *testing.T) { - blake3pow := NewTester(nil, false) - time.Sleep(1 * time.Second) // ensure exit channel is listening - blake3pow.Close() - - api := &API{blake3pow} - if _, err := api.GetWork(); err != errBlake3powStopped { - t.Error("expect to return an error to indicate blake3pow is stopped") - } - - if res := api.SubmitHashrate(hexutil.Uint64(100), common.HexToHash("a")); res { - t.Error("expect to return false when submit hashrate to a stopped blake3pow") - } -} diff --git a/consensus/blake3pow/consensus_test.go b/consensus/blake3pow/consensus_test.go deleted file mode 100644 index 0d7fbe310f..0000000000 --- a/consensus/blake3pow/consensus_test.go +++ /dev/null @@ -1,146 +0,0 @@ -package blake3pow - -import ( - "encoding/binary" - "encoding/json" - "math/big" - "math/rand" - "os" - "path/filepath" - "testing" - - "github.com/dominant-strategies/go-quai/common" - "github.com/dominant-strategies/go-quai/common/math" - "github.com/dominant-strategies/go-quai/core/types" - "github.com/dominant-strategies/go-quai/params" -) - -type diffTest struct { - ParentTimestamp uint64 - ParentDifficulty *big.Int - CurrentTimestamp uint64 - CurrentBlocknumber *big.Int - CurrentDifficulty *big.Int -} - -func (d *diffTest) UnmarshalJSON(b []byte) (err error) { - var ext struct { - ParentTimestamp string - ParentDifficulty string - CurrentTimestamp string - CurrentBlocknumber string - CurrentDifficulty string - } - if err := json.Unmarshal(b, &ext); err != nil { - return err - } - - d.ParentTimestamp = math.MustParseUint64(ext.ParentTimestamp) - d.ParentDifficulty = math.MustParseBig256(ext.ParentDifficulty) - d.CurrentTimestamp = math.MustParseUint64(ext.CurrentTimestamp) - d.CurrentBlocknumber = math.MustParseBig256(ext.CurrentBlocknumber) - d.CurrentDifficulty = math.MustParseBig256(ext.CurrentDifficulty) - - return nil -} - -func TestCalcDifficulty(t *testing.T) { - file, err := os.Open(filepath.Join("..", "..", "tests", "testdata", "BasicTests", "difficulty.json")) - if err != nil { - t.Skip(err) - } - defer file.Close() - - tests := make(map[string]diffTest) - err = json.NewDecoder(file).Decode(&tests) - if err != nil { - t.Fatal(err) - } - - config := ¶ms.ChainConfig{} - - for name, test := range tests { - number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1)) - diff := CalcDifficulty(config, test.CurrentTimestamp, &types.Header{ - Number: number, - Time: test.ParentTimestamp, - Difficulty: test.ParentDifficulty, - }) - if diff.Cmp(test.CurrentDifficulty) != 0 { - t.Error(name, "failed. Expected", test.CurrentDifficulty, "and calculated", diff) - } - } -} - -func randSlice(min, max uint32) []byte { - var b = make([]byte, 4) - rand.Read(b) - a := binary.LittleEndian.Uint32(b) - size := min + a%(max-min) - out := make([]byte, size) - rand.Read(out) - return out -} - -func TestDifficultyCalculators(t *testing.T) { - rand.Seed(2) - for i := 0; i < 5000; i++ { - // 1 to 300 seconds diff - var timeDelta = uint64(1 + rand.Uint32()%3000) - diffBig := big.NewInt(0).SetBytes(randSlice(2, 10)) - if diffBig.Cmp(params.MinimumDifficulty) < 0 { - diffBig.Set(params.MinimumDifficulty) - } - //rand.Read(difficulty) - header := &types.Header{ - Difficulty: diffBig, - Number: new(big.Int).SetUint64(rand.Uint64() % 50_000_000), - Time: rand.Uint64() - timeDelta, - } - if rand.Uint32()&1 == 0 { - header.UncleHash() = types.EmptyUncleHash - } - bombDelay := new(big.Int).SetUint64(rand.Uint64() % 50_000_000) - for i, pair := range []struct { - bigFn func(time uint64, parent *types.Header) *big.Int - u256Fn func(time uint64, parent *types.Header) *big.Int - }{ - {DynamicDifficultyCalculator(bombDelay), MakeDifficultyCalculatorU256(bombDelay)}, - } { - time := header.Time() + timeDelta - want := pair.bigFn(time, header) - have := pair.u256Fn(time, header) - if want.BitLen() > 256 { - continue - } - if want.Cmp(have) != 0 { - t.Fatalf("pair %d: want %x have %x\nparent.Number: %x\np.Time: %x\nc.Time: %x\nBombdelay: %v\n", i, want, have, - header.Number(), header.Time(), time, bombDelay) - } - } - } -} - -func BenchmarkDifficultyCalculator(b *testing.B) { - x1 := makeDifficultyCalculator(big.NewInt(1000000)) - x2 := MakeDifficultyCalculatorU256(big.NewInt(1000000)) - h := &types.Header{ - ParentHash: common.Hash{}, - UncleHash: types.EmptyUncleHash, - Difficulty: big.NewInt(0xffffff), - Number: big.NewInt(500000), - Time: 1000000, - } - b.Run("big-generic", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - x1(1000014, h) - } - }) - b.Run("u256-generic", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - x2(1000014, h) - } - }) -} diff --git a/consensus/blake3pow/sealer_test.go b/consensus/blake3pow/sealer_test.go deleted file mode 100644 index b5d36130d5..0000000000 --- a/consensus/blake3pow/sealer_test.go +++ /dev/null @@ -1,279 +0,0 @@ -package blake3pow - -import ( - "encoding/json" - "io/ioutil" - "math/big" - "net/http" - "net/http/httptest" - "strconv" - "testing" - "time" - - "github.com/dominant-strategies/go-quai/common" - "github.com/dominant-strategies/go-quai/core/types" - "github.com/dominant-strategies/go-quai/internal/testlog" - "github.com/dominant-strategies/go-quai/log" -) - -// Tests whether remote HTTP servers are correctly notified of new work. -func TestRemoteNotify(t *testing.T) { - // Start a simple web server to capture notifications. - sink := make(chan [3]string) - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) - if err != nil { - t.Errorf("failed to read miner notification: %v", err) - } - var work [3]string - if err := json.Unmarshal(blob, &work); err != nil { - t.Errorf("failed to unmarshal miner notification: %v", err) - } - sink <- work - })) - defer server.Close() - - // Create the custom blake3pow engine. - blake3pow := NewTester([]string{server.URL}, false) - defer blake3pow.Close() - - // Stream a work task and ensure the notification bubbles out. - header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)} - block := types.NewBlockWithHeader(header) - - blake3pow.Seal(nil, block, nil, nil) - select { - case work := <-sink: - if want := blake3pow.SealHash(header).Hex(); work[0] != want { - t.Errorf("work packet hash mismatch: have %s, want %s", work[0], want) - } - if want := common.BytesToHash(SeedHash(header.Number().Uint64())).Hex(); work[1] != want { - t.Errorf("work packet seed mismatch: have %s, want %s", work[1], want) - } - target := new(big.Int).Div(new(big.Int).Lsh(big.NewInt(1), 256), header.Difficulty()) - if want := common.BytesToHash(target.Bytes()).Hex(); work[2] != want { - t.Errorf("work packet target mismatch: have %s, want %s", work[2], want) - } - case <-time.After(3 * time.Second): - t.Fatalf("notification timed out") - } -} - -// Tests whether remote HTTP servers are correctly notified of new work. (Full pending block body / --miner.notify.full) -func TestRemoteNotifyFull(t *testing.T) { - // Start a simple web server to capture notifications. - sink := make(chan map[string]interface{}) - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) - if err != nil { - t.Errorf("failed to read miner notification: %v", err) - } - var work map[string]interface{} - if err := json.Unmarshal(blob, &work); err != nil { - t.Errorf("failed to unmarshal miner notification: %v", err) - } - sink <- work - })) - defer server.Close() - - // Create the custom blake3pow engine. - config := Config{ - PowMode: ModeTest, - NotifyFull: true, - Log: testlog.Logger(t, log.LvlWarn), - } - blake3pow := New(config, []string{server.URL}, false) - defer blake3pow.Close() - - // Stream a work task and ensure the notification bubbles out. - header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)} - block := types.NewBlockWithHeader(header) - - blake3pow.Seal(nil, block, nil, nil) - select { - case work := <-sink: - if want := "0x" + strconv.FormatUint(header.Number().Uint64(), 16); work["number"] != want { - t.Errorf("pending block number mismatch: have %v, want %v", work["number"], want) - } - if want := "0x" + header.Difficulty().Text(16); work["difficulty"] != want { - t.Errorf("pending block difficulty mismatch: have %s, want %s", work["difficulty"], want) - } - case <-time.After(3 * time.Second): - t.Fatalf("notification timed out") - } -} - -// Tests that pushing work packages fast to the miner doesn't cause any data race -// issues in the notifications. -func TestRemoteMultiNotify(t *testing.T) { - // Start a simple web server to capture notifications. - sink := make(chan [3]string, 64) - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) - if err != nil { - t.Errorf("failed to read miner notification: %v", err) - } - var work [3]string - if err := json.Unmarshal(blob, &work); err != nil { - t.Errorf("failed to unmarshal miner notification: %v", err) - } - sink <- work - })) - defer server.Close() - - // Create the custom blake3pow engine. - blake3pow := NewTester([]string{server.URL}, false) - blake3pow.config.Log = testlog.Logger(t, log.LvlWarn) - defer blake3pow.Close() - - // Provide a results reader. - // Otherwise the unread results will be logged asynchronously - // and this can happen after the test is finished, causing a panic. - results := make(chan *types.Block, cap(sink)) - - // Stream a lot of work task and ensure all the notifications bubble out. - for i := 0; i < cap(sink); i++ { - header := &types.Header{Number: big.NewInt(int64(i)), Difficulty: big.NewInt(100)} - block := types.NewBlockWithHeader(header) - blake3pow.Seal(nil, block, results, nil) - } - - for i := 0; i < cap(sink); i++ { - select { - case <-sink: - <-results - case <-time.After(10 * time.Second): - t.Fatalf("notification %d timed out", i) - } - } -} - -// Tests that pushing work packages fast to the miner doesn't cause any data race -// issues in the notifications. Full pending block body / --miner.notify.full) -func TestRemoteMultiNotifyFull(t *testing.T) { - // Start a simple web server to capture notifications. - sink := make(chan map[string]interface{}, 64) - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) - if err != nil { - t.Errorf("failed to read miner notification: %v", err) - } - var work map[string]interface{} - if err := json.Unmarshal(blob, &work); err != nil { - t.Errorf("failed to unmarshal miner notification: %v", err) - } - sink <- work - })) - defer server.Close() - - // Create the custom blake3pow engine. - config := Config{ - PowMode: ModeTest, - NotifyFull: true, - Log: testlog.Logger(t, log.LvlWarn), - } - blake3pow := New(config, []string{server.URL}, false) - defer blake3pow.Close() - - // Provide a results reader. - // Otherwise the unread results will be logged asynchronously - // and this can happen after the test is finished, causing a panic. - results := make(chan *types.Block, cap(sink)) - - // Stream a lot of work task and ensure all the notifications bubble out. - for i := 0; i < cap(sink); i++ { - header := &types.Header{Number: big.NewInt(int64(i)), Difficulty: big.NewInt(100)} - block := types.NewBlockWithHeader(header) - blake3pow.Seal(nil, block, results, nil) - } - - for i := 0; i < cap(sink); i++ { - select { - case <-sink: - <-results - case <-time.After(10 * time.Second): - t.Fatalf("notification %d timed out", i) - } - } -} - -// Tests whether stale solutions are correctly processed. -func TestStaleSubmission(t *testing.T) { - blake3pow := NewTester(nil, true) - defer blake3pow.Close() - api := &API{blake3pow} - - fakeNonce, fakeDigest := types.BlockNonce{0x01, 0x02, 0x03}, common.HexToHash("deadbeef") - - testcases := []struct { - headers []*types.Header - submitIndex int - submitRes bool - }{ - // Case1: submit solution for the latest mining package - { - []*types.Header{ - {ParentHash: common.BytesToHash([]byte{0xa}), Number: big.NewInt(1), Difficulty: big.NewInt(100000000)}, - }, - 0, - true, - }, - // Case2: submit solution for the previous package but have same parent. - { - []*types.Header{ - {ParentHash: common.BytesToHash([]byte{0xb}), Number: big.NewInt(2), Difficulty: big.NewInt(100000000)}, - {ParentHash: common.BytesToHash([]byte{0xb}), Number: big.NewInt(2), Difficulty: big.NewInt(100000001)}, - }, - 0, - true, - }, - // Case3: submit stale but acceptable solution - { - []*types.Header{ - {ParentHash: common.BytesToHash([]byte{0xc}), Number: big.NewInt(3), Difficulty: big.NewInt(100000000)}, - {ParentHash: common.BytesToHash([]byte{0xd}), Number: big.NewInt(9), Difficulty: big.NewInt(100000000)}, - }, - 0, - true, - }, - // Case4: submit very old solution - { - []*types.Header{ - {ParentHash: common.BytesToHash([]byte{0xe}), Number: big.NewInt(10), Difficulty: big.NewInt(100000000)}, - {ParentHash: common.BytesToHash([]byte{0xf}), Number: big.NewInt(17), Difficulty: big.NewInt(100000000)}, - }, - 0, - false, - }, - } - results := make(chan *types.Block, 16) - - for id, c := range testcases { - for _, h := range c.headers { - blake3pow.Seal(nil, types.NewBlockWithHeader(h), results, nil) - } - if res := api.SubmitWork(fakeNonce, blake3pow.SealHash(c.headers[c.submitIndex]), fakeDigest); res != c.submitRes { - t.Errorf("case %d submit result mismatch, want %t, get %t", id+1, c.submitRes, res) - } - if !c.submitRes { - continue - } - select { - case res := <-results: - if res.Header().Nonce() != fakeNonce { - t.Errorf("case %d block nonce mismatch, want %x, get %x", id+1, fakeNonce, res.Header().Nonce()) - } - if res.Header().Difficulty().Uint64() != c.headers[c.submitIndex].Difficulty().Uint64() { - t.Errorf("case %d block difficulty mismatch, want %d, get %d", id+1, c.headers[c.submitIndex].Difficulty(), res.Header().Difficulty()) - } - if res.Header().Number().Uint64() != c.headers[c.submitIndex].Number().Uint64() { - t.Errorf("case %d block number mismatch, want %d, get %d", id+1, c.headers[c.submitIndex].Number().Uint64(), res.Header().Number().Uint64()) - } - if res.Header().ParentHash() != c.headers[c.submitIndex].ParentHash() { - t.Errorf("case %d block parent hash mismatch, want %s, get %s", id+1, c.headers[c.submitIndex].ParentHash().Hex(), res.Header().ParentHash().Hex()) - } - case <-time.NewTimer(time.Second).C: - t.Errorf("case %d fetch blake3pow result timeout", id+1) - } - } -} diff --git a/consensus/misc/basefee_test.go b/consensus/misc/basefee_test.go deleted file mode 100644 index 01c80efeda..0000000000 --- a/consensus/misc/basefee_test.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2021 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package misc - -import ( - "fmt" - "math/big" - "testing" - - "github.com/dominant-strategies/go-quai/common" - "github.com/dominant-strategies/go-quai/core/types" - "github.com/dominant-strategies/go-quai/params" -) - -// copyConfig does a _shallow_ copy of a given config. Safe to set new values, but -// do not use e.g. SetInt() on the numbers. For testing only -func copyConfig(original *params.ChainConfig) *params.ChainConfig { - return ¶ms.ChainConfig{ - ChainID: original.ChainID, - Progpow: original.Progpow, - } -} - -func config() *params.ChainConfig { - config := copyConfig(params.TestChainConfig) - return config -} - -// TestBlockGasLimits tests the gasLimit checks for blocks -func TestBlockGasLimits(t *testing.T) { - initial := new(big.Int).SetUint64(params.InitialBaseFee) - - for i, tc := range []struct { - pGasLimit uint64 - pNum int64 - gasLimit uint64 - ok bool - }{ - - {10000000, 4, 20000000, true}, // No change - {10000000, 4, 20019530, true}, // Upper limit - {10000000, 4, 20019531, false}, // Upper +1 - {10000000, 4, 19980470, true}, // Lower limit - {10000000, 4, 19980469, false}, // Lower limit -1 - - {20000000, 5, 20000000, true}, - {20000000, 5, 20019530, true}, // Upper limit - {20000000, 5, 20019531, false}, // Upper limit +1 - {20000000, 5, 19980470, true}, // Lower limit - {20000000, 5, 19980469, false}, // Lower limit -1 - {40000000, 5, 40039061, true}, // Upper limit - {40000000, 5, 40039062, false}, // Upper limit +1 - {40000000, 5, 39960939, true}, // lower limit - {40000000, 5, 39960938, false}, // Lower limit -1 - } { - parent := &types.Header{ - GasUsed: tc.pGasLimit / 2, - GasLimit: tc.pGasLimit, - BaseFee: initial, - Number: big.NewInt(tc.pNum), - } - header := &types.Header{ - GasUsed: tc.gasLimit / 2, - GasLimit: tc.gasLimit, - BaseFee: initial, - Number: big.NewInt(tc.pNum + 1), - } - // Verify that the gas limit remains within allowed bounds - parentGasLimit := parent.GasLimit() - var err error - if err := VerifyGaslimit(parentGasLimit, header.GasLimit()); err != nil { - t.Error(err) - } - // Verify the header is not malformed - if header.BaseFee() == nil { - err = fmt.Errorf("header is missing baseFee") - } - // Verify the baseFee is correct based on the parent header. - expectedBaseFee := CalcBaseFee(config(), parent) - if header.BaseFee().Cmp(expectedBaseFee) != 0 { - err = fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d", - expectedBaseFee, header.BaseFee(), parent.BaseFee(), parent.GasUsed()) - } - - if tc.ok && err != nil { - t.Errorf("test %d: Expected valid header: %s", i, err) - } - if !tc.ok && err == nil { - t.Errorf("test %d: Expected invalid header", i) - } - } -} - -func TestCalcBaseFee(t *testing.T) { - tests := []struct { - parentBaseFee int64 - parentGasLimit uint64 - parentGasUsed uint64 - expectedBaseFee int64 - }{ - {params.InitialBaseFee, 20000000, 10000000, params.InitialBaseFee}, // usage == target - {params.InitialBaseFee, 20000000, 9000000, 987500000}, // usage below target - {params.InitialBaseFee, 20000000, 11000000, 1012500000}, // usage above target - } - for i, test := range tests { - parent := &types.Header{ - Number: common.Big32, - GasLimit: test.parentGasLimit, - GasUsed: test.parentGasUsed, - BaseFee: big.NewInt(test.parentBaseFee), - } - if have, want := CalcBaseFee(config(), parent), big.NewInt(test.expectedBaseFee); have.Cmp(want) != 0 { - t.Errorf("test %d: have %d want %d, ", i, have, want) - } - } -}