Skip to content

Commit

Permalink
refactor: mostly refactors (#2194)
Browse files Browse the repository at this point in the history
* handle errors

* set the reverse index in SetConsumerClientId

* rename method

* create consumer_lifecycle.go with launch/stop logic

* move methods around

* move methods around

* handle ChangeRewardDenoms

* add TODOs

* remove proposal_test

* remove todos

* apply review suggestions

* apply review suggestions

* fix UTs
  • Loading branch information
mpoke authored Aug 30, 2024
1 parent 9bbd274 commit 6262e42
Show file tree
Hide file tree
Showing 21 changed files with 1,520 additions and 1,601 deletions.
15 changes: 10 additions & 5 deletions testutil/ibc_testing/generic_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,15 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
FirstConsumerID = consumerId
}
providerKeeper.SetConsumerChainId(providerChain.GetContext(), consumerId, chainID)
providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata)
providerKeeper.SetConsumerInitializationParameters(providerChain.GetContext(), consumerId, initializationParameters)
providerKeeper.SetConsumerPowerShapingParameters(providerChain.GetContext(), consumerId, powerShapingParameters)
err := providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata)
s.Require().NoError(err)
err = providerKeeper.SetConsumerInitializationParameters(providerChain.GetContext(), consumerId, initializationParameters)
s.Require().NoError(err)
err = providerKeeper.SetConsumerPowerShapingParameters(providerChain.GetContext(), consumerId, powerShapingParameters)
s.Require().NoError(err)
providerKeeper.SetConsumerPhase(providerChain.GetContext(), consumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
providerKeeper.AppendConsumerToBeLaunched(providerChain.GetContext(), consumerId, coordinator.CurrentTime)
err = providerKeeper.AppendConsumerToBeLaunched(providerChain.GetContext(), consumerId, coordinator.CurrentTime)
s.Require().NoError(err)

// opt-in all validators
lastVals, err := providerApp.GetProviderKeeper().GetLastBondedValidators(providerChain.GetContext())
Expand All @@ -173,7 +177,8 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
for _, v := range lastVals {
consAddr, _ := v.GetConsAddr()
providerKeeper.SetOptedIn(providerChain.GetContext(), consumerId, providertypes.NewProviderConsAddress(consAddr))
providerKeeper.AppendOptedInConsumerId(providerChain.GetContext(), providertypes.NewProviderConsAddress(consAddr), consumerId)
err = providerKeeper.AppendOptedInConsumerId(providerChain.GetContext(), providertypes.NewProviderConsAddress(consAddr), consumerId)
s.Require().NoError(err)
}

// commit the state on the provider chain
Expand Down
4 changes: 3 additions & 1 deletion testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ func SetupForStoppingConsumerChain(t *testing.T, ctx sdk.Context,

err := providerKeeper.CreateConsumerClient(ctx, consumerId)
require.NoError(t, err)
providerKeeper.SetClientIdToConsumerId(ctx, "clientID", consumerId)
// set the mapping consumer ID <> client ID for the consumer chain
providerKeeper.SetConsumerClientId(ctx, consumerId, "clientID")
// set the channel ID for the consumer chain
err = providerKeeper.SetConsumerChain(ctx, "channelID")
require.NoError(t, err)
}
Expand Down
3 changes: 1 addition & 2 deletions x/ccv/provider/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func TestOnChanOpenTry(t *testing.T) {

providerKeeper.SetPort(ctx, ccv.ProviderPortID)
providerKeeper.SetConsumerClientId(ctx, "consumerId", "clientIdToConsumer")
providerKeeper.SetClientIdToConsumerId(ctx, "clientIdToConsumer", "consumerId")

// Instantiate valid params as default. Individual test cases mutate these as needed.
params := params{
Expand Down Expand Up @@ -313,7 +312,7 @@ func TestOnChanOpenConfirm(t *testing.T) {
providerKeeper.SetConsumerIdToChannelId(ctx, "consumerChainID", "existingChannelID")
}

providerKeeper.SetClientIdToConsumerId(ctx, "clientID", "consumerChainID")
providerKeeper.SetConsumerClientId(ctx, "consumerChainID", "clientID")

providerModule := provider.NewAppModule(&providerKeeper, *keeperParams.ParamsSubspace, keeperParams.StoreKey)

Expand Down
Loading

0 comments on commit 6262e42

Please sign in to comment.