Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(evidence): update tests for new proposal selection algo #925

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## [1.3.0] - 2024-09-19

### Bug Fixes

- Address already in use (#845)
- Active validators not always connected to each other (#844)
- Validators form islands on genesis (#850)
- Panic on block_results when consensus params change (#923)

### Features

- [**breaking**] Replace dash core quorum sign with quorum platformsign (#828)
- Allow overriding genesis time in InitChain (#847)

### Miscellaneous Tasks

- Update changelog and version to 1.1.0-dev.1 (#842)
- Update changelog and version to 1.1.0-dev.2 (#846)
- Update changelog and version to 1.1.0-dev.3 (#848)

### Build

- Bump bufbuild/buf-setup-action from 1.33.0 to 1.35.0 (#841)
- Run dependabot on default branch, not master (#843)

## [1.2.1] - 2024-08-29

### Bug Fixes
Expand All @@ -8,6 +33,7 @@
### Miscellaneous Tasks

- Update changelog and version to 1.2.1-dev.1
- Update changelog and version to 1.2.1

### Build

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/dashpay/tenderdash/types"
)

//go:generate ../../../../scripts/mockery_generate.sh ProposerSelector

type ProposerSelector interface {
// GetProposer returns the proposer for the given height and round. It calls Update if necessary.
GetProposer(height int64, round int32) (*types.Validator, error)
Expand Down
64 changes: 52 additions & 12 deletions internal/evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/dashpay/tenderdash/crypto"
"github.com/dashpay/tenderdash/internal/consensus/versioned/selectproposer"
psmocks "github.com/dashpay/tenderdash/internal/consensus/versioned/selectproposer/mocks"
"github.com/dashpay/tenderdash/internal/eventbus"
"github.com/dashpay/tenderdash/internal/evidence"
"github.com/dashpay/tenderdash/internal/evidence/mocks"
Expand Down Expand Up @@ -108,27 +110,41 @@ func TestEvidencePoolBasic(t *testing.T) {
require.Equal(t, 1, len(evs))
}

func makeBlockMeta(height int64, time time.Time, vals *types.ValidatorSet) *types.BlockMeta {
return &types.BlockMeta{
Header: types.Header{
Height: height,
Time: time,
ProposerProTxHash: vals.Proposer().ProTxHash,
ValidatorsHash: vals.Hash(),
},
}
}

// Tests inbound evidence for the right time and height
func TestAddExpiredEvidence(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var (
quorumHash = crypto.RandQuorumHash()
val = types.NewMockPVForQuorum(quorumHash)
privval = types.NewMockPVForQuorum(quorumHash)
val = privval.ExtractIntoValidator(ctx, quorumHash)
valSet = types.NewValidatorSet([]*types.Validator{val}, val.PubKey, btcjson.LLMQType_5_60, quorumHash, true)
height = int64(30)
stateStore = initializeValidatorState(ctx, t, val, height, btcjson.LLMQType_5_60, quorumHash)
stateStore = initializeValidatorState(ctx, t, privval, height, btcjson.LLMQType_5_60, quorumHash)
evidenceDB = dbm.NewMemDB()
blockStore = &mocks.BlockStore{}
expiredEvidenceTime = time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC)
expiredHeight = int64(2)
)

blockStore.On("Base").Return(int64(3))
blockStore.On("LoadBlockMeta", mock.AnythingOfType("int64")).Return(func(h int64) *types.BlockMeta {
if h == height || h == expiredHeight {
return &types.BlockMeta{Header: types.Header{Time: defaultEvidenceTime}}
return makeBlockMeta(h, defaultEvidenceTime, valSet)
}
return &types.BlockMeta{Header: types.Header{Time: expiredEvidenceTime}}
return makeBlockMeta(h, expiredEvidenceTime, valSet)
})

logger := log.NewNopLogger()
Expand Down Expand Up @@ -160,7 +176,7 @@ func TestAddExpiredEvidence(t *testing.T) {
defer cancel()

vals := pool.State().Validators
ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, tc.evHeight, tc.evTime, val, evidenceChainID, vals.QuorumType, vals.QuorumHash)
ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, tc.evHeight, tc.evTime, privval, evidenceChainID, vals.QuorumType, vals.QuorumHash)
require.NoError(t, err)
err = pool.AddEvidence(ctx, ev)
if tc.expErr {
Expand Down Expand Up @@ -408,7 +424,9 @@ func TestRecoverPendingEvidence(t *testing.T) {
state, err := stateStore.Load()
require.NoError(t, err)

blockStore, err := initializeBlockStore(dbm.NewMemDB(), state)
propSel := mockProposerSelector(t, val.ExtractIntoValidator(ctx, quorumHash))

blockStore, err := initializeBlockStore(dbm.NewMemDB(), state, propSel)
require.NoError(t, err)

logger := log.NewNopLogger()
Expand Down Expand Up @@ -535,12 +553,12 @@ func initializeValidatorState(

// initializeBlockStore creates a block storage and populates it w/ a dummy
// block at +height+.
func initializeBlockStore(db dbm.DB, state sm.State) (*store.BlockStore, error) {
func initializeBlockStore(db dbm.DB, state sm.State, propsel selectproposer.ProposerSelector) (*store.BlockStore, error) {
blockStore := store.NewBlockStore(db)

for i := int64(1); i <= state.LastBlockHeight; i++ {
lastCommit := makeCommit(i-1, state.Validators.QuorumHash)
prop := state.GetProposerFromState(i, 0)
prop := propsel.MustGetProposer(i, 0)
block := state.MakeBlock(i, []types.Tx{}, lastCommit, nil, prop.ProTxHash, 0)

block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute)
Expand Down Expand Up @@ -573,16 +591,38 @@ func makeCommit(height int64, quorumHash []byte) *types.Commit {
)
}

func mockProposerSelector(t *testing.T, validator *types.Validator) selectproposer.ProposerSelector {
t.Helper()
propSel := psmocks.NewProposerSelector(t)
propSel.On("GetProposer", mock.Anything, mock.Anything).
Return(validator, nil).
Maybe()
propSel.On("MustGetProposer", mock.Anything, mock.Anything).
Return(validator).
Maybe()
propSel.On("UpdateHeightRound", mock.Anything, mock.Anything).
Return(nil).
Maybe()

return propSel
}

func defaultTestPool(ctx context.Context, t *testing.T, height int64) (*evidence.Pool, *types.MockPV, *eventbus.EventBus) {
t.Helper()
quorumHash := crypto.RandQuorumHash()
val := types.NewMockPVForQuorum(quorumHash)
privval := types.NewMockPVForQuorum(quorumHash)
val := privval.ExtractIntoValidator(ctx, quorumHash)

evidenceDB := dbm.NewMemDB()
stateStore := initializeValidatorState(ctx, t, val, height, btcjson.LLMQType_5_60, quorumHash)
stateStore := initializeValidatorState(ctx, t, privval, height, btcjson.LLMQType_5_60, quorumHash)
state, err := stateStore.Load()
require.NoError(t, err)
blockStore, err := initializeBlockStore(dbm.NewMemDB(), state)

propSel := mockProposerSelector(t, val)

require.NoError(t, err)

blockStore, err := initializeBlockStore(dbm.NewMemDB(), state, propSel)
require.NoError(t, err)

logger := log.NewNopLogger()
Expand All @@ -592,7 +632,7 @@ func defaultTestPool(ctx context.Context, t *testing.T, height int64) (*evidence

pool := evidence.NewPool(logger, evidenceDB, stateStore, blockStore, evidence.NopMetrics(), eventBus)
startPool(t, pool, stateStore)
return pool, val, eventBus
return pool, privval, eventBus
}

func createState(height int64, valSet *types.ValidatorSet) sm.State {
Expand Down
3 changes: 2 additions & 1 deletion internal/evidence/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ func setup(ctx context.Context, t *testing.T, stateStores []sm.Store) *reactorTe
evidenceDB := dbm.NewMemDB()
blockStore := &mocks.BlockStore{}
state, _ := stateStores[idx].Load()
blockStore.On("Base").Return(int64(1))
blockStore.On("LoadBlockMeta", mock.AnythingOfType("int64")).Return(func(h int64) *types.BlockMeta {
if h <= state.LastBlockHeight {
return &types.BlockMeta{Header: types.Header{Time: evidenceTime}}
return makeBlockMeta(h, evidenceTime, state.Validators)
}
return nil
})
Expand Down
3 changes: 2 additions & 1 deletion internal/evidence/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/dashpay/dashd-go/btcjson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"

Expand Down Expand Up @@ -110,7 +111,7 @@ func TestVerifyDuplicateVoteEvidence(t *testing.T) {
ConsensusParams: *types.DefaultConsensusParams(),
}
stateStore := &smmocks.Store{}
stateStore.On("LoadValidators", int64(10)).Return(valSet, nil)
stateStore.On("LoadValidators", int64(10), mock.Anything).Return(valSet, nil)
stateStore.On("Load").Return(state, nil)
blockStore := &mocks.BlockStore{}
blockStore.On("LoadBlockMeta", int64(10)).Return(&types.BlockMeta{Header: types.Header{Time: defaultEvidenceTime}})
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var (
const (
// TMVersionDefault is the used as the fallback version for Tenderdash
// when not using git describe. It is formatted with semantic versioning.
TMVersionDefault = "1.2.1"
TMVersionDefault = "1.3.0"
// ABCISemVer is the semantic version of the ABCI library
ABCISemVer = "1.2.0"

Expand Down
Loading