This commit is contained in:
Marko Baricevic
2021-02-10 10:36:52 +01:00
parent c1696abb77
commit a9c44116de
13 changed files with 38 additions and 38 deletions
+2 -2
View File
@@ -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
}
+5 -5
View File
@@ -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",
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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}},
)
+13 -13
View File
@@ -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)
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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},
+2 -2
View File
@@ -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)))
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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)
+2 -2
View File
@@ -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)
+3 -3
View File
@@ -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)
}()
+1 -1
View File
@@ -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())
}