fix(stateless): add minimum test for issue#31631

This commit is contained in:
John Xu 2025-04-17 15:49:40 +08:00
parent cb21177aa8
commit 978de7542d
No known key found for this signature in database
GPG key ID: 86C66198F3647356
5 changed files with 100 additions and 0 deletions

97
core/stateless_test.go Normal file
View file

@ -0,0 +1,97 @@
// Copyright 2024 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 <http://www.gnu.org/licenses/>.
package core
import (
"encoding/json"
"reflect"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/stateless"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
_ "embed"
)
//go:embed stateless_testdata/witness.rlp
var witnessData []byte
//go:embed stateless_testdata/block.rlp
var blockData []byte
//go:embed stateless_testdata/chain_config.json
var chainConfigData []byte
func TestExecuteStateless(t *testing.T) {
var block types.Block
if err := rlp.DecodeBytes(blockData, &block); err != nil {
t.Fatalf("failed to unmarshal block: %v", err)
}
var witness stateless.Witness
if err := rlp.DecodeBytes(witnessData, &witness); err != nil {
t.Fatalf("failed to unmarshal witness: %v", err)
}
var config params.ChainConfig
if err := json.Unmarshal(chainConfigData, &config); err != nil {
t.Fatalf("failed to unmarshal chain config: %v", err)
}
type args struct {
config *params.ChainConfig
vmconfig vm.Config
block *types.Block
witness *stateless.Witness
}
tests := []struct {
name string
args args
want common.Hash
want1 common.Hash
wantErr bool
}{
{
"issue:https://github.com/ethereum/go-ethereum/issues/31631",
args{
&config,
vm.Config{},
&block,
&witness,
},
common.HexToHash("0x9175f245714f8595e099ce523f329f45fde1fe92b57ea10059e4243512ae931d"),
common.HexToHash("0x19d5540a8f734f731969baa459be6a745da2ca3c0397a41605bc6548dc960bb3"),
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := ExecuteStateless(tt.args.config, tt.args.vmconfig, tt.args.block, tt.args.witness)
if (err != nil) != tt.wantErr {
t.Errorf("ExecuteStateless() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ExecuteStateless() got = %v, want %v", got, tt.want)
}
if !reflect.DeepEqual(got1, tt.want1) {
t.Errorf("ExecuteStateless() got1 = %v, want %v", got1, tt.want1)
}
})
}
}

Binary file not shown.

View file

@ -0,0 +1 @@
{"chainId":167009,"homesteadBlock":0,"eip150Block":0,"eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"berlinBlock":0,"londonBlock":0,"shanghaiTime":0,"terminalTotalDifficulty":0,"depositContractAddress":"0x0000000000000000000000000000000000000000","taiko":true,"ontakeBlock":840512,"pacayaBlock":1299888}

Binary file not shown.

View file

@ -519,6 +519,8 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
// check.
cnode, err := t.resolve(n.Children[pos], append(prefix, byte(pos)))
if err != nil {
// Ignore the error will pass the test
// cnode = n.Children[pos]
return false, nil, err
}
if cnode, ok := cnode.(*shortNode); ok {