Skip to content

Commit

Permalink
Remove legacy-submit-proposal consumer-addition
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Aug 6, 2024
1 parent 0e080c3 commit 80ad0a7
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 186 deletions.
2 changes: 0 additions & 2 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ var (
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
ibcproviderclient.ConsumerAdditionProposalHandler,
ibcproviderclient.ConsumerRemovalProposalHandler,
ibcproviderclient.ConsumerModificationProposalHandler,
ibcproviderclient.ChangeRewardDenomsProposalHandler,
Expand Down Expand Up @@ -579,7 +578,6 @@ func New(
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
ibcproviderclient.ConsumerAdditionProposalHandler,
ibcproviderclient.ConsumerRemovalProposalHandler,
ibcproviderclient.ConsumerModificationProposalHandler,
ibcproviderclient.ChangeRewardDenomsProposalHandler,
Expand Down
108 changes: 63 additions & 45 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"encoding/base64"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -273,57 +274,74 @@ func (tr Chain) submitConsumerAdditionProposal(
) {
spawnTime := tr.testConfig.containerConfig.Now.Add(time.Duration(action.SpawnTime) * time.Millisecond)
params := ccvtypes.DefaultParams()
prop := client.ConsumerAdditionProposalJSON{
Title: "Propose the addition of a new chain",
Summary: "Gonna be a great chain",
ChainId: string(tr.testConfig.chainConfigs[action.ConsumerChain].ChainId),
InitialHeight: action.InitialHeight,
GenesisHash: []byte("gen_hash"),
BinaryHash: []byte("bin_hash"),
SpawnTime: spawnTime,
ConsumerRedistributionFraction: params.ConsumerRedistributionFraction,
BlocksPerDistributionTransmission: params.BlocksPerDistributionTransmission,
HistoricalEntries: params.HistoricalEntries,
CcvTimeoutPeriod: params.CcvTimeoutPeriod,
TransferTimeoutPeriod: params.TransferTimeoutPeriod,
UnbondingPeriod: params.UnbondingPeriod,
Deposit: fmt.Sprint(action.Deposit) + `stake`,
DistributionTransmissionChannel: action.DistributionChannel,
TopN: action.TopN,
ValidatorsPowerCap: action.ValidatorsPowerCap,
ValidatorSetCap: action.ValidatorSetCap,
Allowlist: action.Allowlist,
Denylist: action.Denylist,
MinStake: action.MinStake,
AllowInactiveVals: action.AllowInactiveVals,
}

bz, err := json.Marshal(prop)
if err != nil {
log.Fatal(err)
}

jsonStr := string(bz)
if strings.Contains(jsonStr, "'") {
log.Fatal("prop json contains single quote")
}
template := `
{
"messages": [
{
"@type": "/interchain_security.ccv.provider.v1.MsgConsumerAddition",
"chain_id": "%s",
"initial_height": {
"revision_number": "%d",
"revision_height": "%d"
},
"genesis_hash": "%s",
"binary_hash": "%s",
"spawn_time": "%s",
"unbonding_period": "%s",
"ccv_timeout_period": "%s",
"transfer_timeout_period": "%s",
"consumer_redistribution_fraction": "%s",
"blocks_per_distribution_transmission": "%d",
"historical_entries": "%d",
"distribution_transmission_channel": "%s",
"top_N": %d,
"validators_power_cap": %d,
"validator_set_cap": %d,
"allowlist": %s,
"denylist": %s,
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
}
],
"metadata": "ipfs://CID",
"deposit": "%dstake",
"title": "Propose the addition of a new chain",
"summary": "Gonna be a great chain",
"expedited": false
}`
jsonStr := fmt.Sprintf(template,
string(tr.testConfig.chainConfigs[action.ConsumerChain].ChainId),
action.InitialHeight.RevisionNumber,
action.InitialHeight.RevisionHeight,
base64.StdEncoding.EncodeToString([]byte("gen_hash")),
base64.StdEncoding.EncodeToString([]byte("bin_hash")),
spawnTime.Local().Format(time.RFC3339Nano),
params.UnbondingPeriod,
params.CcvTimeoutPeriod,
params.TransferTimeoutPeriod,
params.ConsumerRedistributionFraction,
params.BlocksPerDistributionTransmission,
params.HistoricalEntries,
action.DistributionChannel,
action.TopN,
action.ValidatorsPowerCap,
action.ValidatorSetCap,
action.Allowlist,
action.Denylist,
action.Deposit)

//#nosec G204 -- bypass unsafe quoting warning (no production code)
cmd := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json"))
bz, err = cmd.CombinedOutput()
if verbose {
log.Println("submitConsumerAdditionProposal cmd: ", cmd.String())
}

proposalFile := "/consumer-addition.proposal"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, proposalFile),
).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

// CONSUMER ADDITION PROPOSAL
cmd = tr.target.ExecCommand(
cmd := tr.target.ExecCommand(
tr.testConfig.chainConfigs[action.Chain].BinaryName,
"tx", "gov", "submit-legacy-proposal", "consumer-addition", "/temp-proposal.json",
"tx", "gov", "submit-proposal", proposalFile,
`--from`, `validator`+fmt.Sprint(action.From),
`--chain-id`, string(tr.testConfig.chainConfigs[action.Chain].ChainId),
`--home`, tr.getValidatorHome(action.Chain, action.From),
Expand All @@ -339,15 +357,15 @@ func (tr Chain) submitConsumerAdditionProposal(
}
bz, err = cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
log.Fatal("submit-proposal failed:", err, "\n", string(bz))
}

if verbose {
fmt.Println("submitConsumerAdditionProposal output:", string(bz))
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 10*time.Second)
tr.waitBlocks(action.Chain, 2, 10*time.Second)
}

type SubmitConsumerRemovalProposalAction struct {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
Title: title,
Description: description,
}
case "/interchain_security.ccv.provider.v1.ConsumerAdditionProposal":
case "/interchain_security.ccv.provider.v1.MsgConsumerAddition":
chainId := rawContent.Get("chain_id").String()
spawnTime := rawContent.Get("spawn_time").Time().Sub(tr.containerConfig.Now)

Expand Down Expand Up @@ -555,7 +555,7 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
}
}

log.Fatal("received unknown proposal type: ", propType, "proposal JSON:", propRaw)
log.Fatal("received unknown proposal type: '", propType, "', proposal JSON:", propRaw)

return nil
}
Expand Down
40 changes: 23 additions & 17 deletions tests/integration/provider_gov_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ func (s *CCVTestSuite) TestAfterPropSubmissionAndVotingPeriodEnded() {
govKeeper := s.providerApp.GetTestGovKeeper()
proposer := s.providerChain.SenderAccount

content := testkeeper.GetTestConsumerAdditionProp()
content.ChainId = "newchain-0"
legacyPropContent, err := v1.NewLegacyContent(
content,
authtypes.NewModuleAddress("gov").String(),
)
s.Require().NoError(err)
addConsumerProp := testkeeper.GetTestMsgConsumerAddition()

proposal, err := v1.NewProposal([]sdk.Msg{legacyPropContent}, 1, time.Now(), time.Now().Add(1*time.Hour), "metadata", "title", "summary", proposer.GetAddress(), false)
proposal, err := v1.NewProposal([]sdk.Msg{&addConsumerProp}, 1, time.Now(), time.Now().Add(1*time.Hour), "metadata", "title", "summary", proposer.GetAddress(), false)
s.Require().NoError(err)

err = govKeeper.SetProposal(ctx, proposal)
Expand All @@ -41,14 +35,14 @@ func (s *CCVTestSuite) TestAfterPropSubmissionAndVotingPeriodEnded() {
proposalIdOnProvider, ok := providerKeeper.GetProposedConsumerChain(ctx, proposal.Id)
s.Require().True(ok)
s.Require().NotEmpty(proposalIdOnProvider)
s.Require().Equal(content.ChainId, proposalIdOnProvider)
s.Require().Equal(addConsumerProp.ChainId, proposalIdOnProvider)

providerKeeper.Hooks().AfterProposalVotingPeriodEnded(ctx, proposal.Id)
// verify that the proposal ID is deleted
s.Require().Empty(providerKeeper.GetProposedConsumerChain(ctx, proposal.Id))
}

func (s *CCVTestSuite) TestGetConsumerAdditionLegacyPropFromProp() {
func (s *CCVTestSuite) TestGetConsumerAdditionFromProp() {
ctx := s.providerChain.GetContext()
proposer := s.providerChain.SenderAccount

Expand All @@ -59,13 +53,19 @@ func (s *CCVTestSuite) TestGetConsumerAdditionLegacyPropFromProp() {
Amount: sdk.NewCoins(sdk.NewCoin("stake", math.OneInt())),
}

// create a legacy proposal
textProp, err := v1.NewLegacyContent(
v1beta1.NewTextProposal("a title", "a legacy text prop"),
authtypes.NewModuleAddress("gov").String(),
)
s.Require().NoError(err)

addConsumerProp, err := v1.NewLegacyContent(
// create a valid consumer addition proposal
addConsumerProp := testkeeper.GetTestMsgConsumerAddition()

// create a legacy consumer addition proposal content
// (not supported anymore)
addConsumerPropLegacy, err := v1.NewLegacyContent(
testkeeper.GetTestConsumerAdditionProp(),
authtypes.NewModuleAddress("gov").String(),
)
Expand All @@ -84,7 +84,7 @@ func (s *CCVTestSuite) TestGetConsumerAdditionLegacyPropFromProp() {
expPanic: false,
},
{
name: "msgs in prop contain no legacy props",
name: "msgs in prop contain no consumer addition props",
propMsg: dummyMsg,
expectConsumerPropFound: false,
expPanic: false,
Expand All @@ -98,11 +98,17 @@ func (s *CCVTestSuite) TestGetConsumerAdditionLegacyPropFromProp() {
name: "msgs contain an invalid legacy prop",
propMsg: &v1.MsgExecLegacyContent{},
expectConsumerPropFound: false,
expPanic: true,
expPanic: false,
},
{
name: "msg contains a prop of legacy ConsumerAdditionProposal type - hook should NOT create a new proposed chain",
propMsg: addConsumerPropLegacy,
expectConsumerPropFound: false,
expPanic: false,
},
{
name: "msg contains a prop of ConsumerAdditionProposal type - hook should create a new proposed chain",
propMsg: addConsumerProp,
name: "msg contains a prop of legacy ConsumerAdditionProposal type - hook should create a new proposed chain",
propMsg: &addConsumerProp,
expectConsumerPropFound: true,
expPanic: false,
},
Expand Down Expand Up @@ -132,12 +138,12 @@ func (s *CCVTestSuite) TestGetConsumerAdditionLegacyPropFromProp() {
if tc.expPanic {
s.Require().Panics(func() {
// this panics with a nil pointer dereference because the proposal is invalid and cannot be unmarshalled
providerKeeper.Hooks().GetConsumerAdditionLegacyPropFromProp(ctx, proposal.Id)
providerKeeper.Hooks().GetConsumerAdditionFromProp(ctx, proposal.Id)
})
return
}

savedProp, found := providerKeeper.Hooks().GetConsumerAdditionLegacyPropFromProp(ctx, proposal.Id)
savedProp, found := providerKeeper.Hooks().GetConsumerAdditionFromProp(ctx, proposal.Id)
if tc.expectConsumerPropFound {
s.Require().True(found)
s.Require().NotEmpty(savedProp, savedProp)
Expand Down
12 changes: 2 additions & 10 deletions testutil/integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ func TestAfterPropSubmissionAndVotingPeriodEnded(t *testing.T) {
runCCVTestByName(t, "TestAfterPropSubmissionAndVotingPeriodEnded")
}

func TestGetConsumerAdditionLegacyPropFromProp(t *testing.T) {
runCCVTestByName(t, "TestGetConsumerAdditionLegacyPropFromProp")
func TestGetConsumerAdditionFromProp(t *testing.T) {
runCCVTestByName(t, "TestGetConsumerAdditionFromProp")
}

func TestIBCTransferMiddleware(t *testing.T) {
Expand All @@ -277,14 +277,6 @@ func TestAllocateTokens(t *testing.T) {
runCCVTestByName(t, "TestAllocateTokens")
}

func TestTransferConsumerRewardsToDistributionModule(t *testing.T) {
runCCVTestByName(t, "TransferConsumerRewardsToDistributionModule")
}

func TestAllocateTokensToValidator(t *testing.T) {
runCCVTestByName(t, "TestAllocateTokensToValidator")
}

func TestMultiConsumerRewardsDistribution(t *testing.T) {
runCCVTestByName(t, "TestMultiConsumerRewardsDistribution")
}
Expand Down
24 changes: 24 additions & 0 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"crypto/rand"
"encoding/base64"
"encoding/binary"
"testing"
"time"
Expand Down Expand Up @@ -293,6 +294,29 @@ func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal {
return prop
}

func GetTestMsgConsumerAddition() providertypes.MsgConsumerAddition {
return providertypes.MsgConsumerAddition{
ChainId: "a ChainID",
InitialHeight: clienttypes.NewHeight(4, 5),
GenesisHash: []byte(base64.StdEncoding.EncodeToString([]byte("gen_hash"))),
BinaryHash: []byte(base64.StdEncoding.EncodeToString([]byte("bin_hash"))),
SpawnTime: time.Now(),

Check warning

Code scanning / CodeQL

Calling the system time Warning test

Calling the system time may be a possible source of non-determinism
UnbondingPeriod: types.DefaultConsumerUnbondingPeriod,
CcvTimeoutPeriod: types.DefaultCCVTimeoutPeriod,
TransferTimeoutPeriod: types.DefaultTransferTimeoutPeriod,
ConsumerRedistributionFraction: types.DefaultConsumerRedistributeFrac,
BlocksPerDistributionTransmission: types.DefaultBlocksPerDistributionTransmission,
HistoricalEntries: types.DefaultHistoricalEntries,
DistributionTransmissionChannel: "",
Top_N: 10,
ValidatorsPowerCap: 0,
ValidatorSetCap: 0,
Allowlist: nil,
Denylist: nil,
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
}
}

// Obtains a CrossChainValidator with a newly generated key, and randomized field values
func GetNewCrossChainValidator(t *testing.T) consumertypes.CrossChainValidator {
t.Helper()
Expand Down
Loading

0 comments on commit 80ad0a7

Please sign in to comment.