-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(evm): Augment the Wasm msg handler so that wasm contracts canno…
…t send MsgEthereumTx
- Loading branch information
1 parent
f7a7007
commit 5ce2608
Showing
7 changed files
with
218 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package wasmext_test | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
wasmvm "github.com/CosmWasm/wasmvm/types" | ||
sdkcodec "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/NibiruChain/nibiru/v2/app/wasmext" | ||
"github.com/NibiruChain/nibiru/v2/x/evm" | ||
"github.com/NibiruChain/nibiru/v2/x/evm/evmtest" | ||
) | ||
|
||
type Suite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestWasmExtSuite(t *testing.T) { | ||
suite.Run(t, new(Suite)) | ||
} | ||
|
||
// WasmVM to EVM call pattern is not yet supported. This test verifies the | ||
// Nibiru's [wasmkeeper.Option] function as expected. | ||
func (s *Suite) TestEvmFilter() { | ||
deps := evmtest.NewTestDeps() | ||
// wk := wasmkeeper.NewDefaultPermissionKeeper(deps.App.WasmKeeper) | ||
wasmMsgHandler := wasmext.WasmMessageHandler(deps.App.WasmMsgHandlerArgs) | ||
|
||
s.T().Log("Create a valid Ethereum tx msg") | ||
|
||
to := evmtest.NewEthPrivAcc() | ||
ethTxMsg, err := evmtest.TxTransferWei{ | ||
Deps: &deps, | ||
To: to.EthAddr, | ||
AmountWei: evm.NativeToWei(big.NewInt(420)), | ||
}.Build() | ||
s.NoError(err) | ||
|
||
s.T().Log("Validate Eth tx msg proto encoding as wasmvm.StargateMsg") | ||
wasmContractAddr := deps.Sender.NibiruAddr | ||
protoValueBz, err := deps.EncCfg.Codec.Marshal(ethTxMsg) | ||
s.Require().NoError(err, "expect ethTxMsg to proto marshal", protoValueBz) | ||
|
||
_, ok := deps.EncCfg.Codec.(sdkcodec.AnyUnpacker) | ||
s.Require().True(ok, "codec must be an AnyUnpacker") | ||
|
||
pbAny, err := sdkcodec.NewAnyWithValue(ethTxMsg) | ||
s.NoError(err) | ||
pbAnyBz, err := pbAny.Marshal() | ||
s.NoError(err, pbAnyBz) | ||
|
||
var sdkMsg sdk.Msg | ||
err = deps.EncCfg.Codec.UnpackAny(pbAny, &sdkMsg) | ||
s.Require().NoError(err) | ||
s.Equal("/eth.evm.v1.MsgEthereumTx", sdk.MsgTypeURL(sdkMsg)) | ||
|
||
s.T().Log("Dispatch the Eth tx msg from Wasm (unsuccessfully)") | ||
_, _, err = wasmMsgHandler.DispatchMsg( | ||
deps.Ctx, | ||
wasmContractAddr, | ||
"ibcport-unused", | ||
wasmvm.CosmosMsg{ | ||
Stargate: &wasmvm.StargateMsg{ | ||
TypeURL: sdk.MsgTypeURL(ethTxMsg), | ||
Value: protoValueBz, | ||
}, | ||
}, | ||
) | ||
s.Require().ErrorContains(err, "Wasm VM to EVM call pattern is not yet supported") | ||
} |