Skip to content

Commit

Permalink
Use require library functions in more tests (ava-labs#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu committed May 1, 2023
1 parent ef6a2a2 commit 0d8c59e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 84 deletions.
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func TestGetSubnetConfigsFromFlags(t *testing.T) {
"entry with no config": {
givenJSON: `{"2Ctt6eGAeo4MLqTmGa7AdRecuVMPGWEX9wSsCLBYrLhX4a394i":{}}`,
testF: func(require *require.Assertions, given map[ids.ID]subnets.Config) {
require.True(len(given) == 1)
require.Len(given, 1)
id, _ := ids.FromString("2Ctt6eGAeo4MLqTmGa7AdRecuVMPGWEX9wSsCLBYrLhX4a394i")
config, ok := given[id]
require.True(ok)
Expand Down
40 changes: 20 additions & 20 deletions snow/engine/snowman/syncer/state_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestStateSyncLocalSummaryIsIncludedAmongFrontiersIfAvailable(t *testing.T)
require.NoError(syncer.Connected(context.Background(), vdr.NodeID, version.CurrentApp))
}

require.True(syncer.locallyAvailableSummary == localSummary)
require.Equal(localSummary, syncer.locallyAvailableSummary)
ws, ok := syncer.weightedSummaries[summaryID]
require.True(ok)
require.True(bytes.Equal(ws.summary.Bytes(), summaryBytes))
Expand Down Expand Up @@ -251,14 +251,14 @@ func TestBeaconsAreReachedForFrontiersUponStartup(t *testing.T) {
}

// check that vdrs are reached out for frontiers
require.True(len(contactedFrontiersProviders) == safeMath.Min(vdrs.Len(), common.MaxOutstandingBroadcastRequests))
require.Len(contactedFrontiersProviders, safeMath.Min(vdrs.Len(), common.MaxOutstandingBroadcastRequests))
for beaconID := range contactedFrontiersProviders {
// check that beacon is duly marked as reached out
require.True(syncer.pendingSeeders.Contains(beaconID))
}

// check that, obviously, no summary is yet registered
require.True(len(syncer.weightedSummaries) == 0)
require.Empty(syncer.weightedSummaries)
}

func TestUnRequestedStateSummaryFrontiersAreDropped(t *testing.T) {
Expand Down Expand Up @@ -319,8 +319,8 @@ func TestUnRequestedStateSummaryFrontiersAreDropped(t *testing.T) {
math.MaxInt32,
summaryBytes,
))
require.True(syncer.pendingSeeders.Contains(responsiveBeaconID)) // responsiveBeacon still pending
require.True(len(syncer.weightedSummaries) == 0)
require.Contains(syncer.pendingSeeders, responsiveBeaconID) // responsiveBeacon still pending
require.Empty(syncer.weightedSummaries)

// check a response from unsolicited node is dropped
unsolicitedNodeID := ids.GenerateTestNodeID()
Expand All @@ -330,7 +330,7 @@ func TestUnRequestedStateSummaryFrontiersAreDropped(t *testing.T) {
responsiveBeaconReqID,
summaryBytes,
))
require.True(len(syncer.weightedSummaries) == 0)
require.Empty(syncer.weightedSummaries)

// check a valid response is duly recorded
require.NoError(syncer.StateSummaryFrontier(
Expand All @@ -341,7 +341,7 @@ func TestUnRequestedStateSummaryFrontiersAreDropped(t *testing.T) {
))

// responsiveBeacon not pending anymore
require.False(syncer.pendingSeeders.Contains(responsiveBeaconID))
require.NotContains(syncer.pendingSeeders, responsiveBeaconID)

// valid summary is recorded
ws, ok := syncer.weightedSummaries[summaryID]
Expand Down Expand Up @@ -413,11 +413,11 @@ func TestMalformedStateSummaryFrontiersAreDropped(t *testing.T) {
))

// responsiveBeacon not pending anymore
require.False(syncer.pendingSeeders.Contains(responsiveBeaconID))
require.NotContains(syncer.pendingSeeders, responsiveBeaconID)

// invalid summary is not recorded
require.True(isSummaryDecoded)
require.True(len(syncer.weightedSummaries) == 0)
require.Empty(syncer.weightedSummaries)

// even in case of invalid summaries, other listed vdrs
// are reached for data
Expand Down Expand Up @@ -481,8 +481,8 @@ func TestLateResponsesFromUnresponsiveFrontiersAreNotRecorded(t *testing.T) {
))

// unresponsiveBeacon not pending anymore
require.False(syncer.pendingSeeders.Contains(unresponsiveBeaconID))
require.True(syncer.failedSeeders.Contains(unresponsiveBeaconID))
require.NotContains(syncer.pendingSeeders, unresponsiveBeaconID)
require.Contains(syncer.failedSeeders, unresponsiveBeaconID)

// even in case of timeouts, other listed vdrs
// are reached for data
Expand All @@ -509,7 +509,7 @@ func TestLateResponsesFromUnresponsiveFrontiersAreNotRecorded(t *testing.T) {
))

// late summary is not recorded
require.True(len(syncer.weightedSummaries) == 0)
require.Empty(syncer.weightedSummaries)
}

func TestStateSyncIsRestartedIfTooManyFrontierSeedersTimeout(t *testing.T) {
Expand Down Expand Up @@ -600,10 +600,10 @@ func TestStateSyncIsRestartedIfTooManyFrontierSeedersTimeout(t *testing.T) {
}

// check that some frontier seeders are reached again for the frontier
require.True(syncer.pendingSeeders.Len() > 0)
require.NotEmpty(syncer.pendingSeeders)

// check that no vote requests are issued
require.True(len(contactedVoters) == 0)
require.Empty(contactedVoters)
}

func TestVoteRequestsAreSentAsAllFrontierBeaconsResponded(t *testing.T) {
Expand Down Expand Up @@ -768,8 +768,8 @@ func TestUnRequestedVotesAreDropped(t *testing.T) {
))

// responsiveVoter still pending
require.True(syncer.pendingVoters.Contains(responsiveVoterID))
require.True(syncer.weightedSummaries[summaryID].weight == 0)
require.Contains(syncer.pendingVoters, responsiveVoterID)
require.Zero(syncer.weightedSummaries[summaryID].weight)

// check a response from unsolicited node is dropped
unsolicitedVoterID := ids.GenerateTestNodeID()
Expand All @@ -779,7 +779,7 @@ func TestUnRequestedVotesAreDropped(t *testing.T) {
responsiveVoterReqID,
[]ids.ID{summaryID},
))
require.True(syncer.weightedSummaries[summaryID].weight == 0)
require.Zero(syncer.weightedSummaries[summaryID].weight)

// check a valid response is duly recorded
require.NoError(syncer.AcceptedStateSummary(
Expand All @@ -790,7 +790,7 @@ func TestUnRequestedVotesAreDropped(t *testing.T) {
))

// responsiveBeacon not pending anymore
require.False(syncer.pendingSeeders.Contains(responsiveVoterID))
require.NotContains(syncer.pendingSeeders, responsiveVoterID)
voterWeight := vdrs.GetWeight(responsiveVoterID)
require.Equal(voterWeight, syncer.weightedSummaries[summaryID].weight)

Expand Down Expand Up @@ -890,14 +890,14 @@ func TestVotesForUnknownSummariesAreDropped(t *testing.T) {
require.False(found)

// check that responsiveVoter cannot cast another vote
require.False(syncer.pendingSeeders.Contains(responsiveVoterID))
require.NotContains(syncer.pendingSeeders, responsiveVoterID)
require.NoError(syncer.AcceptedStateSummary(
context.Background(),
responsiveVoterID,
responsiveVoterReqID,
[]ids.ID{summaryID},
))
require.True(syncer.weightedSummaries[summaryID].weight == 0)
require.Zero(syncer.weightedSummaries[summaryID].weight)

// other listed voters are reached out, even in the face of vote
// on unknown summary
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/blocks/builder/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ func TestMempoolNewLocaTxIsGossiped(t *testing.T) {
err = env.Builder.Add(tx)
require.NoError(err)

require.True(gossipedBytes == nil)
require.Nil(gossipedBytes)
}
6 changes: 3 additions & 3 deletions vms/proposervm/indexer/height_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestHeightBlockIndexPostFork(t *testing.T) {
// check that height index is fully built
loadedForkHeight, err := storedState.GetForkHeight()
require.NoError(err)
require.True(loadedForkHeight == 1)
require.Equal(uint64(1), loadedForkHeight)
for height := uint64(1); height <= blkNumber; height++ {
_, err := storedState.GetBlockIDAtHeight(height)
require.NoError(err)
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestHeightBlockIndexAcrossFork(t *testing.T) {
// check that height index is fully built
loadedForkHeight, err := storedState.GetForkHeight()
require.NoError(err)
require.True(loadedForkHeight == forkHeight)
require.Equal(forkHeight, loadedForkHeight)
for height := uint64(0); height < forkHeight; height++ {
_, err := storedState.GetBlockIDAtHeight(height)
require.ErrorIs(err, database.ErrNotFound)
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestHeightBlockIndexResumeFromCheckPoint(t *testing.T) {
// check that height index is fully built
loadedForkHeight, err := storedState.GetForkHeight()
require.NoError(err)
require.True(loadedForkHeight == forkHeight)
require.Equal(forkHeight, loadedForkHeight)
for height := forkHeight; height <= checkpointBlk.Height(); height++ {
_, err := storedState.GetBlockIDAtHeight(height)
require.NoError(err)
Expand Down

0 comments on commit 0d8c59e

Please sign in to comment.