Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clients/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (

// Polygon is the string representation of the Polygon chain
Polygon Chain = "Polygon"

// Sui is the string representation of the Sui chain
Sui Chain = "Sui"
)

// ToLower returns the lowercase string of chain
Expand Down
21 changes: 21 additions & 0 deletions clients/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,25 @@ var (

// ErrNilCryptoHandler signals that a nil crypto handler was provided
ErrNilCryptoHandler = errors.New("nil crypto handler")

// ErrInvalidGasLimit signals that gas limit is invalid
ErrInvalidGasLimit = errors.New("invalid gas limit")

// ErrNilClientWrapper signals that a nil client wrapper was provided
ErrNilClientWrapper = errors.New("nil client wrapper")

// ErrDepositsAndBatchDepositsCountDiffer signals that the deposits count and batch deposits count differ
ErrDepositsAndBatchDepositsCountDiffer = errors.New("deposits and batch.DepositsCount differs")

// ErrStatusIsNotFinal signals that the status is not final
ErrStatusIsNotFinal = errors.New("status is not final")

// ErrQuorumNotReached signals that the quorum was not reached
ErrQuorumNotReached = errors.New("quorum not reached")

// ErrNilBroadcaster signals that a nil broadcaster was provided
ErrNilBroadcaster = errors.New("nil broadcaster")

// ErrNilSignaturesHolder signals that a nil signature holder was provided
ErrNilSignaturesHolder = errors.New("nil signatures holder")
)
16 changes: 8 additions & 8 deletions clients/ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewEthereumClient(args ArgsEthereumClient) (*client, error) {

func checkArgs(args ArgsEthereumClient) error {
if check.IfNil(args.ClientWrapper) {
return errNilClientWrapper
return clients.ErrNilClientWrapper
}
if check.IfNil(args.Erc20ContractsHandler) {
return errNilERC20ContractsHandler
Expand All @@ -112,7 +112,7 @@ func checkArgs(args ArgsEthereumClient) error {
return clients.ErrNilAddressConverter
}
if check.IfNil(args.Broadcaster) {
return errNilBroadcaster
return clients.ErrNilBroadcaster
}
if check.IfNil(args.CryptoHandler) {
return clients.ErrNilCryptoHandler
Expand All @@ -121,16 +121,16 @@ func checkArgs(args ArgsEthereumClient) error {
return clients.ErrNilTokensMapper
}
if check.IfNil(args.SignatureHolder) {
return errNilSignaturesHolder
return clients.ErrNilSignaturesHolder
}
if check.IfNil(args.GasHandler) {
return errNilGasHandler
}
if args.TransferGasLimitBase == 0 {
return errInvalidGasLimit
return clients.ErrInvalidGasLimit
}
if args.TransferGasLimitForEach == 0 {
return errInvalidGasLimit
return clients.ErrInvalidGasLimit
}
if args.ClientAvailabilityAllowDelta < minClientAvailabilityAllowDelta {
return fmt.Errorf("%w for args.AllowedDelta, got: %d, minimum: %d",
Expand All @@ -157,7 +157,7 @@ func (c *client) GetBatch(ctx context.Context, nonce uint64) (*bridgeCore.Transf
}
if int(batch.DepositsCount) != len(deposits) {
return nil, false, fmt.Errorf("%w, batch.DepositsCount: %d, fetched deposits len: %d",
errDepositsAndBatchDepositsCountDiffer, batch.DepositsCount, len(deposits))
clients.ErrDepositsAndBatchDepositsCountDiffer, batch.DepositsCount, len(deposits))
}

transferBatch := &bridgeCore.TransferBatch{
Expand Down Expand Up @@ -359,7 +359,7 @@ func (c *client) ExecuteTransfer(

signatures := c.signatureHolder.Signatures(msgHash.Bytes())
if len(signatures) < quorum {
return "", fmt.Errorf("%w num signatures: %d, quorum: %d", errQuorumNotReached, len(signatures), quorum)
return "", fmt.Errorf("%w num signatures: %d, quorum: %d", clients.ErrQuorumNotReached, len(signatures), quorum)
}
if len(signatures) > quorum {
c.log.Debug("reducing the size of the signatures set",
Expand Down Expand Up @@ -524,7 +524,7 @@ func (c *client) GetTransactionsStatuses(ctx context.Context, batchId uint64) ([
return nil, err
}
if !isFinal {
return nil, errStatusIsNotFinal
return nil, clients.ErrStatusIsNotFinal
}

return buff, nil
Expand Down
18 changes: 9 additions & 9 deletions clients/ethereum/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestNewEthereumClient(t *testing.T) {
args.ClientWrapper = nil
c, err := NewEthereumClient(args)

assert.Equal(t, errNilClientWrapper, err)
assert.Equal(t, clients.ErrNilClientWrapper, err)
assert.True(t, check.IfNil(c))
})
t.Run("nil erc20 contracts handler", func(t *testing.T) {
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestNewEthereumClient(t *testing.T) {
args.Broadcaster = nil
c, err := NewEthereumClient(args)

assert.Equal(t, errNilBroadcaster, err)
assert.Equal(t, clients.ErrNilBroadcaster, err)
assert.True(t, check.IfNil(c))
})
t.Run("nil crypto handler", func(t *testing.T) {
Expand All @@ -155,7 +155,7 @@ func TestNewEthereumClient(t *testing.T) {
args.SignatureHolder = nil
c, err := NewEthereumClient(args)

assert.Equal(t, errNilSignaturesHolder, err)
assert.Equal(t, clients.ErrNilSignaturesHolder, err)
assert.True(t, check.IfNil(c))
})
t.Run("nil gas handler", func(t *testing.T) {
Expand All @@ -171,15 +171,15 @@ func TestNewEthereumClient(t *testing.T) {
args.TransferGasLimitBase = 0
c, err := NewEthereumClient(args)

assert.Equal(t, errInvalidGasLimit, err)
assert.Equal(t, clients.ErrInvalidGasLimit, err)
assert.True(t, check.IfNil(c))
})
t.Run("0 transfer gas limit for each", func(t *testing.T) {
args := createMockEthereumClientArgs()
args.TransferGasLimitForEach = 0
c, err := NewEthereumClient(args)

assert.Equal(t, errInvalidGasLimit, err)
assert.Equal(t, clients.ErrInvalidGasLimit, err)
assert.True(t, check.IfNil(c))
})
t.Run("invalid ClientAvailabilityAllowDelta should error", func(t *testing.T) {
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestClient_GetBatch(t *testing.T) {
}
batch, isFinal, err := c.GetBatch(context.Background(), 1)
assert.Nil(t, batch)
assert.True(t, errors.Is(err, errDepositsAndBatchDepositsCountDiffer))
assert.True(t, errors.Is(err, clients.ErrDepositsAndBatchDepositsCountDiffer))
assert.True(t, strings.Contains(err.Error(), "batch.DepositsCount: 2, fetched deposits len: 0"))
assert.False(t, isFinal)
})
Expand All @@ -288,7 +288,7 @@ func TestClient_GetBatch(t *testing.T) {
}
batch, isFinal, err := c.GetBatch(context.Background(), 1)
assert.Nil(t, batch)
assert.True(t, errors.Is(err, errDepositsAndBatchDepositsCountDiffer))
assert.True(t, errors.Is(err, clients.ErrDepositsAndBatchDepositsCountDiffer))
assert.True(t, strings.Contains(err.Error(), "batch.DepositsCount: 2, fetched deposits len: 1"))
assert.False(t, isFinal)
})
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestClient_ExecuteTransfer(t *testing.T) {
}
hash, err := c.ExecuteTransfer(context.Background(), common.Hash{}, argLists, batch.ID, 10)
assert.Equal(t, "", hash)
assert.True(t, errors.Is(err, errQuorumNotReached))
assert.True(t, errors.Is(err, clients.ErrQuorumNotReached))
assert.True(t, strings.Contains(err.Error(), "num signatures: 9, quorum: 10"))
})
t.Run("not enough balance for fees", func(t *testing.T) {
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func TestClient_GetTransactionsStatuses(t *testing.T) {
c, _ := NewEthereumClient(args)
statuses, err := c.GetTransactionsStatuses(context.Background(), expectedBatchID.Uint64())
assert.Nil(t, statuses)
assert.Equal(t, errStatusIsNotFinal, err)
assert.Equal(t, clients.ErrStatusIsNotFinal, err)
})
t.Run("should work", func(t *testing.T) {
t.Parallel()
Expand Down
19 changes: 6 additions & 13 deletions clients/ethereum/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ package ethereum
import "errors"

var (
errQuorumNotReached = errors.New("quorum not reached")
errInsufficientErc20Balance = errors.New("insufficient ERC20 balance")
errInsufficientBalance = errors.New("insufficient balance")
errPublicKeyCast = errors.New("error casting public key to ECDSA")
errNilClientWrapper = errors.New("nil client wrapper")
errNilERC20ContractsHandler = errors.New("nil ERC20 contracts handler")
errNilBroadcaster = errors.New("nil broadcaster")
errNilSignaturesHolder = errors.New("nil signatures holder")
errNilGasHandler = errors.New("nil gas handler")
errInvalidGasLimit = errors.New("invalid gas limit")
errNilEthClient = errors.New("nil eth client")
errDepositsAndBatchDepositsCountDiffer = errors.New("deposits and batch.DepositsCount differs")
errStatusIsNotFinal = errors.New("status is not final")
errInsufficientErc20Balance = errors.New("insufficient ERC20 balance")
errInsufficientBalance = errors.New("insufficient balance")
errPublicKeyCast = errors.New("error casting public key to ECDSA")
errNilERC20ContractsHandler = errors.New("nil ERC20 contracts handler")
errNilGasHandler = errors.New("nil gas handler")
errNilEthClient = errors.New("nil eth client")
)
2 changes: 1 addition & 1 deletion clients/ethereum/wrappers/ethereumChainWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (wrapper *ethereumChainWrapper) NativeTokens(ctx context.Context, token com
return wrapper.safeContract.NativeTokens(&bind.CallOpts{Context: ctx}, token)
}

// WhitelistedTokens returns true if the token is a native token
// WhitelistedTokens returns true if the token is a whitelisted
func (wrapper *ethereumChainWrapper) WhitelistedTokens(ctx context.Context, token common.Address) (bool, error) {
wrapper.AddIntMetric(core.MetricNumEthClientRequests, 1)
return wrapper.safeContract.WhitelistedTokens(&bind.CallOpts{Context: ctx}, token)
Expand Down
Loading
Loading