cosmos-sdk/x/upgrade/types/proposal_test.go

106 lines
2.8 KiB
Go
Raw Normal View History

package types_test
2019-11-08 06:40:56 -08:00
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
2019-11-08 06:40:56 -08:00
)
type ProposalWrapper struct {
Prop gov.Content
}
func TestContentAccessors(t *testing.T) {
cases := map[string]struct {
p gov.Content
title string
desc string
typ string
str string
}{
"upgrade": {
p: types.NewSoftwareUpgradeProposal("Title", "desc", types.Plan{
Name: "due_height",
Info: "https://foo.bar",
Height: 99999999999,
2019-11-08 06:40:56 -08:00
}),
title: "Title",
desc: "desc",
typ: "SoftwareUpgrade",
str: "Software Upgrade Proposal:\n Title: Title\n Description: desc\n",
},
"cancel": {
p: types.NewCancelSoftwareUpgradeProposal("Cancel", "bad idea"),
2019-11-08 06:40:56 -08:00
title: "Cancel",
desc: "bad idea",
typ: "CancelSoftwareUpgrade",
str: "Cancel Software Upgrade Proposal:\n Title: Cancel\n Description: bad idea\n",
},
}
cdc := codec.NewLegacyAmino()
gov.RegisterLegacyAminoCodec(cdc)
types.RegisterLegacyAminoCodec(cdc)
2019-11-08 06:40:56 -08:00
for name, tc := range cases {
tc := tc // copy to local variable for scopelint
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.title, tc.p.GetTitle())
assert.Equal(t, tc.desc, tc.p.GetDescription())
assert.Equal(t, tc.typ, tc.p.ProposalType())
assert.Equal(t, "upgrade", tc.p.ProposalRoute())
assert.Equal(t, tc.str, tc.p.String())
// try to encode and decode type to ensure codec works
wrap := ProposalWrapper{tc.p}
bz, err := cdc.Marshal(&wrap)
2019-11-08 06:40:56 -08:00
require.NoError(t, err)
unwrap := ProposalWrapper{}
err = cdc.Unmarshal(bz, &unwrap)
2019-11-08 06:40:56 -08:00
require.NoError(t, err)
// all methods should look the same
assert.Equal(t, tc.title, unwrap.Prop.GetTitle())
assert.Equal(t, tc.desc, unwrap.Prop.GetDescription())
assert.Equal(t, tc.typ, unwrap.Prop.ProposalType())
assert.Equal(t, "upgrade", unwrap.Prop.ProposalRoute())
assert.Equal(t, tc.str, unwrap.Prop.String())
})
}
}
Remove IBC logic from x/upgrade (#8673) * add zeroed custom fields check to tm client * remove custom fields function from x/upgrade and fix tests * use []byte in x/upgrade, move abci to 02-client * remove x/ibc from types * whoops, delete testing files * fix upgrade tests * fix tm tests * fix tests * update CHANGELOG * revert proto breakage, use reserved field cc @amaurym * add IBC Upgrade Proposal type * remove IBC from upgrade types * add IBC upgrade logic to 02-client * fix all tests for x/upgrade * Add CLI for IBC Upgrade Proposal * Update x/ibc/core/02-client/types/proposal_test.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * add gRPC for upgraded client state * test fixes * add HandleUpgradeProposal tests * update docs and remove unnecessary code * self review bug and test fixes * neatness * construct empty rest handler * fix tests * fix stringer tests * Update docs/core/proto-docs.md Co-authored-by: Christopher Goes <cwgoes@pluranimity.org> * add key in ibc store tracking ibc upgrade heights Add a new Key to the IBC client store to track the IBC Upgrade Height. This allows IBC upgrades to correctly remove old IBC upgrade states * update abci and tests * revert key storage after discussion with @AdityaSripal Revert using a key to track IBC upgrades. By clearing any IBC state using an old plan in ScheduleUpgrade, IBC upgrades do not need to be tracked by IBC. This reduces code complexity and reduces potential for bugs. * clear IBC states on cancelled upgrades Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Christopher Goes <cwgoes@pluranimity.org>
2021-03-01 08:28:54 -08:00
// tests a software update proposal can be marshaled and unmarshaled
func TestMarshalSoftwareUpdateProposal(t *testing.T) {
// create proposal
plan := types.Plan{
Remove IBC logic from x/upgrade (#8673) * add zeroed custom fields check to tm client * remove custom fields function from x/upgrade and fix tests * use []byte in x/upgrade, move abci to 02-client * remove x/ibc from types * whoops, delete testing files * fix upgrade tests * fix tm tests * fix tests * update CHANGELOG * revert proto breakage, use reserved field cc @amaurym * add IBC Upgrade Proposal type * remove IBC from upgrade types * add IBC upgrade logic to 02-client * fix all tests for x/upgrade * Add CLI for IBC Upgrade Proposal * Update x/ibc/core/02-client/types/proposal_test.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * add gRPC for upgraded client state * test fixes * add HandleUpgradeProposal tests * update docs and remove unnecessary code * self review bug and test fixes * neatness * construct empty rest handler * fix tests * fix stringer tests * Update docs/core/proto-docs.md Co-authored-by: Christopher Goes <cwgoes@pluranimity.org> * add key in ibc store tracking ibc upgrade heights Add a new Key to the IBC client store to track the IBC Upgrade Height. This allows IBC upgrades to correctly remove old IBC upgrade states * update abci and tests * revert key storage after discussion with @AdityaSripal Revert using a key to track IBC upgrades. By clearing any IBC state using an old plan in ScheduleUpgrade, IBC upgrades do not need to be tracked by IBC. This reduces code complexity and reduces potential for bugs. * clear IBC states on cancelled upgrades Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Christopher Goes <cwgoes@pluranimity.org>
2021-03-01 08:28:54 -08:00
Name: "upgrade",
Height: 1000,
}
content := types.NewSoftwareUpgradeProposal("title", "description", plan)
sup, ok := content.(*types.SoftwareUpgradeProposal)
require.True(t, ok)
// create codec
ir := codectypes.NewInterfaceRegistry()
types.RegisterInterfaces(ir)
gov.RegisterInterfaces(ir)
cdc := codec.NewProtoCodec(ir)
// marshal message
bz, err := cdc.MarshalJSON(sup)
require.NoError(t, err)
// unmarshal proposal
newSup := &types.SoftwareUpgradeProposal{}
err = cdc.UnmarshalJSON(bz, newSup)
require.NoError(t, err)
}