Skip to content

Commit

Permalink
nits: test names, minor re-orgs in places.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Mar 26, 2024
1 parent 211c37a commit ee6ec47
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions modules/light-clients/08-wasm/light_client_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ func (suite *WasmTestSuite) TestTimestampAtHeight() {
types.ErrWasmContractCallFailed,
},
{
"error: invalid height",
"failure: error: invalid height",
func() {
height = ibcmock.Height{}
},
ibcerrors.ErrInvalidType,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
Expand Down Expand Up @@ -408,14 +408,14 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
nil,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
clienttypes.ErrClientNotFound,
},
{
"contract returns invalid proof error",
"failure: contract returns invalid proof error",
func() {
proof = wasmtesting.MockInvalidProofBz

Expand All @@ -428,21 +428,21 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
types.ErrWasmContractCallFailed,
},
{
"proof height greater than client state latest height",
"failure: proof height greater than client state latest height",
func() {
proofHeight = clienttypes.NewHeight(1, 100)
},
ibcerrors.ErrInvalidHeight,
},
{
"invalid path argument",
"failure: invalid path argument",
func() {
path = ibcmock.KeyPath{}
},
ibcerrors.ErrInvalidType,
},
{
"proof height is invalid type",
"failure: proof height is invalid type",
func() {
proofHeight = ibcmock.Height{}
},
Expand All @@ -465,7 +465,6 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
proofHeight = clienttypes.NewHeight(0, 1)
value = []byte("value")

clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID)
clientState, ok = endpoint.GetClientState().(*types.ClientState)
suite.Require().True(ok)

Expand All @@ -478,12 +477,12 @@ func (suite *WasmTestSuite) TestVerifyMembership() {

expPass := tc.expError == nil
if expPass {
suite.Require().NoError(err)
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID)

clientStateBz := clientStore.Get(host.ClientStateKey())
suite.Require().Equal(expClientStateBz, clientStateBz)
suite.Require().NoError(err)
suite.Require().Equal(expClientStateBz, clientStore.Get(host.ClientStateKey()))
} else {
suite.Require().ErrorIs(err, tc.expError, "unexpected error in VerifyMembership")
suite.Require().ErrorIs(err, tc.expError)
}
})
}
Expand Down Expand Up @@ -563,14 +562,14 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
nil,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
clienttypes.ErrClientNotFound,
},
{
"wasm vm returns error",
"failure: wasm vm returns error",
func() {
proof = wasmtesting.MockInvalidProofBz

Expand All @@ -583,7 +582,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
types.ErrVMError,
},
{
"contract returns invalid proof error",
"failure: contract returns invalid proof error",
func() {
proof = wasmtesting.MockInvalidProofBz

Expand All @@ -596,21 +595,21 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
types.ErrWasmContractCallFailed,
},
{
"proof height greater than client state latest height",
"failure: proof height greater than client state latest height",
func() {
proofHeight = clienttypes.NewHeight(1, 100)
},
ibcerrors.ErrInvalidHeight,
},
{
"invalid path argument",
"failure: invalid path argument",
func() {
path = ibcmock.KeyPath{}
},
ibcerrors.ErrInvalidType,
},
{
"proof height is invalid type",
"failure: proof height is invalid type",
func() {
proofHeight = ibcmock.Height{}
},
Expand All @@ -632,7 +631,6 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
proof = wasmtesting.MockInvalidProofBz
proofHeight = clienttypes.NewHeight(0, 1)

clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID)
clientState, ok = endpoint.GetClientState().(*types.ClientState)
suite.Require().True(ok)

Expand All @@ -645,12 +643,12 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {

expPass := tc.expError == nil
if expPass {
suite.Require().NoError(err)
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID)

clientStateBz := clientStore.Get(host.ClientStateKey())
suite.Require().Equal(expClientStateBz, clientStateBz)
suite.Require().NoError(err)
suite.Require().Equal(expClientStateBz, clientStore.Get(host.ClientStateKey()))
} else {
suite.Require().ErrorIs(err, tc.expError, "unexpected error in VerifyNonMembership")
suite.Require().ErrorIs(err, tc.expError)
}
})
}
Expand Down Expand Up @@ -693,7 +691,7 @@ func (suite *WasmTestSuite) TestVerifyClientMessage() {
nil,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
Expand Down Expand Up @@ -753,7 +751,6 @@ func (suite *WasmTestSuite) TestVerifyClientMessage() {
tc.malleate()

err = lightClientModule.VerifyClientMessage(suite.chainA.GetContext(), clientID, clientMsg)
// err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMsg)

expPass := tc.expErr == nil
if expPass {
Expand Down Expand Up @@ -819,21 +816,21 @@ func (suite *WasmTestSuite) TestVerifyUpgradeAndUpdateState() {
nil,
},
{
"invalid client state",
"failure: invalid client state",
func() {
upgradedClient = &solomachine.ClientState{Sequence: 20}
},
clienttypes.ErrInvalidClient,
},
{
"invalid height",
"failure: invalid height",
func() {
upgradedClient = &types.ClientState{LatestHeight: clienttypes.ZeroHeight()}
},
ibcerrors.ErrInvalidHeight,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
Expand Down Expand Up @@ -1017,19 +1014,20 @@ func (suite *WasmTestSuite) TestCheckForMisbehaviour() {
nil,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
false, // not applicable
fmt.Errorf("08-wasm-100: %s", clienttypes.ErrClientNotFound),
fmt.Errorf("%s: %s", unusedWasmClientID, clienttypes.ErrClientNotFound),
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
// reset suite to create fresh application state
suite.SetupWasmWithMockVM()

endpoint := wasmtesting.NewWasmEndpoint(suite.chainA)
err := endpoint.CreateClient()
suite.Require().NoError(err)
Expand Down Expand Up @@ -1139,7 +1137,7 @@ func (suite *WasmTestSuite) TestUpdateState() {
[]exported.Height{mockHeight},
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
Expand Down Expand Up @@ -1180,17 +1178,17 @@ func (suite *WasmTestSuite) TestUpdateState() {
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupWasmWithMockVM() // reset
expectedClientStateBz = nil

clientMsg = &types.ClientMessage{
Data: clienttypes.MustMarshalClientMessage(suite.chainA.App.AppCodec(), wasmtesting.MockTendermintClientHeader),
}

endpoint := wasmtesting.NewWasmEndpoint(suite.chainA)
err := endpoint.CreateClient()
suite.Require().NoError(err)
clientID = endpoint.ClientID
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID)

expectedClientStateBz = nil

clientMsg = &types.ClientMessage{
Data: clienttypes.MustMarshalClientMessage(suite.chainA.App.AppCodec(), wasmtesting.MockTendermintClientHeader),
}

lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(clientID)
suite.Require().True(found)
Expand All @@ -1207,6 +1205,8 @@ func (suite *WasmTestSuite) TestUpdateState() {
suite.Require().Equal(tc.expHeights, heights)

if expectedClientStateBz != nil {
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID)

clientStateBz := clientStore.Get(host.ClientStateKey())
suite.Require().Equal(expectedClientStateBz, clientStateBz)
}
Expand Down Expand Up @@ -1289,11 +1289,11 @@ func (suite *WasmTestSuite) TestUpdateStateOnMisbehaviour() {
clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), wasmtesting.CreateMockTendermintClientState(mockHeight)),
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
clientID = unusedWasmClientID
},
fmt.Errorf("08-wasm-100: %s", clienttypes.ErrClientNotFound),
fmt.Errorf("%s: %s", unusedWasmClientID, clienttypes.ErrClientNotFound),
nil,
},
{
Expand Down Expand Up @@ -1331,14 +1331,14 @@ func (suite *WasmTestSuite) TestUpdateStateOnMisbehaviour() {
suite.Run(tc.name, func() {
// reset suite to create fresh application state
suite.SetupWasmWithMockVM()
expectedClientStateBz = nil

endpoint := wasmtesting.NewWasmEndpoint(suite.chainA)
err := endpoint.CreateClient()
suite.Require().NoError(err)
clientID = endpoint.ClientID

store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID)
expectedClientStateBz = nil

clientMsg = &types.ClientMessage{
Data: clienttypes.MustMarshalClientMessage(suite.chainA.App.AppCodec(), wasmtesting.MockTendermintClientMisbehaviour),
}
Expand All @@ -1355,6 +1355,7 @@ func (suite *WasmTestSuite) TestUpdateStateOnMisbehaviour() {
if tc.panicErr == nil {
updateFunc()
if expectedClientStateBz != nil {
store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID)
suite.Require().Equal(expectedClientStateBz, store.Get(host.ClientStateKey()))
}
} else {
Expand Down Expand Up @@ -1408,28 +1409,28 @@ func (suite *WasmTestSuite) TestRecoverClient() {
nil,
},
{
"cannot parse malformed substitute client ID",
"failure: cannot parse malformed substitute client ID",
func() {
substituteClientID = ibctesting.InvalidID
},
host.ErrInvalidID,
},
{
"substitute client ID does not contain 08-wasm prefix",
"failure: substitute client ID does not contain 08-wasm prefix",
func() {
substituteClientID = tmClientID
},
clienttypes.ErrInvalidClientType,
},
{
"cannot find subject client state",
"failure: cannot find subject client state",
func() {
subjectClientID = unusedWasmClientID
},
clienttypes.ErrClientNotFound,
},
{
"cannot find substitute client state",
"failure: cannot find substitute client state",
func() {
substituteClientID = unusedWasmClientID
},
Expand Down Expand Up @@ -1483,20 +1484,19 @@ func (suite *WasmTestSuite) TestRecoverClient() {
tc := tc
suite.Run(tc.name, func() {
suite.SetupWasmWithMockVM()
expectedClientStateBz = nil

subjectEndpoint := wasmtesting.NewWasmEndpoint(suite.chainA)
err := subjectEndpoint.CreateClient()
suite.Require().NoError(err)
subjectClientID = subjectEndpoint.ClientID

subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectClientID)

substituteEndpoint := wasmtesting.NewWasmEndpoint(suite.chainA)
err = substituteEndpoint.CreateClient()
suite.Require().NoError(err)
substituteClientID = substituteEndpoint.ClientID

expectedClientStateBz = nil

lightClientModule, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.Route(subjectClientID)
suite.Require().True(found)

Expand All @@ -1508,8 +1508,8 @@ func (suite *WasmTestSuite) TestRecoverClient() {
if expPass {
suite.Require().NoError(err)

clientStateBz := subjectClientStore.Get(host.ClientStateKey())
suite.Require().Equal(expectedClientStateBz, clientStateBz)
subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectClientID)
suite.Require().Equal(expectedClientStateBz, subjectClientStore.Get(host.ClientStateKey()))
} else {
suite.Require().ErrorIs(err, tc.expErr)
}
Expand All @@ -1532,7 +1532,7 @@ func (suite *WasmTestSuite) TestLatestHeight() {
clienttypes.NewHeight(1, 5),
},
{
"cannot find substitute client state",
"failure: cannot find substitute client state",
func() {
clientID = unusedWasmClientID
},
Expand Down

0 comments on commit ee6ec47

Please sign in to comment.