fix some tests (#857)

* fix cmd/geth/consolecmd_test.go

* fix testBackend

* fix `TestGolangBindings` & `TestAdjustTime`

* update js_tracer tests

* refactor
This commit is contained in:
HAOYUatHZ 2024-06-27 22:30:08 +08:00 committed by GitHub
parent b6a17e33f1
commit 86c37a9075
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 10 deletions

View file

@ -80,8 +80,13 @@ type SimulatedBackend struct {
// and uses a simulated blockchain for testing purposes. // and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337. // A simulated backend always uses chainID 1337.
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend { func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
// copy AllEthashProtocolChanges and enable zktrie
chainCfg := new(params.ChainConfig)
*chainCfg = *params.AllEthashProtocolChanges
chainCfg.Scroll.UseZktrie = true
genesis := core.Genesis{ genesis := core.Genesis{
Config: params.AllEthashProtocolChanges, Config: chainCfg,
GasLimit: gasLimit, GasLimit: gasLimit,
Alloc: alloc, Alloc: alloc,
} }

View file

@ -30,7 +30,7 @@ import (
) )
const ( const (
ipcAPIs = "admin:1.0 clique:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 txpool:1.0 web3:1.0" ipcAPIs = "admin:1.0 clique:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 scroll:1.0 txpool:1.0 web3:1.0"
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0" httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0"
) )

View file

@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
@ -180,6 +181,10 @@ func (b *testBackend) ServiceFilter(ctx context.Context, session *bloombits.Matc
}() }()
} }
func (b *testBackend) StateAt(root common.Hash) (*state.StateDB, error) {
panic("not supported")
}
func newTestFilterSystem(t testing.TB, db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) { func newTestFilterSystem(t testing.TB, db ethdb.Database, cfg Config) (*testBackend, *FilterSystem) {
backend := &testBackend{db: db} backend := &testBackend{db: db}
sys := NewFilterSystem(backend, cfg) sys := NewFilterSystem(backend, cfg)

View file

@ -260,9 +260,9 @@ func TestIsPrecompile(t *testing.T) {
} }
// test sha disabled in archimedes // test sha disabled in archimedes
tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000002'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil) tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000002'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil, nil)
blockCtx = vm.BlockContext{BlockNumber: big.NewInt(450)} blockCtx = vm.BlockContext{BlockNumber: big.NewInt(450)}
res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg) res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -270,9 +270,9 @@ func TestIsPrecompile(t *testing.T) {
t.Errorf("Tracer should not consider blake2f as precompile in archimedes") t.Errorf("Tracer should not consider blake2f as precompile in archimedes")
} }
tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000003'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil) tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000003'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil, nil)
blockCtx = vm.BlockContext{BlockNumber: big.NewInt(450)} blockCtx = vm.BlockContext{BlockNumber: big.NewInt(450)}
res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg) res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -281,8 +281,8 @@ func TestIsPrecompile(t *testing.T) {
} }
// test blake2f disabled in archimedes // test blake2f disabled in archimedes
tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000009'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil) tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000009'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil, nil)
res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg) res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -291,8 +291,8 @@ func TestIsPrecompile(t *testing.T) {
} }
// test ecrecover enabled in archimedes // test ecrecover enabled in archimedes
tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000001'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil) tracer, _ = newJsTracer("{addr: toAddress('0000000000000000000000000000000000000001'), res: null, step: function() { this.res = isPrecompiled(this.addr); }, fault: function() {}, result: function() { return this.res; }}", nil, nil)
res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg) res, err = runTrace(tracer, &vmContext{blockCtx, txCtx}, chaincfg, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }