From a9c44116de0d0128379c23b1c12e17bf904602f4 Mon Sep 17 00:00:00 2001 From: Marko Baricevic Date: Wed, 10 Feb 2021 10:36:52 +0100 Subject: [PATCH] tests --- blockchain/v2/scheduler.go | 4 ++-- blockchain/v2/scheduler_test.go | 10 +++++----- evidence/pool_test.go | 4 ++-- evidence/reactor_test.go | 2 +- evidence/verify_test.go | 26 +++++++++++++------------- light/client_test.go | 4 ++-- light/rpc/client_test.go | 2 +- light/store/db/db_test.go | 4 ++-- state/state_test.go | 2 +- store/store_test.go | 6 +++--- types/block_test.go | 4 ++-- types/event_bus_test.go | 6 +++--- types/evidence_test.go | 2 +- 13 files changed, 38 insertions(+), 38 deletions(-) diff --git a/blockchain/v2/scheduler.go b/blockchain/v2/scheduler.go index 4a07861be..ab603230d 100644 --- a/blockchain/v2/scheduler.go +++ b/blockchain/v2/scheduler.go @@ -466,8 +466,8 @@ func (sc *scheduler) nextHeightToSchedule() uint64 { min = height } } - if min == math.MaxInt64 { - min = 0 //todo: see if this changes logic + if min == math.MaxUint64 { + min = 0 } return min } diff --git a/blockchain/v2/scheduler_test.go b/blockchain/v2/scheduler_test.go index f09f6bdab..ba094b0d4 100644 --- a/blockchain/v2/scheduler_test.go +++ b/blockchain/v2/scheduler_test.go @@ -111,7 +111,7 @@ func TestScMaxHeights(t *testing.T) { tests := []struct { name string sc scheduler - wantMax int64 + wantMax uint64 }{ { name: "no peers", @@ -1157,12 +1157,12 @@ func TestScNextHeightToSchedule(t *testing.T) { tests := []struct { name string fields scTestParams - wantHeight int64 + wantHeight uint64 }{ { name: "no blocks", fields: scTestParams{initHeight: 11, height: 11}, - wantHeight: -1, + wantHeight: 0, }, { name: "only New blocks", @@ -1182,7 +1182,7 @@ func TestScNextHeightToSchedule(t *testing.T) { pending: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, pendingTime: map[uint64]time.Time{1: now, 2: now, 3: now, 4: now}, }, - wantHeight: -1, + wantHeight: 0, }, { name: "only Received blocks", @@ -1192,7 +1192,7 @@ func TestScNextHeightToSchedule(t *testing.T) { allB: []uint64{1, 2, 3, 4}, received: map[uint64]p2p.NodeID{1: "P1", 2: "P1", 3: "P1", 4: "P1"}, }, - wantHeight: -1, + wantHeight: 0, }, { name: "only Processed blocks", diff --git a/evidence/pool_test.go b/evidence/pool_test.go index 5831a22f8..ffb0e582b 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -38,10 +38,10 @@ func TestEvidencePoolBasic(t *testing.T) { valSet, privVals := types.RandValidatorSet(1, 10) - blockStore.On("LoadBlockMeta", mock.AnythingOfType("int64")).Return( + blockStore.On("LoadBlockMeta", mock.AnythingOfType("uint64")).Return( &types.BlockMeta{Header: types.Header{Time: defaultEvidenceTime}}, ) - stateStore.On("LoadValidators", mock.AnythingOfType("int64")).Return(valSet, nil) + stateStore.On("LoadValidators", mock.AnythingOfType("uint64")).Return(valSet, nil) stateStore.On("Load").Return(createState(height+1, valSet), nil) pool, err := evidence.NewPool(log.TestingLogger(), evidenceDB, stateStore, blockStore) diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index 5ed1c818e..45ae0c079 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -101,7 +101,7 @@ func createTestSuites(t *testing.T, stateStores []sm.Store, chBuf uint) []*react logger := log.TestingLogger().With("validator", i) evidenceDB := dbm.NewMemDB() blockStore := &mocks.BlockStore{} - blockStore.On("LoadBlockMeta", mock.AnythingOfType("int64")).Return( + blockStore.On("LoadBlockMeta", mock.AnythingOfType("uint64")).Return( &types.BlockMeta{Header: types.Header{Time: evidenceTime}}, ) diff --git a/evidence/verify_test.go b/evidence/verify_test.go index 7f09f7e4b..a6fd6f06a 100644 --- a/evidence/verify_test.go +++ b/evidence/verify_test.go @@ -94,13 +94,13 @@ func TestVerifyLightClientAttack_Lunatic(t *testing.T) { ConsensusParams: *types.DefaultConsensusParams(), } stateStore := &smmocks.Store{} - stateStore.On("LoadValidators", int64(4)).Return(commonVals, nil) + stateStore.On("LoadValidators", uint64(4)).Return(commonVals, nil) stateStore.On("Load").Return(state, nil) blockStore := &mocks.BlockStore{} - blockStore.On("LoadBlockMeta", int64(4)).Return(&types.BlockMeta{Header: *commonHeader}) - blockStore.On("LoadBlockMeta", int64(10)).Return(&types.BlockMeta{Header: *trustedHeader}) - blockStore.On("LoadBlockCommit", int64(4)).Return(commit) - blockStore.On("LoadBlockCommit", int64(10)).Return(trustedCommit) + blockStore.On("LoadBlockMeta", uint64(4)).Return(&types.BlockMeta{Header: *commonHeader}) + blockStore.On("LoadBlockMeta", uint64(10)).Return(&types.BlockMeta{Header: *trustedHeader}) + blockStore.On("LoadBlockCommit", uint64(4)).Return(commit) + blockStore.On("LoadBlockCommit", uint64(10)).Return(trustedCommit) pool, err := evidence.NewPool(log.TestingLogger(), dbm.NewMemDB(), stateStore, blockStore) require.NoError(t, err) @@ -193,11 +193,11 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { ConsensusParams: *types.DefaultConsensusParams(), } stateStore := &smmocks.Store{} - stateStore.On("LoadValidators", int64(10)).Return(conflictingVals, nil) + stateStore.On("LoadValidators", uint64(10)).Return(conflictingVals, nil) stateStore.On("Load").Return(state, nil) blockStore := &mocks.BlockStore{} - blockStore.On("LoadBlockMeta", int64(10)).Return(&types.BlockMeta{Header: *trustedHeader}) - blockStore.On("LoadBlockCommit", int64(10)).Return(trustedCommit) + blockStore.On("LoadBlockMeta", uint64(10)).Return(&types.BlockMeta{Header: *trustedHeader}) + blockStore.On("LoadBlockCommit", uint64(10)).Return(trustedCommit) pool, err := evidence.NewPool(log.TestingLogger(), dbm.NewMemDB(), stateStore, blockStore) require.NoError(t, err) @@ -267,11 +267,11 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) { ConsensusParams: *types.DefaultConsensusParams(), } stateStore := &smmocks.Store{} - stateStore.On("LoadValidators", int64(10)).Return(conflictingVals, nil) + stateStore.On("LoadValidators", uint64(10)).Return(conflictingVals, nil) stateStore.On("Load").Return(state, nil) blockStore := &mocks.BlockStore{} - blockStore.On("LoadBlockMeta", int64(10)).Return(&types.BlockMeta{Header: *trustedHeader}) - blockStore.On("LoadBlockCommit", int64(10)).Return(trustedCommit) + blockStore.On("LoadBlockMeta", uint64(10)).Return(&types.BlockMeta{Header: *trustedHeader}) + blockStore.On("LoadBlockCommit", uint64(10)).Return(trustedCommit) pool, err := evidence.NewPool(log.TestingLogger(), dbm.NewMemDB(), stateStore, blockStore) require.NoError(t, err) @@ -360,10 +360,10 @@ func TestVerifyDuplicateVoteEvidence(t *testing.T) { ConsensusParams: *types.DefaultConsensusParams(), } stateStore := &smmocks.Store{} - stateStore.On("LoadValidators", int64(10)).Return(valSet, nil) + stateStore.On("LoadValidators", uint64(10)).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}}) + blockStore.On("LoadBlockMeta", uint64(10)).Return(&types.BlockMeta{Header: types.Header{Time: defaultEvidenceTime}}) pool, err := evidence.NewPool(log.TestingLogger(), dbm.NewMemDB(), stateStore, blockStore) require.NoError(t, err) diff --git a/light/client_test.go b/light/client_test.go index 2489b23c8..ac0e4b483 100644 --- a/light/client_test.go +++ b/light/client_test.go @@ -114,7 +114,7 @@ func TestValidateTrustOptions(t *testing.T) { func TestMock(t *testing.T) { l, _ := fullNode.LightBlock(ctx, 3) - assert.Equal(t, int64(3), l.Height) + assert.Equal(t, uint64(3), l.Height) } func TestClient_SequentialVerification(t *testing.T) { @@ -1020,7 +1020,7 @@ func TestClientPrunesHeadersAndValidatorSets(t *testing.T) { h, err := c.Update(ctx, bTime.Add(2*time.Hour)) require.NoError(t, err) - require.Equal(t, int64(3), h.Height) + require.Equal(t, uint64(3), h.Height) _, err = c.TrustedLightBlock(1) assert.Error(t, err) diff --git a/light/rpc/client_test.go b/light/rpc/client_test.go index f614f44d3..002d64edf 100644 --- a/light/rpc/client_test.go +++ b/light/rpc/client_test.go @@ -64,7 +64,7 @@ func TestABCIQuery(t *testing.T) { lc := &lcmock.LightClient{} appHash, _ := hex.DecodeString("5EFD44055350B5CC34DBD26085347A9DBBE44EA192B9286A9FC107F40EA1FAC5") - lc.On("VerifyLightBlockAtHeight", context.Background(), int64(2), mock.AnythingOfType("time.Time")).Return( + lc.On("VerifyLightBlockAtHeight", context.Background(), uint64(2), mock.AnythingOfType("time.Time")).Return( &types.LightBlock{ SignedHeader: &types.SignedHeader{ Header: &types.Header{AppHash: appHash}, diff --git a/light/store/db/db_test.go b/light/store/db/db_test.go index 7b68f1815..b6156fd67 100644 --- a/light/store/db/db_test.go +++ b/light/store/db/db_test.go @@ -23,11 +23,11 @@ func TestLast_FirstLightBlockHeight(t *testing.T) { // Empty store height, err := dbStore.LastLightBlockHeight() require.NoError(t, err) - assert.EqualValues(t, -1, height) + assert.EqualValues(t, 0, height) height, err = dbStore.FirstLightBlockHeight() require.NoError(t, err) - assert.EqualValues(t, -1, height) + assert.EqualValues(t, 0, height) // 1 key err = dbStore.SaveLightBlock(randLightBlock(uint64(1))) diff --git a/state/state_test.go b/state/state_test.go index 8bc25d4cb..2ff1f193f 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -926,7 +926,7 @@ func TestManyValidatorChangesSaveLoad(t *testing.T) { tearDown, stateDB, state := setupTestCase(t) defer tearDown(t) stateStore := sm.NewStore(stateDB) - require.Equal(t, int64(0), state.LastBlockHeight) + require.Equal(t, uint64(0), state.LastBlockHeight) state.Validators = genValSet(valSetSize) state.NextValidators = state.Validators.CopyIncrementProposerPriority(1) err := stateStore.Save(state) diff --git a/store/store_test.go b/store/store_test.go index ad762eefc..2f352efb3 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -96,8 +96,8 @@ func TestMain(m *testing.M) { func TestBlockStoreSaveLoadBlock(t *testing.T) { state, bs, cleanup := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer))) defer cleanup() - require.Equal(t, bs.Base(), int64(0), "initially the base should be zero") - require.Equal(t, bs.Height(), int64(0), "initially the height should be zero") + require.Equal(t, bs.Base(), uint64(0), "initially the base should be zero") + require.Equal(t, bs.Height(), uint64(0), "initially the height should be zero") // check there are no blocks at various heights noBlockHeights := []uint64{0, 100, 1000, 2} @@ -479,7 +479,7 @@ func TestLoadBlockMeta(t *testing.T) { func TestBlockFetchAtHeight(t *testing.T) { state, bs, cleanup := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer))) defer cleanup() - require.Equal(t, bs.Height(), int64(0), "initially the height should be zero") + require.Equal(t, bs.Height(), uint64(0), "initially the height should be zero") block := makeBlock(bs.Height()+1, state, new(types.Commit)) partSet := block.MakePartSet(2) diff --git a/types/block_test.go b/types/block_test.go index 3bbef311c..21b78a415 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -329,7 +329,7 @@ func TestHeaderHash(t *testing.T) { LastResultsHash: tmhash.Sum([]byte("last_results_hash")), EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: crypto.AddressHash([]byte("proposer_address")), - }, hexBytesFromString("F740121F553B5418C3EFBD343C2DBFE9E007BB67B0D020A0741374BAB65242A4")}, + }, hexBytesFromString("4DF6AC935DB1FF0C01F23BC4F4ACCC547E0DE90C0F19ED36320592ECC945B7B5")}, {"nil header yields nil", nil, nil}, {"nil ValidatorsHash yields nil", &Header{ Version: version.Consensus{Block: 1, App: 2}, @@ -366,7 +366,7 @@ func TestHeaderHash(t *testing.T) { s.Type().Field(i).Name) switch f := f.Interface().(type) { - case int64, bytes.HexBytes, string: + case uint64, bytes.HexBytes, string: byteSlices = append(byteSlices, cdcEncode(f)) case time.Time: bz, err := gogotypes.StdTimeMarshal(f) diff --git a/types/event_bus_test.go b/types/event_bus_test.go index a0a2e2e5f..0d3053eeb 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -43,7 +43,7 @@ func TestEventBusPublishEventTx(t *testing.T) { go func() { msg := <-txsSub.Out() edt := msg.Data().(EventDataTx) - assert.Equal(t, int64(1), edt.Height) + assert.Equal(t, uint64(1), edt.Height) assert.Equal(t, uint32(0), edt.Index) assert.EqualValues(t, tx, edt.Tx) assert.Equal(t, result, edt.Result) @@ -193,7 +193,7 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) { select { case msg := <-sub.Out(): data := msg.Data().(EventDataTx) - assert.Equal(t, int64(1), data.Height) + assert.Equal(t, uint64(1), data.Height) assert.Equal(t, uint32(0), data.Index) assert.EqualValues(t, tx, data.Tx) assert.Equal(t, result, data.Result) @@ -296,7 +296,7 @@ func TestEventBusPublishEventNewEvidence(t *testing.T) { msg := <-evSub.Out() edt := msg.Data().(EventDataNewEvidence) assert.Equal(t, ev, edt.Evidence) - assert.Equal(t, int64(4), edt.Height) + assert.Equal(t, uint64(4), edt.Height) close(done) }() diff --git a/types/evidence_test.go b/types/evidence_test.go index f3b74aa2c..ed7d2edd5 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -147,7 +147,7 @@ func TestLightClientAttackEvidence(t *testing.T) { CommonHeight: height - 2, } assert.NotEqual(t, lcae.Hash(), differentEv.Hash()) - assert.Equal(t, lcae.Height(), int64(4)) // Height should be the common Height + assert.Equal(t, lcae.Height(), uint64(4)) // Height should be the common Height assert.NotNil(t, lcae.Bytes()) }