Skip to content

Commit

Permalink
Merge PR #3502: Fixing bug in genesis Equal
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni authored and cwgoes committed Feb 6, 2019
1 parent 9f30bfd commit 1766a73
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
47 changes: 47 additions & 0 deletions x/gov/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1766a73

Please sign in to comment.