Пример #1
0
 def show_event_callback(self, node, event):
     self.show_event_data.append({
         'queryId':
         convert_to_hex(event['args']['queryId']),
         'response':
         event['args']['response'],
         'hash':
         convert_to_hex(event['args']['hash'])
     })
Пример #2
0
 def to_oracle_node_event_callback(self, node, event):
     timeout = int(event['args']['timeout'])
     query_id = convert_to_hex(event['args']['queryId'])
     request = event['args']['request']
     if timeout > 0:
         gevent.sleep(timeout)
     print('in OracleNodeClient - event: query id {0}, request {1}'.format(
         query_id, request))
     request_handler = RequestHandler(event['args']['request'])
     response = request_handler.execute_request()
     OracleCore(self._config_path).result_sent_back(
         query_id, response, convert_to_hex(Web3.sha3(text=response)),
         **{'from': self._oracle_owner})
Пример #3
0
 def sent_event_callback(self, node, event):
     self.sent_event_data.append({
         'queryId':
         convert_to_hex(event['args']['queryId']),
         'request':
         event['args']['request']
     })
Пример #4
0
    def test_single_event(self):
        self.to_oracle_node_data = []
        self.show_event_data = []
        self.sent_event_data = []
        example_daemon = HodlOracleClient(config_path=_TEST_CONFIG,
                                          sent_callback_objs=[self],
                                          show_callback_objs=[self],
                                          wait_time=1)
        example_daemon.start()

        node_daemon = OracleNodeClient(config_path=_TEST_CONFIG,
                                       to_oracle_node_callback_objs=[self],
                                       wait_time=1)
        node_daemon.start()

        hodl_oracle = HodlOracle(_TEST_CONFIG)
        # self.assertEqual(0, hodl_oracle.get_lastest_query_id(), 'There is no query id')

        hodl_oracle.deposit(**{
            'value': convert_to_wei(20000, 'wei'),
            'from': self._hodl_owner
        })
        hodl_oracle.trigger(**{'from': self._hodl_owner})
        hodl_oracle_queryid = hodl_oracle.get_lastest_query_id(
            **{'from': self._hodl_owner})
        gevent.sleep(5)

        for idx, test_list in enumerate([
                self.to_oracle_node_data, self.sent_event_data,
                self.show_event_data
        ]):
            self.assertEqual(
                len(test_list), 1,
                '{0} has more than one entry {1}'.format(test_list, idx))

        # check queryid
        for idx, test_list in enumerate([
                self.to_oracle_node_data, self.sent_event_data,
                self.show_event_data
        ]):
            self.assertEqual(
                test_list[0]['queryId'], hodl_oracle_queryid,
                'query id {0} != {1}, {2}'.format(test_list[0]['queryId'],
                                                  hodl_oracle_queryid, idx))

        # check resquest
        self.assertEqual(self.to_oracle_node_data[0]['request'],
                         self.sent_event_data[0]['request'],
                         'two request should be the same')

        # check response
        self.assertRegex(self.show_event_data[0]['response'], '^(\d+\.?\d+)$')

        self.assertEqual(
            convert_to_hex(self.show_event_data[0]['hash']),
            convert_to_hex(
                Web3.sha3(text=self.show_event_data[0]['response'])))

        # check the result is correct
        example_daemon.kill()
        node_daemon.kill()
        get_all_fee_reports()
 def l_get_address(self, name, **kargs):
     transaction_data = self.compose_transaction_dict(kargs)
     address = self.get_contract_inst().functions.getAddress(name).call(
         transaction_data)
     return convert_to_hex(address)
Пример #6
0
    def l_get_lastest_query_id(self, **kargs):
        transaction_data = self.compose_transaction_dict(kargs)

        query_id = self.get_contract_inst().functions.getLastestQueryId().call(transaction_data)
        return convert_to_hex(query_id)