-
Notifications
You must be signed in to change notification settings - Fork 1
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 #13 from scorum/betting
Betting
- Loading branch information
Showing
15 changed files
with
1,069 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package betting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/scorum/scorum-go/transport/http" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const nodeHTTPS = "https://testnet.scorum.com" | ||
|
||
func TestGetGameWinners(t *testing.T) { | ||
t.Skip("need to start and finish game to get results") | ||
transport := http.NewTransport(nodeHTTPS) | ||
api := NewAPI(transport) | ||
|
||
uuid, err := uuid.Parse("3bd3fb0a-4c3c-4103-b736-61849157062a") | ||
require.NoError(t, err) | ||
|
||
winners, err := api.GetGameWinners(uuid) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, winners) | ||
} |
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
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,53 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/pkg/errors" | ||
"reflect" | ||
) | ||
|
||
const ( | ||
SoccerGameType = 0 | ||
HockeyGameType = 1 | ||
) | ||
|
||
var ( | ||
errUnsupportedGameType = errors.New("unsupported game type") | ||
) | ||
|
||
type GameType uint8 | ||
|
||
var GameTypeNames = map[GameType]string{ | ||
SoccerGameType: "soccer_game", | ||
HockeyGameType: "hockey_game", | ||
} | ||
|
||
func (g GameType) MarshalJSON() ([]byte, error) { | ||
var err error | ||
|
||
a := make([]json.RawMessage, 2) | ||
a[0], err = json.Marshal(GameTypeNames[g]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
a[1] = json.RawMessage("{}") | ||
|
||
return json.Marshal(a) | ||
} | ||
|
||
func (g *GameType) UnmarshalJSON(b []byte) error { | ||
var gt []interface{} | ||
if err := json.Unmarshal(b, >); err != nil { | ||
return err | ||
} | ||
|
||
gName := gt[0].(string) | ||
for k, v := range GameTypeNames { | ||
if v == gName { | ||
reflect.Indirect(reflect.ValueOf(g)).SetUint(uint64(k)) | ||
return nil | ||
} | ||
} | ||
|
||
return errUnsupportedGameType | ||
} |
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,30 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
const ( | ||
testGameSoccerJSON = `["soccer_game",{}]` | ||
testGameHockeyJSON = `["hockey_game",{}]` | ||
testGameUnsupportedJSON = `["doka2_trade_game",{}]` | ||
) | ||
|
||
func TestGameSocckerUnmarshalJSON(t *testing.T) { | ||
var game GameType | ||
require.NoError(t, json.Unmarshal([]byte(testGameSoccerJSON), &game)) | ||
require.EqualValues(t, 0, game) | ||
} | ||
|
||
func TestGameHockeyUnmarshalJSON(t *testing.T) { | ||
var game GameType | ||
require.NoError(t, json.Unmarshal([]byte(testGameHockeyJSON), &game)) | ||
require.EqualValues(t, 1, game) | ||
} | ||
|
||
func TestUnsupportedUnmarshalJSON(t *testing.T) { | ||
var game GameType | ||
require.Error(t, json.Unmarshal([]byte(testGameUnsupportedJSON), &game)) | ||
} |
Oops, something went wrong.