Skip to content

Commit

Permalink
Add check less than 0 when create auction details
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisngyn committed Aug 19, 2024
1 parent 1fcc00b commit d520732
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions pkg/oneinch/fusionorder/auction_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"

"github.com/KyberNetwork/tradinglib/pkg/oneinch/decode"
"github.com/ethereum/go-ethereum/common/math"
)
Expand All @@ -13,11 +14,11 @@ const (
)

var (
ErrGasBumpEstimateTooLarge = errors.New("gas bump estimate is too large")
ErrGasPriceEstimateTooLarge = errors.New("gas price estimate is too large")
ErrStartTimeTooLarge = errors.New("start time is too large")
ErrDurationTooLarge = errors.New("duration is too large")
ErrInitialRateBumpTooLarge = errors.New("initial rate bump is too large")
ErrGasBumpEstimateInvalid = errors.New("gas bump estimate is invalid")
ErrGasPriceEstimateInvalid = errors.New("gas price estimate is invalid")
ErrStartTimeInvalid = errors.New("start time is invalid")
ErrDurationInvalid = errors.New("duration is invalid")
ErrInitialRateBumpInvalid = errors.New("initial rate bump is invalid")
)

type AuctionDetails struct {
Expand All @@ -35,20 +36,20 @@ func NewAuctionDetails(
points []AuctionPoint,
gasCost AuctionGasCostInfo,
) (AuctionDetails, error) {
if gasCost.GasBumpEstimate > MaxUint24 {
return AuctionDetails{}, ErrGasBumpEstimateTooLarge
if gasCost.GasBumpEstimate > MaxUint24 || gasCost.GasBumpEstimate < 0 {
return AuctionDetails{}, ErrGasBumpEstimateInvalid
}
if gasCost.GasPriceEstimate > math.MaxUint32 {
return AuctionDetails{}, ErrGasPriceEstimateTooLarge
if gasCost.GasPriceEstimate > math.MaxUint32 || gasCost.GasPriceEstimate < 0 {
return AuctionDetails{}, ErrGasPriceEstimateInvalid
}
if startTime > math.MaxUint32 {
return AuctionDetails{}, ErrStartTimeTooLarge
if startTime > math.MaxUint32 || startTime <= 0 {
return AuctionDetails{}, ErrStartTimeInvalid
}
if duration > MaxUint24 {
return AuctionDetails{}, ErrDurationTooLarge
if duration > MaxUint24 || duration <= 0 {
return AuctionDetails{}, ErrDurationInvalid
}
if initialRateBump > MaxUint24 {
return AuctionDetails{}, ErrInitialRateBumpTooLarge
if initialRateBump > MaxUint24 || initialRateBump < 0 {
return AuctionDetails{}, ErrInitialRateBumpInvalid
}

return AuctionDetails{
Expand Down Expand Up @@ -143,7 +144,6 @@ func decodeAuctionPoints(data []byte) ([]AuctionPoint, error) {
Coefficient: int64(coefficient),
Delay: int64(delay),
})

}
return points, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oneinch/limitorder/extension_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package limitorder_test

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/KyberNetwork/tradinglib/pkg/oneinch/limitorder"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -30,7 +30,7 @@ func TestExtension(t *testing.T) {
require.Equal(t, extension, decodedExtension)
})

t.Run("decode emtpy", func(t *testing.T) {
t.Run("decode empty", func(t *testing.T) {
encodedExtension := "0x"
e, err := limitorder.DecodeExtension(encodedExtension)
require.NoError(t, err)
Expand Down

0 comments on commit d520732

Please sign in to comment.