Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix golangci-lint errors #235

Merged
merged 5 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/consumer/ante/msg_filter_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var validMsgsCCVDisabled = map[string]struct{}{}

type (
// ConsumerKeeper defines the interface required by a consumer module keeper.
ConsumerKeeper interface {
Expand Down
17 changes: 0 additions & 17 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/mint"
Expand Down Expand Up @@ -121,22 +120,6 @@ const (

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler
// this line is used by starport scaffolding # stargate/app/govProposalHandlers

govProposalHandlers = append(govProposalHandlers,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
upgradeclient.CancelProposalHandler,
ibcproviderclient.ProposalHandler,
// this line is used by starport scaffolding # stargate/app/govProposalHandler
)

return govProposalHandlers
}

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ type ConsumerProposal struct {

func (p ConsumerProposal) isProposal() {}

type ConsumerGenesis struct {
}

func (s System) getState(modelState State) State {
systemState := State{}
for k, modelState := range modelState {
Expand Down
10 changes: 3 additions & 7 deletions integration-tests/steps.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"time"

clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
)

Expand All @@ -11,8 +9,6 @@ type Step struct {
state State
}

var now = time.Now().UTC()

var happyPathSteps = []Step{
{
action: StartChainAction{
Expand Down Expand Up @@ -55,7 +51,7 @@ var happyPathSteps = []Step{
deposit: 10000001,
consumerChain: 1,
spawnTime: 0,
initialHeight: clienttypes.Height{0, 1},
initialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
},
state: State{
0: ChainState{
Expand All @@ -68,7 +64,7 @@ var happyPathSteps = []Step{
Deposit: 10000001,
Chain: 1,
SpawnTime: 0,
InitialHeight: clienttypes.Height{0, 1},
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
},
},
Expand All @@ -89,7 +85,7 @@ var happyPathSteps = []Step{
Deposit: 10000001,
Chain: 1,
SpawnTime: 0,
InitialHeight: clienttypes.Height{0, 1},
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: "PROPOSAL_STATUS_PASSED",
},
},
Expand Down
28 changes: 17 additions & 11 deletions x/ccv/consumer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ func (suite *KeeperTestSuite) SetupTest() {
for i := 0; i < len(providerValUpdates); i++ {
addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i])
addr2 := utils.GetChangePubKeyAddress(consumerValUpdates[i])
suite.Require().True(bytes.Compare(addr1, addr2) == 0, "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
}

// move both chains to the next block
suite.providerChain.NextBlock()
suite.consumerChain.NextBlock()

// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
suite.providerChain.GetContext(),
suite.consumerChain.ChainID,
suite.consumerChain.LastHeader.GetHeight().(clienttypes.Height),
false,
)
suite.Require().NoError(err)
// move provider to next block to commit the state
suite.providerChain.NextBlock()

Expand Down Expand Up @@ -118,8 +119,10 @@ func (suite *KeeperTestSuite) SetupTest() {

// set chains sender account number
// TODO: to be fixed in #151
suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
err = suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.Require().NoError(err)
err = suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
suite.Require().NoError(err)

suite.ctx = suite.consumerChain.GetContext()
}
Expand All @@ -146,7 +149,7 @@ func (suite *KeeperTestSuite) TestProviderClient() {
providerClient, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClient(suite.ctx)
suite.Require().True(ok)

clientState, ok := suite.consumerChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, providerClient)
clientState, _ := suite.consumerChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, providerClient)
suite.Require().Equal(suite.providerClient, clientState, "stored client state does not match genesis provider client")
}

Expand Down Expand Up @@ -180,7 +183,8 @@ func (suite *KeeperTestSuite) TestPendingChanges() {
nil,
)

suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetPendingChanges(suite.ctx, pd)
err = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetPendingChanges(suite.ctx, pd)
suite.Require().NoError(err)
gotPd, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetPendingChanges(suite.ctx)
suite.Require().True(ok)
suite.Require().Equal(&pd, gotPd, "packet data in store does not equal packet data set")
Expand Down Expand Up @@ -232,7 +236,8 @@ func (suite *KeeperTestSuite) TestVerifyProviderChain() {
providerUnbondingPeriod := suite.providerChain.App.(*appProvider.App).GetStakingKeeper().UnbondingTime(suite.providerChain.GetContext())
consumerUnbondingPeriod := utils.ComputeConsumerUnbondingPeriod(providerUnbondingPeriod)
suite.CreateCustomClient(suite.path.EndpointB, consumerUnbondingPeriod)
suite.path.EndpointB.CreateClient()
err := suite.path.EndpointB.CreateClient()
suite.Require().NoError(err)

suite.coordinator.CreateConnections(suite.path)

Expand Down Expand Up @@ -566,7 +571,7 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() {
ctx := suite.consumerChain.GetContext()

// should return false
ccVal, foud := app.ConsumerKeeper.GetCCValidator(ctx, ed25519.GenPrivKey().PubKey().Address())
_, foud := app.ConsumerKeeper.GetCCValidator(ctx, ed25519.GenPrivKey().PubKey().Address())
suite.Require().False(foud)

// get a validator from consumer chain
Expand All @@ -577,7 +582,7 @@ func (suite *KeeperTestSuite) TestCrossChainValidator() {
suite.Require().NoError(err)

// set cross chain validator
ccVal, err = types.NewCCValidator(val.Address, 1000, pubkey)
ccVal, err := types.NewCCValidator(val.Address, 1000, pubkey)
suite.Require().NoError(err)

app.ConsumerKeeper.SetCCValidator(ctx, ccVal)
Expand Down Expand Up @@ -662,8 +667,9 @@ func (suite *KeeperTestSuite) SendEmptyVSCPacket() {
packet := channeltypes.NewPacket(pd.GetBytes(), seq, providertypes.PortID, suite.path.EndpointB.ChannelID,
consumertypes.PortID, suite.path.EndpointA.ChannelID, clienttypes.Height{}, timeout)

suite.path.EndpointB.SendPacket(packet)
err := suite.path.EndpointA.RecvPacket(packet)
err := suite.path.EndpointB.SendPacket(packet)
suite.Require().NoError(err)
err = suite.path.EndpointA.RecvPacket(packet)
suite.Require().NoError(err)
}

Expand Down
17 changes: 11 additions & 6 deletions x/ccv/consumer/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ func (suite *ConsumerTestSuite) SetupTest() {
for i := 0; i < len(providerValUpdates); i++ {
addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i])
addr2 := utils.GetChangePubKeyAddress(consumerValUpdates[i])
suite.Require().True(bytes.Compare(addr1, addr2) == 0, "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
}

// move both chains to the next block
suite.providerChain.NextBlock()
suite.consumerChain.NextBlock()

// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
suite.providerChain.GetContext(),
suite.consumerChain.ChainID,
suite.consumerChain.LastHeader.GetHeight().(clienttypes.Height),
false,
)
suite.Require().NoError(err)
// move provider to next block to commit the state
suite.providerChain.NextBlock()

Expand Down Expand Up @@ -112,8 +113,10 @@ func (suite *ConsumerTestSuite) SetupTest() {

// set chains sender account number
// TODO: to be fixed in #151
suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
err = suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.Require().NoError(err)
err = suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
suite.Require().NoError(err)

suite.ctx = suite.consumerChain.GetContext()

Expand Down Expand Up @@ -220,8 +223,10 @@ func (suite *ConsumerTestSuite) TestOnChanOpenInit() {
path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED

// create consumer client on provider chain, and provider client on consumer chain
suite.CreateCustomClient(path.EndpointB, consumerUnbondingPeriod)
suite.CreateCustomClient(path.EndpointA, providerUnbondingPeriod)
err := suite.CreateCustomClient(path.EndpointB, consumerUnbondingPeriod)
suite.Require().NoError(err)
err = suite.CreateCustomClient(path.EndpointA, providerUnbondingPeriod)
suite.Require().NoError(err)

suite.coordinator.CreateConnections(path)
suite.path = path
Expand Down
11 changes: 7 additions & 4 deletions x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ func (suite *KeeperTestSuite) SetupTest() {
for i := 0; i < len(providerValUpdates); i++ {
addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i])
addr2 := utils.GetChangePubKeyAddress(consumerValUpdates[i])
suite.Require().True(bytes.Compare(addr1, addr2) == 0, "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
}

// move both chains to the next block
suite.providerChain.NextBlock()
suite.consumerChain.NextBlock()

// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
suite.providerChain.GetContext(),
suite.consumerChain.ChainID,
suite.consumerChain.LastHeader.GetHeight().(clienttypes.Height),
false,
)
suite.Require().NoError(err)
// move provider to next block to commit the state
suite.providerChain.NextBlock()

Expand Down Expand Up @@ -115,8 +116,10 @@ func (suite *KeeperTestSuite) SetupTest() {

// set chains sender account number
// TODO: to be fixed in #151
suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
err = suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.Require().NoError(err)
err = suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
suite.Require().NoError(err)

suite.ctx = suite.providerChain.GetContext()
}
Expand Down
8 changes: 5 additions & 3 deletions x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ func (suite *KeeperTestSuite) TestMakeConsumerGenesis() {
actualGenesis, err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.MakeConsumerGenesis(suite.providerChain.GetContext())
suite.Require().NoError(err)

jsonString := `{"params":{"enabled":true, "blocks_per_distribution_transmission":1000, "lock_unbonding_on_timeout": false},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:10Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}},"power":1}]}`
jsonString := `{"params":{"enabled":true, "blocks_per_distribution_transmission":1000, "lock_unbonding_on_timeout": false},"new_chain":true,"provider_client_state":{"chain_id":"testchain1","trust_level":{"numerator":1,"denominator":3},"trusting_period":907200000000000,"unbonding_period":1814400000000000,"max_clock_drift":10000000000,"frozen_height":{},"latest_height":{"revision_height":5},"proof_specs":[{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"hash":1}},{"leaf_spec":{"hash":1,"prehash_value":1,"length":1,"prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"hash":1}}],"upgrade_path":["upgrade","upgradedIBCState"],"allow_update_after_expiry":true,"allow_update_after_misbehaviour":true},"provider_consensus_state":{"timestamp":"2020-01-02T00:00:10Z","root":{"hash":"LpGpeyQVLUo9HpdsgJr12NP2eCICspcULiWa5u9udOA="},"next_validators_hash":"E30CE736441FB9101FADDAF7E578ABBE6DFDB67207112350A9A904D554E1F5BE"},"unbonding_sequences":null,"initial_val_set":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="},"power":1}]}`
Copy link
Contributor Author

@shaspitz shaspitz Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was necessary to change the hardcoded json string here to prevent test failure. Previously this bug was undetected, since the unmarshaling error was not being checked below.

The public key for the single validator in the val set at genesis needed to be changed to a format like

"pub_key": {
   "type": "tendermint/PubKeyEd25519",
   "value": "0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="
}

instead of

"pub_key":{
    "Sum":{"ed25519":"dcASx5/LIKZqagJWN0frOlFtcvz91frYmj/zmoZRWro="}
}

I got inspiration from this issue. Tbh it's still not super clear to me where the type and value fields are defined and how/why the object resolves to a crypto.isPublicKey_Sum, but this works! Explanations welcome :)


var expectedGenesis consumertypes.GenesisState
json.Unmarshal([]byte(jsonString), &expectedGenesis)
err = json.Unmarshal([]byte(jsonString), &expectedGenesis)
suite.Require().NoError(err)

// Zero out differing fields- TODO: figure out how to get the test suite to
// keep these deterministic
Expand Down Expand Up @@ -164,8 +165,9 @@ func (suite *KeeperTestSuite) TestIteratePendingClientInfo() {
}

for _, tc := range testCases {
suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetPendingClientInfo(
err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.SetPendingClientInfo(
suite.providerChain.GetContext(), &tc.CreateConsumerChainProposal)
suite.Require().NoError(err)
}

ctx := suite.providerChain.GetContext().WithBlockTime(testCases[0].SpawnTime)
Expand Down
19 changes: 11 additions & 8 deletions x/ccv/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ type ProviderTestSuite struct {

path *ibctesting.Path
transferPath *ibctesting.Path

providerDistrIndex int
}

func (suite *ProviderTestSuite) SetupTest() {
Expand All @@ -56,20 +54,21 @@ func (suite *ProviderTestSuite) SetupTest() {
for i := 0; i < len(providerValUpdates); i++ {
addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i])
addr2 := utils.GetChangePubKeyAddress(consumerValUpdates[i])
suite.Require().True(bytes.Compare(addr1, addr2) == 0, "validator mismatch")
suite.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
}

// move both chains to the next block
suite.providerChain.NextBlock()
suite.consumerChain.NextBlock()

// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient(
suite.providerCtx(),
suite.consumerChain.ChainID,
suite.consumerChain.LastHeader.GetHeight().(clienttypes.Height),
false,
)
suite.Require().NoError(err)
// move provider to next block to commit the state
suite.providerChain.NextBlock()

Expand Down Expand Up @@ -113,8 +112,10 @@ func (suite *ProviderTestSuite) SetupTest() {

// set chains sender account number
// TODO: to be fixed in #151
suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
err = suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6)
suite.Require().NoError(err)
err = suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1)
suite.Require().NoError(err)

// create path for the transfer channel
suite.transferPath = ibctesting.NewPath(suite.consumerChain, suite.providerChain)
Expand Down Expand Up @@ -148,7 +149,8 @@ func (suite *ProviderTestSuite) CompleteSetupCCVChannel() {
suite.Require().NoError(err)

// ensure counterparty is up to date
suite.path.EndpointA.UpdateClient()
err = suite.path.EndpointA.UpdateClient()
suite.Require().NoError(err)
}

func (suite *ProviderTestSuite) SetupTransferChannel() {
Expand All @@ -175,7 +177,8 @@ func (suite *ProviderTestSuite) SetupTransferChannel() {
suite.Require().NoError(err)

// ensure counterparty is up to date
suite.transferPath.EndpointA.UpdateClient()
err = suite.transferPath.EndpointA.UpdateClient()
suite.Require().NoError(err)
}

func TestProviderTestSuite(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/provider/stop_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ func (s *ProviderTestSuite) SendEmptyVSCPacket() {
packet := channeltypes.NewPacket(pd.GetBytes(), seq, providertypes.PortID, s.path.EndpointB.ChannelID,
consumertypes.PortID, s.path.EndpointA.ChannelID, clienttypes.Height{}, timeout)

s.path.EndpointB.SendPacket(packet)
err := s.path.EndpointA.RecvPacket(packet)
err := s.path.EndpointB.SendPacket(packet)
s.Require().NoError(err)
err = s.path.EndpointA.RecvPacket(packet)
s.Require().NoError(err)
}
12 changes: 0 additions & 12 deletions x/ccv/provider/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ import (
"github.com/stretchr/testify/require"
)

const (
chainID = "gaia"
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
ubdPeriod time.Duration = time.Hour * 24 * 7 * 3
maxClockDrift time.Duration = time.Second * 10
)

var (
height = clienttypes.NewHeight(0, 4)
upgradePath = []string{"upgrade", "upgradedIBCState"}
)

func TestValidateGenesisState(t *testing.T) {
testCases := []struct {
name string
Expand Down
Loading