Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkushin committed Sep 23, 2023
1 parent 489fa5d commit ed35119
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions modules/light-clients/08-wasm/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,55 @@ func (suite *WasmTestSuite) TestPushNewWasmCodeWithErrors() {
suite.Require().Error(err)
}

func (suite *WasmTestSuite) TestUpdateWasmCodeId() {
suite.SetupWithChannel()
signer := authtypes.NewModuleAddress(govtypes.ModuleName).String()
data, err := os.ReadFile("test_data/ics07_tendermint_cw.wasm.gz")
suite.Require().NoError(err)

msg := wasmtypes.NewMsgPushNewWasmCode(signer, data)
response, err := suite.wasmKeeper.PushNewWasmCode(suite.ctx, msg)
suite.Require().NoError(err)
newCodeId := response.CodeId

msgUpdate := wasmtypes.NewMsgUpdateWasmCodeId(signer, newCodeId, "08-wasm-0")
_, err = suite.wasmKeeper.UpdateWasmCodeId(suite.ctx, msgUpdate)
suite.Require().NoError(err)

cs, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, "08-wasm-0")
suite.Require().True(ok)
wasmCs, ok := cs.(*wasmtypes.ClientState)
suite.Require().True(ok)
suite.Require().Equal(newCodeId, wasmCs.CodeId)
}

func (suite *WasmTestSuite) TestUpdateWasmCodeIdWithErrors() {
suite.SetupWithEmptyClient()
signer := authtypes.NewModuleAddress(govtypes.ModuleName).String()
data, err := os.ReadFile("test_data/ics07_tendermint_cw.wasm.gz")
suite.Require().NoError(err)

msg := wasmtypes.NewMsgPushNewWasmCode(signer, data)
response, err := suite.wasmKeeper.PushNewWasmCode(suite.ctx, msg)
suite.Require().NoError(err)
newCodeId := response.CodeId

// test invalid signer
msgUpdate := wasmtypes.NewMsgUpdateWasmCodeId("invalid", newCodeId, "08-wasm-0")
_, err = suite.wasmKeeper.UpdateWasmCodeId(suite.ctx, msgUpdate)
suite.Require().Error(err)

// test invalid code id
msgUpdate = wasmtypes.NewMsgUpdateWasmCodeId(signer, []byte{}, "08-wasm-0")
_, err = suite.wasmKeeper.UpdateWasmCodeId(suite.ctx, msgUpdate)
suite.Require().Error(err)

// test invalid client id
msgUpdate = wasmtypes.NewMsgUpdateWasmCodeId(signer, newCodeId, "invalid")
_, err = suite.wasmKeeper.UpdateWasmCodeId(suite.ctx, msgUpdate)
suite.Require().Error(err)
}

func (suite *WasmTestSuite) TestQueryWasmCode() {
// test invalid query request
_, err := suite.wasmKeeper.WasmCode(suite.ctx, &wasmtypes.WasmCodeQuery{})
Expand Down

0 comments on commit ed35119

Please sign in to comment.