当前位置: 首页>>代码示例>>Python>>正文


Python BtcTxStore.create_key方法代码示例

本文整理汇总了Python中btctxstore.BtcTxStore.create_key方法的典型用法代码示例。如果您正苦于以下问题:Python BtcTxStore.create_key方法的具体用法?Python BtcTxStore.create_key怎么用?Python BtcTxStore.create_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在btctxstore.BtcTxStore的用法示例。


在下文中一共展示了BtcTxStore.create_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestGetAddress

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
class TestGetAddress(unittest.TestCase):

    def setUp(self):
        self.api = BtcTxStore(dryrun=True, testnet=True)

    def test_standard(self):
        wif = self.api.create_key()
        address = self.api.get_address(wif)
        self.assertTrue(validate.is_address_valid(address, allowable_netcodes=['XTN']))

    def test_input_validation(self):

        # test correct types
        a = self.api.get_address(S_WIF)
        b = self.api.get_address(B_WIF)
        c = self.api.get_address(U_WIF)
        self.assertEqual(a, b, c)

        # TODO invalid types
        # TODO invalid input data

    def test_standards_compliant(self):
        wif = self.api.create_key()
        address = self.api.get_address(S_WIF)
        self.assertEqual(address, EXPECTED)
开发者ID:F483,项目名称:btctxstore,代码行数:27,代码来源:get_address.py

示例2: test_fail

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
    def test_fail(self):
        # register without auth headres fails
        rv = self.app.get('/api/register/{0}'.format(addresses["eta"]))
        self.assertEqual(rv.status_code, 401)

        # register first because ping is lazy
        blockchain = BtcTxStore()
        wif = blockchain.create_key()
        address = blockchain.get_address(wif)
        header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
                                 localtime=True, usegmt=True)
        message = app.config["ADDRESS"] + " " + header_date
        header_authorization = blockchain.sign_unicode(wif, message)
        headers = {"Date": header_date, "Authorization": header_authorization}
        url = '/api/register/{0}'.format(address)
        rv = self.app.get(url, headers=headers)
        self.assertEqual(rv.status_code, 200)

        # ping without auth headres fails
        time.sleep(app.config["MAX_PING"])
        rv = self.app.get('/api/ping/{0}'.format(address))
        self.assertEqual(rv.status_code, 401)

        # set height without auth headres fails
        rv = self.app.get('/api/height/{0}/10'.format(addresses["eta"]))
        self.assertEqual(rv.status_code, 401)
开发者ID:StorjOld,项目名称:dataserv,代码行数:28,代码来源:test_App.py

示例3: test_core_audit

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
    def test_core_audit(self):
        """
        Test of providing correct arguments to the ``requests.post()``
        and returning gotten response object.
        """
        test_url_address = 'http://test.url.com'
        file_hash = sha256(b'some test data').hexdigest()
        seed = sha256(b'some test challenge seed').hexdigest()
        btctx_api = BtcTxStore(testnet=True, dryrun=True)
        sender_key = btctx_api.create_key()
        audit_call_result = core.audit(test_url_address, sender_key,
                                       btctx_api, file_hash, seed)

        expected_calls = [call(
                urljoin(test_url_address, '/api/audit/'),
                data={
                    'data_hash': file_hash,
                    'challenge_seed': seed,
                },
                headers={
                    'sender-address': btctx_api.get_address(sender_key),
                    'signature': btctx_api.sign_unicode(sender_key, file_hash),
                }
        )]
        self.assertListEqual(
            self.mock_post.call_args_list,
            expected_calls,
            'In the audit() function requests.post() calls are unexpected'
        )
        self.assertIs(
            self.mock_post.return_value,
            audit_call_result,
            'Returned value must be the object returned by the '
            '``requests.post()``'
        )
开发者ID:StorjOld,项目名称:metatool,代码行数:37,代码来源:test_metatool_core_unit.py

示例4: test_together_sender_key_and_btctx_api

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
    def test_together_sender_key_and_btctx_api(self):
        """
        Test of possibility to provide the ``sender_key`` and ``btctx_api``
        only together.
        """
        btctx_api = BtcTxStore(testnet=True, dryrun=True)
        sender_key = btctx_api.create_key()
        self.mock_get.return_value = Response()

        # test only "sender_key" given
        self.assertRaises(
            TypeError,
            core.download,
            *(self.test_url_address, self.file_hash),
            **{'sender_key': sender_key}
        )

        # test only "btctx_api" given
        self.assertRaises(
            TypeError,
            core.download,
            *(self.test_url_address, self.file_hash),
            **{'btctx_api': btctx_api}
        )

        # test of now exception when both args are given
        download_call_result = core.download(
            self.test_url_address,
            self.file_hash,
            sender_key=sender_key,
            btctx_api=btctx_api
        )
        self.assertIsInstance(download_call_result, Response,
                              'Must return a response object')
开发者ID:StorjOld,项目名称:metatool,代码行数:36,代码来源:test_metatool_core_unit.py

示例5: test_authenticate_headers_provide

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
    def test_authenticate_headers_provide(self):
        """
        Test of preparing and providing credential headers when ``sender_key``
        and ``btctx_api`` are provided.
        """
        btctx_api = BtcTxStore(testnet=True, dryrun=True)
        sender_key = btctx_api.create_key()
        signature = btctx_api.sign_unicode(sender_key, self.file_hash)
        sender_address = btctx_api.get_address(sender_key)
        self.mock_get.return_value = Response()
        self.test_data_for_requests['headers'] = {
                'sender-address': sender_address,
                'signature': signature,
            }
        download_call_result = core.download(
            self.test_url_address,
            self.file_hash,
            sender_key=sender_key,
            btctx_api=btctx_api
        )
        expected_mock_calls = [call(
            urljoin(self.test_url_address, '/api/files/' + self.file_hash),
            **self.test_data_for_requests
        )]

        self.assertListEqual(
            self.mock_get.call_args_list,
            expected_mock_calls,
            'In the download() function requests.get() calls are unexpected'
        )
        self.assertIsInstance(download_call_result, Response,
                              'Must return a response object')
开发者ID:StorjOld,项目名称:metatool,代码行数:34,代码来源:test_metatool_core_unit.py

示例6: setUp

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
    def setUp(self):
        # Create a temporary that will be used as uploaded file.
        self.testing_dir = os.path.dirname(os.path.abspath(__file__))
        self.test_source_file = tempfile.NamedTemporaryFile(
            prefix='tmp_',
            suffix='.spam',
            mode="w+",
            dir=self.testing_dir,
        )
        self.test_source_file.write('some file content')
        self.test_source_file.flush()

        # Mock the ``requests`` package.
        self.post_patch = patch('requests.post')
        self.mock_post = self.post_patch.start()
        self.mock_post.return_value = Response()

        # Prepare common arguments for the API's ``upload()`` function call.
        btctx_api = BtcTxStore(testnet=True, dryrun=True)
        self.upload_param = dict(
            url_base='http://test.url.com',
            btctx_api=btctx_api,
            sender_key=btctx_api.create_key(),
            file_role='101',
        )
开发者ID:StorjOld,项目名称:metatool,代码行数:27,代码来源:test_metatool_core_unit.py

示例7: args_prepare

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
def args_prepare(required_args, parsed_args):
    """
    Filling all missed, but required by the core API function arguments.
    Return dictionary that will be passed to the API function.

    :param required_args: list of required argument's names for
        the API function
    :type required_args: list of stings
    :param parsed_args: can be any object with appropriate names of attributes
        required by the core API function
    :type parsed_args: argparse.Namespace

    :returns: dictionary that will be used like the ``**kwargs`` argument
    :rtype: dictionary
    """
    prepared_args = {}
    if 'sender_key' in required_args and 'btctx_api' in required_args:
        btctx_api = BtcTxStore(testnet=True, dryrun=True)
        args_base = dict(
            sender_key=btctx_api.create_key(),
            btctx_api=btctx_api,
        )
    for required_arg in required_args:
        try:
            prepared_args[required_arg] = getattr(parsed_args, required_arg)
        except AttributeError:
            prepared_args[required_arg] = args_base[required_arg]
    return prepared_args
开发者ID:StorjOld,项目名称:metatool,代码行数:30,代码来源:cli.py

示例8: TestValidateKeyMainnet

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
class TestValidateKeyMainnet(unittest.TestCase):

    def setUp(self):
        self.testnet_api = BtcTxStore(dryrun=True, testnet=True)
        self.mainnet_api = BtcTxStore(dryrun=True, testnet=False)

    def test_valid_network(self):
        key = self.mainnet_api.create_key()
        self.assertTrue(self.mainnet_api.validate_key(key))

    def test_invalid_network(self):
        key = self.testnet_api.create_key()
        self.assertFalse(self.mainnet_api.validate_key(key))

    def test_invalid_data(self):
        self.assertFalse(self.mainnet_api.validate_key("f483"))

    def test_invalid_type(self):
        self.assertFalse(self.mainnet_api.validate_key(None))
开发者ID:F483,项目名称:btctxstore,代码行数:21,代码来源:other.py

示例9: callback

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
        def callback():
            blockchain = BtcTxStore()
            wif = blockchain.create_key()
            address = blockchain.get_address(wif)
            farmer = Farmer(address)

            header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
                                     localtime=True, usegmt=True)
            header_authorization = blockchain.sign_unicode(wif, "lalala-wrong")
            farmer.authenticate(header_authorization, header_date)
开发者ID:jorgebonilla,项目名称:dataserv,代码行数:12,代码来源:test_Farmer.py

示例10: TestAuth

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
class TestAuth(unittest.TestCase):

    def setUp(self):
        self.btctxstore = BtcTxStore()
        self.sender_wif = self.btctxstore.create_key()
        self.sender = self.btctxstore.get_address(self.sender_wif)
        recipient_wif = self.btctxstore.create_key()
        self.recipient = self.btctxstore.get_address(recipient_wif)

    def test_self_validates(self):
        headers = storjcore.auth.create_headers(self.btctxstore,
                                                self.recipient,
                                                self.sender_wif)

        self.assertTrue(storjcore.auth.verify_headers(self.btctxstore,
                                                      headers,
                                                      5, self.sender,
                                                      self.recipient))

    def test_invalid_signature(self):
        def callback():
            headers = storjcore.auth.create_headers(self.btctxstore,
                                                    self.recipient,
                                                    self.sender_wif)
            headers["Authorization"] = base64.b64encode(65 * b"x")
            storjcore.auth.verify_headers(self.btctxstore, headers,
                                          5, self.sender, self.recipient)
        self.assertRaises(storjcore.auth.AuthError, callback)

    def test_timeout_to_old(self):
        def callback():
            headers = storjcore.auth.create_headers(self.btctxstore,
                                                    self.recipient,
                                                    self.sender_wif)
            time.sleep(5)
            storjcore.auth.verify_headers(self.btctxstore, headers,
                                          5, self.sender, self.recipient)
        self.assertRaises(storjcore.auth.AuthError, callback)

    @unittest.skip("TODO implement")
    def test_timeout_to_young(self):
        pass  # FIXME how to test this?
开发者ID:cloud-school,项目名称:storjcore,代码行数:44,代码来源:test_auth.py

示例11: test_authentication_success

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
    def test_authentication_success(self):
        blockchain = BtcTxStore()
        wif = blockchain.create_key()
        address = blockchain.get_address(wif)
        farmer = Farmer(address)

        header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
                                 localtime=True, usegmt=True)
        message = farmer.get_server_address() + " " + header_date
        header_authorization = blockchain.sign_unicode(wif, message)
        self.assertTrue(farmer.authenticate(header_authorization, header_date))
开发者ID:F483,项目名称:dataserv,代码行数:13,代码来源:test_Farmer.py

示例12: callback

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
        def callback():
            blockchain = BtcTxStore()
            wif = blockchain.create_key()
            address = blockchain.get_address(wif)
            farmer = Farmer(address)

            header_date = formatdate(timeval=mktime(datetime.now().timetuple())
                                     , localtime=True, usegmt=True)
            message = farmer.get_server_address() + " " + header_date
            header_authorization = blockchain.sign_unicode(wif, message)
            headers = {"Date": None, "Authorization": header_authorization}
            farmer.authenticate(headers)
开发者ID:StorjOld,项目名称:dataserv,代码行数:14,代码来源:test_Farmer.py

示例13: callback

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
        def callback():
            blockchain = BtcTxStore()
            wif = blockchain.create_key()
            address = blockchain.get_address(wif)
            farmer = Farmer(address)

            timeout = farmer.get_server_authentication_timeout()

            date = datetime.now() - timedelta(seconds=timeout)
            header_date = formatdate(timeval=mktime(date.timetuple()),
                                     localtime=True, usegmt=True)
            message = farmer.get_server_address() + " " + header_date
            header_authorization = blockchain.sign_unicode(wif, message)
            farmer.authenticate(header_authorization, header_date)
开发者ID:F483,项目名称:dataserv,代码行数:16,代码来源:test_Farmer.py

示例14: TestValidateAddressTestnet

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
class TestValidateAddressTestnet(unittest.TestCase):

    def setUp(self):
        self.testnet_api = BtcTxStore(dryrun=True, testnet=True)
        self.mainnet_api = BtcTxStore(dryrun=True, testnet=False)

    def test_valid_string(self):
        address = 'migiScBNvVKYwEiCFhgBNGtZ87cdygtuSQ'
        self.assertTrue(self.testnet_api.validate_address(address))

    def test_valid_network(self):
        address = self.testnet_api.get_address(self.testnet_api.create_key())
        self.assertTrue(self.testnet_api.validate_address(address))

    def test_invalid_network(self):
        address = self.mainnet_api.get_address(self.mainnet_api.create_key())
        self.assertFalse(self.testnet_api.validate_address(address))

    def test_invalid_data(self):
        self.assertFalse(self.testnet_api.validate_address("f483"))

    def test_invalid_type(self):
        self.assertFalse(self.testnet_api.validate_address(None))
开发者ID:F483,项目名称:btctxstore,代码行数:25,代码来源:other.py

示例15: TestValidateAddressMainnet

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import create_key [as 别名]
class TestValidateAddressMainnet(unittest.TestCase):

    def setUp(self):
        self.testnet_api = BtcTxStore(dryrun=True, testnet=True)
        self.mainnet_api = BtcTxStore(dryrun=True, testnet=False)

    def test_valid_string(self):
        address = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
        self.assertTrue(self.mainnet_api.validate_address(address))

    def test_valid_network(self):
        address = self.mainnet_api.get_address(self.mainnet_api.create_key())
        self.assertTrue(self.mainnet_api.validate_address(address))

    def test_invalid_network(self):
        address = self.testnet_api.get_address(self.testnet_api.create_key())
        self.assertFalse(self.mainnet_api.validate_address(address))

    def test_invalid_data(self):
        self.assertFalse(self.mainnet_api.validate_address("f483"))

    def test_invalid_type(self):
        self.assertFalse(self.mainnet_api.validate_address(None))
开发者ID:F483,项目名称:btctxstore,代码行数:25,代码来源:other.py


注:本文中的btctxstore.BtcTxStore.create_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。