def test_has_result_outcome(self): self.clear_data_before_test() o = Outcome() db.session.add(o) db.session.commit() actual = outcome_bl.has_result(o) expected = False self.assertEqual(actual, expected) o.result = 4 db.session.merge(o) db.session.commit() actual = outcome_bl.has_result(o) expected = False self.assertEqual(actual, expected) o.result = 1 db.session.merge(o) db.session.commit() actual = outcome_bl.has_result(o) expected = True self.assertEqual(actual, expected)
def setUp(self): # create contract contract = Contract.find_contract_by_id(1) if contract is None: contract = Contract(id=1, contract_name="contract1", contract_address="0x123", json_name="name1") db.session.add(contract) db.session.commit() # create user user = User.find_user_with_id(109) if user is None: user = User(id=109) db.session.add(user) db.session.commit() # create match match = Match.find_match_by_id(1) if match is None: match = Match(id=1) db.session.add(match) db.session.commit() # create outcome outcome = Outcome.find_outcome_by_id(109) if outcome is None: outcome = Outcome(id=109, match_id=match.id, hid=109, contract_id=contract.id) db.session.add(outcome) db.session.commit() else: outcome.result = -1 outcome.contract_id = contract.id db.session.commit()
def test_can_refund_for_shaker(self): self.clear_data_before_test() match = Match.find_match_by_id(1) if match is None: match = Match( public=1, date=seconds - 100, reportTime=seconds + 1000, disputeTime=seconds + 1000, source_id = source.id ) db.session.add(match) db.session.commit() else: match.date = time.time() - 100 match.disputeTime = time.time() + 1000 match.reportTime = time.time() + 1000 db.session.merge(match) db.session.commit() outcome = Outcome.find_outcome_by_id(88) if outcome is not None: outcome.result = 1 outcome.match_id=match.id else: outcome = Outcome( id=88, match_id=match.id, result=1, hid=88, contract_id=1 ) db.session.add(outcome) db.session.commit() arr_hs = [] # ----- handshake = Handshake( hs_type=3, chain_id=4, user_id=88, outcome_id=88, odds=1.5, amount=1, currency='ETH', side=2, remaining_amount=0, from_address='0x123', status=0 ) db.session.add(handshake) db.session.commit() arr_hs.append(handshake) # ----- shaker = Shaker( shaker_id=66, amount=0.2, currency='ETH', odds=6, side=1, handshake_id=handshake.id, from_address='0x123', chain_id=4, status=2 ) db.session.add(shaker) db.session.commit() arr_hs.append(shaker) actual = handshake_bl.can_refund(None, shaker=shaker) expected = False self.assertEqual(actual, expected) outcome = Outcome.find_outcome_by_id(88) outcome.result = 3 db.session.merge(outcome) db.session.flush() actual = handshake_bl.can_refund(None, shaker=shaker) expected = True self.assertEqual(actual, expected) for item in arr_hs: db.session.delete(item) db.session.commit()
def init_data_before_test(self): # create token token = Token.find_token_by_id(1) if token is None: token = Token(id=1, name="SHURIKEN", symbol="SHURI", decimal=18) db.session.add(token) db.session.commit() # create contract contract = Contract.find_contract_by_id(1) if contract is None: contract = Contract(id=1, contract_name="contract1", contract_address="0x123", json_name="name1") db.session.add(contract) db.session.commit() # create match match = Match.find_match_by_id(1) if match is None: match = Match(id=1) db.session.add(match) db.session.commit() # create user user = User.find_user_with_id(88) if user is None: user = User(id=88) db.session.add(user) db.session.commit() user = User.find_user_with_id(99) if user is None: user = User(id=99) db.session.add(user) db.session.commit() user = User.find_user_with_id(100) if user is None: user = User(id=100) db.session.add(user) db.session.commit() user = User.find_user_with_id(109) if user is None: user = User(id=109) db.session.add(user) db.session.commit() user = User.find_user_with_id(66) if user is None: user = User(id=66) db.session.add(user) db.session.commit() # create outcome outcome = Outcome.find_outcome_by_id(88) if outcome is None: outcome = Outcome(id=88, match_id=1, hid=88, contract_id=contract.id) db.session.add(outcome) db.session.commit() else: outcome.result = -1 outcome.contract_id = contract.id db.session.commit() # add redeem try: for i in range(1, 3): chars = string.ascii_uppercase + string.ascii_lowercase code = ''.join(random.choice(chars) for _ in range(i)) if Redeem.find_redeem_by_code(code) is None: r = Redeem(code=code) db.session.add(r) db.session.commit() except Exception as ex: db.session.rollback()