Skip to content

Commit b34986e

Browse files
committed
geth upgrade test
1 parent 3a3af97 commit b34986e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1476
-477
lines changed

Diff for: app/ante_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
app "github.com/sei-protocol/sei-chain/app"
2828
"github.com/sei-protocol/sei-chain/app/apptesting"
2929
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
30-
"github.com/sei-protocol/sei-chain/x/evm/types"
3130
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
3231
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
3332
"github.com/stretchr/testify/require"
@@ -243,7 +242,7 @@ func TestEvmAnteErrorHandler(t *testing.T) {
243242
require.Nil(t, err)
244243
txwrapper, err := ethtx.NewLegacyTx(tx)
245244
require.Nil(t, err)
246-
req, err := types.NewMsgEVMTransaction(txwrapper)
245+
req, err := evmtypes.NewMsgEVMTransaction(txwrapper)
247246
require.Nil(t, err)
248247
builder := testkeeper.EVMTestApp.GetTxConfig().NewTxBuilder()
249248
builder.SetMsgs(req)

Diff for: app/eth_replay.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
ethtypes "github.com/ethereum/go-ethereum/core/types"
1818
"github.com/ethereum/go-ethereum/params"
1919
ethtests "github.com/ethereum/go-ethereum/tests"
20+
"github.com/holiman/uint256"
2021
"github.com/sei-protocol/sei-chain/utils"
2122
"github.com/sei-protocol/sei-chain/x/evm/state"
2223
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
@@ -85,7 +86,7 @@ func Replay(a *App) {
8586
for _, w := range b.Withdrawals() {
8687
amount := new(big.Int).SetUint64(w.Amount)
8788
amount = amount.Mul(amount, big.NewInt(params.GWei))
88-
s.AddBalance(w.Address, amount, tracing.BalanceIncreaseWithdrawal)
89+
s.AddBalance(w.Address, uint256.MustFromBig(amount), tracing.BalanceIncreaseWithdrawal)
8990
}
9091
_, _ = s.Finalize()
9192
for _, tx := range b.Txs {
@@ -123,6 +124,19 @@ func BlockTest(a *App, bt *ethtests.BlockTest) {
123124
panic(err)
124125
}
125126

127+
ethblocks := make([]*ethtypes.Block, len(bt.Json.Blocks))
128+
for i, btBlock := range bt.Json.Blocks {
129+
b, err := btBlock.Decode()
130+
if err != nil {
131+
panic(err)
132+
}
133+
ethblocks[i] = b
134+
}
135+
if bf := ethblocks[0].BaseFee(); bf != nil {
136+
a.EvmKeeper.SetCurrBaseFeePerGas(a.GetContextForDeliverTx([]byte{}), sdk.NewDecFromBigInt(bf))
137+
} else {
138+
a.EvmKeeper.SetCurrBaseFeePerGas(a.GetContextForDeliverTx([]byte{}), sdk.ZeroDec())
139+
}
126140
for addr, genesisAccount := range a.EvmKeeper.BlockTest.Json.Pre {
127141
usei, wei := state.SplitUseiWeiAmount(genesisAccount.Balance)
128142
seiAddr := a.EvmKeeper.GetSeiAddressOrDefault(a.GetContextForDeliverTx([]byte{}), addr)
@@ -148,14 +162,12 @@ func BlockTest(a *App, bt *ethtests.BlockTest) {
148162
panic("no blocks found")
149163
}
150164

151-
ethblocks := make([]*ethtypes.Block, 0)
152165
for i, btBlock := range bt.Json.Blocks {
153166
h := int64(i + 1)
154167
b, err := btBlock.Decode()
155168
if err != nil {
156169
panic(err)
157170
}
158-
ethblocks = append(ethblocks, b)
159171
hash := make([]byte, 8)
160172
binary.BigEndian.PutUint64(hash, uint64(h))
161173
_, err = a.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{
@@ -169,6 +181,13 @@ func BlockTest(a *App, bt *ethtests.BlockTest) {
169181
if err != nil {
170182
panic(err)
171183
}
184+
if i+1 < len(ethblocks) {
185+
if bf := ethblocks[i+1].BaseFee(); bf != nil {
186+
a.EvmKeeper.SetCurrBaseFeePerGas(a.GetContextForDeliverTx([]byte{}), sdk.NewDecFromBigInt(bf))
187+
} else {
188+
a.EvmKeeper.SetCurrBaseFeePerGas(a.GetContextForDeliverTx([]byte{}), sdk.ZeroDec())
189+
}
190+
}
172191
_, err = a.Commit(context.Background())
173192
if err != nil {
174193
panic(err)
@@ -183,7 +202,7 @@ func BlockTest(a *App, bt *ethtests.BlockTest) {
183202
continue
184203
}
185204
// Not checking compliance with EIP-4788
186-
if addr == params.BeaconRootsStorageAddress {
205+
if addr == params.BeaconRootsAddress {
187206
fmt.Println("Skipping beacon roots storage address: ", addr)
188207
continue
189208
}

Diff for: evmrpc/block.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/ethereum/go-ethereum/common"
2020
"github.com/ethereum/go-ethereum/common/hexutil"
2121
ethtypes "github.com/ethereum/go-ethereum/core/types"
22-
"github.com/ethereum/go-ethereum/lib/ethapi"
22+
"github.com/ethereum/go-ethereum/export"
2323
"github.com/ethereum/go-ethereum/rpc"
2424
"github.com/sei-protocol/sei-chain/x/evm/keeper"
2525
"github.com/sei-protocol/sei-chain/x/evm/state"
@@ -303,6 +303,7 @@ func EncodeTmBlock(
303303
transactions := []interface{}{}
304304

305305
for i, txRes := range blockRes.TxsResults {
306+
fmt.Println(i)
306307
blockGasUsed += txRes.GasUsed
307308
decoded, err := txDecoder(block.Block.Txs[i])
308309
if err != nil {
@@ -335,7 +336,7 @@ func EncodeTmBlock(
335336
if !fullTx {
336337
transactions = append(transactions, hash)
337338
} else {
338-
newTx := ethapi.NewRPCTransaction(ethtx, blockhash, number.Uint64(), uint64(blockTime.Second()), uint64(receipt.TransactionIndex), baseFeePerGas, chainConfig)
339+
newTx := export.NewRPCTransaction(ethtx, blockhash, number.Uint64(), uint64(blockTime.Second()), uint64(receipt.TransactionIndex), baseFeePerGas, chainConfig)
339340
transactions = append(transactions, newTx)
340341
}
341342
case *wasmtypes.MsgExecuteContract:
@@ -352,7 +353,7 @@ func EncodeTmBlock(
352353
} else {
353354
ti := uint64(receipt.TransactionIndex)
354355
to := k.GetEVMAddressOrDefault(ctx, sdk.MustAccAddressFromBech32(m.Contract))
355-
transactions = append(transactions, &ethapi.RPCTransaction{
356+
transactions = append(transactions, &export.RPCTransaction{
356357
BlockHash: &blockhash,
357358
BlockNumber: (*hexutil.Big)(number),
358359
From: common.HexToAddress(receipt.From),
@@ -370,7 +371,7 @@ func EncodeTmBlock(
370371
if !fullTx {
371372
transactions = append(transactions, "0x"+hex.EncodeToString(th[:]))
372373
} else {
373-
rpcTx := &ethapi.RPCTransaction{
374+
rpcTx := &export.RPCTransaction{
374375
BlockHash: &blockhash,
375376
BlockNumber: (*hexutil.Big)(number),
376377
Hash: th,

Diff for: evmrpc/block_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/ethereum/go-ethereum/common"
1515
"github.com/ethereum/go-ethereum/common/hexutil"
1616
ethtypes "github.com/ethereum/go-ethereum/core/types"
17-
"github.com/ethereum/go-ethereum/lib/ethapi"
17+
"github.com/ethereum/go-ethereum/export"
1818
"github.com/sei-protocol/sei-chain/evmrpc"
1919
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
2020
"github.com/sei-protocol/sei-chain/x/evm/types"
@@ -306,7 +306,7 @@ func TestEncodeWasmExecuteMsg(t *testing.T) {
306306
ti := uint64(1)
307307
bh := common.HexToHash(MockBlockID.Hash.String())
308308
to := common.Address(toSeiAddr)
309-
require.Equal(t, &ethapi.RPCTransaction{
309+
require.Equal(t, &export.RPCTransaction{
310310
BlockHash: &bh,
311311
BlockNumber: (*hexutil.Big)(big.NewInt(MockHeight8)),
312312
From: fromEvmAddr,
@@ -317,7 +317,7 @@ func TestEncodeWasmExecuteMsg(t *testing.T) {
317317
V: nil,
318318
R: nil,
319319
S: nil,
320-
}, txs[0].(*ethapi.RPCTransaction))
320+
}, txs[0].(*export.RPCTransaction))
321321
}
322322

323323
func TestEncodeBankTransferMsg(t *testing.T) {
@@ -365,7 +365,7 @@ func TestEncodeBankTransferMsg(t *testing.T) {
365365
require.Equal(t, 1, len(txs))
366366
bh := common.HexToHash(MockBlockID.Hash.String())
367367
to := common.Address(toSeiAddr)
368-
require.Equal(t, &ethapi.RPCTransaction{
368+
require.Equal(t, &export.RPCTransaction{
369369
BlockHash: &bh,
370370
BlockNumber: (*hexutil.Big)(big.NewInt(MockHeight8)),
371371
From: fromEvmAddr,
@@ -375,5 +375,5 @@ func TestEncodeBankTransferMsg(t *testing.T) {
375375
V: nil,
376376
R: nil,
377377
S: nil,
378-
}, txs[0].(*ethapi.RPCTransaction))
378+
}, txs[0].(*export.RPCTransaction))
379379
}

Diff for: evmrpc/send.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/common/hexutil"
1313
ethtypes "github.com/ethereum/go-ethereum/core/types"
14-
"github.com/ethereum/go-ethereum/lib/ethapi"
14+
"github.com/ethereum/go-ethereum/export"
1515
"github.com/ethereum/go-ethereum/signer/core/apitypes"
1616
"github.com/sei-protocol/sei-chain/x/evm/keeper"
1717
"github.com/sei-protocol/sei-chain/x/evm/types"
@@ -94,10 +94,13 @@ func (s *SendAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (
9494
return
9595
}
9696

97-
func (s *SendAPI) SignTransaction(_ context.Context, args apitypes.SendTxArgs, _ *string) (result *ethapi.SignTransactionResult, returnErr error) {
97+
func (s *SendAPI) SignTransaction(_ context.Context, args apitypes.SendTxArgs, _ *string) (result *export.SignTransactionResult, returnErr error) {
9898
startTime := time.Now()
9999
defer recordMetrics("eth_signTransaction", s.connectionType, startTime, returnErr == nil)
100-
var unsignedTx = args.ToTransaction()
100+
unsignedTx, err := args.ToTransaction()
101+
if err != nil {
102+
return nil, err
103+
}
101104
signedTx, err := s.signTransaction(unsignedTx, args.From.Address().Hex())
102105
if err != nil {
103106
return nil, err
@@ -106,16 +109,16 @@ func (s *SendAPI) SignTransaction(_ context.Context, args apitypes.SendTxArgs, _
106109
if err != nil {
107110
return nil, err
108111
}
109-
return &ethapi.SignTransactionResult{Raw: data, Tx: signedTx}, nil
112+
return &export.SignTransactionResult{Raw: data, Tx: signedTx}, nil
110113
}
111114

112-
func (s *SendAPI) SendTransaction(ctx context.Context, args ethapi.TransactionArgs) (result common.Hash, returnErr error) {
115+
func (s *SendAPI) SendTransaction(ctx context.Context, args export.TransactionArgs) (result common.Hash, returnErr error) {
113116
startTime := time.Now()
114117
defer recordMetrics("eth_sendTransaction", s.connectionType, startTime, returnErr == nil)
115-
if err := args.SetDefaults(ctx, s.backend); err != nil {
118+
if err := args.SetDefaults(ctx, s.backend, false); err != nil {
116119
return common.Hash{}, err
117120
}
118-
var unsignedTx = args.ToTransaction()
121+
var unsignedTx = args.ToTransaction(ethtypes.LegacyTxType)
119122
signedTx, err := s.signTransaction(unsignedTx, args.From.Hex())
120123
if err != nil {
121124
return common.Hash{}, err

Diff for: evmrpc/setup_test.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/sei-protocol/sei-chain/x/evm/config"
3030
"github.com/sei-protocol/sei-chain/x/evm/keeper"
3131
"github.com/sei-protocol/sei-chain/x/evm/types"
32-
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
3332
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
3433
"github.com/stretchr/testify/require"
3534
abci "github.com/tendermint/tendermint/abci/types"
@@ -62,9 +61,9 @@ var MultiTxBlockHash = "0x000000000000000000000000000000000000000000000000000000
6261
var TestCosmosTxHash = "690D39ADF56D4C811B766DFCD729A415C36C4BFFE80D63E305373B9518EBFB14"
6362
var TestEvmTxHash = "0xf02362077ac075a397344172496b28e913ce5294879d811bb0269b3be20a872e"
6463

65-
var TestNonPanicTxHash = "0x566f1c956c74b089643a1e6f880ac65745de0e5cd8cfc3c7482d20a486576219"
66-
var TestPanicTxHash = "0x0ea197de8403de9c2e8cf9ec724e43734e9dbd3a8294a09d031acd67914b73e4"
67-
var TestSyntheticTxHash = "0x3ca69dcca32f435b642fcb13e50a1c6934b04c6f901deffa42cec6eb58c40f20"
64+
var TestNonPanicTxHash string
65+
var TestPanicTxHash string
66+
var TestSyntheticTxHash string
6867
var TestBlockHash = "0x0000000000000000000000000000000000000000000000000000000000000001"
6968

7069
var EncodingConfig = app.MakeEncodingConfig()
@@ -515,7 +514,7 @@ func init() {
515514
Ctx = testApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(8)
516515
MultiTxCtx, _ = Ctx.CacheContext()
517516
EVMKeeper = &testApp.EvmKeeper
518-
EVMKeeper.InitGenesis(Ctx, *evmtypes.DefaultGenesis())
517+
EVMKeeper.InitGenesis(Ctx, *types.DefaultGenesis())
519518
seiAddr, err := sdk.AccAddressFromHex(common.Bytes2Hex([]byte("seiAddr")))
520519
if err != nil {
521520
panic(err)
@@ -643,7 +642,7 @@ func generateTxData() {
643642
})
644643
debugTraceTxBuilder, _ := buildTx(ethtypes.DynamicFeeTx{
645644
Nonce: 0,
646-
GasFeeCap: big.NewInt(10),
645+
GasFeeCap: big.NewInt(1000000000),
647646
Gas: 22000,
648647
To: &to,
649648
Value: big.NewInt(1000),
@@ -652,7 +651,7 @@ func generateTxData() {
652651
})
653652
debugTraceNonPanicTxBuilder, _ := buildTx(ethtypes.DynamicFeeTx{
654653
Nonce: 0,
655-
GasFeeCap: big.NewInt(10),
654+
GasFeeCap: big.NewInt(1000000000),
656655
Gas: 22000,
657656
To: &to,
658657
Value: big.NewInt(1000),
@@ -685,8 +684,14 @@ func generateTxData() {
685684
MultiTxBlockSynthTx = synthTxBuilder.GetTx()
686685
DebugTraceTx = debugTraceTxBuilder.GetTx()
687686
DebugTracePanicTx = debugTracePanicTxBuilder.GetTx()
687+
panicEthTx, _ := DebugTracePanicTx.GetMsgs()[0].(*types.MsgEVMTransaction).AsTransaction()
688+
TestPanicTxHash = panicEthTx.Hash().Hex()
688689
DebugTraceNonPanicTx = debugTraceNonPanicTxBuilder.GetTx()
690+
nonPanicEthTx, _ := DebugTraceNonPanicTx.GetMsgs()[0].(*types.MsgEVMTransaction).AsTransaction()
691+
TestNonPanicTxHash = nonPanicEthTx.Hash().Hex()
689692
DebugTraceSyntheticTx = debugTraceSyntheticTxBuilder.GetTx()
693+
syntheticEthTx, _ := DebugTraceSyntheticTx.GetMsgs()[0].(*types.MsgEVMTransaction).AsTransaction()
694+
TestSyntheticTxHash = syntheticEthTx.Hash().Hex()
690695
TxNonEvm = app.TestTx{}
691696
TxNonEvmWithSyntheticLog = app.TestTx{}
692697
bloomTx1 := ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: []*ethtypes.Log{{

0 commit comments

Comments
 (0)