-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from scorpioborn/refactor/bet-place-payload
Refactor/ App Keepers pointers and Bet
- Loading branch information
Showing
19 changed files
with
222 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/sge-network/sge/utils" | ||
) | ||
|
||
// BetFieldsValidation validates fields of the given bet | ||
func BetFieldsValidation(bet *PlaceBetFields) error { | ||
if !utils.IsValidUID(bet.UID) { | ||
return ErrInvalidBetUID | ||
} | ||
|
||
if bet.Amount.IsNil() || !bet.Amount.IsPositive() { | ||
return ErrInvalidAmount | ||
} | ||
|
||
if bet.Ticket == "" || strings.Contains(bet.Ticket, " ") { | ||
return ErrInvalidTicket | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/sge-network/sge/x/bet/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBetFieldsValidation(t *testing.T) { | ||
tcs := []struct { | ||
desc string | ||
bet *types.PlaceBetFields | ||
err error | ||
}{ | ||
{ | ||
desc: "space in UID", | ||
bet: &types.PlaceBetFields{ | ||
UID: " ", | ||
Amount: sdk.NewInt(int64(10)), | ||
Ticket: "Ticket", | ||
}, | ||
err: types.ErrInvalidBetUID, | ||
}, | ||
{ | ||
desc: "invalid UID", | ||
bet: &types.PlaceBetFields{ | ||
UID: "invalidUID", | ||
Amount: sdk.NewInt(int64(10)), | ||
Ticket: "Ticket", | ||
}, | ||
err: types.ErrInvalidBetUID, | ||
}, | ||
{ | ||
desc: "invalid amount", | ||
bet: &types.PlaceBetFields{ | ||
UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", | ||
Amount: sdk.NewInt(int64(-1)), | ||
Ticket: "Ticket", | ||
}, | ||
err: types.ErrInvalidAmount, | ||
}, | ||
{ | ||
desc: "empty amount", | ||
bet: &types.PlaceBetFields{ | ||
UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", | ||
Ticket: "Ticket", | ||
}, | ||
err: types.ErrInvalidAmount, | ||
}, | ||
{ | ||
desc: "space in ticket", | ||
bet: &types.PlaceBetFields{ | ||
UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", | ||
Amount: sdk.NewInt(int64(10)), | ||
Ticket: " ", | ||
}, | ||
err: types.ErrInvalidTicket, | ||
}, | ||
{ | ||
desc: "valid message", | ||
bet: &types.PlaceBetFields{ | ||
UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", | ||
Amount: sdk.NewInt(int64(10)), | ||
Ticket: "Ticket", | ||
}, | ||
}, | ||
} | ||
for _, tc := range tcs { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
err := types.BetFieldsValidation(tc.bet) | ||
if tc.err != nil { | ||
require.ErrorIs(t, err, tc.err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/sge-network/sge/utils" | ||
) | ||
|
||
// Validate validates fields of the given ticketData | ||
func (payload *BetPlacementTicketPayload) Validate(creator string) error { | ||
if payload.SelectedOdds == nil { | ||
return ErrOddsDataNotFound | ||
} | ||
|
||
if !payload.KycData.Validate(creator) { | ||
return sdkerrors.Wrapf(ErrUserKycFailed, "%s", creator) | ||
} | ||
|
||
if !utils.IsValidUID(payload.SelectedOdds.MarketUID) { | ||
return ErrInvalidMarketUID | ||
} | ||
|
||
if !utils.IsValidUID(payload.SelectedOdds.UID) { | ||
return ErrInvalidOddsUID | ||
} | ||
|
||
if len(strings.TrimSpace(payload.SelectedOdds.Value)) == 0 { | ||
return ErrEmptyOddsValue | ||
} | ||
|
||
if payload.SelectedOdds.MaxLossMultiplier.IsNil() || | ||
payload.SelectedOdds.MaxLossMultiplier.LTE(sdk.ZeroDec()) { | ||
return ErrMaxLossMultiplierCanNotBeZero | ||
} | ||
|
||
if payload.SelectedOdds.MaxLossMultiplier.GT(sdk.OneDec()) { | ||
return ErrMaxLossMultiplierCanNotBeMoreThanOne | ||
} | ||
|
||
if payload.OddsType < OddsType_ODDS_TYPE_DECIMAL || | ||
payload.OddsType > OddsType_ODDS_TYPE_MONEYLINE { | ||
return ErrInvalidOddsType | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.