Skip to content
Open
4 changes: 2 additions & 2 deletions .avalanche-golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ linters:
forbidigo:
# Forbid the following identifiers (list of regexp).
forbid:
# - pattern: require\.Error$(# ErrorIs should be used instead)?
# - pattern: require\.ErrorContains$(# ErrorIs should be used instead)?
- pattern: require\.Error$(# ErrorIs should be used instead)?
- pattern: require\.ErrorContains$(# ErrorIs should be used instead)?
# - pattern: require\.EqualValues$(# Equal should be used instead)?
# - pattern: require\.NotEqualValues$(# NotEqual should be used instead)?
- pattern: ^(t|b|tb|f)\.(Fatal|Fatalf|Error|Errorf)$(# the require library should be used instead)?
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/abi_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestUnpackInputIntoInterface(t *testing.T) {
err = abi.UnpackInputIntoInterface(&v, "receive", data, test.strictMode) // skips 4 byte selector

if test.expectedErrorSubstring != "" {
require.ErrorContains(t, err, test.expectedErrorSubstring)
require.ErrorContains(t, err, test.expectedErrorSubstring) //nolint:forbidigo // uses upstream code
} else {
require.NoError(t, err)
require.Equal(t, input, v)
Expand Down
3 changes: 2 additions & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (

var (
errAcquiringSemaphore = errors.New("error acquiring semaphore")
errEmptyNodeID = errors.New("cannot send request to empty nodeID")
errExpiredRequest = errors.New("expired request")
errNoPeersFound = errors.New("no peers found matching version")
_ Network = (*network)(nil)
Expand Down Expand Up @@ -187,7 +188,7 @@ func (n *network) SendAppRequestAny(ctx context.Context, minVersion *version.App
// SendAppRequest sends request message bytes to specified nodeID, notifying the responseHandler on response or failure
func (n *network) SendAppRequest(ctx context.Context, nodeID ids.NodeID, request []byte, responseHandler message.ResponseHandler) error {
if nodeID == ids.EmptyNodeID {
return fmt.Errorf("cannot send request to empty nodeID, nodeID=%s, requestLen=%d", nodeID, len(request))
return fmt.Errorf("%w, nodeID=%s, requestLen=%d", errEmptyNodeID, nodeID, len(request))
}

// If the context was cancelled, we can skip sending this request.
Expand Down
12 changes: 6 additions & 6 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,8 @@ func TestRequestRequestsRoutingAndResponse(t *testing.T) {
}

// ensure empty nodeID is not allowed
require.ErrorContains(t,
net.SendAppRequest(context.Background(), ids.EmptyNodeID, []byte("hello there"), nil),
"cannot send request to empty nodeID",
)
err = net.SendAppRequest(context.Background(), ids.EmptyNodeID, []byte("hello there"), nil)
require.ErrorIs(t, err, errEmptyNodeID)
}

func TestAppRequestOnShutdown(t *testing.T) {
Expand Down Expand Up @@ -554,7 +552,8 @@ func TestNetworkPropagatesRequestHandlerError(t *testing.T) {
ctx := snowtest.Context(t, snowtest.CChainID)
clientNetwork, err := NewNetwork(ctx, sender, codecManager, 1, prometheus.NewRegistry())
require.NoError(t, err)
clientNetwork.SetRequestHandler(&testRequestHandler{err: errors.New("fail")}) // Return an error from the request handler
errTest := errors.New("test error")
clientNetwork.SetRequestHandler(&testRequestHandler{err: errTest}) // Return an error from the request handler

require.NoError(t, clientNetwork.Connected(context.Background(), nodeID, defaultPeerVersion))

Expand All @@ -565,7 +564,8 @@ func TestNetworkPropagatesRequestHandlerError(t *testing.T) {
require.NoError(t, err)

// Check that if the request handler returns an error, it is propagated as a fatal error.
require.ErrorContains(t, clientNetwork.AppRequest(context.Background(), nodeID, requestID, time.Now().Add(time.Second), requestMessage), "fail")
err = clientNetwork.AppRequest(context.Background(), nodeID, requestID, time.Now().Add(time.Second), requestMessage)
require.ErrorIs(t, err, errTest)
}

func TestNetworkAppRequestAfterShutdown(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions plugin/evm/atomic/export_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ var (
_ secp256k1fx.UnsignedTx = (*UnsignedExportTx)(nil)
ErrExportNonAVAXInputBanff = errors.New("export input cannot contain non-AVAX in Banff")
ErrExportNonAVAXOutputBanff = errors.New("export output cannot contain non-AVAX in Banff")
ErrInsufficientFunds = errors.New("insufficient funds")
ErrInvalidNonce = errors.New("invalid nonce")
ErrNoExportOutputs = errors.New("tx has no export outputs")
errOverflowExport = errors.New("overflow when computing export amount + txFee")
errInsufficientFunds = errors.New("insufficient funds")
)

// UnsignedExportTx is an unsigned ExportTx
Expand Down Expand Up @@ -323,14 +323,14 @@ func (utx *UnsignedExportTx) EVMStateTransfer(ctx *snow.Context, state StateDB)
uint256.NewInt(X2CRate.Uint64()),
)
if state.GetBalance(from.Address).Cmp(amount) < 0 {
return errInsufficientFunds
return ErrInsufficientFunds
}
state.SubBalance(from.Address, amount)
} else {
log.Debug("export_tx", "dest", utx.DestinationChain, "addr", from.Address, "amount", from.Amount, "assetID", from.AssetID)
amount := new(big.Int).SetUint64(from.Amount)
if state.GetBalanceMultiCoin(from.Address, common.Hash(from.AssetID)).Cmp(amount) < 0 {
return errInsufficientFunds
return ErrInsufficientFunds
}
state.SubBalanceMultiCoin(from.Address, common.Hash(from.AssetID), amount)
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func getSpendableFunds(
}

if amount > 0 {
return nil, nil, errInsufficientFunds
return nil, nil, ErrInsufficientFunds
}

return inputs, signers, nil
Expand Down Expand Up @@ -487,7 +487,7 @@ func getSpendableAVAXWithFee(
}

if amount > 0 {
return nil, nil, errInsufficientFunds
return nil, nil, ErrInsufficientFunds
}

return inputs, signers, nil
Expand Down
3 changes: 2 additions & 1 deletion plugin/evm/atomic/state/atomic_trie_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ func TestIteratorHandlesInvalidData(t *testing.T) {
require.NoError(err)
for iter.Next() {
}
require.Error(iter.Error())
err = iter.Error()
require.ErrorIs(err, errKeyLength)
}
4 changes: 2 additions & 2 deletions plugin/evm/atomic/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
var (
ErrWrongNetworkID = errors.New("tx was issued with a different network ID")
ErrNilTx = errors.New("tx is nil")
errNoValueOutput = errors.New("output has no value")
ErrNoValueOutput = errors.New("output has no value")
ErrNoValueInput = errors.New("input has no value")
ErrNoGasUsed = errors.New("no gas used")
errNilOutput = errors.New("nil output")
Expand Down Expand Up @@ -97,7 +97,7 @@ func (out *EVMOutput) Verify() error {
case out == nil:
return errNilOutput
case out.Amount == 0:
return errNoValueOutput
return ErrNoValueOutput
case out.AssetID == ids.Empty:
return errEmptyAssetID
}
Expand Down
Loading
Loading