Skip to content

Commit

Permalink
Merge pull request cosmos#23 from notional-labs/lint-7one
Browse files Browse the repository at this point in the history
lint 7.1
  • Loading branch information
misko9 authored Mar 17, 2023
2 parents a14553c + adfd546 commit dc64743
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 99 deletions.
2 changes: 1 addition & 1 deletion modules/core/02-client/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ func validateClients(i interface{}) error {
}

return nil
}
}
6 changes: 3 additions & 3 deletions modules/light-clients/08-wasm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func (k Keeper) PushNewWasmCode(goCtx context.Context, msg *types.MsgPushNewWasm
return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority: expected %s, got %s", k.authority, msg.Signer)
}

codeId, err := k.storeWasmCode(ctx, msg.Code)
codeID, err := k.storeWasmCode(ctx, msg.Code)
if err != nil {
return nil, sdkerrors.Wrap(err, "pushing new wasm code failed")
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
clienttypes.EventTypePushWasmCode,
sdk.NewAttribute(clienttypes.AttributeKeyWasmCodeID, hex.EncodeToString(codeId)),
sdk.NewAttribute(clienttypes.AttributeKeyWasmCodeID, hex.EncodeToString(codeID)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -39,6 +39,6 @@ func (k Keeper) PushNewWasmCode(goCtx context.Context, msg *types.MsgPushNewWasm
})

return &types.MsgPushNewWasmCodeResponse{
CodeId: codeId,
CodeId: codeID,
}, nil
}
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package wasm
import (
"encoding/json"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/client/cli"
"github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/keeper"
Expand Down
11 changes: 7 additions & 4 deletions modules/light-clients/08-wasm/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ func (c ClientState) Validate() error {
return nil
}

type statusPayloadInner struct {}
type statusPayload struct {
Status statusPayloadInner `json:"status"`
}
type (
statusPayloadInner struct{}
statusPayload struct {
Status statusPayloadInner `json:"status"`
}
)

func (c ClientState) Status(ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec) exported.Status {
status := exported.Unknown
payload := statusPayload{Status: statusPayloadInner{}}
Expand Down
98 changes: 48 additions & 50 deletions modules/light-clients/08-wasm/types/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
ibctesting "github.com/cosmos/ibc-go/v7/testing"
ibcmock "github.com/cosmos/ibc-go/v7/testing/mock"
)

func (suite *WasmTestSuite) TestStatus() {
testCases := []struct {
name string
Expand All @@ -27,8 +28,8 @@ func (suite *WasmTestSuite) TestStatus() {
suite.Require().NoError(err)

frozenClientState := wasmtypes.ClientState{
Data: cs,
CodeId: suite.codeId,
Data: cs,
CodeId: suite.codeID,
LatestHeight: clienttypes.Height{
RevisionNumber: 2000,
RevisionHeight: 5,
Expand All @@ -42,14 +43,14 @@ func (suite *WasmTestSuite) TestStatus() {
suite.Require().NoError(err)

clientState := wasmtypes.ClientState{
Data: cs,
CodeId: suite.codeId,
Data: cs,
CodeId: suite.codeID,
LatestHeight: clienttypes.Height{
RevisionNumber: 2000,
RevisionHeight: 36, // This doesn't matter, but the grandpa client state is set to this
},
}

suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.ctx, "08-wasm-0", &clientState)
}, exported.Expired},
// ics10-grandpa client state doesn't have a trusting period, so this might be removed
Expand Down Expand Up @@ -101,7 +102,6 @@ func (suite *WasmTestSuite) TestValidate() {
clientState: wasmtypes.NewClientState([]byte{0}, []byte{}, clienttypes.Height{}),
expPass: false,
},

}

for _, tc := range testCases {
Expand Down Expand Up @@ -156,13 +156,13 @@ func (suite *WasmTestSuite) TestInitialize() {

func (suite *WasmTestSuite) TestVerifyMembership() {
var (
clientState exported.ClientState
err error
height exported.Height
path exported.Path
proof []byte
value []byte
delayTimePeriod uint64
clientState exported.ClientState
err error
height exported.Height
path exported.Path
proof []byte
value []byte
delayTimePeriod uint64
delayBlockPeriod uint64
)
clientID := "07-tendermint-0"
Expand All @@ -185,13 +185,12 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
{
"successful Connection verification",
func() {

clientState = suite.clientState

height = clienttypes.NewHeight(2000, 11)
key := host.ConnectionPath(connectionID)
merklePath := commitmenttypes.NewMerklePath(key)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
suite.Require().NoError(err)

proof, err = base64.StdEncoding.DecodeString(suite.testData["connection_proof_try"])
Expand All @@ -200,13 +199,13 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
value, err = suite.chainA.Codec.Marshal(&types.ConnectionEnd{
ClientId: clientID,
Counterparty: types.Counterparty{
ClientId: "08-wasm-0",
ClientId: "08-wasm-0",
ConnectionId: connectionID,
Prefix: suite.chainA.GetPrefix(),
Prefix: suite.chainA.GetPrefix(),
},
DelayPeriod: 0,
State: types.TRYOPEN,
Versions: []*types.Version{types.DefaultIBCVersion},
State: types.TRYOPEN,
Versions: []*types.Version{types.DefaultIBCVersion},
})
suite.Require().NoError(err)
},
Expand All @@ -215,26 +214,25 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
{
"successful Channel verification",
func() {

clientState = suite.clientState

height = clienttypes.NewHeight(2000, 20)
key := host.ChannelPath(portID, channelID)
merklePath := commitmenttypes.NewMerklePath(key)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["channel_proof_try"])
suite.Require().NoError(err)

value, err = suite.chainA.Codec.Marshal(&channeltypes.Channel{
State: channeltypes.TRYOPEN,
State: channeltypes.TRYOPEN,
Ordering: channeltypes.UNORDERED,
Counterparty: channeltypes.Counterparty{
PortId: portID,
PortId: portID,
ChannelId: channelID,
},
ConnectionHops: []string{connectionID},
Version: "ics20-1",
Version: "ics20-1",
})
suite.Require().NoError(err)
},
Expand All @@ -256,11 +254,11 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
)
key := host.PacketCommitmentPath(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
merklePath := commitmenttypes.NewMerklePath(key)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["packet_commitment_proof"])
suite.Require().NoError(err)

value = channeltypes.CommitPacket(suite.chainA.App.GetIBCKeeper().Codec(), packet)
},
true,
Expand All @@ -281,7 +279,7 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
)
key := host.PacketAcknowledgementKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["ack_proof"])
suite.Require().NoError(err)
Expand Down Expand Up @@ -357,20 +355,20 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
height = clienttypes.NewHeight(2000, 11)
key := host.FullClientStateKey(clientID)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["client_state_proof"])
suite.Require().NoError(err)

value, err = suite.chainA.Codec.MarshalInterface(&tmtypes.ClientState{
ChainId: "simd",
TrustLevel: tmtypes.Fraction{
Numerator: 1,
Numerator: 1,
Denominator: 3,
},
TrustingPeriod: time.Duration(time.Second * 64000),
UnbondingPeriod: time.Duration(time.Second * 1814400),
MaxClockDrift: time.Duration(time.Second * 15),
TrustingPeriod: time.Second * 64000,
UnbondingPeriod: time.Second * 1814400,
MaxClockDrift: time.Second * 15,
FrozenHeight: clienttypes.Height{
RevisionNumber: 0,
RevisionHeight: 0,
Expand All @@ -379,9 +377,9 @@ func (suite *WasmTestSuite) TestVerifyMembership() {
RevisionNumber: 0,
RevisionHeight: 46,
},
ProofSpecs: commitmenttypes.GetSDKSpecs(),
UpgradePath: []string{"upgrade", "upgradedIBCState"},
AllowUpdateAfterExpiry: false,
ProofSpecs: commitmenttypes.GetSDKSpecs(),
UpgradePath: []string{"upgrade", "upgradedIBCState"},
AllowUpdateAfterExpiry: false,
AllowUpdateAfterMisbehaviour: false,
})
suite.Require().NoError(err)
Expand All @@ -405,19 +403,19 @@ func (suite *WasmTestSuite) TestVerifyMembership() {

func (suite *WasmTestSuite) TestVerifyNonMembership() {
var (
clientState exported.ClientState
err error
height exported.Height
path exported.Path
proof []byte
delayTimePeriod uint64
clientState exported.ClientState
err error
height exported.Height
path exported.Path
proof []byte
delayTimePeriod uint64
delayBlockPeriod uint64
)
clientID := "07-tendermint-0"
portID := "transfer"
invalidClientID := "09-tendermint-0"
invalidConnectionID := "connection-100"
invalidChannelID := "channel-800"
invalidChannelID := "channel-800"
pathPrefix := "ibc/"

testCases := []struct {
Expand All @@ -436,7 +434,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
height = clienttypes.NewHeight(2000, 11)
key := host.FullConsensusStateKey(invalidClientID, suite.clientState.GetLatestHeight())
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["client_state_proof"])
suite.Require().NoError(err)
Expand All @@ -448,7 +446,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
height = clienttypes.NewHeight(2000, 11)
key := host.ConnectionKey(invalidConnectionID)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["connection_proof_try"])
suite.Require().NoError(err)
Expand All @@ -460,7 +458,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
height = clienttypes.NewHeight(2000, 20)
key := host.ChannelKey(portID, invalidChannelID)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["channel_proof_try"])
suite.Require().NoError(err)
Expand All @@ -472,7 +470,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
height = clienttypes.NewHeight(2000, 32)
key := host.PacketCommitmentKey(portID, invalidChannelID, 1)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["packet_commitment_proof"])
suite.Require().NoError(err)
Expand All @@ -483,7 +481,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
height = clienttypes.NewHeight(2000, 29)
key := host.PacketAcknowledgementKey(portID, invalidChannelID, 1)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["ack_proof"])
suite.Require().NoError(err)
Expand Down Expand Up @@ -542,7 +540,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
// change the value being proved
key := host.FullClientStateKey(clientID)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)

proof, err = base64.StdEncoding.DecodeString(suite.testData["client_state_proof"])
suite.Require().NoError(err)
Expand All @@ -561,7 +559,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
height = clienttypes.NewHeight(2000, 11)
key := host.FullClientStateKey(invalidClientID)
merklePath := commitmenttypes.NewMerklePath(string(key))
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
path = commitmenttypes.NewMerklePath(append([]string{pathPrefix}, merklePath.KeyPath...)...)
proof, err = base64.StdEncoding.DecodeString(suite.testData["client_state_proof"])
suite.Require().NoError(err)
tc.setup()
Expand All @@ -579,4 +577,4 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() {
}
})
}
}
}
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import (
// ExportMetadata is a no-op since wasm client does not store any metadata in client store
func (c ClientState) ExportMetadata(store sdk.KVStore) []exported.GenesisMetadata {
return nil
}
}
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/types/misbehaviour_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ func (c ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec
}

return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ func (suite *WasmTestSuite) TestVerifyMisbehaviour() {
}

func (suite *WasmTestSuite) TestCheckForMisbehaviour() {
var (
clientMsg exported.ClientMessage
//clientState exported.ClientState
)
var clientMsg exported.ClientMessage // clientState exported.ClientState

testCases := []struct {
name string
Expand Down Expand Up @@ -150,4 +147,4 @@ func (suite *WasmTestSuite) TestCheckForMisbehaviour() {
}
})
}
}
}
Loading

0 comments on commit dc64743

Please sign in to comment.