Ejemplo n.º 1
0
 def test_cmp_different_id_assetid(self):
     name = hexlify("name".encode())
     asset1 = AssetID(
         name, "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7")
     asset2 = AssetID(
         name, "a1a815a7323c69c86abbafb66dbfdb1aa76b8d07d69639e9413dd637")
     self.assertNotEqual(asset1, asset2)
Ejemplo n.º 2
0
 def test_cmp_same_assetid(self):
     asset1 = AssetID(
         "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7", "name"
     )
     asset2 = AssetID(
         "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7", "name"
     )
     self.assertEqual(asset1, asset2)
Ejemplo n.º 3
0
 def test_cmp_different_name_assetid(self):
     asset1 = AssetID(
         "name1", "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
     )
     asset2 = AssetID(
         "name2", "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
     )
     self.assertNotEqual(asset1, asset2)
Ejemplo n.º 4
0
 def test_cmp_same_assetid(self):
     name = hexlify("name".encode())
     asset1 = AssetID(
         name,
         "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7",
     )
     asset2 = AssetID(
         name,
         "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7",
     )
     self.assertEqual(asset1, asset2)
Ejemplo n.º 5
0
 def test_ascii(self):
     name = "test coin"
     name_hex = hexlify(name.encode("ascii")).decode()
     asset = AssetID(
         name_hex,
         "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7")
     self.assertEqual(asset.name_bytes, name.encode("ascii"))
Ejemplo n.º 6
0
 def test_utf8(self):
     name = "zażółć gęślą jaźń"
     name_hex = hexlify(name.encode("utf-8")).decode()
     asset = AssetID(
         name_hex,
         "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7")
     self.assertEqual(asset.name_bytes, name.encode("utf-8"))
Ejemplo n.º 7
0
 def test_cmp_bytes_to_assetid(self):
     asset1 = (
         "name:6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7".encode()
     )
     asset2 = AssetID(
         "name", "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
     )
     self.assertEqual(asset1, asset2)
Ejemplo n.º 8
0
 def test_cmp_assetid_to_bytes(self):
     name = hexlify("name".encode())
     asset1 = AssetID(
         name, "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7")
     asset2 = (
         "6e616d65:6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
         .encode())
     self.assertEqual(asset1, asset2)
Ejemplo n.º 9
0
 def test_retrieve_wallet_with_assets(self):
     responses.add(
         responses.GET,
         self._url("wallets/eff9cc89621111677a501493ace8c3f05608c0ce"),
         json=self._read(
             "test_retrieve_wallet_with_assets-00-GET_wallets_eff9cc89621111677a501493ace8c3f05608c0ce.json"
         ),
         status=200,
     )
     wallet = self.service.wallet("eff9cc89621111677a501493ace8c3f05608c0ce")
     self.assertIsInstance(wallet, Wallet)
     self.assertEqual(wallet.wid, "eff9cc89621111677a501493ace8c3f05608c0ce")
     assets = wallet.assets()
     self.assertEqual(len(assets), 14)
     exp_assets = {
         AssetID(
             "6c6f766164616e6674",
             "0c306361512844fbdb83294f278937c04af6e56ab1d94d2dd187d725",
         ),
         AssetID(
             "6c6f766164616e6674",
             "0f5e9e9143f4eb0317584aa295d0d2dc9741edfdbbe1af64f241aa32",
         ),
         AssetID(
             "6c6f766164616e6674",
             "19b5961ad59574e2eb90d80894bbca8b51b7e2fbfe8ac649697c1255",
         ),
         AssetID(
             "6c6f766164616e6674",
             "1c088dec595714fb23d3eb806dcffaaaec8c275b502e2cc047026012",
         ),
         AssetID(
             "6c6f766164616e6674",
             "2efcadf7209b422c7742c1b1ceb8b82cfd6ae6b099226bc195daddfa",
         ),
         AssetID(
             "6c6f766164616e6674",
             "57fbec4da0c525282f50f2ff2567ecb529c276ea972dd31a1e1d8e41",
         ),
         AssetID(
             "6c6f766164616e6674",
             "618e9db244d4832faf1bd937a423f3f8aea558bed396f74fa82f8fea",
         ),
         AssetID(
             "6c6f766164616e6674",
             "6604684337b45547a5fdfb418c6ad140aba3d02e65b0bb0dc3c492a1",
         ),
         AssetID(
             "6c6f766164616e6674",
             "68bf925a392af499964003a5caaef10edd1ceac7d2c08e7bd7b287d0",
         ),
         AssetID(
             "6c6f766164616e6674",
             "73d4f77b57be5bbdf7c7cb475662083a4111f6e018cffb056142f14e",
         ),
         AssetID(
             "6c6f766164616e6674",
             "88c5393b19640c59611a73bf7ec7e7884fc228544a24b2e384d3ed32",
         ),
         AssetID(
             "6c6f766164616e6674",
             "9dfc0ed69a98a12f97b6a74e6a41cfb9aecdc5883b2ecbf2f9d13672",
         ),
         AssetID(
             "6c6f766164616e6674",
             "b03f3f89862ecb51522832535e525ec014c884e047f63acc786567bb",
         ),
         AssetID(
             "6c6f766164616e6674",
             "dcb9bccdb63474aaa16f0ef041c59c582bbd85ad19cca7119ba5ea79",
         ),
     }
     self.assertSetEqual(set(assets.keys()), exp_assets)
     for asset_id, balance in assets.items():
         self.assertEqual(balance.available, balance.total)
         self.assertGreater(balance.total, 0)
         self.assertIsNone(balance.reward)
Ejemplo n.º 10
0
    def test_transfer_asset(self):
        responses.add(
            responses.POST,
            self._url("wallets/{:s}/transactions".format(self.wala.wid)),
            json=self._read(
                "test_transfer_asset-10-POST_transfer_{:s}.json".format(self.wala.wid)
            ),
            status=200,
        )
        responses.add(
            responses.GET,
            self._url("wallets/{:s}/addresses".format(self.wala.wid)),
            json=self._read(
                "test_transfer_asset-20-GET_addresses_{:s}.json".format(self.wala.wid)
            ),
            status=200,
        )
        responses.add(
            responses.GET,
            self._url("wallets/{:s}".format(self.wala.wid)),
            json=self._read(
                "test_transfer_asset-30-GET_wallets_{:s}.json".format(self.wala.wid)
            ),
            status=200,
        )
        responses.add(
            responses.GET,
            self._url("wallets/{:s}/transactions".format(self.walb.wid)),
            json=self._read(
                "test_transfer_asset-40-GET_transactions_{:s}.json".format(
                    self.walb.wid
                )
            ),
            status=200,
        )
        responses.add(
            responses.GET,
            self._url("wallets/{:s}/addresses".format(self.walb.wid)),
            json=self._read(
                "test_transfer_asset-50-GET_addresses_{:s}.json".format(self.walb.wid)
            ),
            status=200,
        )
        responses.add(
            responses.GET,
            self._url("wallets/{:s}".format(self.walb.wid)),
            json=self._read(
                "test_transfer_asset-60-GET_wallets_{:s}.json".format(self.walb.wid)
            ),
            status=200,
        )

        asset_id = AssetID(
            "", "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
        )
        tx_out = self.wala.transfer(
            "addr_test1qqpwa4lv202c9q4fag5kepr0jjnreq8yxrjgau7u4ulppa9c69u4ed55s8p7nuef3z65fkjjxcslwdu3h75zl7zeuzgqv3l7cc",
            2,
            assets=[(asset_id, 1)],
        )
        self.assertEqual(tx_out.amount_in, 0)
        self.assertEqual(tx_out.amount_out, 2)
        self.assertEqual(len(tx_out.inputs), 2)  # one with asset, one with fee
        self.assertEqual(len(tx_out.local_inputs), 2)  # both are local
        self.assertEqual(len(tx_out.outputs), 2)  # payment + change
        self.assertEqual(len(tx_out.local_outputs), 1)  # change

        assetsa = self.wala.assets()
        self.assertEqual(len(assetsa), 1)
        self.assertIn(asset_id, assetsa)
        self.assertEqual(assetsa[asset_id].total, 1)
        self.assertEqual(assetsa[asset_id].available, 1)

        tx_in = self.walb.transactions()[0]
        self.assertEqual(tx_in.amount_in, 2)
        self.assertEqual(tx_in.amount_out, 0)
        self.assertEqual(len(tx_in.inputs), 2)  # one with asset, one with fee
        self.assertEqual(len(tx_in.local_inputs), 0)  # none are local
        self.assertEqual(len(tx_in.outputs), 2)  # payment + change
        self.assertEqual(len(tx_in.local_outputs), 1)  # payment

        assetsb = self.walb.assets()
Ejemplo n.º 11
0
 def test_cmp_assetid_to_none(self):
     asset1 = AssetID(
         "name", "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
     )
     self.assertNotEqual(asset1, None)
Ejemplo n.º 12
0
 def test_cmp_string_to_assetid(self):
     asset1 = "name:6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
     asset2 = AssetID(
         "name", "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7"
     )
     self.assertEqual(asset1, asset2)
Ejemplo n.º 13
0
 def test_cmp_assetid_to_none(self):
     name = hexlify("name".encode())
     asset1 = AssetID(
         name, "6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7")
     self.assertNotEqual(asset1, None)