Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 18, 2024
1 parent d1ff90b commit 42caff6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ require (
)

replace (
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.2.0
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.2.0-tmp
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.26
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ github.com/sei-protocol/sei-tendermint v0.3.4 h1:pAMXB2Cd0/rmmEkPgcEdIEjw7k64K7+
github.com/sei-protocol/sei-tendermint v0.3.4/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
github.com/sei-protocol/sei-tm-db v0.0.5/go.mod h1:Cpa6rGyczgthq7/0pI31jys2Fw0Nfrc+/jKdP1prVqY=
github.com/sei-protocol/sei-wasmd v0.2.0 h1:DiR5u7ZRtRKMYjvGPsH+/nMnJAprcFovbaITLf1Et0Y=
github.com/sei-protocol/sei-wasmd v0.2.0/go.mod h1:EnQkqvUA3tYpdgXjqatHK8ym9LCm1z+lM7XMqR9SA3o=
github.com/sei-protocol/sei-wasmd v0.2.0-tmp h1:16guJLPO6evKdoZORLboi8aYuZpD9eG9wKNjHKoQIFw=
github.com/sei-protocol/sei-wasmd v0.2.0-tmp/go.mod h1:EnQkqvUA3tYpdgXjqatHK8ym9LCm1z+lM7XMqR9SA3o=
github.com/sei-protocol/tm-db v0.0.4 h1:7Y4EU62Xzzg6wKAHEotm7SXQR0aPLcGhKHkh3qd0tnk=
github.com/sei-protocol/tm-db v0.0.4/go.mod h1:PWsIWOTwdwC7Ow/GUvx8HgUJTO691pBuorIQD8JvwAs=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (k *Keeper) CallEVM(ctx sdk.Context, from common.Address, to *common.Addres
bloom.SetBytes(receipt.LogsBloom)
k.AppendToEvmTxDeferredInfo(ctx, bloom, ctx.TxSum(), surplus)
ctx.EVMEventManager().EmitEvents(stateDB.GetAllLogs())
return ctx, res.ReturnData, nil
return stateDB.Ctx(), res.ReturnData, nil
}

func (k *Keeper) StaticCallEVM(ctx sdk.Context, from sdk.AccAddress, to *common.Address, data []byte) ([]byte, error) {
Expand Down
8 changes: 5 additions & 3 deletions x/evm/keeper/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ func TestInternalCall(t *testing.T) {
_, err = k.HandleInternalEVMCall(ctx, req)

Check failure on line 69 in x/evm/keeper/evm_test.go

View workflow job for this annotation

GitHub Actions / tests (14)

assignment mismatch: 2 variables but k.HandleInternalEVMCall returns 3 values
require.Equal(t, "sei does not support EVM->CW->EVM call pattern", err.Error())
ctx = ctx.WithIsEVM(false)
_, ret, err := k.HandleInternalEVMCall(ctx, req)
resCtx, ret, err := k.HandleInternalEVMCall(ctx, req)
require.Nil(t, err)
contractAddr := crypto.CreateAddress(senderEvmAddr, 0)
require.NotEmpty(t, k.GetCode(ctx, contractAddr))
require.Equal(t, ret.Data, k.GetCode(ctx, contractAddr))
k.SetERC20NativePointer(ctx, "test", contractAddr)

ctx = resCtx
require.NotNil(t, types.GetCtxEVM(ctx))
receiverAddr, evmAddr := testkeeper.MockAddressPair()
k.SetAddressMapping(ctx, receiverAddr, evmAddr)
args, err = abi.Pack("transfer", evmAddr, big.NewInt(1000))
Expand All @@ -89,9 +91,9 @@ func TestInternalCall(t *testing.T) {
Data: args,
Value: &val,
}
_, _, err = k.HandleInternalEVMCall(ctx, req)
resCtx, _, err = k.HandleInternalEVMCall(ctx, req)
require.Nil(t, err)
require.Equal(t, int64(1000), testkeeper.EVMTestApp.BankKeeper.GetBalance(ctx, receiverAddr, "test").Amount.Int64())
require.Equal(t, int64(1000), testkeeper.EVMTestApp.BankKeeper.GetBalance(resCtx, receiverAddr, "test").Amount.Int64())
}

func TestStaticCall(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions x/evm/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/vm"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/state"
"github.com/sei-protocol/sei-chain/x/evm/types"
Expand Down Expand Up @@ -166,3 +167,16 @@ func TestSnapshot(t *testing.T) {
require.Equal(t, common.Hash{}, newStateDB.GetTransientState(evmAddr, tkey))
require.Equal(t, val, newStateDB.GetState(evmAddr, key))
}

func TestSetEVM(t *testing.T) {
k, ctx := testkeeper.MockEVMKeeper()
statedb := state.NewDBImpl(ctx, k, false)
rev1 := statedb.Snapshot()
statedb.SetEVM(&vm.EVM{})
rev2 := statedb.Snapshot()
require.NotNil(t, types.GetCtxEVM(statedb.Ctx()))
statedb.RevertToSnapshot(rev2)
require.NotNil(t, types.GetCtxEVM(statedb.Ctx()))
statedb.RevertToSnapshot(rev1)
require.NotNil(t, types.GetCtxEVM(statedb.Ctx()))
}
3 changes: 2 additions & 1 deletion x/evm/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (s *DBImpl) SetLogger(logger *tracing.Hooks) {
s.logger = logger
}

// for interface compliance
func (s *DBImpl) SetEVM(evm *vm.EVM) {
s.ctx = types.SetCtxEVM(s.ctx, evm)
s.snapshottedCtxs = utils.Map(s.snapshottedCtxs, func(ctx sdk.Context) sdk.Context { return types.SetCtxEVM(ctx, evm) })
Expand Down Expand Up @@ -109,6 +108,8 @@ func (s *DBImpl) Finalize() (surplus sdk.Int, err error) {
for i := len(s.snapshottedCtxs) - 1; i > 0; i-- {
s.flushCtx(s.snapshottedCtxs[i])
}
s.ctx = s.snapshottedCtxs[0]
s.snapshottedCtxs = []sdk.Context{}

surplus = s.tempStateCurrent.surplus
for _, ts := range s.tempStatesHist {
Expand Down
20 changes: 20 additions & 0 deletions x/evm/types/context_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package types_test

import (
"context"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/stretchr/testify/require"
)

func TestCtxEvm(t *testing.T) {
ctx := sdk.Context{}.WithContext(context.Background())
require.Nil(t, types.GetCtxEVM(ctx))
ctx = types.SetCtxEVM(ctx, &vm.EVM{})
require.NotNil(t, types.GetCtxEVM(ctx))
ctx = ctx.WithContext(context.WithValue(ctx.Context(), types.CtxEVMKey, 123))
require.Nil(t, types.GetCtxEVM(ctx))
}

0 comments on commit 42caff6

Please sign in to comment.