Beispiel #1
0
    def test_scenario4(self):
        self._create_room(self.test1_wallet)
        self._join_room(self.test2_wallet, self.test1_wallet.get_address())

        tx_result_toggle_ready = self._toggle_ready(self.test1_wallet)
        self.assertTrue('status' in tx_result_toggle_ready)
        self.assertEqual(1, tx_result_toggle_ready['status'])

        tx_result_game_start = self._game_start(self.test1_wallet)
        self.assertTrue('status' in tx_result_game_start)
        self.assertEqual(0, tx_result_game_start['status'])

        tx_result_toggle_ready = self._toggle_ready(self.test2_wallet)
        self.assertTrue('status' in tx_result_toggle_ready)
        self.assertEqual(1, tx_result_toggle_ready['status'])

        tx_result_hit = self._hit(self.test1_wallet)
        self.assertTrue('status' in tx_result_hit)
        self.assertEqual(0, tx_result_hit['status'])

        tx_result_game_start = self._game_start(self.test2_wallet)
        self.assertTrue('status' in tx_result_game_start)
        self.assertEqual(0, tx_result_game_start['status'])

        tx_result_game_start = self._game_start(self.test1_wallet)
        self.assertTrue('status' in tx_result_game_start)
        self.assertEqual(1, tx_result_game_start['status'])

        tx_result_escape = self._escape(self.test1_wallet)
        self.assertTrue('status' in tx_result_escape)
        self.assertEqual(0, tx_result_escape['status'])

        for _ in range(5):
            tx_result_hit = self._hit(self.test1_wallet)
            self.assertTrue('status' in tx_result_hit)
            self.assertEqual(1, tx_result_hit['status'])

            result_show_mine = self._show_mine(self.test1_wallet)
            if json_loads(result_show_mine)['value'] > 21:
                break

            tx_result_hit = self._hit(self.test2_wallet)
            self.assertTrue('status' in tx_result_hit)
            self.assertEqual(1, tx_result_hit['status'])

            result_show_mine = self._show_mine(self.test2_wallet)
            if json_loads(result_show_mine)['value'] > 21:
                break

        result_get_results = self._get_results(self.test2_wallet)
        print(result_get_results)

        result_show_game_room_list = self._show_game_room_list(self.test2_wallet)
        print(result_show_game_room_list)
Beispiel #2
0
    def add(self, account_id, token_type, contract_addr, to, amount,
            dids) -> str:
        """

        :param account_id:
        :param token_type:
        :param contract_addr:
        :param to:
        :param amount:
        :param dids:
        :return:
        """
        # get need data
        last_tx_id = self._last_pending_tx_id_db.get() + 1

        pending_tx_id_list_as_str = self._pending_tx_id_list_db.get()
        if pending_tx_id_list_as_str == "":
            pending_tx_id_list_as_str = json_dumps([])

        pending_tx_id_list = json_loads(pending_tx_id_list_as_str)

        # create pending tx
        pending_tx = {
            "id": last_tx_id,
            "tokenType": token_type,
            "contractAddr": contract_addr,
            "from": account_id,
            "to": to,
            "amount": amount,
            "dids": dids
        }

        # update db
        pending_tx_as_str = json_dumps(pending_tx)
        self._pending_tx_list[last_tx_id] = pending_tx_as_str
        self._last_pending_tx_id_db.set(last_tx_id)
        pending_tx_id_list.append(last_tx_id)
        self._pending_tx_id_list_db.set(json_dumps(pending_tx_id_list))
        return pending_tx_as_str
Beispiel #3
0
 def remove(self, tx_id: int):
     del self._pending_tx_list[tx_id]
     pending_tx_id_list = json_loads(
         self._pending_tx_id_list_db.get())  # type: List
     pending_tx_id_list.remove(tx_id)
     self._pending_tx_id_list_db.set(json_dumps(pending_tx_id_list))
Beispiel #4
0
 def get(self, tx_id: int) -> dict:
     if self._pending_tx_list[tx_id] != "":
         return json_loads(self._pending_tx_list[tx_id])
     return {}