Skip to content

Commit

Permalink
changed Game from Enum to StaticVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
MKashevsky committed Oct 24, 2018
1 parent 9046bf3 commit 175a0c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
26 changes: 17 additions & 9 deletions scorum/graphenebase/betting/game.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import struct
from enum import Enum
from scorum.graphenebase.objects import GrapheneObject, StaticVariantObject

GAMES = [
'soccer_game',
'hockey_game'
]

class Game(Enum):
soccer = 0
hockey = 1

def __bytes__(self):
return struct.pack("<B", self.value)
class Game(StaticVariantObject):
def __init__(self, game_type):
super().__init__(game_type, GAMES)
self.name = self.get_name(game_type) + "_game"
self.id = self.get_id(self.name)

def __str__(self):
return "{0}".format(self.name)

class Soccer(GrapheneObject):
pass


class Hockey(GrapheneObject):
pass
39 changes: 20 additions & 19 deletions tests/graphenebase/test_betting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from binascii import hexlify

from scorum.graphenebase.betting import market, Game, Market, wincase, Wincase
from scorum.graphenebase.betting import game, Game, market, Market, wincase, Wincase
from scorum.graphenebase import operations_fabric as ops
from scorum.graphenebase.signedtransactions import SignedTransaction

Expand All @@ -11,12 +11,12 @@ def to_hex(data):
return hexlify(bytes(data))


@pytest.mark.parametrize('game,val', [
(Game.hockey, b'01'),
(Game.soccer, b'00')
@pytest.mark.parametrize('game_type,val', [
(game.Hockey(), b'01'),
(game.Soccer(), b'00')
])
def test_serialize_game_type_to_hex(game, val):
assert to_hex(game) == val
def test_serialize_game_type_to_hex(game_type, val):
assert to_hex(Game(game_type)) == val


@pytest.mark.parametrize('market_type, val', [
Expand Down Expand Up @@ -77,31 +77,32 @@ def test_serialize_wincases_to_hex(wincase_type, val):
assert to_hex(Wincase(wincase_type)) == val


@pytest.mark.parametrize('game,markets,result_bin', [
@pytest.mark.parametrize('game_type,market_types,result_bin', [
(
Game.soccer,
game.Soccer(),
[],
b'23e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e0967616d65206e616d659b2a645b210000000000'
),
(
Game.soccer,
game.Soccer(),
[market.Total(1000)],
b'23e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e0967616d65206e616d659b2a645b2100000000010ce803'
),
(
Game.hockey,
game.Hockey(),
[],
b'23e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e0967616d65206e616d659b2a645b210000000100'
),
(
Game.hockey,
game.Hockey(),
[market.CorrectScore(home=1, away=2)],
b'23e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e0967616d65206e616d659b2a645b2100000001010801000200'
)
])
def test_serialize_create_game_to_hex(game, markets, result_bin):
def test_serialize_create_game_to_hex(game_type, market_types, result_bin):
op = ops.create_game(
'e629f9aa-6b2c-46aa-8fa8-36770e7a7a5f', "admin", "game name", "2018-08-03T10:12:43", 33, game, markets
'e629f9aa-6b2c-46aa-8fa8-36770e7a7a5f', "admin", "game name", "2018-08-03T10:12:43", 33,
game_type, market_types
)
signed_ops = SignedTransaction.cast_operations_to_array_of_opklass([op])
assert to_hex(signed_ops.data[0]) == result_bin
Expand Down Expand Up @@ -141,19 +142,19 @@ def test_serialize_development_committee_change_betting_resolve_delay_to_hex():
assert hexlify(bytes(signed_ops.data[0])) == result_bin


@pytest.mark.parametrize('wincases,result_bin', [
@pytest.mark.parametrize('wincase_types,result_bin', [
([wincase.ResultHomeYes()], b'27e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e0100'),
([wincase.HandicapOver(1000)], b'27e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e0108e803'),
([wincase.TotalOver()], b'27e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e01180000'),
([wincase.CorrectScoreYes(home=1, away=2)], b'27e629f9aa6b2c46aa8fa836770e7a7a5f0561646d696e011001000200'),
])
def test_serialize_post_game_results_to_hex(wincases, result_bin):
op = ops.post_game_results("e629f9aa-6b2c-46aa-8fa8-36770e7a7a5f", "admin", wincases)
def test_serialize_post_game_results_to_hex(wincase_types, result_bin):
op = ops.post_game_results("e629f9aa-6b2c-46aa-8fa8-36770e7a7a5f", "admin", wincase_types)
signed_ops = SignedTransaction.cast_operations_to_array_of_opklass([op])
assert hexlify(bytes(signed_ops.data[0])) == result_bin


@pytest.mark.parametrize('wincase,odds,result_bin', [
@pytest.mark.parametrize('wincase_type,odds,result_bin', [
(
wincase.CorrectScoreYes(17, 23),
[1, 2],
Expand All @@ -173,9 +174,9 @@ def test_serialize_post_game_results_to_hex(wincases, result_bin):
b'000000095343520000000001'
)
])
def test_serialize_post_bet_to_hex(wincase, odds, result_bin):
def test_serialize_post_bet_to_hex(wincase_type, odds, result_bin):
uuid = "e629f9aa-6b2c-46aa-8fa8-36770e7a7a5f"
op = ops.post_bet(uuid, "admin", uuid, wincase, odds, "10.000000000 SCR", True)
op = ops.post_bet(uuid, "admin", uuid, wincase_type, odds, "10.000000000 SCR", True)
signed_ops = SignedTransaction.cast_operations_to_array_of_opklass([op])
assert hexlify(bytes(signed_ops.data[0])) == result_bin

Expand Down

0 comments on commit 175a0c2

Please sign in to comment.