Пример #1
0
    def test_init(self):
        config = storage.InRamConfigurationStore()
        key_store = storage.InRamPlainKeyStore(config=config)
        wallet = Wallet(key_store=key_store)
        # InRamStore does not come with a default key
        self.assertFalse(wallet.created())

        self.assertTrue(bool(wallet.rpc))
        self.assertEqual(wallet.prefix, "BTS")
        wif1 = PrivateKey()
        wif2 = PrivateKey()
        wallet.setKeys([
            wif1, wif2
        ])
        self.assertIn(
            str(wif1.pubkey),
            wallet.store.getPublicKeys()
        )
        self.assertIn(
            str(wif2.pubkey),
            wallet.store.getPublicKeys()
        )
        self.assertEqual(
            wallet.getPrivateKeyForPublicKey(
                wif1.pubkey
            ),
            str(wif1)
        )
        self.assertEqual(
            wallet.getPrivateKeyForPublicKey(
                wif2.pubkey
            ),
            str(wif2)
        )
        # wallet.unlock("")
        # wallet.lock()
        # is unlocked because InRamKeyStore and not encrypted
        self.assertFalse(wallet.store.is_encrypted())
        self.assertFalse(wallet.is_encrypted())
        self.assertTrue(wallet.unlocked())
        self.assertFalse(wallet.locked())

        wif3 = PrivateKey()
        wallet.addPrivateKey(wif3)
        self.assertIn(
            str(wif3.pubkey),
            wallet.store.getPublicKeys()
        )
        self.assertEqual(
            wallet.getPrivateKeyForPublicKey(
                wif3.pubkey
            ),
            str(wif3)
        )

        wallet.removePrivateKeyFromPublicKey(wif3.pubkey)
        with self.assertRaises(KeyNotFound):
            wallet.getPrivateKeyForPublicKey(
                wif3.pubkey
            )
Пример #2
0
 def test_create_account(self):
     bts = self.bts
     name = ''.join(random.choice(string.ascii_lowercase) for _ in range(12))
     key1 = PrivateKey()
     key2 = PrivateKey()
     key3 = PrivateKey()
     key4 = PrivateKey()
     tx = bts.create_account(
         name,
         registrar="init0",   # 1.2.7
         referrer="init1",    # 1.2.8
         referrer_percent=33,
         owner_key=format(key1.pubkey, core_unit),
         active_key=format(key2.pubkey, core_unit),
         memo_key=format(key3.pubkey, core_unit),
         additional_owner_keys=[format(key4.pubkey, core_unit)],
         additional_active_keys=[format(key4.pubkey, core_unit)],
         additional_owner_accounts=["committee-account"],  # 1.2.0
         additional_active_accounts=["committee-account"],
         proxy_account="init0",
         storekeys=False
     )
     self.assertEqual(
         getOperationNameForId(tx["operations"][0][0]),
         "account_create"
     )
     op = tx["operations"][0][1]
     role = "active"
     self.assertIn(
         format(key4.pubkey, core_unit),
         [x[0] for x in op[role]["key_auths"]])
     self.assertIn(
         format(key4.pubkey, core_unit),
         [x[0] for x in op[role]["key_auths"]])
     self.assertIn(
         "1.2.0",
         [x[0] for x in op[role]["account_auths"]])
     role = "owner"
     self.assertIn(
         format(key4.pubkey, core_unit),
         [x[0] for x in op[role]["key_auths"]])
     self.assertIn(
         format(key4.pubkey, core_unit),
         [x[0] for x in op[role]["key_auths"]])
     self.assertIn(
         "1.2.0",
         [x[0] for x in op[role]["account_auths"]])
     self.assertEqual(
         op["options"]["voting_account"],
         "1.2.6")
     self.assertEqual(
         op["registrar"],
         "1.2.6")
     self.assertEqual(
         op["referrer"],
         "1.2.7")
     self.assertEqual(
         op["referrer_percent"],
         33 * 100)
Пример #3
0
    def test_shared_secrets_equal(self):

        wifs = cycle([x[0] for x in test_shared_secrets])

        for i in range(len(test_shared_secrets)):
            sender_private_key = PrivateKey(next(wifs))
            sender_public_key = sender_private_key.pubkey
            receiver_private_key = PrivateKey(next(wifs))
            receiver_public_key = receiver_private_key.pubkey

            self.assertEqual(
                get_shared_secret(sender_private_key, receiver_public_key),
                get_shared_secret(receiver_private_key, sender_public_key))
Пример #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(nobroadcast=True, wif=[wif])
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")

        cache = ObjectCache(default_expiration=5, no_overwrite=True)
        init0 = {
            'active': {
                'account_auths': [],
                'address_auths': [],
                'key_auths': [[str(PrivateKey(wif).pubkey), 1]],
                'weight_threshold': 1
            },
            'active_special_authority': [0, {}],
            'blacklisted_accounts': [],
            'blacklisting_accounts': [],
            'cashback_vb': '1.13.102',
            'id': '1.2.90742',
            'lifetime_referrer': '1.2.90742',
            'lifetime_referrer_fee_percentage': 8000,
            'membership_expiration_date': '1969-12-31T23:59:59',
            'name': 'init0',
            'network_fee_percentage': 2000,
            'options': {
                'extensions': [],
                'memo_key': str(PrivateKey(wif).pubkey),
                'num_committee': 0,
                'num_witness': 0,
                'votes': [],
                'voting_account': '1.2.5'
            },
            'owner': {
                'account_auths': [],
                'address_auths': [],
                'key_auths': [[str(PrivateKey(wif).pubkey), 1]],
                'weight_threshold': 1
            },
            'owner_special_authority': [0, {}],
            'referrer': '1.2.90742',
            'referrer_rewards_percentage': 0,
            'registrar': '1.2.90742',
            'statistics': '2.6.90742',
            'top_n_control_flags': 0,
            'whitelisted_accounts': [],
            'whitelisting_accounts': []
        }
        cache[init0["id"]] = init0
        cache[init0["name"]] = init0
        BlockchainObject._cache = cache
    def compareConstructedTX(self):
        self.maxDiff = None
        self.op = operations.Call_order_update(
            **{
                "fee": {"amount": 100, "asset_id": "1.3.0"},
                "delta_debt": {"amount": 10000, "asset_id": "1.3.22"},
                "delta_collateral": {"amount": 100000000, "asset_id": "1.3.0"},
                "funding_account": "1.2.29",
                "extensions": {"target_collateral_ratio": 12345},
            }
        )
        ops = [Operation(self.op)]
        tx = Signed_Transaction(
            ref_block_num=ref_block_num,
            ref_block_prefix=ref_block_prefix,
            expiration=expiration,
            operations=ops,
        )
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], prefix)
        txWire = hexlify(bytes(tx)).decode("ascii")
        print("=" * 80)
        pprint(tx.json())
        print("=" * 80)

        # Test against Bitshares backened
        self.cm = bitshares.rpc.get_transaction_hex(tx.json())

        print("soll: %s" % self.cm[:-130])
        print("ist:  %s" % txWire[:-130])
        print(txWire[:-130] == self.cm[:-130])
        self.assertEqual(self.cm[:-130], txWire[:-130])
Пример #6
0
 def validate_private_key_type(self, account, private_key):
     account = Account(account)
     pubkey = format(PrivateKey(private_key).pubkey, self.bitshares.prefix)
     key_type = self.bitshares.wallet.getKeyType(account, pubkey)
     if key_type != 'active':
         return False
     return True
Пример #7
0
    def encrypt(self, memo):
        """ Encrypt a memo

            :param str memo: clear text memo message
            :returns: encrypted memo
            :rtype: str
        """
        if not memo:
            return None

        nonce = str(random.getrandbits(64))
        memo_wif = self.bitshares.wallet.getPrivateKeyForPublicKey(
            self.from_account["options"]["memo_key"])
        if not memo_wif:
            raise MissingKeyError("Memo key for %s missing!" %
                                  self.from_account["name"])

        enc = BtsMemo.encode_memo(
            PrivateKey(memo_wif),
            PublicKey(self.to_account["options"]["memo_key"],
                      prefix=self.bitshares.prefix), nonce, memo)

        return {
            "message": enc,
            "nonce": nonce,
            "from": self.from_account["options"]["memo_key"],
            "to": self.to_account["options"]["memo_key"]
        }
Пример #8
0
    async def _encrypt_memo(self, to, memo):
        ''' 加密备注信息
        '''
        if not memo:
            return None

        # 生成nonce
        nonce = str(random.getrandbits(64))
        if SysConfig().memo_key == None:
            raise MissingKeyError('Memo key {0} missing!'.format(SysConfig().account))

        # 加密备注信息
        prefix = self.client.chain_params['prefix']
        to_account = await self.client.get_account_by_name(to)
        enc = BtsMemo.encode_memo(
            PrivateKey(SysConfig().memo_key, prefix=prefix),
            PublicKey(
                prefix=prefix,
                pk=to_account['options']['memo_key']
            ),
            nonce,
            memo
        )

        # 返回结构信息
        memo_data = {
            'nonce': nonce,
            'message': enc,
            'to': to_account['options']['memo_key'],
            'from': self.account['options']['memo_key']
        }
        return to_account['id'], memo_data
    def compareConstructedTX(self):
        #    def test_online(self):
        #        self.maxDiff = None
        op = operations.Asset_reserve(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "payer": "1.2.0",
                "amount_to_reserve": {
                    "amount": 1234567890,
                    "asset_id": "1.3.0"
                },
                "extensions": []
            })
        ops = [Operation(op)]
        tx = Signed_Transaction(ref_block_num=ref_block_num,
                                ref_block_prefix=ref_block_prefix,
                                expiration=expiration,
                                operations=ops)
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], "BTS")
        txWire = hexlify(bytes(tx)).decode("ascii")
        print("=" * 80)
        pprint(tx.json())
        print("=" * 80)

        from grapheneapi.grapheneapi import GrapheneAPI
        rpc = GrapheneAPI("localhost", 8092)
        compare = rpc.serialize_transaction(tx.json())
        print(compare[:-130])
        print(txWire[:-130])
        print(txWire[:-130] == compare[:-130])
        self.assertEqual(compare[:-130], txWire[:-130])
 def test_override_transfer(self):
     s = {
         "fee": {
             "amount": 0,
             "asset_id": "1.3.0"
         },
         "issuer": "1.2.29",
         "from": "1.2.104",
         "to": "1.2.29",
         "amount": {
             "amount": 100000,
             "asset_id": "1.3.105"
         },
         "extensions": []
     }
     op = operations.Override_transfer(**s)
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c8045701260000000000000000001d681da086"
                "01000000000069000000012030cc81722c3e67442d2f59deba18"
                "8f6079c8ba2d8318a642e6a70a125655515f20e2bd3adb2ea886"
                "cdbc7f6590c7f8c80818d9176d9085c176c736686ab6c9fd")
     self.assertEqual(compare[:-130], txWire[:-130])
Пример #11
0
    async def append_signer(self, account, wifkey, prefix, permission):
        """ 添加签名
        """
        pubkey = PrivateKey(wifkey, prefix=prefix).pubkey
        required_treshold = account[permission]['weight_threshold']

        async def fetchkeys(account, perm, level=0):
            r = []
            if level > 2:
                return r
            for authority in account[perm]['key_auths']:
                if authority[0] == str(pubkey):
                    r.append([wifkey, authority[1]])
            
            if sum([x[1] for x in r]) < required_treshold:
                for authority in account[perm]['account_auths']:
                    auth_account = await self.node_api.get_account_by_name(authority[0])
                    r.extend(fetchkeys(auth_account, perm, level + 1))
            return r

        assert permission in ['active', 'owner'], 'Invalid permission'

        if account not in self.available_signers:
            keys = await fetchkeys(account, permission)
            if permission != 'owner':
                keys.extend(await fetchkeys(account, 'owner'))
            self.wifs.extend([x[0] for x in keys])
            self.available_signers.append(account)
Пример #12
0
    def compareConstructedTX(self):
        self.maxDiff = None
        self.op = operations.Committee_member_create(**{
            "fee": {
                "amount": 0,
                "asset_id": "1.3.0"
            },
            "committee_member_account": "1.2.0",
            "url": "foobar"
        })
        ops = [Operation(self.op)]
        tx = Signed_Transaction(
            ref_block_num=ref_block_num,
            ref_block_prefix=ref_block_prefix,
            expiration=expiration,
            operations=ops
        )
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], prefix)
        txWire = hexlify(bytes(tx)).decode("ascii")
        print("=" * 80)
        pprint(tx.json())
        print("=" * 80)

        from grapheneapi.grapheneapi import GrapheneAPI
        rpc = GrapheneAPI("localhost", 8092)
        self.cm = rpc.serialize_transaction(tx.json())
        print("soll: %s" % self.cm[:-130])
        print("ist:  %s" % txWire[:-130])
        print(txWire[:-130] == self.cm[:-130])
        self.assertEqual(self.cm[:-130], txWire[:-130])
Пример #13
0
    def validate_private_key(self, account, private_key):
        """ Check whether private key is associated with account

            :param str account: bitshares account name
            :param str private_key: private key
        """
        wallet = self.bitshares.wallet
        if not private_key:
            # Check if the account is already in the database
            account_ids = wallet.getAccounts()
            accounts = [
                Account(account_id, bitshares_instance=self.bitshares)
                for account_id in account_ids
            ]
            if any(account == account['name'] for account in accounts):
                return True
            return False

        try:
            pubkey = format(
                PrivateKey(private_key).pubkey, self.bitshares.prefix)
        except ValueError:
            return False

        # Load all accounts with corresponding public key from the blockchain
        account_ids = wallet.getAccountsFromPublicKey(pubkey)
        account_names = [
            Account(account_id, bitshares_instance=self.bitshares).name
            for account_id in account_ids
        ]

        if account in account_names:
            return True
        else:
            return False
Пример #14
0
    def compareConstructedTX(self):
        self.maxDiff = None
        self.op = operations.Custom(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "payer": "1.2.0",
                "required_auths": ["1.2.100", "1.2.101"],
                "id": "35235",
                "data": hexlify(b"Foobar").decode("ascii")
            })
        ops = [Operation(self.op)]
        tx = Signed_Transaction(ref_block_num=ref_block_num,
                                ref_block_prefix=ref_block_prefix,
                                expiration=expiration,
                                operations=ops)
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], prefix)
        txWire = hexlify(bytes(tx)).decode("ascii")
        print("=" * 80)
        pprint(tx.json())
        print("=" * 80)

        # Test against Bitshares backened
        self.cm = bitshares.rpc.get_transaction_hex(tx.json())

        print("soll: %s" % self.cm[:-130])
        print("ist:  %s" % txWire[:-130])
        print(txWire[:-130] == self.cm[:-130])
        self.assertEqual(self.cm[:-130], txWire[:-130])
Пример #15
0
    def decrypt(self, memo):
        """ Decrypt a memo

            :param str memo: encrypted memo message
            :returns: encrypted memo
            :rtype: str
        """
        if not memo:
            return None

        # We first try to decode assuming we received the memo
        try:
            memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(
                memo["to"])
            pubkey = memo["from"]
        except KeyNotFound:
            try:
                # if that failed, we assume that we have sent the memo
                memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(
                    memo["from"])
                pubkey = memo["to"]
            except KeyNotFound:
                # if all fails, raise exception
                raise MissingKeyError(
                    "Non of the required memo keys are installed!"
                    "Need any of {}".format([memo["to"], memo["from"]]))

        if not hasattr(self, 'chain_prefix'):
            self.chain_prefix = self.blockchain.prefix

        return BtsMemo.decode_memo(PrivateKey(memo_wif),
                                   PublicKey(pubkey, prefix=self.chain_prefix),
                                   memo.get("nonce"), memo.get("message"))
 def test_fee_pool(self):
     s = {
         "fee": {
             "amount": 10001,
             "asset_id": "1.3.0"
         },
         "from_account": "1.2.282",
         "asset_id": "1.3.32",
         "amount": 15557238,
         "extensions": []
     }
     op = operations.Asset_fund_fee_pool(**s)
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c8045701101127000000000000009a02207662"
                "ed00000000000000011f39f7dc7745076c9c7e612d40c68ee92d"
                "3f4b2696b1838037ce2a35ac259883ba6c6c49d91ad05a7e78d8"
                "0bb83482c273dbbc911587487bf468b85fb4f537da3d")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_call_update(self):
     op = operations.Call_order_update(
         **{
             'fee': {
                 'amount': 100,
                 'asset_id': '1.3.0'
             },
             'delta_debt': {
                 'amount': 10000,
                 'asset_id': '1.3.22'
             },
             'delta_collateral': {
                 'amount': 100000000,
                 'asset_id': '1.3.0'
             },
             'funding_account': '1.2.29',
             'extensions': []
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c8045701036400000000000000001d00e1f"
                "50500000000001027000000000000160000011f2627efb5c5"
                "144440e06ff567f1a09928d699ac6f5122653cd7173362a1a"
                "e20205952c874ed14ccec050be1c86c1a300811763ef3b481"
                "e562e0933c09b40e31fb")
     self.assertEqual(compare[:-130], txWire[:-130])
Пример #18
0
    def compareConstructedTX(self):
        self.maxDiff = None
        self.op = operations.Bid_collateral(**{
            'fee': {'amount': 100,
                    'asset_id': '1.3.0'},
            'additional_collateral': {
                'amount': 10000,
                'asset_id': '1.3.22'},
            'debt_covered': {
                'amount': 100000000,
                'asset_id': '1.3.0'},
            'bidder': '1.2.29',
            'extensions': []
        })
        ops = [Operation(self.op)]
        tx = Signed_Transaction(
            ref_block_num=ref_block_num,
            ref_block_prefix=ref_block_prefix,
            expiration=expiration,
            operations=ops
        )
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], "BTS")
        txWire = hexlify(bytes(tx)).decode("ascii")
        print("=" * 80)
        pprint(tx.json())
        print("=" * 80)

        from grapheneapi.grapheneapi import GrapheneAPI
        rpc = GrapheneAPI("localhost", 8092)
        self.cm = rpc.serialize_transaction(tx.json())
        print("soll: %s" % self.cm[:-130])
        print("ist:  %s" % txWire[:-130])
        print(txWire[:-130] == self.cm[:-130])
        self.assertEqual(self.cm[:-130], txWire[:-130])
 def test_worker_create(self):
     op = operations.Worker_create(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "owner": "1.2.0",
             "work_begin_date": "1970-01-01T00:00:00",
             "work_end_date": "1970-01-01T00:00:00",
             "daily_pay": 0,
             "name": "Myname",
             "url": "myURL",
             "initializer": [1, {
                 "pay_vesting_period_days": 125
             }]
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c804570122000000000000000000000000000"
                "0000000000000000000000000064d796e616d65056d7955524c"
                "017d0000012049a1430c8045ce7e7a3c0882f537aa9d4547fca"
                "65a6c17967c5daf47aad383175e9f95d0187398da8b8f5b4c78"
                "561f4427b0fc8758e4a3a92afab9388f849f5a")
     self.assertEqual(compare[:-130], txWire[:-130])
Пример #20
0
    def doit(self, printWire=False):
        ops = [Operation(self.op)]
        tx = Signed_Transaction(
            ref_block_num=ref_block_num,
            ref_block_prefix=ref_block_prefix,
            expiration=expiration,
            operations=ops,
        )
        pprint(tx.json())
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], prefix)
        txWire = hexlify(bytes(tx)).decode("ascii")

        if printWire:
            print()
            print(txWire)
            print()

        # Test against Bitshares backened
        live = bitshares.rpc.get_transaction_hex(tx.json())

        # Compare expected result with online backend
        self.assertEqual(live[:-130], self.cm[:-130])

        # Compare expected result with online result
        self.assertEqual(live[:-130], txWire[:-130])

        # Compare expected result with test unit
        self.assertEqual(self.cm[:-130], txWire[:-130])
 def test_feed_producer_update(self):
     op = operations.Asset_update_feed_producers(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "issuer": "1.2.214",
             "asset_to_update": "1.3.132",
             "new_feed_producers": ["1.2.214", "1.2.341", "1.2.2414"],
             "extensions": []
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c80457010d000000000000000000d60184010"
                "3d601d502ee120000011f34dc3aafe350f3f8608cc3d0db3b64"
                "a8f40b60d3528c9fa9e88fc3185fc27f4922ef5612f657205ad"
                "6fc6fed68ec78c4776e1fd125278ab03c8477b37e4c569a")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_asset_reserve(self):
     op = operations.Asset_reserve(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "payer": "1.2.0",
             "amount_to_reserve": {
                 "amount": 1234567890,
                 "asset_id": "1.3.0"
             },
             "extensions": []
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c80457010f00000000000000000000d202964"
                "900000000000000011f75065cb1155bfcaabaf55d3357d69679"
                "c7c1fe589b6dc0919fe1dde1a305009c360823a40c28907299a"
                "40c241db9cad86e27369d0e5a76b5832d585505ff177d")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_witness_update(self):
     op = operations.Witness_update(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "prefix":
             "TEST",
             "witness":
             "1.6.63",
             "witness_account":
             "1.2.212",
             "new_url":
             "https://example.com",
             "new_signing_key":
             "BTS5vfCLKyXYb44znYjbrJXCyvvx3SuifhmvemnQsdbf61EtoR36z"
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c8045701150000000000000000003fd401011"
                "368747470733a2f2f6578616d706c652e636f6d0102889f66e3"
                "584423e86b615e3b07593ebec4b1ac0e08ad4a3748f0726dae7"
                "c874f0001205628a49ef823ab54f4b4c56304f5ac57bdc3768c"
                "62ac630a92de9858f5d90fad01c43bdc406293edad734d53dca"
                "a1c96546a50e3ec96d07cf1224ed329177af5")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_vesting_withdraw(self):
     op = operations.Vesting_balance_withdraw(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "vesting_balance": "1.13.0",
             "owner": "1.2.0",
             "amount": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "prefix": "TEST"
         })
     ops = [Operation(op)]
     tx = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                          ref_block_prefix=ref_block_prefix,
                                          expiration=expiration,
                                          operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c80457012100000000000000000000"
                "0000000000000000000000011f07ae9b0d1cb494e248"
                "6b99cccdf78ef8b785522af8f2233de364d4455c0626"
                "935d2d32414a2f7a6b9cdf3451730062965adeec8aa2"
                "03fca97f608411dce84309")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_whitelist(self):
     op = operations.Account_whitelist(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "authorizing_account": "1.2.0",
             "account_to_list": "1.2.1",
             "new_listing": 0x1,
             "extensions": []
         })
     ops = [Operation(op)]
     tx = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                          ref_block_prefix=ref_block_prefix,
                                          expiration=expiration,
                                          operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c8045701070000000000000000000001010"
                "000011f14eef2978e40b369273907072dddf4b4043d9f3a08"
                "da125311c4e6b54b3e7c2a3606594fab7cf6ce381544eceda"
                "9945c8c9fccebd587cfa2d2f6a146b1639f8c")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_limit_order_create(self):
     op = operations.Limit_order_create(
         **{
             "fee": {
                 "amount": 100,
                 "asset_id": "1.3.0"
             },
             "seller": "1.2.29",
             "amount_to_sell": {
                 "amount": 100000,
                 "asset_id": "1.3.0"
             },
             "min_to_receive": {
                 "amount": 10000,
                 "asset_id": "1.3.105"
             },
             "expiration": "2016-05-18T09:22:05",
             "fill_or_kill": False,
             "extensions": []
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c8045701016400000000000000001da08601000"
                "0000000001027000000000000693d343c57000000011f75cbfd49"
                "ae8d9b04af76cc0a7de8b6e30b71167db7fe8e2197ef9d858df18"
                "77043493bc24ffdaaffe592357831c978fd8a296b913979f106de"
                "be940d60d77b50")
     self.assertEqual(compare[:-130], txWire[:-130])
 def test_update_account(self):
     op = operations.Account_update(
         **{
             "fee": {
                 "amount": 1467634,
                 "asset_id": "1.3.0"
             },
             "account": "1.2.15",
             "owner": {
                 "weight_threshold":
                 1,
                 "account_auths": [["1.2.96086", 1]],
                 'key_auths': [[
                     'BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x',
                     1
                 ]],
                 "address_auths": []
             },
             "active": {
                 "weight_threshold":
                 1,
                 "account_auths": [["1.2.96086", 1]],
                 'key_auths': [[
                     'BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7',
                     1
                 ]],
                 "address_auths": []
             },
             "new_options": {
                 "memo_key":
                 "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
                 "voting_account": "1.2.5",
                 "num_witness": 0,
                 "num_committee": 0,
                 "votes": [],
                 "extensions": []
             },
             "extensions": {}
         })
     ops = [Operation(op)]
     tx = Signed_Transaction(ref_block_num=ref_block_num,
                             ref_block_prefix=ref_block_prefix,
                             expiration=expiration,
                             operations=ops)
     tx = tx.sign([wif], chain=prefix)
     tx.verify([PrivateKey(wif).pubkey], "BTS")
     txWire = hexlify(bytes(tx)).decode("ascii")
     compare = ("f68585abf4dce7c804570106f264160000000000000"
                "f010100000001d6ee0501000102fe8cc11cc8251de6"
                "977636b55c1ab8a9d12b0b26154ac78e56e7c4257d8"
                "bcf69010000010100000001d6ee0501000103b453f4"
                "6013fdbccb90b09ba169c388c34d84454a3b9fbec68"
                "d5a7819a734fca001000001024ab336b4b14ba6d881"
                "675d1c782912783c43dbbe31693aa710ac1896bd7c3"
                "d61050000000000000000011f78b989df5ab29697a3"
                "311f8d7fa8599c548a93809e173ab550b7d8c5051fa"
                "432699d8e24ea82399990c43528ddaf2b3cd8cd2500"
                "1c91f8094d66ae2620effc25")
     self.assertEqual(compare[:-130], txWire[:-130])
 def appendWif(self, wif):
     """ Add a wif that should be used for signing of the transaction.
     """
     if wif:
         try:
             PrivateKey(wif)
             self.wifs.append(wif)
         except:
             raise InvalidWifError
Пример #29
0
 def test_decrypt_bugged_padding(self):
     for memo in not_enough_padding:
         dec = decode_memo(
             PrivateKey(memo["wif"]),
             PublicKey(memo["to"], prefix="GPH"),
             memo["nonce"],
             memo["message"],
         )
         self.assertEqual(memo["plain"], dec)
Пример #30
0
 def test_encrypt(self):
     for memo in test_cases:
         enc = encode_memo(
             PrivateKey(memo["wif"]),
             PublicKey(memo["to"], prefix="GPH"),
             memo["nonce"],
             memo["plain"],
         )
         self.assertEqual(memo["message"], enc)