From c125bc185fc7c6ddec3793a83627ab3e0969d5a3 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Wed, 3 May 2023 12:59:03 -0400 Subject: [PATCH] Ban `require.EqualValues` (#1457) --- .golangci.yml | 1 + api/admin/client_test.go | 5 +- indexer/client_test.go | 18 ++-- indexer/index_test.go | 14 +-- indexer/indexer_test.go | 28 +++--- network/network_test.go | 2 +- network/peer/ip_signer_test.go | 14 +-- .../throttling/bandwidth_throttler_test.go | 4 +- .../inbound_msg_buffer_throttler_test.go | 10 +- .../inbound_msg_byte_throttler_test.go | 98 +++++++++---------- .../inbound_resource_throttler_test.go | 8 +- .../throttling/outbound_msg_throttler_test.go | 74 +++++++------- node/beacon_manager_test.go | 2 +- snow/consensus/snowman/consensus_test.go | 8 +- snow/engine/common/queue/jobs_test.go | 6 +- snow/engine/common/tracker/peers_test.go | 6 +- snow/networking/handler/message_queue_test.go | 58 +++++------ snow/networking/router/chain_router_test.go | 6 +- snow/uptime/locked_calculator_test.go | 2 +- .../gvalidators/validator_state_test.go | 2 +- snow/validators/manager_test.go | 12 +-- snow/validators/set_test.go | 32 +++--- utils/compression/compressor_test.go | 26 ++--- utils/compression/no_compressor_test.go | 10 +- utils/linkedhashmap/linkedhashmap_test.go | 26 ++--- utils/set/set_test.go | 20 ++-- vms/avm/index_test.go | 6 +- vms/components/avax/utxo_fetching_test.go | 2 +- vms/platformvm/blocks/builder/builder_test.go | 2 +- .../blocks/executor/standard_block_test.go | 2 +- vms/platformvm/service_test.go | 22 ++--- .../txs/executor/advance_time_test.go | 2 +- vms/platformvm/vm_regression_test.go | 10 +- vms/platformvm/vm_test.go | 6 +- vms/proposervm/batched_vm_test.go | 32 +++--- vms/proposervm/proposer/windower_test.go | 14 +-- vms/proposervm/vm_test.go | 2 +- 37 files changed, 298 insertions(+), 294 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fa13accfb72..85dcbf77638 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -67,6 +67,7 @@ linters-settings: forbid: - 'require\.Error$(# ErrorIs should be used instead)?' - 'require\.ErrorContains$(# ErrorIs should be used instead)?' + - 'require\.EqualValues$(# Equal should be used instead)?' exclude_godoc_examples: false # https://golangci-lint.run/usage/linters#gosec gosec: diff --git a/api/admin/client_test.go b/api/admin/client_test.go index b357965b262..d5857436c88 100644 --- a/api/admin/client_test.go +++ b/api/admin/client_test.go @@ -337,9 +337,10 @@ func TestGetLoggerLevel(t *testing.T) { tt.loggerName, ) require.ErrorIs(err, tt.clientErr) - if tt.clientErr == nil { - require.EqualValues(tt.serviceResponse, res) + if tt.clientErr != nil { + return } + require.Equal(tt.serviceResponse, res) }) } } diff --git a/indexer/client_test.go b/indexer/client_test.go index 4fb34cf955e..004c8eeb283 100644 --- a/indexer/client_test.go +++ b/indexer/client_test.go @@ -42,7 +42,7 @@ func TestIndexClient(t *testing.T) { } index, err := client.GetIndex(context.Background(), ids.Empty) require.NoError(err) - require.EqualValues(5, index) + require.Equal(uint64(5), index) } { // Test GetLastAccepted @@ -64,9 +64,9 @@ func TestIndexClient(t *testing.T) { } container, index, err := client.GetLastAccepted(context.Background()) require.NoError(err) - require.EqualValues(id, container.ID) - require.EqualValues(bytes, container.Bytes) - require.EqualValues(index, 10) + require.Equal(id, container.ID) + require.Equal(bytes, container.Bytes) + require.Equal(uint64(10), index) } { // Test GetContainerRange @@ -88,8 +88,8 @@ func TestIndexClient(t *testing.T) { containers, err := client.GetContainerRange(context.Background(), 1, 10) require.NoError(err) require.Len(containers, 1) - require.EqualValues(id, containers[0].ID) - require.EqualValues(bytes, containers[0].Bytes) + require.Equal(id, containers[0].ID) + require.Equal(bytes, containers[0].Bytes) } { // Test IsAccepted @@ -125,8 +125,8 @@ func TestIndexClient(t *testing.T) { } container, index, err := client.GetContainerByID(context.Background(), id) require.NoError(err) - require.EqualValues(id, container.ID) - require.EqualValues(bytes, container.Bytes) - require.EqualValues(index, 10) + require.Equal(id, container.ID) + require.Equal(bytes, container.Bytes) + require.Equal(uint64(10), index) } } diff --git a/indexer/index_test.go b/indexer/index_test.go index 1572fb8837f..9a25bebcc8e 100644 --- a/indexer/index_test.go +++ b/indexer/index_test.go @@ -49,8 +49,8 @@ func TestIndex(t *testing.T) { lastAcceptedIndex, ok := idx.lastAcceptedIndex() require.True(ok) - require.EqualValues(i, lastAcceptedIndex) - require.EqualValues(i+1, idx.nextAcceptedIndex) + require.Equal(i, lastAcceptedIndex) + require.Equal(i+1, idx.nextAcceptedIndex) gotContainer, err := idx.GetContainerByID(containerID) require.NoError(err) @@ -58,7 +58,7 @@ func TestIndex(t *testing.T) { gotIndex, err := idx.GetIndex(containerID) require.NoError(err) - require.EqualValues(i, gotIndex) + require.Equal(i, gotIndex) gotContainer, err = idx.GetContainerByIndex(i) require.NoError(err) @@ -104,7 +104,7 @@ func TestIndex(t *testing.T) { for _, container := range containersList { require.False(sawContainers.Contains(container.ID)) // Should only see this container once require.Contains(containers, container.ID) - require.EqualValues(containers[container.ID], container.Bytes) + require.Equal(containers[container.ID], container.Bytes) // Timestamps should be non-decreasing require.True(container.Timestamp >= lastTimestamp) lastTimestamp = container.Timestamp @@ -150,8 +150,8 @@ func TestIndexGetContainerByRangeMaxPageSize(t *testing.T) { containers, err = idx.GetContainerRange(MaxFetchedByRange-1, MaxFetchedByRange) require.NoError(err) require.Len(containers, 2) - require.EqualValues(containers[1], containers2[MaxFetchedByRange-1]) - require.EqualValues(containers[0], containers2[MaxFetchedByRange-2]) + require.Equal(containers[1], containers2[MaxFetchedByRange-1]) + require.Equal(containers[0], containers2[MaxFetchedByRange-2]) } func TestDontIndexSameContainerTwice(t *testing.T) { @@ -173,5 +173,5 @@ func TestDontIndexSameContainerTwice(t *testing.T) { require.ErrorIs(err, errNoContainerAtIndex) gotContainer, err := idx.GetContainerByID(containerID) require.NoError(err) - require.EqualValues(gotContainer.Bytes, []byte{1, 2, 3}, "should not have accepted same container twice") + require.Equal([]byte{1, 2, 3}, gotContainer.Bytes) } diff --git a/indexer/indexer_test.go b/indexer/indexer_test.go index 79af29fb90c..6ad1784046f 100644 --- a/indexer/indexer_test.go +++ b/indexer/indexer_test.go @@ -174,9 +174,9 @@ func TestIndexer(t *testing.T) { previouslyIndexed, err = idxr.previouslyIndexed(chain1Ctx.ChainID) require.NoError(err) require.True(previouslyIndexed) - require.EqualValues(1, server.timesCalled) - require.EqualValues("index/chain1", server.bases[0]) - require.EqualValues("/block", server.endpoints[0]) + require.Equal(1, server.timesCalled) + require.Equal("index/chain1", server.bases[0]) + require.Equal("/block", server.endpoints[0]) require.Len(idxr.blockIndices, 1) require.Len(idxr.txIndices, 0) require.Len(idxr.vtxIndices, 0) @@ -207,7 +207,7 @@ func TestIndexer(t *testing.T) { // Verify GetIndex is right index, err := blkIdx.GetIndex(blkID) require.NoError(err) - require.EqualValues(0, index) + require.Zero(index) // Verify GetContainerByIndex is right container, err = blkIdx.GetContainerByIndex(0) @@ -257,7 +257,7 @@ func TestIndexer(t *testing.T) { container, err = blkIdx.GetLastAccepted() require.NoError(err) require.Equal(blkID, container.ID) - require.EqualValues(1, server.timesCalled) // block index for chain + require.Equal(1, server.timesCalled) // block index for chain require.Contains(server.endpoints, "/block") // Register a DAG chain @@ -272,7 +272,7 @@ func TestIndexer(t *testing.T) { dagVM := vertex.NewMockLinearizableVM(ctrl) idxr.RegisterChain("chain2", chain2Ctx, dagVM) require.NoError(err) - require.EqualValues(4, server.timesCalled) // block index for chain, block index for dag, vtx index, tx index + require.Equal(4, server.timesCalled) // block index for chain, block index for dag, vtx index, tx index require.Contains(server.bases, "index/chain2") require.Contains(server.endpoints, "/block") require.Contains(server.endpoints, "/vtx") @@ -307,7 +307,7 @@ func TestIndexer(t *testing.T) { // Verify GetIndex is right index, err = vtxIdx.GetIndex(vtxID) require.NoError(err) - require.EqualValues(0, index) + require.Zero(index) // Verify GetContainerByIndex is right vtx, err = vtxIdx.GetContainerByIndex(0) @@ -356,7 +356,7 @@ func TestIndexer(t *testing.T) { // Verify GetIndex is right index, err = txIdx.GetIndex(txID) require.NoError(err) - require.EqualValues(0, index) + require.Zero(index) // Verify GetContainerByIndex is right tx, err = txIdx.GetContainerByIndex(0) @@ -373,13 +373,13 @@ func TestIndexer(t *testing.T) { // happen on the block/tx index. Similar for tx. lastAcceptedTx, err := txIdx.GetLastAccepted() require.NoError(err) - require.EqualValues(txID, lastAcceptedTx.ID) + require.Equal(txID, lastAcceptedTx.ID) lastAcceptedVtx, err := vtxIdx.GetLastAccepted() require.NoError(err) - require.EqualValues(vtxID, lastAcceptedVtx.ID) + require.Equal(vtxID, lastAcceptedVtx.ID) lastAcceptedBlk, err := blkIdx.GetLastAccepted() require.NoError(err) - require.EqualValues(blkID, lastAcceptedBlk.ID) + require.Equal(blkID, lastAcceptedBlk.ID) // Close the indexer again require.NoError(config.DB.(*versiondb.Database).Commit()) @@ -397,13 +397,13 @@ func TestIndexer(t *testing.T) { // Verify state lastAcceptedTx, err = idxr.txIndices[chain2Ctx.ChainID].GetLastAccepted() require.NoError(err) - require.EqualValues(txID, lastAcceptedTx.ID) + require.Equal(txID, lastAcceptedTx.ID) lastAcceptedVtx, err = idxr.vtxIndices[chain2Ctx.ChainID].GetLastAccepted() require.NoError(err) - require.EqualValues(vtxID, lastAcceptedVtx.ID) + require.Equal(vtxID, lastAcceptedVtx.ID) lastAcceptedBlk, err = idxr.blockIndices[chain1Ctx.ChainID].GetLastAccepted() require.NoError(err) - require.EqualValues(blkID, lastAcceptedBlk.ID) + require.Equal(blkID, lastAcceptedBlk.ID) } // Make sure the indexer doesn't allow incomplete indices unless explicitly allowed diff --git a/network/network_test.go b/network/network_test.go index a09ab9af693..0afab859d80 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -341,7 +341,7 @@ func TestSend(t *testing.T) { toSend := set.Set[ids.NodeID]{} toSend.Add(nodeIDs[1]) sentTo := net0.Send(outboundGetMsg, toSend, constants.PrimaryNetworkID, subnets.NoOpAllower) - require.EqualValues(toSend, sentTo) + require.Equal(toSend, sentTo) inboundGetMsg := <-received require.Equal(message.GetOp, inboundGetMsg.Op()) diff --git a/network/peer/ip_signer_test.go b/network/peer/ip_signer_test.go index 1633c7e63a7..6d7203a409b 100644 --- a/network/peer/ip_signer_test.go +++ b/network/peer/ip_signer_test.go @@ -34,22 +34,22 @@ func TestIPSigner(t *testing.T) { signedIP1, err := s.GetSignedIP() require.NoError(err) - require.EqualValues(dynIP.IPPort(), signedIP1.IPPort) - require.EqualValues(10, signedIP1.Timestamp) + require.Equal(dynIP.IPPort(), signedIP1.IPPort) + require.Equal(uint64(10), signedIP1.Timestamp) s.clock.Set(time.Unix(11, 0)) signedIP2, err := s.GetSignedIP() require.NoError(err) - require.EqualValues(dynIP.IPPort(), signedIP2.IPPort) - require.EqualValues(10, signedIP2.Timestamp) - require.EqualValues(signedIP1.Signature, signedIP2.Signature) + require.Equal(dynIP.IPPort(), signedIP2.IPPort) + require.Equal(uint64(10), signedIP2.Timestamp) + require.Equal(signedIP1.Signature, signedIP2.Signature) dynIP.SetIP(net.IPv4(1, 2, 3, 4)) signedIP3, err := s.GetSignedIP() require.NoError(err) - require.EqualValues(dynIP.IPPort(), signedIP3.IPPort) - require.EqualValues(11, signedIP3.Timestamp) + require.Equal(dynIP.IPPort(), signedIP3.IPPort) + require.Equal(uint64(11), signedIP3.Timestamp) require.NotEqualValues(signedIP2.Signature, signedIP3.Signature) } diff --git a/network/throttling/bandwidth_throttler_test.go b/network/throttling/bandwidth_throttler_test.go index 9b4b7eaf983..b4955959eed 100644 --- a/network/throttling/bandwidth_throttler_test.go +++ b/network/throttling/bandwidth_throttler_test.go @@ -29,8 +29,8 @@ func TestBandwidthThrottler(t *testing.T) { require.True(ok) require.NotNil(throttler.log) require.NotNil(throttler.limiters) - require.EqualValues(throttler.RefillRate, 8) - require.EqualValues(throttler.MaxBurstSize, 10) + require.Equal(config.RefillRate, throttler.RefillRate) + require.Equal(config.MaxBurstSize, throttler.MaxBurstSize) require.Len(throttler.limiters, 0) // Add a node diff --git a/network/throttling/inbound_msg_buffer_throttler_test.go b/network/throttling/inbound_msg_buffer_throttler_test.go index 329957cb778..e6c0c6c087c 100644 --- a/network/throttling/inbound_msg_buffer_throttler_test.go +++ b/network/throttling/inbound_msg_buffer_throttler_test.go @@ -27,15 +27,15 @@ func TestMsgBufferThrottler(t *testing.T) { throttler.Acquire(context.Background(), nodeID1) throttler.Acquire(context.Background(), nodeID1) require.Len(throttler.nodeToNumProcessingMsgs, 1) - require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID1]) + require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID1]) // Acquire shouldn't block for other node throttler.Acquire(context.Background(), nodeID2) throttler.Acquire(context.Background(), nodeID2) throttler.Acquire(context.Background(), nodeID2) require.Len(throttler.nodeToNumProcessingMsgs, 2) - require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID1]) - require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID2]) + require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID1]) + require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID2]) // Acquire should block for 4th acquire done := make(chan struct{}) @@ -53,7 +53,7 @@ func TestMsgBufferThrottler(t *testing.T) { // fourth acquire should be unblocked <-done require.Len(throttler.nodeToNumProcessingMsgs, 2) - require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID2]) + require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID2]) // Releasing from other node should have no effect throttler.release(nodeID2) @@ -80,7 +80,7 @@ func TestMsgBufferThrottlerContextCancelled(t *testing.T) { throttler.Acquire(vdr1Context, nodeID1) throttler.Acquire(vdr1Context, nodeID1) require.Len(throttler.nodeToNumProcessingMsgs, 1) - require.EqualValues(3, throttler.nodeToNumProcessingMsgs[nodeID1]) + require.Equal(uint64(3), throttler.nodeToNumProcessingMsgs[nodeID1]) // Acquire should block for 4th acquire done := make(chan struct{}) diff --git a/network/throttling/inbound_msg_byte_throttler_test.go b/network/throttling/inbound_msg_byte_throttler_test.go index 6565d0b6253..37f04214137 100644 --- a/network/throttling/inbound_msg_byte_throttler_test.go +++ b/network/throttling/inbound_msg_byte_throttler_test.go @@ -86,7 +86,7 @@ func TestInboundMsgByteThrottlerCancelContext(t *testing.T) { throttler.lock.Lock() require.Len(throttler.nodeToWaitingMsgID, 1) require.Contains(throttler.nodeToWaitingMsgID, vdr2ID) - require.EqualValues(1, throttler.waitingToAcquire.Len()) + require.Equal(1, throttler.waitingToAcquire.Len()) _, exists := throttler.waitingToAcquire.Get(throttler.nodeToWaitingMsgID[vdr2ID]) require.True(exists) throttler.lock.Unlock() @@ -137,16 +137,16 @@ func TestInboundMsgByteThrottler(t *testing.T) { // Take from at-large allocation. // Should return immediately. throttler.Acquire(context.Background(), 1, vdr1ID) - require.EqualValues(config.AtLargeAllocSize-1, throttler.remainingAtLargeBytes) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize-1, throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) require.Len(throttler.nodeToVdrBytesUsed, 0) require.Len(throttler.nodeToAtLargeBytesUsed, 1) - require.EqualValues(1, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(uint64(1), throttler.nodeToAtLargeBytesUsed[vdr1ID]) // Release the bytes throttler.release(&msgMetadata{msgSize: 1}, vdr1ID) - require.EqualValues(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) require.Len(throttler.nodeToVdrBytesUsed, 0) require.Len(throttler.nodeToAtLargeBytesUsed, 0) @@ -154,32 +154,32 @@ func TestInboundMsgByteThrottler(t *testing.T) { // Should return immediately. throttler.Acquire(context.Background(), config.AtLargeAllocSize+1, vdr1ID) // vdr1 at-large bytes used: 1024. Validator bytes used: 1 - require.EqualValues(0, throttler.remainingAtLargeBytes) - require.EqualValues(config.VdrAllocSize-1, throttler.remainingVdrBytes) - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr1ID], 1) + require.Zero(throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize-1, throttler.remainingVdrBytes) + require.Equal(uint64(1), throttler.nodeToVdrBytesUsed[vdr1ID]) require.Len(throttler.nodeToVdrBytesUsed, 1) require.Len(throttler.nodeToAtLargeBytesUsed, 1) - require.EqualValues(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) // The other validator should be able to acquire half the validator allocation. // Should return immediately. throttler.Acquire(context.Background(), config.AtLargeAllocSize/2, vdr2ID) // vdr2 at-large bytes used: 0. Validator bytes used: 512 - require.EqualValues(config.VdrAllocSize/2-1, throttler.remainingVdrBytes) - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr1ID], 1) - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr2ID], config.VdrAllocSize/2) + require.Equal(config.VdrAllocSize/2-1, throttler.remainingVdrBytes) + require.Equal(uint64(1), throttler.nodeToVdrBytesUsed[vdr1ID]) + require.Equal(config.VdrAllocSize/2, throttler.nodeToVdrBytesUsed[vdr2ID]) require.Len(throttler.nodeToVdrBytesUsed, 2) require.Len(throttler.nodeToAtLargeBytesUsed, 1) require.Len(throttler.nodeToWaitingMsgID, 0) - require.EqualValues(0, throttler.waitingToAcquire.Len()) + require.Zero(throttler.waitingToAcquire.Len()) // vdr1 should be able to acquire the rest of the validator allocation // Should return immediately. throttler.Acquire(context.Background(), config.VdrAllocSize/2-1, vdr1ID) // vdr1 at-large bytes used: 1024. Validator bytes used: 512 - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr1ID], config.VdrAllocSize/2) + require.Equal(config.VdrAllocSize/2, throttler.nodeToVdrBytesUsed[vdr1ID]) require.Len(throttler.nodeToAtLargeBytesUsed, 1) - require.EqualValues(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) // Trying to take more bytes for either node should block vdr1Done := make(chan struct{}) @@ -195,7 +195,7 @@ func TestInboundMsgByteThrottler(t *testing.T) { throttler.lock.Lock() require.Len(throttler.nodeToWaitingMsgID, 1) require.Contains(throttler.nodeToWaitingMsgID, vdr1ID) - require.EqualValues(1, throttler.waitingToAcquire.Len()) + require.Equal(1, throttler.waitingToAcquire.Len()) _, exists := throttler.waitingToAcquire.Get(throttler.nodeToWaitingMsgID[vdr1ID]) require.True(exists) throttler.lock.Unlock() @@ -214,7 +214,7 @@ func TestInboundMsgByteThrottler(t *testing.T) { require.Len(throttler.nodeToWaitingMsgID, 2) require.Contains(throttler.nodeToWaitingMsgID, vdr2ID) - require.EqualValues(2, throttler.waitingToAcquire.Len()) + require.Equal(2, throttler.waitingToAcquire.Len()) _, exists = throttler.waitingToAcquire.Get(throttler.nodeToWaitingMsgID[vdr2ID]) require.True(exists) throttler.lock.Unlock() @@ -233,7 +233,7 @@ func TestInboundMsgByteThrottler(t *testing.T) { throttler.lock.Lock() require.Len(throttler.nodeToWaitingMsgID, 3) require.Contains(throttler.nodeToWaitingMsgID, nonVdrID) - require.EqualValues(3, throttler.waitingToAcquire.Len()) + require.Equal(3, throttler.waitingToAcquire.Len()) _, exists = throttler.waitingToAcquire.Get(throttler.nodeToWaitingMsgID[nonVdrID]) require.True(exists) throttler.lock.Unlock() @@ -248,23 +248,23 @@ func TestInboundMsgByteThrottler(t *testing.T) { <-vdr2Done <-nonVdrDone - require.EqualValues(config.NodeMaxAtLargeBytes/2, throttler.remainingVdrBytes) + require.Equal(config.NodeMaxAtLargeBytes/2, throttler.remainingVdrBytes) require.Len(throttler.nodeToAtLargeBytesUsed, 3) // vdr1, vdr2, nonVdrID - require.EqualValues(config.AtLargeAllocSize/2, throttler.nodeToAtLargeBytesUsed[vdr1ID]) - require.EqualValues(1, throttler.nodeToAtLargeBytesUsed[vdr2ID]) - require.EqualValues(1, throttler.nodeToAtLargeBytesUsed[nonVdrID]) + require.Equal(config.AtLargeAllocSize/2, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(uint64(1), throttler.nodeToAtLargeBytesUsed[vdr2ID]) + require.Equal(uint64(1), throttler.nodeToAtLargeBytesUsed[nonVdrID]) require.Len(throttler.nodeToVdrBytesUsed, 1) - require.EqualValues(0, throttler.nodeToVdrBytesUsed[vdr1ID]) - require.EqualValues(config.AtLargeAllocSize/2-2, throttler.remainingAtLargeBytes) + require.Zero(throttler.nodeToVdrBytesUsed[vdr1ID]) + require.Equal(config.AtLargeAllocSize/2-2, throttler.remainingAtLargeBytes) require.Len(throttler.nodeToWaitingMsgID, 0) - require.EqualValues(0, throttler.waitingToAcquire.Len()) + require.Zero(throttler.waitingToAcquire.Len()) // Non-validator should be able to take the rest of the at-large bytes throttler.Acquire(context.Background(), config.AtLargeAllocSize/2-2, nonVdrID) - require.EqualValues(0, throttler.remainingAtLargeBytes) - require.EqualValues(config.AtLargeAllocSize/2-1, throttler.nodeToAtLargeBytesUsed[nonVdrID]) + require.Zero(throttler.remainingAtLargeBytes) + require.Equal(config.AtLargeAllocSize/2-1, throttler.nodeToAtLargeBytesUsed[nonVdrID]) require.Len(throttler.nodeToWaitingMsgID, 0) - require.EqualValues(0, throttler.waitingToAcquire.Len()) + require.Zero(throttler.waitingToAcquire.Len()) // But should block on subsequent Acquires go func() { @@ -279,7 +279,7 @@ func TestInboundMsgByteThrottler(t *testing.T) { throttler.lock.Lock() require.Contains(throttler.nodeToWaitingMsgID, nonVdrID) require.Contains(throttler.nodeToWaitingMsgID, nonVdrID) - require.EqualValues(1, throttler.waitingToAcquire.Len()) + require.Equal(1, throttler.waitingToAcquire.Len()) _, exists = throttler.waitingToAcquire.Get(throttler.nodeToWaitingMsgID[nonVdrID]) require.True(exists) throttler.lock.Unlock() @@ -290,34 +290,34 @@ func TestInboundMsgByteThrottler(t *testing.T) { <-nonVdrDone - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[vdr2ID]) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Zero(throttler.nodeToAtLargeBytesUsed[vdr2ID]) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) require.Len(throttler.nodeToVdrBytesUsed, 0) - require.EqualValues(0, throttler.remainingAtLargeBytes) + require.Zero(throttler.remainingAtLargeBytes) require.NotContains(throttler.nodeToWaitingMsgID, nonVdrID) - require.EqualValues(0, throttler.waitingToAcquire.Len()) + require.Zero(throttler.waitingToAcquire.Len()) // Release all of vdr1's messages throttler.release(&msgMetadata{msgSize: 1}, vdr1ID) throttler.release(&msgMetadata{msgSize: config.AtLargeAllocSize/2 - 1}, vdr1ID) require.Len(throttler.nodeToVdrBytesUsed, 0) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) - require.EqualValues(config.AtLargeAllocSize/2, throttler.remainingAtLargeBytes) - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize/2, throttler.remainingAtLargeBytes) + require.Zero(throttler.nodeToAtLargeBytesUsed[vdr1ID]) require.NotContains(throttler.nodeToWaitingMsgID, nonVdrID) - require.EqualValues(0, throttler.waitingToAcquire.Len()) + require.Zero(throttler.waitingToAcquire.Len()) // Release nonVdr's messages throttler.release(&msgMetadata{msgSize: 1}, nonVdrID) throttler.release(&msgMetadata{msgSize: 1}, nonVdrID) throttler.release(&msgMetadata{msgSize: config.AtLargeAllocSize/2 - 2}, nonVdrID) require.Len(throttler.nodeToVdrBytesUsed, 0) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) - require.EqualValues(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) require.Len(throttler.nodeToAtLargeBytesUsed, 0) - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[nonVdrID]) + require.Zero(throttler.nodeToAtLargeBytesUsed[nonVdrID]) require.NotContains(throttler.nodeToWaitingMsgID, nonVdrID) - require.EqualValues(0, throttler.waitingToAcquire.Len()) + require.Zero(throttler.waitingToAcquire.Len()) } // Ensure that the limit on taking from the at-large allocation is enforced @@ -360,11 +360,11 @@ func TestSybilMsgThrottlerMaxNonVdr(t *testing.T) { // Validator should only be able to take [MaxAtLargeBytes] throttler.Acquire(context.Background(), config.NodeMaxAtLargeBytes+1, vdr1ID) - require.EqualValues(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[vdr1ID]) - require.EqualValues(1, throttler.nodeToVdrBytesUsed[vdr1ID]) - require.EqualValues(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID1]) - require.EqualValues(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID2]) - require.EqualValues(config.AtLargeAllocSize-config.NodeMaxAtLargeBytes*3, throttler.remainingAtLargeBytes) + require.Equal(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(uint64(1), throttler.nodeToVdrBytesUsed[vdr1ID]) + require.Equal(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID1]) + require.Equal(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID2]) + require.Equal(config.AtLargeAllocSize-config.NodeMaxAtLargeBytes*3, throttler.remainingAtLargeBytes) } // Test that messages waiting to be acquired by a given node execute next @@ -423,12 +423,12 @@ func TestMsgThrottlerNextMsg(t *testing.T) { // Release 1 byte throttler.release(&msgMetadata{msgSize: 1}, vdr1ID) // Byte should have gone toward next validator message - require.EqualValues(2, throttler.waitingToAcquire.Len()) + require.Equal(2, throttler.waitingToAcquire.Len()) require.Contains(throttler.nodeToWaitingMsgID, vdr1ID) firstMsgID := throttler.nodeToWaitingMsgID[vdr1ID] firstMsg, exists := throttler.waitingToAcquire.Get(firstMsgID) require.True(exists) - require.EqualValues(maxBytes-2, firstMsg.bytesNeeded) + require.Equal(maxBytes-2, firstMsg.bytesNeeded) select { case <-doneVdr: diff --git a/network/throttling/inbound_resource_throttler_test.go b/network/throttling/inbound_resource_throttler_test.go index 266dd070dbc..70bd4404e78 100644 --- a/network/throttling/inbound_resource_throttler_test.go +++ b/network/throttling/inbound_resource_throttler_test.go @@ -42,10 +42,10 @@ func TestNewSystemThrottler(t *testing.T) { require.NoError(err) throttler, ok := throttlerIntf.(*systemThrottler) require.True(ok) - require.EqualValues(clock, config.Clock) - require.EqualValues(time.Second, config.MaxRecheckDelay) - require.EqualValues(cpuTracker, throttler.tracker) - require.EqualValues(targeter, throttler.targeter) + require.Equal(clock, config.Clock) + require.Equal(time.Second, config.MaxRecheckDelay) + require.Equal(cpuTracker, throttler.tracker) + require.Equal(targeter, throttler.targeter) } func TestSystemThrottler(t *testing.T) { diff --git a/network/throttling/outbound_msg_throttler_test.go b/network/throttling/outbound_msg_throttler_test.go index f260558d8a1..207041cad1b 100644 --- a/network/throttling/outbound_msg_throttler_test.go +++ b/network/throttling/outbound_msg_throttler_test.go @@ -55,16 +55,16 @@ func TestSybilOutboundMsgThrottler(t *testing.T) { msg := testMsgWithSize(ctrl, 1) acquired := throttlerIntf.Acquire(msg, vdr1ID) require.True(acquired) - require.EqualValues(config.AtLargeAllocSize-1, throttler.remainingAtLargeBytes) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize-1, throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) require.Len(throttler.nodeToVdrBytesUsed, 0) require.Len(throttler.nodeToAtLargeBytesUsed, 1) - require.EqualValues(1, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(uint64(1), throttler.nodeToAtLargeBytesUsed[vdr1ID]) // Release the bytes throttlerIntf.Release(msg, vdr1ID) - require.EqualValues(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) require.Len(throttler.nodeToVdrBytesUsed, 0) require.Len(throttler.nodeToAtLargeBytesUsed, 0) @@ -73,21 +73,21 @@ func TestSybilOutboundMsgThrottler(t *testing.T) { acquired = throttlerIntf.Acquire(msg, vdr1ID) require.True(acquired) // vdr1 at-large bytes used: 1024. Validator bytes used: 1 - require.EqualValues(0, throttler.remainingAtLargeBytes) - require.EqualValues(config.VdrAllocSize-1, throttler.remainingVdrBytes) - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr1ID], 1) + require.Zero(throttler.remainingAtLargeBytes) + require.Equal(throttler.remainingVdrBytes, config.VdrAllocSize-1) + require.Equal(uint64(1), throttler.nodeToVdrBytesUsed[vdr1ID]) require.Len(throttler.nodeToVdrBytesUsed, 1) require.Len(throttler.nodeToAtLargeBytesUsed, 1) - require.EqualValues(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) // The other validator should be able to acquire half the validator allocation. msg = testMsgWithSize(ctrl, config.AtLargeAllocSize/2) acquired = throttlerIntf.Acquire(msg, vdr2ID) require.True(acquired) // vdr2 at-large bytes used: 0. Validator bytes used: 512 - require.EqualValues(config.VdrAllocSize/2-1, throttler.remainingVdrBytes) - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr1ID], 1) - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr2ID], config.VdrAllocSize/2) + require.Equal(throttler.remainingVdrBytes, config.VdrAllocSize/2-1) + require.Equal(uint64(1), throttler.nodeToVdrBytesUsed[vdr1ID], 1) + require.Equal(config.VdrAllocSize/2, throttler.nodeToVdrBytesUsed[vdr2ID]) require.Len(throttler.nodeToVdrBytesUsed, 2) require.Len(throttler.nodeToAtLargeBytesUsed, 1) @@ -96,9 +96,9 @@ func TestSybilOutboundMsgThrottler(t *testing.T) { acquired = throttlerIntf.Acquire(msg, vdr1ID) require.True(acquired) // vdr1 at-large bytes used: 1024. Validator bytes used: 512 - require.EqualValues(throttler.nodeToVdrBytesUsed[vdr1ID], config.VdrAllocSize/2) + require.Equal(throttler.nodeToVdrBytesUsed[vdr1ID], config.VdrAllocSize/2) require.Len(throttler.nodeToAtLargeBytesUsed, 1) - require.EqualValues(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.AtLargeAllocSize, throttler.nodeToAtLargeBytesUsed[vdr1ID]) // Trying to take more bytes for either node should fail msg = testMsgWithSize(ctrl, 1) @@ -117,11 +117,11 @@ func TestSybilOutboundMsgThrottler(t *testing.T) { msg = testMsgWithSize(ctrl, config.AtLargeAllocSize+1) throttlerIntf.Release(msg, vdr1ID) - require.EqualValues(config.NodeMaxAtLargeBytes/2, throttler.remainingVdrBytes) + require.Equal(config.NodeMaxAtLargeBytes/2, throttler.remainingVdrBytes) require.Len(throttler.nodeToAtLargeBytesUsed, 1) // vdr1 - require.EqualValues(config.AtLargeAllocSize/2-1, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.AtLargeAllocSize/2-1, throttler.nodeToAtLargeBytesUsed[vdr1ID]) require.Len(throttler.nodeToVdrBytesUsed, 1) - require.EqualValues(config.AtLargeAllocSize/2+1, throttler.remainingAtLargeBytes) + require.Equal(config.AtLargeAllocSize/2+1, throttler.remainingAtLargeBytes) // Non-validator should be able to take the rest of the at-large bytes // nonVdrID at-large bytes used: 513 @@ -129,8 +129,8 @@ func TestSybilOutboundMsgThrottler(t *testing.T) { msg = testMsgWithSize(ctrl, config.AtLargeAllocSize/2+1) acquired = throttlerIntf.Acquire(msg, nonVdrID) require.True(acquired) - require.EqualValues(0, throttler.remainingAtLargeBytes) - require.EqualValues(config.AtLargeAllocSize/2+1, throttler.nodeToAtLargeBytesUsed[nonVdrID]) + require.Zero(throttler.remainingAtLargeBytes) + require.Equal(config.AtLargeAllocSize/2+1, throttler.nodeToAtLargeBytesUsed[nonVdrID]) // Non-validator shouldn't be able to acquire more since at-large allocation empty msg = testMsgWithSize(ctrl, 1) @@ -140,27 +140,27 @@ func TestSybilOutboundMsgThrottler(t *testing.T) { // Release all of vdr2's messages msg = testMsgWithSize(ctrl, config.AtLargeAllocSize/2) throttlerIntf.Release(msg, vdr2ID) - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[vdr2ID]) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Zero(throttler.nodeToAtLargeBytesUsed[vdr2ID]) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) require.Len(throttler.nodeToVdrBytesUsed, 0) - require.EqualValues(0, throttler.remainingAtLargeBytes) + require.Zero(throttler.remainingAtLargeBytes) // Release all of vdr1's messages msg = testMsgWithSize(ctrl, config.VdrAllocSize/2-1) throttlerIntf.Release(msg, vdr1ID) require.Len(throttler.nodeToVdrBytesUsed, 0) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) - require.EqualValues(config.AtLargeAllocSize/2-1, throttler.remainingAtLargeBytes) - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize/2-1, throttler.remainingAtLargeBytes) + require.Zero(throttler.nodeToAtLargeBytesUsed[vdr1ID]) // Release nonVdr's messages msg = testMsgWithSize(ctrl, config.AtLargeAllocSize/2+1) throttlerIntf.Release(msg, nonVdrID) require.Len(throttler.nodeToVdrBytesUsed, 0) - require.EqualValues(config.VdrAllocSize, throttler.remainingVdrBytes) - require.EqualValues(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) + require.Equal(config.VdrAllocSize, throttler.remainingVdrBytes) + require.Equal(config.AtLargeAllocSize, throttler.remainingAtLargeBytes) require.Len(throttler.nodeToAtLargeBytesUsed, 0) - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[nonVdrID]) + require.Zero(throttler.nodeToAtLargeBytesUsed[nonVdrID]) } // Ensure that the limit on taking from the at-large allocation is enforced @@ -205,11 +205,11 @@ func TestSybilOutboundMsgThrottlerMaxNonVdr(t *testing.T) { // Validator should only be able to take [MaxAtLargeBytes] msg = testMsgWithSize(ctrl, config.NodeMaxAtLargeBytes+1) throttlerIntf.Acquire(msg, vdr1ID) - require.EqualValues(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[vdr1ID]) - require.EqualValues(1, throttler.nodeToVdrBytesUsed[vdr1ID]) - require.EqualValues(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID1]) - require.EqualValues(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID2]) - require.EqualValues(config.AtLargeAllocSize-config.NodeMaxAtLargeBytes*3, throttler.remainingAtLargeBytes) + require.Equal(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Equal(uint64(1), throttler.nodeToVdrBytesUsed[vdr1ID]) + require.Equal(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID1]) + require.Equal(config.NodeMaxAtLargeBytes, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID2]) + require.Equal(config.AtLargeAllocSize-config.NodeMaxAtLargeBytes*3, throttler.remainingAtLargeBytes) } // Ensure that the throttler honors requested bypasses @@ -262,10 +262,10 @@ func TestBypassThrottling(t *testing.T) { msg.EXPECT().Op().Return(message.AppGossipOp).AnyTimes() msg.EXPECT().Bytes().Return(make([]byte, config.NodeMaxAtLargeBytes+1)).AnyTimes() throttlerIntf.Acquire(msg, vdr1ID) - require.EqualValues(0, throttler.nodeToAtLargeBytesUsed[vdr1ID]) - require.EqualValues(0, throttler.nodeToVdrBytesUsed[vdr1ID]) - require.EqualValues(1, throttler.nodeToAtLargeBytesUsed[nonVdrNodeID1]) - require.EqualValues(config.AtLargeAllocSize-1, throttler.remainingAtLargeBytes) + require.Zero(throttler.nodeToAtLargeBytesUsed[vdr1ID]) + require.Zero(throttler.nodeToVdrBytesUsed[vdr1ID]) + require.Equal(uint64(1), throttler.nodeToAtLargeBytesUsed[nonVdrNodeID1]) + require.Equal(config.AtLargeAllocSize-1, throttler.remainingAtLargeBytes) } func testMsgWithSize(ctrl *gomock.Controller, size uint64) message.OutboundMessage { diff --git a/node/beacon_manager_test.go b/node/beacon_manager_test.go index 4e5ce1b4e83..fad7671db71 100644 --- a/node/beacon_manager_test.go +++ b/node/beacon_manager_test.go @@ -66,7 +66,7 @@ func TestBeaconManager_DataRace(t *testing.T) { wg.Wait() // we should have a weight of numValidators now - require.EqualValues(numValidators, b.numConns) + require.Equal(int64(numValidators), b.numConns) // disconnect numValidators validators wg.Add(numValidators) diff --git a/snow/consensus/snowman/consensus_test.go b/snow/consensus/snowman/consensus_test.go index ee731a28783..323c94ab99a 100644 --- a/snow/consensus/snowman/consensus_test.go +++ b/snow/consensus/snowman/consensus_test.go @@ -626,8 +626,8 @@ func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) { require.False(sm.Finalized()) metrics := gatherCounterGauge(t, registerer) - require.EqualValues(0, metrics["polls_failed"]) - require.EqualValues(1, metrics["polls_successful"]) + require.Zero(metrics["polls_failed"]) + require.Equal(float64(1), metrics["polls_successful"]) // The second poll will do nothing require.NoError(sm.RecordPoll(context.Background(), votes)) @@ -635,8 +635,8 @@ func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) { require.False(sm.Finalized()) metrics = gatherCounterGauge(t, registerer) - require.EqualValues(1, metrics["polls_failed"]) - require.EqualValues(1, metrics["polls_successful"]) + require.Equal(float64(1), metrics["polls_failed"]) + require.Equal(float64(1), metrics["polls_successful"]) } func RecordPollWhenFinalizedTest(t *testing.T, factory Factory) { diff --git a/snow/engine/common/queue/jobs_test.go b/snow/engine/common/queue/jobs_test.go index 7ad245905e4..d89d01640dc 100644 --- a/snow/engine/common/queue/jobs_test.go +++ b/snow/engine/common/queue/jobs_test.go @@ -482,12 +482,12 @@ func TestInitializeNumJobs(t *testing.T) { pushed, err := jobs.Push(context.Background(), job0) require.True(pushed) require.NoError(err) - require.EqualValues(1, jobs.state.numJobs) + require.Equal(uint64(1), jobs.state.numJobs) pushed, err = jobs.Push(context.Background(), job1) require.True(pushed) require.NoError(err) - require.EqualValues(2, jobs.state.numJobs) + require.Equal(uint64(2), jobs.state.numJobs) err = jobs.Commit() require.NoError(err) @@ -502,7 +502,7 @@ func TestInitializeNumJobs(t *testing.T) { if err != nil { t.Fatal(err) } - require.EqualValues(2, jobs.state.numJobs) + require.Equal(uint64(2), jobs.state.numJobs) } func TestClearAll(t *testing.T) { diff --git a/snow/engine/common/tracker/peers_test.go b/snow/engine/common/tracker/peers_test.go index 8c8b082101f..802386f8468 100644 --- a/snow/engine/common/tracker/peers_test.go +++ b/snow/engine/common/tracker/peers_test.go @@ -29,11 +29,11 @@ func TestPeers(t *testing.T) { err := p.Connected(context.Background(), nodeID, version.CurrentApp) require.NoError(err) - require.EqualValues(5, p.ConnectedWeight()) + require.Equal(uint64(5), p.ConnectedWeight()) require.Contains(p.PreferredPeers(), nodeID) p.OnValidatorWeightChanged(nodeID, 5, 10) - require.EqualValues(10, p.ConnectedWeight()) + require.Equal(uint64(10), p.ConnectedWeight()) require.Contains(p.PreferredPeers(), nodeID) p.OnValidatorRemoved(nodeID, 10) @@ -41,7 +41,7 @@ func TestPeers(t *testing.T) { require.Contains(p.PreferredPeers(), nodeID) p.OnValidatorAdded(nodeID, nil, ids.Empty, 5) - require.EqualValues(5, p.ConnectedWeight()) + require.Equal(uint64(5), p.ConnectedWeight()) require.Contains(p.PreferredPeers(), nodeID) err = p.Disconnected(context.Background(), nodeID) diff --git a/snow/networking/handler/message_queue_test.go b/snow/networking/handler/message_queue_test.go index 8e1bf550446..cfe5d82768a 100644 --- a/snow/networking/handler/message_queue_test.go +++ b/snow/networking/handler/message_queue_test.go @@ -56,48 +56,48 @@ func TestQueue(t *testing.T) { // messages on [u.msgs] cpuTracker.EXPECT().Usage(vdr1ID, gomock.Any()).Return(0.1).Times(1) u.Push(context.Background(), msg1) - require.EqualValues(1, u.nodeToUnprocessedMsgs[vdr1ID]) - require.EqualValues(1, u.Len()) + require.Equal(1, u.nodeToUnprocessedMsgs[vdr1ID]) + require.Equal(1, u.Len()) _, gotMsg1, ok := u.Pop() require.True(ok) require.Len(u.nodeToUnprocessedMsgs, 0) - require.EqualValues(0, u.Len()) - require.EqualValues(msg1, gotMsg1) + require.Zero(u.Len()) + require.Equal(msg1, gotMsg1) cpuTracker.EXPECT().Usage(vdr1ID, gomock.Any()).Return(0.0).Times(1) u.Push(context.Background(), msg1) - require.EqualValues(1, u.nodeToUnprocessedMsgs[vdr1ID]) - require.EqualValues(1, u.Len()) + require.Equal(1, u.nodeToUnprocessedMsgs[vdr1ID]) + require.Equal(1, u.Len()) _, gotMsg1, ok = u.Pop() require.True(ok) require.Len(u.nodeToUnprocessedMsgs, 0) - require.EqualValues(0, u.Len()) - require.EqualValues(msg1, gotMsg1) + require.Zero(u.Len()) + require.Equal(msg1, gotMsg1) cpuTracker.EXPECT().Usage(vdr1ID, gomock.Any()).Return(1.0).Times(1) u.Push(context.Background(), msg1) - require.EqualValues(1, u.nodeToUnprocessedMsgs[vdr1ID]) - require.EqualValues(1, u.Len()) + require.Equal(1, u.nodeToUnprocessedMsgs[vdr1ID]) + require.Equal(1, u.Len()) _, gotMsg1, ok = u.Pop() require.True(ok) require.Len(u.nodeToUnprocessedMsgs, 0) - require.EqualValues(0, u.Len()) - require.EqualValues(msg1, gotMsg1) + require.Zero(u.Len()) + require.Equal(msg1, gotMsg1) cpuTracker.EXPECT().Usage(vdr1ID, gomock.Any()).Return(0.0).Times(1) u.Push(context.Background(), msg1) - require.EqualValues(1, u.nodeToUnprocessedMsgs[vdr1ID]) - require.EqualValues(1, u.Len()) + require.Equal(1, u.nodeToUnprocessedMsgs[vdr1ID]) + require.Equal(1, u.Len()) _, gotMsg1, ok = u.Pop() require.True(ok) require.Len(u.nodeToUnprocessedMsgs, 0) - require.EqualValues(0, u.Len()) - require.EqualValues(msg1, gotMsg1) + require.Zero(u.Len()) + require.Equal(msg1, gotMsg1) // Push msg1 from vdr1ID u.Push(context.Background(), msg1) - require.EqualValues(1, u.nodeToUnprocessedMsgs[vdr1ID]) - require.EqualValues(1, u.Len()) + require.Equal(1, u.nodeToUnprocessedMsgs[vdr1ID]) + require.Equal(1, u.Len()) msg2 := Message{ InboundMessage: message.InboundPullQuery( @@ -113,21 +113,21 @@ func TestQueue(t *testing.T) { // Push msg2 from vdr2ID u.Push(context.Background(), msg2) - require.EqualValues(2, u.Len()) - require.EqualValues(1, u.nodeToUnprocessedMsgs[vdr2ID]) + require.Equal(2, u.Len()) + require.Equal(1, u.nodeToUnprocessedMsgs[vdr2ID]) // Set vdr1's usage to 99% and vdr2's to .01 cpuTracker.EXPECT().Usage(vdr1ID, gomock.Any()).Return(.99).Times(2) cpuTracker.EXPECT().Usage(vdr2ID, gomock.Any()).Return(.01).Times(1) // Pop should return msg2 first because vdr1 has exceeded it's portion of CPU time _, gotMsg2, ok := u.Pop() require.True(ok) - require.EqualValues(1, u.Len()) - require.EqualValues(msg2, gotMsg2) + require.Equal(1, u.Len()) + require.Equal(msg2, gotMsg2) _, gotMsg1, ok = u.Pop() require.True(ok) - require.EqualValues(msg1, gotMsg1) + require.Equal(msg1, gotMsg1) require.Len(u.nodeToUnprocessedMsgs, 0) - require.EqualValues(0, u.Len()) + require.Zero(u.Len()) // u is now empty // Non-validators should be able to put messages onto [u] @@ -143,7 +143,7 @@ func TestQueue(t *testing.T) { u.Push(context.Background(), msg3) u.Push(context.Background(), msg4) u.Push(context.Background(), msg1) - require.EqualValues(3, u.Len()) + require.Equal(3, u.Len()) // msg1 should get popped first because nonVdrNodeID1 and nonVdrNodeID2 // exceeded their limit @@ -154,15 +154,15 @@ func TestQueue(t *testing.T) { // u.msgs is [msg3, msg4, msg1] _, gotMsg1, ok = u.Pop() require.True(ok) - require.EqualValues(msg1, gotMsg1) + require.Equal(msg1, gotMsg1) // u.msgs is [msg3, msg4] cpuTracker.EXPECT().Usage(nonVdrNodeID1, gomock.Any()).Return(.51).Times(2) _, gotMsg4, ok := u.Pop() require.True(ok) - require.EqualValues(msg4, gotMsg4) + require.Equal(msg4, gotMsg4) // u.msgs is [msg3] _, gotMsg3, ok := u.Pop() require.True(ok) - require.EqualValues(msg3, gotMsg3) - require.EqualValues(0, u.Len()) + require.Equal(msg3, gotMsg3) + require.Zero(u.Len()) } diff --git a/snow/networking/router/chain_router_test.go b/snow/networking/router/chain_router_test.go index f235064b28f..b843f17cd5b 100644 --- a/snow/networking/router/chain_router_test.go +++ b/snow/networking/router/chain_router_test.go @@ -783,6 +783,8 @@ func TestRouterHonorsRequestedEngine(t *testing.T) { } { + engineType := p2p.EngineType(100) + requestID++ msg := message.InboundPushQuery( ctx.ChainID, @@ -790,11 +792,11 @@ func TestRouterHonorsRequestedEngine(t *testing.T) { 0, nil, nodeID, - 100, + engineType, ) h.EXPECT().Push(gomock.Any(), gomock.Any()).Do(func(_ context.Context, msg handler.Message) { - require.EqualValues(100, msg.EngineType) + require.Equal(engineType, msg.EngineType) }) chainRouter.HandleInbound(context.Background(), msg) } diff --git a/snow/uptime/locked_calculator_test.go b/snow/uptime/locked_calculator_test.go index 3123a5b7980..13ae35fb909 100644 --- a/snow/uptime/locked_calculator_test.go +++ b/snow/uptime/locked_calculator_test.go @@ -48,7 +48,7 @@ func TestLockedCalculator(t *testing.T) { require.ErrorIs(err, errStillBootstrapping) _, err = lc.CalculateUptimePercentFrom(nodeID, subnetID, time.Now()) - require.EqualValues(errStillBootstrapping, err) + require.ErrorIs(err, errStillBootstrapping) isBootstrapped.Set(true) diff --git a/snow/validators/gvalidators/validator_state_test.go b/snow/validators/gvalidators/validator_state_test.go index 136919e1c23..6f72f03e988 100644 --- a/snow/validators/gvalidators/validator_state_test.go +++ b/snow/validators/gvalidators/validator_state_test.go @@ -197,7 +197,7 @@ func TestPublicKeyDeserialize(t *testing.T) { pkBytes := pk.Serialize() pkDe := new(bls.PublicKey).Deserialize(pkBytes) require.NotNil(pkDe) - require.EqualValues(pk, pkDe) + require.Equal(pk, pkDe) } // BenchmarkGetValidatorSet measures the time it takes complete a gRPC client diff --git a/snow/validators/manager_test.go b/snow/validators/manager_test.go index 433033caa27..1b500d58d06 100644 --- a/snow/validators/manager_test.go +++ b/snow/validators/manager_test.go @@ -28,8 +28,7 @@ func TestAdd(t *testing.T) { err = Add(m, subnetID, nodeID, nil, ids.Empty, 1) require.NoError(err) - weight := s.Weight() - require.EqualValues(1, weight) + require.Equal(uint64(1), s.Weight()) } func TestAddWeight(t *testing.T) { @@ -55,8 +54,7 @@ func TestAddWeight(t *testing.T) { err = AddWeight(m, subnetID, nodeID, 1) require.NoError(err) - weight := s.Weight() - require.EqualValues(2, weight) + require.Equal(uint64(2), s.Weight()) } func TestRemoveWeight(t *testing.T) { @@ -79,14 +77,12 @@ func TestRemoveWeight(t *testing.T) { err = RemoveWeight(m, subnetID, nodeID, 1) require.NoError(err) - weight := s.Weight() - require.EqualValues(1, weight) + require.Equal(uint64(1), s.Weight()) err = RemoveWeight(m, subnetID, nodeID, 1) require.NoError(err) - weight = s.Weight() - require.Zero(weight) + require.Zero(s.Weight()) } func TestContains(t *testing.T) { diff --git a/snow/validators/set_test.go b/snow/validators/set_test.go index 59d6b1e5755..cebd565ea65 100644 --- a/snow/validators/set_test.go +++ b/snow/validators/set_test.go @@ -48,8 +48,7 @@ func TestSetAddOverflow(t *testing.T) { err = s.Add(ids.GenerateTestNodeID(), nil, ids.Empty, stdmath.MaxUint64) require.ErrorIs(err, math.ErrOverflow) - weight := s.Weight() - require.EqualValues(1, weight) + require.Equal(uint64(1), s.Weight()) } func TestSetAddWeightZeroWeight(t *testing.T) { @@ -80,8 +79,7 @@ func TestSetAddWeightOverflow(t *testing.T) { err = s.AddWeight(nodeID, stdmath.MaxUint64-1) require.ErrorIs(err, math.ErrOverflow) - weight := s.Weight() - require.EqualValues(2, weight) + require.Equal(uint64(2), s.Weight()) } func TestSetGetWeight(t *testing.T) { @@ -96,8 +94,7 @@ func TestSetGetWeight(t *testing.T) { err := s.Add(nodeID, nil, ids.Empty, 1) require.NoError(err) - weight = s.GetWeight(nodeID) - require.EqualValues(1, weight) + require.Equal(uint64(1), s.GetWeight(nodeID)) } func TestSetSubsetWeight(t *testing.T) { @@ -171,8 +168,7 @@ func TestSetRemoveWeightUnderflow(t *testing.T) { err = s.RemoveWeight(nodeID, 2) require.ErrorIs(err, math.ErrUnderflow) - weight := s.Weight() - require.EqualValues(2, weight) + require.Equal(uint64(2), s.Weight()) } func TestSetGet(t *testing.T) { @@ -195,7 +191,7 @@ func TestSetGet(t *testing.T) { require.True(ok) require.Equal(nodeID, vdr0.NodeID) require.Equal(pk, vdr0.PublicKey) - require.EqualValues(1, vdr0.Weight) + require.Equal(uint64(1), vdr0.Weight) err = s.AddWeight(nodeID, 1) require.NoError(err) @@ -204,10 +200,10 @@ func TestSetGet(t *testing.T) { require.True(ok) require.Equal(nodeID, vdr0.NodeID) require.Equal(pk, vdr0.PublicKey) - require.EqualValues(1, vdr0.Weight) + require.Equal(uint64(1), vdr0.Weight) require.Equal(nodeID, vdr1.NodeID) require.Equal(pk, vdr1.PublicKey) - require.EqualValues(2, vdr1.Weight) + require.Equal(uint64(2), vdr1.Weight) } func TestSetContains(t *testing.T) { @@ -289,7 +285,7 @@ func TestSetList(t *testing.T) { node0 := list[0] require.Equal(nodeID0, node0.NodeID) require.Equal(pk, node0.PublicKey) - require.EqualValues(2, node0.Weight) + require.Equal(uint64(2), node0.Weight) nodeID1 := ids.GenerateTestNodeID() err = s.Add(nodeID1, nil, ids.Empty, 1) @@ -301,18 +297,18 @@ func TestSetList(t *testing.T) { node0 = list[0] require.Equal(nodeID0, node0.NodeID) require.Equal(pk, node0.PublicKey) - require.EqualValues(2, node0.Weight) + require.Equal(uint64(2), node0.Weight) node1 := list[1] require.Equal(nodeID1, node1.NodeID) require.Nil(node1.PublicKey) - require.EqualValues(1, node1.Weight) + require.Equal(uint64(1), node1.Weight) err = s.RemoveWeight(nodeID0, 1) require.NoError(err) require.Equal(nodeID0, node0.NodeID) require.Equal(pk, node0.PublicKey) - require.EqualValues(2, node0.Weight) + require.Equal(uint64(2), node0.Weight) list = s.List() require.Len(list, 2) @@ -320,12 +316,12 @@ func TestSetList(t *testing.T) { node0 = list[0] require.Equal(nodeID0, node0.NodeID) require.Equal(pk, node0.PublicKey) - require.EqualValues(1, node0.Weight) + require.Equal(uint64(1), node0.Weight) node1 = list[1] require.Equal(nodeID1, node1.NodeID) require.Nil(node1.PublicKey) - require.EqualValues(1, node1.Weight) + require.Equal(uint64(1), node1.Weight) err = s.RemoveWeight(nodeID0, 1) require.NoError(err) @@ -336,7 +332,7 @@ func TestSetList(t *testing.T) { node0 = list[0] require.Equal(nodeID1, node0.NodeID) require.Nil(node0.PublicKey) - require.EqualValues(1, node0.Weight) + require.Equal(uint64(1), node0.Weight) err = s.RemoveWeight(nodeID1, 1) require.NoError(err) diff --git a/utils/compression/compressor_test.go b/utils/compression/compressor_test.go index cbd2eb114a4..0f343874705 100644 --- a/utils/compression/compressor_test.go +++ b/utils/compression/compressor_test.go @@ -72,38 +72,40 @@ func TestDecompressZipBombs(t *testing.T) { func TestCompressDecompress(t *testing.T) { for compressionType, newCompressorFunc := range newCompressorFuncs { t.Run(compressionType.String(), func(t *testing.T) { + require := require.New(t) + data := utils.RandomBytes(4096) data2 := utils.RandomBytes(4096) compressor, err := newCompressorFunc(maxMessageSize) - require.NoError(t, err) + require.NoError(err) dataCompressed, err := compressor.Compress(data) - require.NoError(t, err) + require.NoError(err) data2Compressed, err := compressor.Compress(data2) - require.NoError(t, err) + require.NoError(err) dataDecompressed, err := compressor.Decompress(dataCompressed) - require.NoError(t, err) - require.EqualValues(t, data, dataDecompressed) + require.NoError(err) + require.Equal(data, dataDecompressed) data2Decompressed, err := compressor.Decompress(data2Compressed) - require.NoError(t, err) - require.EqualValues(t, data2, data2Decompressed) + require.NoError(err) + require.Equal(data2, data2Decompressed) dataDecompressed, err = compressor.Decompress(dataCompressed) - require.NoError(t, err) - require.EqualValues(t, data, dataDecompressed) + require.NoError(err) + require.Equal(data, dataDecompressed) maxMessage := utils.RandomBytes(maxMessageSize) maxMessageCompressed, err := compressor.Compress(maxMessage) - require.NoError(t, err) + require.NoError(err) maxMessageDecompressed, err := compressor.Decompress(maxMessageCompressed) - require.NoError(t, err) + require.NoError(err) - require.EqualValues(t, maxMessage, maxMessageDecompressed) + require.Equal(maxMessage, maxMessageDecompressed) }) } } diff --git a/utils/compression/no_compressor_test.go b/utils/compression/no_compressor_test.go index 3535dc55721..95000667658 100644 --- a/utils/compression/no_compressor_test.go +++ b/utils/compression/no_compressor_test.go @@ -10,13 +10,15 @@ import ( ) func TestNoCompressor(t *testing.T) { + require := require.New(t) + data := []byte{1, 2, 3} compressor := NewNoCompressor() compressedBytes, err := compressor.Compress(data) - require.NoError(t, err) - require.EqualValues(t, data, compressedBytes) + require.NoError(err) + require.Equal(data, compressedBytes) decompressedBytes, err := compressor.Decompress(compressedBytes) - require.NoError(t, err) - require.EqualValues(t, data, decompressedBytes) + require.NoError(err) + require.Equal(data, decompressedBytes) } diff --git a/utils/linkedhashmap/linkedhashmap_test.go b/utils/linkedhashmap/linkedhashmap_test.go index 4b251a0af99..c9144f7f977 100644 --- a/utils/linkedhashmap/linkedhashmap_test.go +++ b/utils/linkedhashmap/linkedhashmap_test.go @@ -108,7 +108,7 @@ func TestIterator(t *testing.T) { require.False(iter.Next()) require.False(iter.Next()) // Should be empty - require.EqualValues(ids.Empty, iter.Key()) + require.Equal(ids.Empty, iter.Key()) require.Zero(iter.Value()) } @@ -119,16 +119,16 @@ func TestIterator(t *testing.T) { require.NotNil(iter) lh.Put(id1, 1) require.True(iter.Next()) - require.EqualValues(id1, iter.Key()) - require.EqualValues(1, iter.Value()) + require.Equal(id1, iter.Key()) + require.Equal(1, iter.Value()) // Should be empty require.False(iter.Next()) // Re-assign id1 --> 10 lh.Put(id1, 10) iter = lh.NewIterator() // New iterator require.True(iter.Next()) - require.EqualValues(id1, iter.Key()) - require.EqualValues(10, iter.Value()) + require.Equal(id1, iter.Key()) + require.Equal(10, iter.Value()) // Should be empty require.False(iter.Next()) // Delete id1 @@ -148,14 +148,14 @@ func TestIterator(t *testing.T) { iter := lh.NewIterator() // Should give back all 3 elements require.True(iter.Next()) - require.EqualValues(id1, iter.Key()) - require.EqualValues(1, iter.Value()) + require.Equal(id1, iter.Key()) + require.Equal(1, iter.Value()) require.True(iter.Next()) - require.EqualValues(id2, iter.Key()) - require.EqualValues(2, iter.Value()) + require.Equal(id2, iter.Key()) + require.Equal(2, iter.Value()) require.True(iter.Next()) - require.EqualValues(id3, iter.Key()) - require.EqualValues(3, iter.Value()) + require.Equal(id3, iter.Key()) + require.Equal(3, iter.Value()) // Should be exhausted require.False(iter.Next()) } @@ -172,8 +172,8 @@ func TestIterator(t *testing.T) { lh.Delete(id1) lh.Delete(id2) require.True(iter.Next()) - require.EqualValues(id3, iter.Key()) - require.EqualValues(3, iter.Value()) + require.Equal(id3, iter.Key()) + require.Equal(3, iter.Value()) // Should be exhausted require.False(iter.Next()) } diff --git a/utils/set/set_test.go b/utils/set/set_test.go index 341d4661f29..ed516cd33eb 100644 --- a/utils/set/set_test.go +++ b/utils/set/set_test.go @@ -88,29 +88,31 @@ func TestSetClear(t *testing.T) { } func TestSetPop(t *testing.T) { + require := require.New(t) + var s Set[int] _, ok := s.Pop() - require.False(t, ok) + require.False(ok) s = make(Set[int]) _, ok = s.Pop() - require.False(t, ok) + require.False(ok) id1, id2 := 0, 1 s.Add(id1, id2) got, ok := s.Pop() - require.True(t, ok) - require.True(t, got == id1 || got == id2) - require.EqualValues(t, 1, s.Len()) + require.True(ok) + require.True(got == id1 || got == id2) + require.Equal(1, s.Len()) got, ok = s.Pop() - require.True(t, ok) - require.True(t, got == id1 || got == id2) - require.EqualValues(t, 0, s.Len()) + require.True(ok) + require.True(got == id1 || got == id2) + require.Zero(s.Len()) _, ok = s.Pop() - require.False(t, ok) + require.False(ok) } func TestSetMarshalJSON(t *testing.T) { diff --git a/vms/avm/index_test.go b/vms/avm/index_test.go index f8b18900862..5ce7af2ae83 100644 --- a/vms/avm/index_test.go +++ b/vms/avm/index_test.go @@ -547,6 +547,8 @@ func setupTestVM(t *testing.T, ctx *snow.Context, baseDBManager manager.Manager, } func assertLatestIdx(t *testing.T, db database.Database, sourceAddress ids.ShortID, assetID ids.ID, expectedIdx uint64) { + require := require.New(t) + addressDB := prefixdb.New(sourceAddress[:], db) assetDB := prefixdb.New(assetID[:], addressDB) @@ -554,9 +556,9 @@ func assertLatestIdx(t *testing.T, db database.Database, sourceAddress ids.Short binary.BigEndian.PutUint64(expectedIdxBytes, expectedIdx) idxBytes, err := assetDB.Get([]byte("idx")) - require.NoError(t, err) + require.NoError(err) - require.EqualValues(t, expectedIdxBytes, idxBytes) + require.Equal(expectedIdxBytes, idxBytes) } func checkIndexedTX(db database.Database, index uint64, sourceAddress ids.ShortID, assetID ids.ID, transactionID ids.ID) error { diff --git a/vms/components/avax/utxo_fetching_test.go b/vms/components/avax/utxo_fetching_test.go index 2af04f53628..0b8f4f71f8c 100644 --- a/vms/components/avax/utxo_fetching_test.go +++ b/vms/components/avax/utxo_fetching_test.go @@ -64,7 +64,7 @@ func TestFetchUTXOs(t *testing.T) { balance, err := GetBalance(s, addrs) require.NoError(err) - require.EqualValues(12345, balance) + require.Equal(uint64(12345), balance) } // TestGetPaginatedUTXOs tests diff --git a/vms/platformvm/blocks/builder/builder_test.go b/vms/platformvm/blocks/builder/builder_test.go index 5eed4d56a3e..f10791e2972 100644 --- a/vms/platformvm/blocks/builder/builder_test.go +++ b/vms/platformvm/blocks/builder/builder_test.go @@ -678,7 +678,7 @@ func TestBuildBlock(t *testing.T) { return } require.NoError(err) - require.EqualValues(tt.expectedBlkF(require), gotBlk) + require.Equal(tt.expectedBlkF(require), gotBlk) }) } } diff --git a/vms/platformvm/blocks/executor/standard_block_test.go b/vms/platformvm/blocks/executor/standard_block_test.go index 017379f76bf..1388c5e091a 100644 --- a/vms/platformvm/blocks/executor/standard_block_test.go +++ b/vms/platformvm/blocks/executor/standard_block_test.go @@ -343,7 +343,7 @@ func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { currentValidator, err := updatedState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) require.NoError(err) require.Equal(addPendingValidatorTx.ID(), currentValidator.TxID) - require.EqualValues(1370, currentValidator.PotentialReward) // See rewards tests to explain why 1370 + require.Equal(uint64(1370), currentValidator.PotentialReward) // See rewards tests to explain why 1370 _, err = updatedState.GetPendingValidator(constants.PrimaryNetworkID, nodeID) require.ErrorIs(err, database.ErrNotFound) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index d154718ab42..1cc0abf5e86 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -441,7 +441,7 @@ func TestGetStake(t *testing.T) { } response := GetStakeReply{} require.NoError(service.GetStake(nil, &args, &response)) - require.EqualValues(uint64(defaultWeight), uint64(response.Staked)) + require.Equal(defaultWeight, uint64(response.Staked)) require.Len(response.Outputs, 1) // Unmarshal into an output @@ -453,8 +453,8 @@ func TestGetStake(t *testing.T) { require.NoError(err) out := output.Out.(*secp256k1fx.TransferOutput) - require.EqualValues(defaultWeight, out.Amount()) - require.EqualValues(1, out.Threshold) + require.Equal(defaultWeight, out.Amount()) + require.Equal(uint32(1), out.Threshold) require.Len(out.Addrs, 1) require.Equal(keys[i].PublicKey().Address(), out.Addrs[0]) require.Zero(out.Locktime) @@ -469,7 +469,7 @@ func TestGetStake(t *testing.T) { } response := GetStakeReply{} require.NoError(service.GetStake(nil, &args, &response)) - require.EqualValues(len(genesis.Validators)*defaultWeight, response.Staked) + require.Equal(len(genesis.Validators)*int(defaultWeight), int(response.Staked)) require.Len(response.Outputs, len(genesis.Validators)) for _, outputStr := range response.Outputs { @@ -481,13 +481,13 @@ func TestGetStake(t *testing.T) { require.NoError(err) out := output.Out.(*secp256k1fx.TransferOutput) - require.EqualValues(defaultWeight, out.Amount()) - require.EqualValues(1, out.Threshold) + require.Equal(defaultWeight, out.Amount()) + require.Equal(uint32(1), out.Threshold) require.Zero(out.Locktime) require.Len(out.Addrs, 1) } - oldStake := uint64(defaultWeight) + oldStake := defaultWeight // Add a delegator stakeAmount := service.vm.MinDelegatorStake + 12345 @@ -519,7 +519,7 @@ func TestGetStake(t *testing.T) { addr, _ := service.addrManager.FormatLocalAddress(keys[0].PublicKey().Address()) args.Addresses = []string{addr} require.NoError(service.GetStake(nil, &args, &response)) - require.EqualValues(oldStake+stakeAmount, uint64(response.Staked)) + require.Equal(oldStake+stakeAmount, uint64(response.Staked)) require.Len(response.Outputs, 2) // Unmarshal into transferable outputs @@ -532,7 +532,7 @@ func TestGetStake(t *testing.T) { } // Make sure the stake amount is as expected - require.EqualValues(stakeAmount+oldStake, outputs[0].Out.Amount()+outputs[1].Out.Amount()) + require.Equal(stakeAmount+oldStake, outputs[0].Out.Amount()+outputs[1].Out.Amount()) oldStake = uint64(response.Staked) @@ -565,7 +565,7 @@ func TestGetStake(t *testing.T) { // Make sure the delegator has the right stake (old stake + stakeAmount) require.NoError(service.GetStake(nil, &args, &response)) - require.EqualValues(oldStake+stakeAmount, response.Staked) + require.Equal(oldStake+stakeAmount, uint64(response.Staked)) require.Len(response.Outputs, 3) // Unmarshal @@ -578,7 +578,7 @@ func TestGetStake(t *testing.T) { } // Make sure the stake amount is as expected - require.EqualValues(stakeAmount+oldStake, outputs[0].Out.Amount()+outputs[1].Out.Amount()+outputs[2].Out.Amount()) + require.Equal(stakeAmount+oldStake, outputs[0].Out.Amount()+outputs[1].Out.Amount()+outputs[2].Out.Amount()) } // Test method GetCurrentValidators diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index e58392add81..1a8a26accd5 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -60,7 +60,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { validatorStaker, err := executor.OnCommitState.GetCurrentValidator(constants.PrimaryNetworkID, nodeID) require.NoError(err) require.Equal(addPendingValidatorTx.ID(), validatorStaker.TxID) - require.EqualValues(1370, validatorStaker.PotentialReward) // See rewards tests to explain why 1370 + require.Equal(uint64(1370), validatorStaker.PotentialReward) // See rewards tests to explain why 1370 _, err = executor.OnCommitState.GetPendingValidator(constants.PrimaryNetworkID, nodeID) require.ErrorIs(err, database.ErrNotFound) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index b704f2baeaf..d8bedcd7853 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -997,11 +997,11 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { { staker0, err := vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID0) require.NoError(err) - require.EqualValues(60000000, staker0.PotentialReward) + require.Equal(uint64(60000000), staker0.PotentialReward) staker1, err := vm.state.GetCurrentValidator(constants.PrimaryNetworkID, nodeID1) require.NoError(err) - require.EqualValues(59999999, staker1.PotentialReward) + require.Equal(uint64(59999999), staker1.PotentialReward) _, err = vm.state.GetPendingValidator(constants.PrimaryNetworkID, nodeID0) require.ErrorIs(err, database.ErrNotFound) @@ -1034,7 +1034,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { currentHeight, err := vm.GetCurrentHeight(context.Background()) require.NoError(err) - require.EqualValues(1, currentHeight) + require.Equal(uint64(1), currentHeight) expectedValidators1 := map[ids.NodeID]uint64{ nodeID0: defaultWeight, @@ -1089,7 +1089,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { currentHeight, err = vm.GetCurrentHeight(context.Background()) require.NoError(err) - require.EqualValues(2, currentHeight) + require.Equal(uint64(2), currentHeight) for i := uint64(1); i <= 2; i++ { validators, err = vm.GetValidatorSet(context.Background(), i, constants.PrimaryNetworkID) @@ -1124,7 +1124,7 @@ func TestValidatorSetAtCacheOverwriteRegression(t *testing.T) { currentHeight, err = vm.GetCurrentHeight(context.Background()) require.NoError(err) - require.EqualValues(3, currentHeight) + require.Equal(uint64(3), currentHeight) for i := uint64(1); i <= 2; i++ { validators, err = vm.GetValidatorSet(context.Background(), i, constants.PrimaryNetworkID) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index c20d5ae25eb..b3bc441e56e 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -76,8 +76,8 @@ import ( ) const ( - testNetworkID = 10 // To be used in tests - defaultWeight = 10000 + testNetworkID = 10 // To be used in tests + defaultWeight uint64 = 10000 ) var ( @@ -2089,7 +2089,7 @@ func TestMaxStakeAmount(t *testing.T) { amount, err := txexecutor.GetMaxWeight(vm.state, staker, test.startTime, test.endTime) require.NoError(err) - require.EqualValues(defaultWeight, amount) + require.Equal(defaultWeight, amount) }) } } diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index 55ac42ae663..153cd5b4ee1 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -162,9 +162,9 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { // ... and check returned values are as expected require.NoError(err, "Error calling GetAncestors: %v", err) require.Len(res, 3, "GetAncestor returned %v entries instead of %v", len(res), 3) - require.EqualValues(res[0], builtBlk3.Bytes()) - require.EqualValues(res[1], builtBlk2.Bytes()) - require.EqualValues(res[2], builtBlk1.Bytes()) + require.Equal(res[0], builtBlk3.Bytes()) + require.Equal(res[1], builtBlk2.Bytes()) + require.Equal(res[2], builtBlk1.Bytes()) // another good call reqBlkID = builtBlk1.ID() @@ -177,7 +177,7 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { ) require.NoError(err, "Error calling GetAncestors: %v", err) require.Len(res, 1, "GetAncestor returned %v entries instead of %v", len(res), 1) - require.EqualValues(res[0], builtBlk1.Bytes()) + require.Equal(res[0], builtBlk1.Bytes()) // a faulty call reqBlkID = ids.Empty @@ -311,9 +311,9 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { // ... and check returned values are as expected require.NoError(err, "Error calling GetAncestors: %v", err) require.Len(res, 3) - require.EqualValues(res[0], builtBlk3.Bytes()) - require.EqualValues(res[1], builtBlk2.Bytes()) - require.EqualValues(res[2], builtBlk1.Bytes()) + require.Equal(res[0], builtBlk3.Bytes()) + require.Equal(res[1], builtBlk2.Bytes()) + require.Equal(res[2], builtBlk1.Bytes()) // another good call reqBlkID = builtBlk1.ID() @@ -326,7 +326,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) { ) require.NoError(err, "Error calling GetAncestors: %v", err) require.Len(res, 1, "GetAncestor returned %v entries instead of %v", len(res), 1) - require.EqualValues(res[0], builtBlk1.Bytes()) + require.Equal(res[0], builtBlk1.Bytes()) // a faulty call reqBlkID = ids.Empty @@ -498,10 +498,10 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { // ... and check returned values are as expected require.NoError(err, "Error calling GetAncestors") require.Len(res, 4, "Wrong GetAncestor response") - require.EqualValues(res[0], builtBlk4.Bytes()) - require.EqualValues(res[1], builtBlk3.Bytes()) - require.EqualValues(res[2], builtBlk2.Bytes()) - require.EqualValues(res[3], builtBlk1.Bytes()) + require.Equal(res[0], builtBlk4.Bytes()) + require.Equal(res[1], builtBlk3.Bytes()) + require.Equal(res[2], builtBlk2.Bytes()) + require.Equal(res[3], builtBlk1.Bytes()) // Regression case: load some prefork and some postfork blocks. reqBlkID = builtBlk4.ID() @@ -517,9 +517,9 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { // ... and check returned values are as expected require.NoError(err, "Error calling GetAncestors") require.Len(res, 3, "Wrong GetAncestor response") - require.EqualValues(res[0], builtBlk4.Bytes()) - require.EqualValues(res[1], builtBlk3.Bytes()) - require.EqualValues(res[2], builtBlk2.Bytes()) + require.Equal(res[0], builtBlk4.Bytes()) + require.Equal(res[1], builtBlk3.Bytes()) + require.Equal(res[2], builtBlk2.Bytes()) // another good call reqBlkID = builtBlk1.ID() @@ -532,7 +532,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { ) require.NoError(err, "Error calling GetAncestors") require.Len(res, 1, "Wrong GetAncestor response") - require.EqualValues(res[0], builtBlk1.Bytes()) + require.Equal(res[0], builtBlk1.Bytes()) // a faulty call reqBlkID = ids.Empty diff --git a/vms/proposervm/proposer/windower_test.go b/vms/proposervm/proposer/windower_test.go index ef7cc706c26..ec222500323 100644 --- a/vms/proposervm/proposer/windower_test.go +++ b/vms/proposervm/proposer/windower_test.go @@ -32,7 +32,7 @@ func TestWindowerNoValidators(t *testing.T) { delay, err := w.Delay(context.Background(), 1, 0, nodeID) require.NoError(err) - require.EqualValues(0, delay) + require.Zero(delay) } func TestWindowerRepeatedValidator(t *testing.T) { @@ -58,11 +58,11 @@ func TestWindowerRepeatedValidator(t *testing.T) { validatorDelay, err := w.Delay(context.Background(), 1, 0, validatorID) require.NoError(err) - require.EqualValues(0, validatorDelay) + require.Zero(validatorDelay) nonValidatorDelay, err := w.Delay(context.Background(), 1, 0, nonValidatorID) require.NoError(err) - require.EqualValues(MaxDelay, nonValidatorDelay) + require.Equal(MaxDelay, nonValidatorDelay) } func TestWindowerChangeByHeight(t *testing.T) { @@ -102,7 +102,7 @@ func TestWindowerChangeByHeight(t *testing.T) { vdrID := validatorIDs[i] validatorDelay, err := w.Delay(context.Background(), 1, 0, vdrID) require.NoError(err) - require.EqualValues(expectedDelay, validatorDelay) + require.Equal(expectedDelay, validatorDelay) } expectedDelays2 := []time.Duration{ @@ -117,7 +117,7 @@ func TestWindowerChangeByHeight(t *testing.T) { vdrID := validatorIDs[i] validatorDelay, err := w.Delay(context.Background(), 2, 0, vdrID) require.NoError(err) - require.EqualValues(expectedDelay, validatorDelay) + require.Equal(expectedDelay, validatorDelay) } } @@ -165,7 +165,7 @@ func TestWindowerChangeByChain(t *testing.T) { vdrID := validatorIDs[i] validatorDelay, err := w0.Delay(context.Background(), 1, 0, vdrID) require.NoError(err) - require.EqualValues(expectedDelay, validatorDelay) + require.Equal(expectedDelay, validatorDelay) } expectedDelays1 := []time.Duration{ @@ -180,6 +180,6 @@ func TestWindowerChangeByChain(t *testing.T) { vdrID := validatorIDs[i] validatorDelay, err := w1.Delay(context.Background(), 1, 0, vdrID) require.NoError(err) - require.EqualValues(expectedDelay, validatorDelay) + require.Equal(expectedDelay, validatorDelay) } } diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 0aecbe122d8..cf2423f484b 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -2413,7 +2413,7 @@ func TestVMInnerBlkCache(t *testing.T) { gotBlk, ok := vm.innerBlkCache.Get(blkNearTip.ID()) require.True(ok) require.Equal(mockInnerBlkNearTip, gotBlk) - require.EqualValues(0, vm.lastAcceptedHeight) + require.Zero(vm.lastAcceptedHeight) // Clear the cache vm.innerBlkCache.Flush()