Merge PR #3502: Fixing bug in genesis Equal
This commit is contained in:
parent
9f30bfdbd9
commit
1766a73a4c
@ -22,6 +22,7 @@ BREAKING CHANGES
|
||||
* SDK
|
||||
* [\#3487](https://github.com/cosmos/cosmos-sdk/pull/3487) Move HTTP/REST utilities out of client/utils into a new dedicated client/rest package.
|
||||
* [\#3490](https://github.com/cosmos/cosmos-sdk/issues/3490) ReadRESTReq() returns bool to avoid callers to write error responses twice.
|
||||
* [\#3502](https://github.com/cosmos/cosmos-sdk/pull/3502) Fixes issue when comparing genesis states
|
||||
|
||||
* Tendermint
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ func DefaultGenesisState() GenesisState {
|
||||
|
||||
// Checks whether 2 GenesisState structs are equivalent.
|
||||
func (data GenesisState) Equal(data2 GenesisState) bool {
|
||||
if data.StartingProposalID != data.StartingProposalID ||
|
||||
if data.StartingProposalID != data2.StartingProposalID ||
|
||||
!data.DepositParams.Equal(data2.DepositParams) ||
|
||||
data.VotingParams != data2.VotingParams ||
|
||||
data.TallyParams != data2.TallyParams {
|
||||
@ -97,7 +97,7 @@ func (data GenesisState) Equal(data2 GenesisState) bool {
|
||||
return false
|
||||
}
|
||||
for i := range data.Proposals {
|
||||
if data.Proposals[i] != data.Proposals[i] {
|
||||
if !ProposalEqual(data.Proposals[i], data2.Proposals[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,53 @@ import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
func TestEqualProposalID(t *testing.T) {
|
||||
state1 := GenesisState{}
|
||||
state2 := GenesisState{}
|
||||
require.Equal(t, state1, state2)
|
||||
|
||||
// Proposals
|
||||
state1.StartingProposalID = 1
|
||||
require.NotEqual(t, state1, state2)
|
||||
require.False(t, state1.Equal(state2))
|
||||
|
||||
state2.StartingProposalID = 1
|
||||
require.Equal(t, state1, state2)
|
||||
require.True(t, state1.Equal(state2))
|
||||
}
|
||||
|
||||
func TestEqualProposals(t *testing.T) {
|
||||
// Generate mock app and keepers
|
||||
mapp, keeper, _, addrs, _, _ := getMockApp(t, 2, GenesisState{}, nil)
|
||||
SortAddresses(addrs)
|
||||
mapp.BeginBlock(abci.RequestBeginBlock{})
|
||||
ctx := mapp.BaseApp.NewContext(false, abci.Header{})
|
||||
|
||||
// Create two proposals
|
||||
proposal1 := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||
proposal2 := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||
|
||||
// They are similar but their IDs should be different
|
||||
require.NotEqual(t, proposal1, proposal2)
|
||||
require.False(t, ProposalEqual(proposal1, proposal2))
|
||||
|
||||
// Now create two genesis blocks
|
||||
state1 := GenesisState{Proposals: []Proposal{proposal1}}
|
||||
state2 := GenesisState{Proposals: []Proposal{proposal2}}
|
||||
require.NotEqual(t, state1, state2)
|
||||
require.False(t, state1.Equal(state2))
|
||||
|
||||
// Now make proposals identical by setting both IDs to 55
|
||||
proposal1.SetProposalID(55)
|
||||
proposal2.SetProposalID(55)
|
||||
require.Equal(t, proposal1, proposal1)
|
||||
require.True(t, ProposalEqual(proposal1, proposal2))
|
||||
|
||||
// State should be identical now..
|
||||
require.Equal(t, state1, state2)
|
||||
require.True(t, state1.Equal(state2))
|
||||
}
|
||||
|
||||
func TestImportExportQueues(t *testing.T) {
|
||||
|
||||
// Generate mock app and keepers
|
||||
|
||||
Loading…
Reference in New Issue
Block a user