From 743746a7dd3c6405f2cc85a79cf9e4d3bd80e180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Tue, 8 Mar 2022 09:17:57 +0100 Subject: [PATCH] fix: make `TestValidatorSetHandling` even more stable (#314) * fix: make `TestValidatorSetHandling` even more stable * docs: update CHANGELOG-PENDING.md --- CHANGELOG-PENDING.md | 1 + rpc/client/client_test.go | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG-PENDING.md b/CHANGELOG-PENDING.md index 7754f239ae8..1c86bbf214b 100644 --- a/CHANGELOG-PENDING.md +++ b/CHANGELOG-PENDING.md @@ -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/) diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index b63cf29c9b7..83ecb0c28bb 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -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++ { @@ -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) @@ -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