Skip to content

Commit 686f485

Browse files
committed
tests: updates
core, core/txpool/blobpool: fix tests core/vm: fix tests core/txpool/legacypool: fix tests eth/tracers: fix tests trie: fix tests core/state, core/vm/runtime: fix tests eth: fix tests miner: fix tests
1 parent db338c9 commit 686f485

27 files changed

+209
-198
lines changed

core/blockchain_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/ethdb"
4141
"github.com/ethereum/go-ethereum/params"
4242
"github.com/ethereum/go-ethereum/trie"
43+
"github.com/holiman/uint256"
4344
)
4445

4546
// So we can deterministically seed different blockchains
@@ -3652,7 +3653,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) {
36523653
defer chain.Stop()
36533654

36543655
statedb, _ := chain.State()
3655-
if got, exp := statedb.GetBalance(aa), big.NewInt(100000); got.Cmp(exp) != 0 {
3656+
if got, exp := statedb.GetBalance(aa), uint256.NewInt(100000); got.Cmp(exp) != 0 {
36563657
t.Fatalf("Genesis err, got %v exp %v", got, exp)
36573658
}
36583659
// First block tries to create, but fails
@@ -3662,7 +3663,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) {
36623663
t.Fatalf("block %d: failed to insert into chain: %v", block.NumberU64(), err)
36633664
}
36643665
statedb, _ = chain.State()
3665-
if got, exp := statedb.GetBalance(aa), big.NewInt(100000); got.Cmp(exp) != 0 {
3666+
if got, exp := statedb.GetBalance(aa), uint256.NewInt(100000); got.Cmp(exp) != 0 {
36663667
t.Fatalf("block %d: got %v exp %v", block.NumberU64(), got, exp)
36673668
}
36683669
}
@@ -3848,17 +3849,17 @@ func testEIP1559Transition(t *testing.T, scheme string) {
38483849
state, _ := chain.State()
38493850

38503851
// 3: Ensure that miner received only the tx's tip.
3851-
actual := state.GetBalance(block.Coinbase())
3852+
actual := state.GetBalance(block.Coinbase()).ToBig()
38523853
expected := new(big.Int).Add(
38533854
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()),
3854-
ethash.ConstantinopleBlockReward,
3855+
ethash.ConstantinopleBlockReward.ToBig(),
38553856
)
38563857
if actual.Cmp(expected) != 0 {
38573858
t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual)
38583859
}
38593860

38603861
// 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
3861-
actual = new(big.Int).Sub(funds, state.GetBalance(addr1))
3862+
actual = new(big.Int).Sub(funds, state.GetBalance(addr1).ToBig())
38623863
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64()))
38633864
if actual.Cmp(expected) != 0 {
38643865
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual)
@@ -3888,17 +3889,17 @@ func testEIP1559Transition(t *testing.T, scheme string) {
38883889
effectiveTip := block.Transactions()[0].GasTipCap().Uint64() - block.BaseFee().Uint64()
38893890

38903891
// 6+5: Ensure that miner received only the tx's effective tip.
3891-
actual = state.GetBalance(block.Coinbase())
3892+
actual = state.GetBalance(block.Coinbase()).ToBig()
38923893
expected = new(big.Int).Add(
38933894
new(big.Int).SetUint64(block.GasUsed()*effectiveTip),
3894-
ethash.ConstantinopleBlockReward,
3895+
ethash.ConstantinopleBlockReward.ToBig(),
38953896
)
38963897
if actual.Cmp(expected) != 0 {
38973898
t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual)
38983899
}
38993900

39003901
// 4: Ensure the tx sender paid for the gasUsed * (effectiveTip + block baseFee).
3901-
actual = new(big.Int).Sub(funds, state.GetBalance(addr2))
3902+
actual = new(big.Int).Sub(funds, state.GetBalance(addr2).ToBig())
39023903
expected = new(big.Int).SetUint64(block.GasUsed() * (effectiveTip + block.BaseFee().Uint64()))
39033904
if actual.Cmp(expected) != 0 {
39043905
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual)
@@ -4703,14 +4704,14 @@ func TestEIP3651(t *testing.T) {
47034704
state, _ := chain.State()
47044705

47054706
// 3: Ensure that miner received only the tx's tip.
4706-
actual := state.GetBalance(block.Coinbase())
4707+
actual := state.GetBalance(block.Coinbase()).ToBig()
47074708
expected := new(big.Int).SetUint64(block.GasUsed() * block.Transactions()[0].GasTipCap().Uint64())
47084709
if actual.Cmp(expected) != 0 {
47094710
t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual)
47104711
}
47114712

47124713
// 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
4713-
actual = new(big.Int).Sub(funds, state.GetBalance(addr1))
4714+
actual = new(big.Int).Sub(funds, state.GetBalance(addr1).ToBig())
47144715
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64()))
47154716
if actual.Cmp(expected) != 0 {
47164717
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual)

core/state/snapshot/generate_test.go

+57-57
Large diffs are not rendered by default.

core/state/snapshot/snapshot_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
crand "crypto/rand"
2121
"encoding/binary"
2222
"fmt"
23-
"math/big"
2423
"math/rand"
2524
"testing"
2625
"time"
@@ -30,6 +29,7 @@ import (
3029
"github.com/ethereum/go-ethereum/core/rawdb"
3130
"github.com/ethereum/go-ethereum/core/types"
3231
"github.com/ethereum/go-ethereum/rlp"
32+
"github.com/holiman/uint256"
3333
)
3434

3535
// randomHash generates a random blob of data and returns it as a hash.
@@ -44,7 +44,7 @@ func randomHash() common.Hash {
4444
// randomAccount generates a random account and returns it RLP encoded.
4545
func randomAccount() []byte {
4646
a := &types.StateAccount{
47-
Balance: big.NewInt(rand.Int63()),
47+
Balance: uint256.NewInt(rand.Uint64()),
4848
Nonce: rand.Uint64(),
4949
Root: randomHash(),
5050
CodeHash: types.EmptyCodeHash[:],

core/state/state_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package state
1919
import (
2020
"bytes"
2121
"encoding/json"
22-
"math/big"
2322
"testing"
2423

2524
"github.com/ethereum/go-ethereum/common"
@@ -28,6 +27,7 @@ import (
2827
"github.com/ethereum/go-ethereum/crypto"
2928
"github.com/ethereum/go-ethereum/ethdb"
3029
"github.com/ethereum/go-ethereum/trie"
30+
"github.com/holiman/uint256"
3131
)
3232

3333
type stateEnv struct {
@@ -49,11 +49,11 @@ func TestDump(t *testing.T) {
4949

5050
// generate a few entries
5151
obj1 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x01}))
52-
obj1.AddBalance(big.NewInt(22))
52+
obj1.AddBalance(uint256.NewInt(22))
5353
obj2 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x01, 0x02}))
5454
obj2.SetCode(crypto.Keccak256Hash([]byte{3, 3, 3, 3, 3, 3, 3}), []byte{3, 3, 3, 3, 3, 3, 3})
5555
obj3 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x02}))
56-
obj3.SetBalance(big.NewInt(44))
56+
obj3.SetBalance(uint256.NewInt(44))
5757

5858
// write some of them to the trie
5959
s.state.updateStateObject(obj1)
@@ -106,13 +106,13 @@ func TestIterativeDump(t *testing.T) {
106106

107107
// generate a few entries
108108
obj1 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x01}))
109-
obj1.AddBalance(big.NewInt(22))
109+
obj1.AddBalance(uint256.NewInt(22))
110110
obj2 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x01, 0x02}))
111111
obj2.SetCode(crypto.Keccak256Hash([]byte{3, 3, 3, 3, 3, 3, 3}), []byte{3, 3, 3, 3, 3, 3, 3})
112112
obj3 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x02}))
113-
obj3.SetBalance(big.NewInt(44))
113+
obj3.SetBalance(uint256.NewInt(44))
114114
obj4 := s.state.getOrNewStateObject(common.BytesToAddress([]byte{0x00}))
115-
obj4.AddBalance(big.NewInt(1337))
115+
obj4.AddBalance(uint256.NewInt(1337))
116116

117117
// write some of them to the trie
118118
s.state.updateStateObject(obj1)
@@ -208,7 +208,7 @@ func TestSnapshot2(t *testing.T) {
208208

209209
// db, trie are already non-empty values
210210
so0 := state.getStateObject(stateobjaddr0)
211-
so0.SetBalance(big.NewInt(42))
211+
so0.SetBalance(uint256.NewInt(42))
212212
so0.SetNonce(43)
213213
so0.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e'}), []byte{'c', 'a', 'f', 'e'})
214214
so0.selfDestructed = false
@@ -220,7 +220,7 @@ func TestSnapshot2(t *testing.T) {
220220

221221
// and one with deleted == true
222222
so1 := state.getStateObject(stateobjaddr1)
223-
so1.SetBalance(big.NewInt(52))
223+
so1.SetBalance(uint256.NewInt(52))
224224
so1.SetNonce(53)
225225
so1.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e', '2'}), []byte{'c', 'a', 'f', 'e', '2'})
226226
so1.selfDestructed = true

core/state/statedb_fuzz_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"math"
25-
"math/big"
2625
"math/rand"
2726
"reflect"
2827
"strings"
@@ -38,6 +37,7 @@ import (
3837
"github.com/ethereum/go-ethereum/trie"
3938
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
4039
"github.com/ethereum/go-ethereum/trie/triestate"
40+
"github.com/holiman/uint256"
4141
)
4242

4343
// A stateTest checks that the state changes are correctly captured. Instances
@@ -60,7 +60,7 @@ func newStateTestAction(addr common.Address, r *rand.Rand, index int) testAction
6060
{
6161
name: "SetBalance",
6262
fn: func(a testAction, s *StateDB) {
63-
s.SetBalance(addr, big.NewInt(a.args[0]))
63+
s.SetBalance(addr, uint256.NewInt(uint64(a.args[0])))
6464
},
6565
args: make([]int64, 1),
6666
},

0 commit comments

Comments
 (0)