Skip to content

Commit

Permalink
fix: make TestValidatorSetHandling even more stable (cosmos#314)
Browse files Browse the repository at this point in the history
* fix: make `TestValidatorSetHandling` even more stable
* docs: update CHANGELOG-PENDING.md
  • Loading branch information
tzdybal authored Mar 8, 2022
1 parent 4f0fd20 commit 743746a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
### IMPROVEMENTS

### BUG FIXES
- fix: make TestValidatorSetHandling even more stable ([#314](https://github.com/celestiaorg/optimint/pull/314)) [@tzdybal](https://github.com/tzdybal/)
24 changes: 15 additions & 9 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,17 @@ func TestValidatorSetHandling(t *testing.T) {
err = node.Start()
require.NoError(err)

// test latest block a few times - ensure that validator set from genesis is handled correctly
lastHeight := int64(-1)
for i := 0; i < 3; i++ {
time.Sleep(10 * time.Millisecond)
vals, err := rpc.Validators(context.Background(), nil, nil, nil)
<-waitCh

// test first blocks
for h := int64(1); h <= 6; h++ {
vals, err := rpc.Validators(context.Background(), &h, nil, nil)
assert.NoError(err)
assert.NotNil(vals)
assert.EqualValues(len(genesisValidators), vals.Total)
assert.Len(vals.Validators, len(genesisValidators))
assert.Greater(vals.BlockHeight, lastHeight)
lastHeight = vals.BlockHeight
assert.EqualValues(vals.BlockHeight, h)
}
<-waitCh

// 6th EndBlock removes first validator from the list
for h := int64(7); h <= 8; h++ {
Expand All @@ -690,7 +688,7 @@ func TestValidatorSetHandling(t *testing.T) {
}

// 8th EndBlock adds validator back
for h := int64(9); h < 12; h++ {
for h := int64(9); h <= 12; h++ {
<-waitCh
vals, err := rpc.Validators(context.Background(), &h, nil, nil)
assert.NoError(err)
Expand All @@ -699,6 +697,14 @@ func TestValidatorSetHandling(t *testing.T) {
assert.Len(vals.Validators, len(genesisValidators))
assert.EqualValues(vals.BlockHeight, h)
}

// check for "latest block"
vals, err := rpc.Validators(context.Background(), nil, nil, nil)
assert.NoError(err)
assert.NotNil(vals)
assert.EqualValues(len(genesisValidators), vals.Total)
assert.Len(vals.Validators, len(genesisValidators))
assert.GreaterOrEqual(vals.BlockHeight, int64(12))
}

// copy-pasted from store/store_test.go
Expand Down

0 comments on commit 743746a

Please sign in to comment.