diff --git a/.golangci.yml b/.golangci.yml index 8e70442cce97..ea01133e92aa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -46,11 +46,11 @@ linters: enable: - asciicheck - bodyclose + - copyloopvar - depguard - dupword - errcheck - errorlint - - exportloopref - forbidigo - gci - goconst diff --git a/chains/atomic/gsharedmemory/shared_memory_client.go b/chains/atomic/gsharedmemory/shared_memory_client.go index 096a8117e7a1..5e4af1eb558d 100644 --- a/chains/atomic/gsharedmemory/shared_memory_client.go +++ b/chains/atomic/gsharedmemory/shared_memory_client.go @@ -67,8 +67,6 @@ func (c *Client) Apply(requests map[ids.ID]*atomic.Requests, batches ...database Batches: make([]*sharedmemorypb.Batch, len(batches)), } for key, value := range requests { - key := key - chainReq := &sharedmemorypb.AtomicRequest{ RemoveRequests: value.RemoveRequests, PutRequests: make([]*sharedmemorypb.Element, len(value.PutRequests)), diff --git a/genesis/genesis.go b/genesis/genesis.go index 89967d10a48a..4c0805f89a15 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -495,7 +495,6 @@ func splitAllocations(allocations []Allocation, numSplits int) [][]Allocation { currentAllocation.UnlockSchedule = nil for _, unlock := range allocation.UnlockSchedule { - unlock := unlock for currentNodeAmount+unlock.Amount > nodeWeight && len(allNodeAllocations) < numSplits-1 { amountToAdd := nodeWeight - currentNodeAmount currentAllocation.UnlockSchedule = append(currentAllocation.UnlockSchedule, LockedAmount{ diff --git a/go.mod b/go.mod index a46e68049850..9adffcb43685 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,12 @@ module github.com/ava-labs/avalanchego -// Changes to the minimum golang version must also be replicated in -// CONTRIBUTING.md -// README.md -// go.mod (here) +// - Changes to the minimum golang version must also be replicated in: +// - CONTRIBUTING.md +// - README.md +// - go.mod (here) +// +// - If updating between minor versions (e.g. 1.22.x -> 1.23.x): +// - Consider updating the version of golangci-lint (in scripts/lint.sh). go 1.22.8 require ( diff --git a/message/inbound_msg_builder.go b/message/inbound_msg_builder.go index b7b6048d89c8..4e3eac1ed6aa 100644 --- a/message/inbound_msg_builder.go +++ b/message/inbound_msg_builder.go @@ -316,7 +316,6 @@ func InboundAppResponse( func encodeIDs(ids []ids.ID, result [][]byte) { for i, id := range ids { - id := id result[i] = id[:] } } diff --git a/message/inbound_msg_builder_test.go b/message/inbound_msg_builder_test.go index 92d18b6836be..a8fed2c3f3a5 100644 --- a/message/inbound_msg_builder_test.go +++ b/message/inbound_msg_builder_test.go @@ -142,7 +142,6 @@ func TestInboundMsgBuilder(t *testing.T) { require.Equal(requestID, innerMsg.RequestId) summaryIDsBytes := make([][]byte, len(summaryIDs)) for i, id := range summaryIDs { - id := id summaryIDsBytes[i] = id[:] } require.Equal(summaryIDsBytes, innerMsg.SummaryIds) @@ -244,7 +243,6 @@ func TestInboundMsgBuilder(t *testing.T) { require.Equal(requestID, innerMsg.RequestId) containerIDsBytes := make([][]byte, len(containerIDs)) for i, id := range containerIDs { - id := id containerIDsBytes[i] = id[:] } require.Equal(containerIDsBytes, innerMsg.ContainerIds) diff --git a/network/network_test.go b/network/network_test.go index 1cae830e036e..9791060f6f35 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -231,8 +231,6 @@ func newFullyConnectedTestNetwork(t *testing.T, handlers []router.InboundHandler require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeID, nil, ids.GenerateTestID(), 1)) } - config := config - config.Beacons = beacons config.Validators = vdrs @@ -461,8 +459,6 @@ func TestTrackDoesNotDialPrivateIPs(t *testing.T) { require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeID, nil, ids.GenerateTestID(), 1)) } - config := config - config.Beacons = beacons config.Validators = vdrs config.AllowPrivateIPs = false @@ -541,8 +537,6 @@ func TestDialDeletesNonValidators(t *testing.T) { beacons := validators.NewManager() require.NoError(beacons.AddStaker(constants.PrimaryNetworkID, nodeIDs[0], nil, ids.GenerateTestID(), 1)) - config := config - config.Beacons = beacons config.Validators = vdrs config.AllowPrivateIPs = false @@ -696,8 +690,6 @@ func TestAllowConnectionAsAValidator(t *testing.T) { vdrs := validators.NewManager() require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeIDs[0], nil, ids.GenerateTestID(), 1)) - config := config - config.Beacons = beacons config.Validators = vdrs config.RequireValidatorToConnect = true diff --git a/node/beacon_manager_test.go b/node/beacon_manager_test.go index 57c3323476ad..3adc66b96915 100644 --- a/node/beacon_manager_test.go +++ b/node/beacon_manager_test.go @@ -55,7 +55,6 @@ func TestBeaconManager_DataRace(t *testing.T) { }) for _, nodeID := range validatorIDs { - nodeID := nodeID go func() { b.Connected(nodeID, version.CurrentApp, constants.PrimaryNetworkID) b.Connected(nodeID, version.CurrentApp, ids.GenerateTestID()) diff --git a/node/process_context_test.go b/node/process_context_test.go index b81a23dd0a16..d5636898ecae 100644 --- a/node/process_context_test.go +++ b/node/process_context_test.go @@ -56,7 +56,7 @@ func TestProcessContext(t *testing.T) { contextJSON, err := json.MarshalIndent(test.context, "", "\t") require.NoError(err) - require.Equal(test.expected, string(contextJSON)) + require.JSONEq(test.expected, string(contextJSON)) }) } } diff --git a/scripts/lint.sh b/scripts/lint.sh index 41eedec65e92..89dd610859c7 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -32,7 +32,7 @@ fi TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_no_error_inline_func import_testing_only_in_tests"} function test_golangci_lint { - go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 + go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 golangci-lint run --config .golangci.yml } diff --git a/snow/engine/avalanche/bootstrap/queue/state.go b/snow/engine/avalanche/bootstrap/queue/state.go index 9ad87d682453..f65ed702a9cf 100644 --- a/snow/engine/avalanche/bootstrap/queue/state.go +++ b/snow/engine/avalanche/bootstrap/queue/state.go @@ -283,7 +283,6 @@ func (s *state) DisableCaching() { func (s *state) AddMissingJobIDs(missingIDs set.Set[ids.ID]) error { for missingID := range missingIDs { - missingID := missingID if err := s.missingJobIDs.Put(missingID[:], nil); err != nil { return err } @@ -293,7 +292,6 @@ func (s *state) AddMissingJobIDs(missingIDs set.Set[ids.ID]) error { func (s *state) RemoveMissingJobIDs(missingIDs set.Set[ids.ID]) error { for missingID := range missingIDs { - missingID := missingID if err := s.missingJobIDs.Delete(missingID[:]); err != nil { return err } diff --git a/snow/engine/snowman/voter.go b/snow/engine/snowman/voter.go index fe4985108c7d..31cbe0ff9566 100644 --- a/snow/engine/snowman/voter.go +++ b/snow/engine/snowman/voter.go @@ -56,7 +56,6 @@ func (v *voter) Execute(ctx context.Context, _ []ids.ID, _ []ids.ID) error { } for _, result := range results { - result := result v.e.Ctx.Log.Debug("finishing poll", zap.Stringer("result", &result), ) diff --git a/tests/fixture/bootstrapmonitor/cmd/main.go b/tests/fixture/bootstrapmonitor/cmd/main.go index ea93b1e0d81c..1e82f9010fd8 100644 --- a/tests/fixture/bootstrapmonitor/cmd/main.go +++ b/tests/fixture/bootstrapmonitor/cmd/main.go @@ -50,7 +50,7 @@ func main() { if len(version.GitCommit) > 0 { msg += ", commit=" + version.GitCommit } - fmt.Fprintf(os.Stdout, msg+"\n") + fmt.Fprintln(os.Stdout, msg) return nil }, } diff --git a/tests/fixture/tmpnet/cmd/main.go b/tests/fixture/tmpnet/cmd/main.go index f8eff5782c51..15afd472925e 100644 --- a/tests/fixture/tmpnet/cmd/main.go +++ b/tests/fixture/tmpnet/cmd/main.go @@ -48,7 +48,7 @@ func main() { if len(version.GitCommit) > 0 { msg += ", commit=" + version.GitCommit } - fmt.Fprintf(os.Stdout, msg+"\n") + fmt.Fprintln(os.Stdout, msg) return nil }, } diff --git a/utils/bimap/bimap_test.go b/utils/bimap/bimap_test.go index 1792bec9a3dd..908d7bf56f40 100644 --- a/utils/bimap/bimap_test.go +++ b/utils/bimap/bimap_test.go @@ -349,7 +349,7 @@ func TestBiMapJSON(t *testing.T) { require.NoError(err) expectedJSONBytes := []byte(`{"1":2,"2":3}`) - require.Equal(expectedJSONBytes, jsonBytes) + require.JSONEq(string(expectedJSONBytes), string(jsonBytes)) var unmarshalledMap BiMap[int, int] require.NoError(json.Unmarshal(jsonBytes, &unmarshalledMap)) diff --git a/utils/formatting/encoding_test.go b/utils/formatting/encoding_test.go index ec759f339c1e..9fbc4e0ed13f 100644 --- a/utils/formatting/encoding_test.go +++ b/utils/formatting/encoding_test.go @@ -17,7 +17,7 @@ func TestEncodingMarshalJSON(t *testing.T) { enc := Hex jsonBytes, err := enc.MarshalJSON() require.NoError(err) - require.Equal(`"hex"`, string(jsonBytes)) + require.JSONEq(`"hex"`, string(jsonBytes)) } func TestEncodingUnmarshalJSON(t *testing.T) { diff --git a/utils/hashing/hashing.go b/utils/hashing/hashing.go index 84e44a1da1fc..97c64c2e8651 100644 --- a/utils/hashing/hashing.go +++ b/utils/hashing/hashing.go @@ -9,7 +9,11 @@ import ( "fmt" "io" - "golang.org/x/crypto/ripemd160" + // This algorithm does not represent a security risk since it is + // only used to convert a public key into an address during "Does + // this key own these funds" checks in the P-chain, X-chain, and + // C-chain. + "golang.org/x/crypto/ripemd160" //nolint:gosec ) const ( @@ -51,7 +55,8 @@ func ComputeHash160Array(buf []byte) Hash160 { // ComputeHash160 computes a cryptographically strong 160 bit hash of the input // byte slice. func ComputeHash160(buf []byte) []byte { - ripe := ripemd160.New() + // See comment on the import for why this is not a security risk + ripe := ripemd160.New() //nolint:gosec _, err := io.Writer(ripe).Write(buf) if err != nil { panic(err) diff --git a/utils/json/float32_test.go b/utils/json/float32_test.go index 519ca7f4d561..57b020a9aea9 100644 --- a/utils/json/float32_test.go +++ b/utils/json/float32_test.go @@ -50,7 +50,7 @@ func TestFloat32(t *testing.T) { for _, tt := range tests { jsonBytes, err := tt.f.MarshalJSON() require.NoError(err) - require.Equal(fmt.Sprintf(`"%s"`, tt.expectedStr), string(jsonBytes)) + require.JSONEq(fmt.Sprintf(`"%s"`, tt.expectedStr), string(jsonBytes)) var f Float32 require.NoError(f.UnmarshalJSON(jsonBytes)) diff --git a/utils/set/sampleable_set_test.go b/utils/set/sampleable_set_test.go index 31bd07712db5..8933743560c8 100644 --- a/utils/set/sampleable_set_test.go +++ b/utils/set/sampleable_set_test.go @@ -65,7 +65,7 @@ func TestSampleableSetMarshalJSON(t *testing.T) { { asJSON, err := set.MarshalJSON() require.NoError(err) - require.Equal("[]", string(asJSON)) + require.JSONEq("[]", string(asJSON)) } id1, id2 := 1, 2 id1JSON, err := json.Marshal(id1) @@ -76,13 +76,13 @@ func TestSampleableSetMarshalJSON(t *testing.T) { { asJSON, err := set.MarshalJSON() require.NoError(err) - require.Equal(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON)) + require.JSONEq(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON)) } set.Add(id2) { asJSON, err := set.MarshalJSON() require.NoError(err) - require.Equal(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON)) + require.JSONEq(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON)) } } diff --git a/utils/set/set_test.go b/utils/set/set_test.go index 3b0a7e1822f8..7f5b2f0a1fc7 100644 --- a/utils/set/set_test.go +++ b/utils/set/set_test.go @@ -134,7 +134,7 @@ func TestSetMarshalJSON(t *testing.T) { { asJSON, err := set.MarshalJSON() require.NoError(err) - require.Equal("[]", string(asJSON)) + require.JSONEq("[]", string(asJSON)) } id1, id2 := 1, 2 id1JSON, err := json.Marshal(id1) @@ -145,13 +145,13 @@ func TestSetMarshalJSON(t *testing.T) { { asJSON, err := set.MarshalJSON() require.NoError(err) - require.Equal(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON)) + require.JSONEq(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON)) } set.Add(id2) { asJSON, err := set.MarshalJSON() require.NoError(err) - require.Equal(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON)) + require.JSONEq(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON)) } } @@ -207,7 +207,7 @@ func TestSetReflectJSONMarshal(t *testing.T) { { asJSON, err := json.Marshal(set) require.NoError(err) - require.Equal("[]", string(asJSON)) + require.JSONEq("[]", string(asJSON)) } id1JSON, err := json.Marshal(1) require.NoError(err) @@ -217,12 +217,12 @@ func TestSetReflectJSONMarshal(t *testing.T) { { asJSON, err := json.Marshal(set) require.NoError(err) - require.Equal(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON)) + require.JSONEq(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON)) } set.Add(2) { asJSON, err := json.Marshal(set) require.NoError(err) - require.Equal(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON)) + require.JSONEq(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON)) } } diff --git a/vms/avm/index_test.go b/vms/avm/index_test.go index dfd62198c312..8e5c91566a24 100644 --- a/vms/avm/index_test.go +++ b/vms/avm/index_test.go @@ -320,7 +320,6 @@ func initTestTxIndex(t *testing.T, db *versiondb.Database, address ids.ShortID, for i, txID := range testTxs { idxBytes := database.PackUInt64(uint64(i)) - txID := txID require.NoError(assetPrefixDB.Put(idxBytes, txID[:])) } _, err := db.CommitBatch() diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index c6e20c6ecb51..e861fc7f9fee 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -3029,7 +3029,7 @@ func TestServiceGetBlock(t *testing.T) { expectedJSON, err := json.Marshal(expected) require.NoError(err) - require.Equal(json.RawMessage(expectedJSON), reply.Block) + require.JSONEq(string(expectedJSON), string(reply.Block)) }) } } @@ -3235,7 +3235,7 @@ func TestServiceGetBlockByHeight(t *testing.T) { expectedJSON, err := json.Marshal(expected) require.NoError(err) - require.Equal(json.RawMessage(expectedJSON), reply.Block) + require.JSONEq(string(expectedJSON), string(reply.Block)) }) } } diff --git a/vms/avm/state/state.go b/vms/avm/state/state.go index 4230a4f72bdf..9c49fa119e75 100644 --- a/vms/avm/state/state.go +++ b/vms/avm/state/state.go @@ -447,7 +447,6 @@ func (s *state) writeUTXOs() error { func (s *state) writeTxs() error { for txID, tx := range s.addedTxs { - txID := txID txBytes := tx.Bytes() delete(s.addedTxs, txID) @@ -474,7 +473,6 @@ func (s *state) writeBlockIDs() error { func (s *state) writeBlocks() error { for blkID, blk := range s.addedBlocks { - blkID := blkID blkBytes := blk.Bytes() delete(s.addedBlocks, blkID) diff --git a/vms/avm/utxo/spender.go b/vms/avm/utxo/spender.go index 1c6fd0142b88..42f3b4db5dab 100644 --- a/vms/avm/utxo/spender.go +++ b/vms/avm/utxo/spender.go @@ -189,9 +189,6 @@ func (s *spender) SpendNFT( keys := [][]*secp256k1.PrivateKey{} for _, utxo := range utxos { - // makes sure that the variable isn't overwritten with the next iteration - utxo := utxo - if len(ops) > 0 { // we have already been able to create the operation needed break @@ -311,9 +308,6 @@ func (s *spender) Mint( keys := [][]*secp256k1.PrivateKey{} for _, utxo := range utxos { - // makes sure that the variable isn't overwritten with the next iteration - utxo := utxo - assetID := utxo.AssetID() amount := amounts[assetID] if amount == 0 { @@ -385,9 +379,6 @@ func (s *spender) MintNFT( keys := [][]*secp256k1.PrivateKey{} for _, utxo := range utxos { - // makes sure that the variable isn't overwritten with the next iteration - utxo := utxo - if len(ops) > 0 { // we have already been able to create the operation needed break diff --git a/vms/platformvm/block/serialization_test.go b/vms/platformvm/block/serialization_test.go index 8e2002c3636c..f5d46b47d25e 100644 --- a/vms/platformvm/block/serialization_test.go +++ b/vms/platformvm/block/serialization_test.go @@ -142,7 +142,7 @@ func TestBanffProposalBlockJSON(t *testing.T) { simpleBanffProposalBlockBytes, err := json.MarshalIndent(simpleBanffProposalBlock, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "time": 123456, "txs": null, "parentID": "rVcYrvnGXdoJBeYQRm5ZNaCGHeVyqcHHJu8Yd89kJcef6V5Eg", @@ -186,7 +186,7 @@ func TestBanffProposalBlockJSON(t *testing.T) { complexBanffProposalBlockBytes, err := json.MarshalIndent(complexBanffProposalBlock, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "time": 123456, "txs": [ { diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 9e05dada0c7b..5e2eb96eac99 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -427,7 +427,7 @@ func TestGetTx(t *testing.T) { tx.Unsigned.InitCtx(service.vm.ctx) expectedTxJSON, err := json.Marshal(tx) require.NoError(err) - require.Equal(expectedTxJSON, []byte(response.Tx)) + require.JSONEq(string(expectedTxJSON), string(response.Tx)) } }) } @@ -1043,7 +1043,7 @@ func TestGetBlock(t *testing.T) { statelessBlock.InitCtx(service.vm.ctx) expectedBlockJSON, err := json.Marshal(statelessBlock) require.NoError(err) - require.Equal(expectedBlockJSON, []byte(response.Block)) + require.JSONEq(string(expectedBlockJSON), string(response.Block)) default: var blockStr string require.NoError(json.Unmarshal(response.Block, &blockStr)) @@ -1276,7 +1276,7 @@ func TestServiceGetBlockByHeight(t *testing.T) { expectedJSON, err := json.Marshal(expected) require.NoError(err) - require.Equal(json.RawMessage(expectedJSON), reply.Block) + require.JSONEq(string(expectedJSON), string(reply.Block)) }) } } diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index 95d973b2e4ed..3c5cf60efcdd 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -2266,7 +2266,6 @@ func (s *state) CommitBatch() (database.Batch, error) { func (s *state) writeBlocks() error { for blkID, blk := range s.addedBlocks { - blkID := blkID blkBytes := blk.Bytes() blkHeight := blk.Height() heightKey := database.PackUInt64(blkHeight) @@ -2889,8 +2888,6 @@ func (s *state) writeL1Validators() error { func (s *state) writeTXs() error { for txID, txStatus := range s.addedTxs { - txID := txID - stx := txBytesAndStatus{ Tx: txStatus.tx.Bytes(), Status: txStatus.status, @@ -2965,8 +2962,6 @@ func (s *state) writeSubnets() error { func (s *state) writeSubnetOwners() error { for subnetID, owner := range s.subnetOwners { - subnetID := subnetID - owner := owner delete(s.subnetOwners, subnetID) ownerBytes, err := block.GenesisCodec.Marshal(block.CodecVersion, &owner) @@ -3022,7 +3017,6 @@ func (s *state) writeTransformedSubnets() error { func (s *state) writeSubnetSupplies() error { for subnetID, supply := range s.modifiedSupplies { - supply := supply delete(s.modifiedSupplies, subnetID) s.supplyCache.Put(subnetID, &supply) if err := database.PutUInt64(s.supplyDB, subnetID[:], supply); err != nil { diff --git a/vms/platformvm/txs/add_permissionless_delegator_tx_test.go b/vms/platformvm/txs/add_permissionless_delegator_tx_test.go index 7f5625b6e50c..7a00a9c8995c 100644 --- a/vms/platformvm/txs/add_permissionless_delegator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_delegator_tx_test.go @@ -615,7 +615,7 @@ func TestAddPermissionlessPrimaryDelegatorSerialization(t *testing.T) { unsignedComplexAddPrimaryTxJSONBytes, err := json.MarshalIndent(unsignedComplexAddPrimaryTx, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "networkID": 1, "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ @@ -1371,7 +1371,7 @@ func TestAddPermissionlessSubnetDelegatorSerialization(t *testing.T) { unsignedComplexAddSubnetTxJSONBytes, err := json.MarshalIndent(unsignedComplexAddSubnetTx, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "networkID": 1, "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ diff --git a/vms/platformvm/txs/base_tx_test.go b/vms/platformvm/txs/base_tx_test.go index 14bfc7b2f236..e301fdf28438 100644 --- a/vms/platformvm/txs/base_tx_test.go +++ b/vms/platformvm/txs/base_tx_test.go @@ -374,7 +374,7 @@ func TestBaseTxSerialization(t *testing.T) { unsignedComplexBaseTxJSONBytes, err := json.MarshalIndent(unsignedComplexBaseTx, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "networkID": 1, "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ diff --git a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index 0d93f0bd41d0..1192b2c52997 100644 --- a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -6,7 +6,6 @@ package txs import ( "encoding/hex" "encoding/json" - "strings" "testing" "github.com/stretchr/testify/require" @@ -540,11 +539,7 @@ func TestConvertSubnetToL1TxSerialization(t *testing.T) { txJSON, err := json.MarshalIndent(test.tx, "", "\t") require.NoError(err) - require.Equal( - // Normalize newlines for Windows - strings.ReplaceAll(string(test.expectedJSON), "\r\n", "\n"), - string(txJSON), - ) + require.JSONEq(string(test.expectedJSON), string(txJSON)) }) } } diff --git a/vms/platformvm/txs/disable_l1_validator_tx_test.go b/vms/platformvm/txs/disable_l1_validator_tx_test.go index 393140048b7e..3c9304be53fe 100644 --- a/vms/platformvm/txs/disable_l1_validator_tx_test.go +++ b/vms/platformvm/txs/disable_l1_validator_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "encoding/json" - "strings" "testing" "github.com/stretchr/testify/require" @@ -315,11 +314,7 @@ func TestDisableL1ValidatorTxSerialization(t *testing.T) { txJSON, err := json.MarshalIndent(unsignedTx, "", "\t") require.NoError(err) - require.Equal( - // Normalize newlines for Windows - strings.ReplaceAll(string(disableL1ValidatorTxJSON), "\r\n", "\n"), - string(txJSON), - ) + require.JSONEq(string(disableL1ValidatorTxJSON), string(txJSON)) } func TestDisableL1ValidatorTxSyntacticVerify(t *testing.T) { diff --git a/vms/platformvm/txs/increase_l1_validator_balance_tx_test.go b/vms/platformvm/txs/increase_l1_validator_balance_tx_test.go index 112782777e64..c3b1bc9a5580 100644 --- a/vms/platformvm/txs/increase_l1_validator_balance_tx_test.go +++ b/vms/platformvm/txs/increase_l1_validator_balance_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "encoding/json" - "strings" "testing" "github.com/stretchr/testify/require" @@ -309,11 +308,7 @@ func TestIncreaseL1ValidatorBalanceTxSerialization(t *testing.T) { txJSON, err := json.MarshalIndent(unsignedTx, "", "\t") require.NoError(err) - require.Equal( - // Normalize newlines for Windows - strings.ReplaceAll(string(increaseL1ValidatorBalanceTxJSON), "\r\n", "\n"), - string(txJSON), - ) + require.JSONEq(string(increaseL1ValidatorBalanceTxJSON), string(txJSON)) } func TestIncreaseL1ValidatorBalanceTxSyntacticVerify(t *testing.T) { diff --git a/vms/platformvm/txs/register_l1_validator_tx_test.go b/vms/platformvm/txs/register_l1_validator_tx_test.go index d1751d1c9061..5c1f126ac64c 100644 --- a/vms/platformvm/txs/register_l1_validator_tx_test.go +++ b/vms/platformvm/txs/register_l1_validator_tx_test.go @@ -6,7 +6,6 @@ package txs import ( "encoding/hex" "encoding/json" - "strings" "testing" "github.com/stretchr/testify/require" @@ -327,11 +326,7 @@ func TestRegisterL1ValidatorTxSerialization(t *testing.T) { txJSON, err := json.MarshalIndent(unsignedTx, "", "\t") require.NoError(err) - require.Equal( - // Normalize newlines for Windows - strings.ReplaceAll(string(registerL1ValidatorTxJSON), "\r\n", "\n"), - string(txJSON), - ) + require.JSONEq(string(registerL1ValidatorTxJSON), string(txJSON)) } func TestRegisterL1ValidatorTxSyntacticVerify(t *testing.T) { diff --git a/vms/platformvm/txs/remove_subnet_validator_tx_test.go b/vms/platformvm/txs/remove_subnet_validator_tx_test.go index 605190977957..33f30a4787d0 100644 --- a/vms/platformvm/txs/remove_subnet_validator_tx_test.go +++ b/vms/platformvm/txs/remove_subnet_validator_tx_test.go @@ -432,7 +432,7 @@ func TestRemoveSubnetValidatorTxSerialization(t *testing.T) { unsignedComplexRemoveValidatorTxJSONBytes, err := json.MarshalIndent(unsignedComplexRemoveValidatorTx, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "networkID": 1, "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ diff --git a/vms/platformvm/txs/set_l1_validator_weight_tx_test.go b/vms/platformvm/txs/set_l1_validator_weight_tx_test.go index 54bd1e979871..086ae4e8510e 100644 --- a/vms/platformvm/txs/set_l1_validator_weight_tx_test.go +++ b/vms/platformvm/txs/set_l1_validator_weight_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "encoding/json" - "strings" "testing" "github.com/stretchr/testify/require" @@ -299,11 +298,7 @@ func TestSetL1ValidatorWeightTxSerialization(t *testing.T) { txJSON, err := json.MarshalIndent(unsignedTx, "", "\t") require.NoError(err) - require.Equal( - // Normalize newlines for Windows - strings.ReplaceAll(string(setL1ValidatorWeightTxJSON), "\r\n", "\n"), - string(txJSON), - ) + require.JSONEq(string(setL1ValidatorWeightTxJSON), string(txJSON)) } func TestSetL1ValidatorWeightTxSyntacticVerify(t *testing.T) { diff --git a/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go b/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go index a84a1492920e..f34b4ddc6596 100644 --- a/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go +++ b/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go @@ -453,7 +453,7 @@ func TestTransferSubnetOwnershipTxSerialization(t *testing.T) { unsignedComplexTransferSubnetOwnershipTxJSONBytes, err := json.MarshalIndent(unsignedComplexTransferSubnetOwnershipTx, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "networkID": 1, "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ diff --git a/vms/platformvm/txs/transform_subnet_tx_test.go b/vms/platformvm/txs/transform_subnet_tx_test.go index f007a49e32b7..4b9dc797b56c 100644 --- a/vms/platformvm/txs/transform_subnet_tx_test.go +++ b/vms/platformvm/txs/transform_subnet_tx_test.go @@ -535,7 +535,7 @@ func TestTransformSubnetTxSerialization(t *testing.T) { unsignedComplexTransformTxJSONBytes, err := json.MarshalIndent(unsignedComplexTransformTx, "", "\t") require.NoError(err) - require.Equal(`{ + require.JSONEq(`{ "networkID": 1, "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ diff --git a/vms/secp256k1fx/output_owners_test.go b/vms/secp256k1fx/output_owners_test.go index 02b41f687d28..fa2d6c068fef 100644 --- a/vms/secp256k1fx/output_owners_test.go +++ b/vms/secp256k1fx/output_owners_test.go @@ -163,5 +163,5 @@ func TestMarshalJSONDoesNotRequireCtx(t *testing.T) { b, err := out.MarshalJSON() require.NoError(err) - require.Equal(`{"addresses":["6HgC8KRBEhXYbF4riJyJFLSHt37UNuRt","111111111111111111116DBWJs"],"locktime":2,"threshold":1}`, string(b)) + require.JSONEq(`{"addresses":["6HgC8KRBEhXYbF4riJyJFLSHt37UNuRt","111111111111111111116DBWJs"],"locktime":2,"threshold":1}`, string(b)) } diff --git a/vms/types/blob_data_test.go b/vms/types/blob_data_test.go index 82c692a9468e..7ea8bc59151f 100644 --- a/vms/types/blob_data_test.go +++ b/vms/types/blob_data_test.go @@ -38,7 +38,7 @@ func TestJSON(t *testing.T) { jsonBytes, err := json.Marshal(test.value) require.NoError(err) - require.Equal(test.expectedJSON, string(jsonBytes)) + require.JSONEq(test.expectedJSON, string(jsonBytes)) var unmarshaled JSONByteSlice require.NoError(json.Unmarshal(jsonBytes, &unmarshaled)) diff --git a/x/merkledb/key_test.go b/x/merkledb/key_test.go index d2e4e3001400..b60dc1c01f4e 100644 --- a/x/merkledb/key_test.go +++ b/x/merkledb/key_test.go @@ -253,7 +253,6 @@ func Test_Key_Token(t *testing.T) { } for i := 0; i < 256; i++ { - i := i tests = append(tests, test{ name: fmt.Sprintf("branch factor 256, byte %d", i), inputBytes: []byte{byte(i)}, diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index a938ee80faf0..612b3b08ba30 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -75,7 +75,6 @@ func (node *ProofNode) ToProto() *pb.ProofNode { } for childIndex, childID := range node.Children { - childID := childID pbNode.Children[uint32(childIndex)] = childID[:] }