craft-nft

A standalone NFT implementation for real-world arts and crafts assets
Info | Log | Files | Refs | README

test_basic.py (23371B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import json
      5 import logging
      6 
      7 # external imports
      8 from chainlib.eth.unittest.ethtester import EthTesterCase
      9 from chainlib.connection import RPCConnection
     10 from chainlib.eth.nonce import RPCNonceOracle
     11 from chainlib.eth.address import to_checksum_address
     12 from chainlib.eth.tx import (
     13         receipt,
     14         transaction,
     15         TxFormat,
     16         )
     17 from chainlib.eth.contract import (
     18         abi_decode_single,
     19         ABIContractType,
     20         )
     21 from chainlib.eth.address import is_same_address
     22 from chainlib.error import JSONRPCException
     23 from chainlib.eth.constant import ZERO_ADDRESS
     24 from hexathon import (
     25         add_0x,
     26         strip_0x,
     27         )
     28 from chainlib.eth.tx import TxFormat
     29 from chainlib.eth.contract import ABIContractEncoder
     30 from eth_interface.unittest import TestERC165
     31 
     32 
     33 # local imports
     34 from craft_nft import CraftNFT
     35 from craft_nft.unittest import TestCraftNFT
     36 from craft_nft.error import InvalidBatchError
     37 from craft_nft.eth import ABIContractType
     38 from craft_nft.nft import to_batch_key
     39 
     40 logging.basicConfig(level=logging.DEBUG)
     41 logg = logging.getLogger()
     42 
     43 testdir = os.path.dirname(__file__)
     44 
     45 hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
     46 hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
     47 
     48 
     49 class Test(TestCraftNFT, TestERC165):
     50 
     51     def setUp(self):
     52         super(Test, self).setUp()
     53         self.flush_interface_check()
     54         for ifc in [
     55             'ed75b333',
     56             'abe1f1f5',
     57             'f0440c0f',
     58             '449a52f8',
     59             '982ab05d',
     60             #'150b7a02',
     61             'dd9d2087',
     62             'd283ef1d',
     63             'c22876c3',
     64             ]:
     65             self.add_interface_check(ifc)
     66 
     67     def test_allocate(self):
     68         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     69         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     70         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=0)
     71         self.rpc.do(o)
     72         o = receipt(tx_hash_hex)
     73         r = self.conn.do(o)
     74         self.assertEqual(r['status'], 1)
     75 
     76     
     77     def test_allocate_batch(self):
     78         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     79         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     80         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10)
     81         self.rpc.do(o)
     82         o = receipt(tx_hash_hex)
     83         r = self.conn.do(o)
     84         self.assertEqual(r['status'], 1)
     85 
     86 
     87     def test_batch_of(self):
     88         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     89         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     90         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10)
     91         self.rpc.do(o)
     92 
     93         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=20)
     94         self.rpc.do(o)
     95         o = receipt(tx_hash_hex)
     96         r = self.conn.do(o)
     97         self.assertEqual(r['status'], 1)
     98 
     99         r = c.batch_of(self.rpc, self.address, hash_of_foo, 9, sender_address=self.accounts[0])
    100         self.assertEqual(r, 0)
    101 
    102         r = c.batch_of(self.rpc, self.address, hash_of_foo, 10, sender_address=self.accounts[0])
    103         self.assertEqual(r, 1)
    104 
    105         r = c.batch_of(self.rpc, self.address, hash_of_foo, 29, sender_address=self.accounts[0])
    106         self.assertEqual(r, 1)
    107 
    108         with self.assertRaises(ValueError):
    109             c.batch_of(self.rpc, self.address, hash_of_foo, 30, sender_address=self.accounts[0])
    110 
    111 
    112     def test_mint_to(self):
    113         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    114         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    115 
    116         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    117         self.rpc.do(o)
    118         o = receipt(tx_hash_hex)
    119         r = self.conn.do(o)
    120         self.assertEqual(r['status'], 0)
    121 
    122         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=20)
    123         self.rpc.do(o)
    124         o = receipt(tx_hash_hex)
    125         r = self.conn.do(o)
    126         self.assertEqual(r['status'], 1)
    127 
    128         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    129         self.rpc.do(o)
    130         o = receipt(tx_hash_hex)
    131         r = self.conn.do(o)
    132         self.assertEqual(r['status'], 1)
    133 
    134 
    135     def test_mint_to_limit(self):
    136         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    137         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    138         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10)
    139         self.rpc.do(o)
    140         o = receipt(tx_hash_hex)
    141         r = self.conn.do(o)
    142         self.assertEqual(r['status'], 1)
    143 
    144         for i in range(10):
    145             (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[(i%8)+i], hash_of_foo, 0)
    146             self.rpc.do(o)
    147             o = receipt(tx_hash_hex)
    148             r = self.conn.do(o)
    149             self.assertEqual(r['status'], 1)
    150 
    151 
    152         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0)
    153         self.rpc.do(o)
    154         o = receipt(tx_hash_hex)
    155         r = self.conn.do(o)
    156         self.assertEqual(r['status'], 0)
    157 
    158 
    159 
    160     def test_mint_to_single(self):
    161         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    162         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    163 
    164         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    165         self.rpc.do(o)
    166         o = receipt(tx_hash_hex)
    167         r = self.conn.do(o)
    168         self.assertEqual(r['status'], 0)
    169 
    170         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=0)
    171         self.rpc.do(o)
    172         o = receipt(tx_hash_hex)
    173         r = self.conn.do(o)
    174         self.assertEqual(r['status'], 1)
    175 
    176         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 1)
    177         self.rpc.do(o)
    178         o = receipt(tx_hash_hex)
    179         r = self.conn.do(o)
    180         self.assertEqual(r['status'], 0)
    181 
    182         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    183         self.rpc.do(o)
    184         o = receipt(tx_hash_hex)
    185         r = self.conn.do(o)
    186         self.assertEqual(r['status'], 1)
    187 
    188         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    189         self.rpc.do(o)
    190         o = receipt(tx_hash_hex)
    191         r = self.conn.do(o)
    192         self.assertEqual(r['status'], 0)
    193 
    194         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 1)
    195         self.rpc.do(o)
    196         o = receipt(tx_hash_hex)
    197         r = self.conn.do(o)
    198         self.assertEqual(r['status'], 0)
    199 
    200         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], hash_of_foo, 0)
    201         self.rpc.do(o)
    202         o = receipt(tx_hash_hex)
    203         r = self.conn.do(o)
    204         self.assertEqual(r['status'], 0)
    205 
    206         int_of_foo = int(hash_of_foo, 16)
    207         o = c.owner_of(self.address, int_of_foo, sender_address=self.accounts[0])
    208         r = self.rpc.do(o) 
    209         owner = strip_0x(r)
    210         self.assertTrue(is_same_address(owner[24:], self.accounts[1]))
    211 
    212 
    213 
    214     def test_mint_to_batch(self):
    215         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    216         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    217 
    218         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10)
    219         self.rpc.do(o)
    220 
    221         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    222         self.rpc.do(o)
    223         o = receipt(tx_hash_hex)
    224         r = self.conn.do(o)
    225         self.assertEqual(r['status'], 1)
    226 
    227         expected_id = hash_of_foo[:64-16] + '0000000000000000'
    228         o = c.get_token(self.address, expected_id, sender_address=self.accounts[0])
    229         r = self.rpc.do(o)
    230         o = receipt(tx_hash_hex)
    231         r = self.conn.do(o)
    232         self.assertEqual(r['status'], 1)
    233 
    234         o = c.owner_of(self.address, int(expected_id, 16), sender_address=self.accounts[0])
    235         r = self.rpc.do(o) 
    236         owner = strip_0x(r)
    237         self.assertTrue(is_same_address(owner[24:], self.accounts[1]))
    238 
    239         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], hash_of_foo, 0)
    240         self.rpc.do(o)
    241         o = receipt(tx_hash_hex)
    242         r = self.conn.do(o)
    243         self.assertEqual(r['status'], 1)
    244 
    245         expected_id = hash_of_foo[:64-16] + '0000000000000001'
    246         o = c.get_token(self.address, expected_id, sender_address=self.accounts[0])
    247         r = self.rpc.do(o)
    248 
    249         o = c.owner_of(self.address, int(expected_id, 16), sender_address=self.accounts[0])
    250         r = self.rpc.do(o) 
    251         owner = strip_0x(r)
    252         self.assertTrue(is_same_address(owner[24:], self.accounts[2]))
    253 
    254 
    255     def test_mint_to_dup(self):
    256         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    257         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    258 
    259         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10)
    260         self.rpc.do(o)
    261 
    262         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    263         self.rpc.do(o)
    264         o = receipt(tx_hash_hex)
    265         r = self.conn.do(o)
    266         self.assertEqual(r['status'], 1)
    267 
    268         enc = ABIContractEncoder()
    269         enc.method('mintTo')
    270         enc.typ(ABIContractType.ADDRESS)
    271         enc.typ(ABIContractType.BYTES32)
    272         enc.typ(ABIContractType.UINT256)
    273         enc.address(self.accounts[1])
    274         enc.bytes32(hash_of_foo)
    275         enc.uint256(0)
    276         data = enc.get()
    277         tx = c.template(self.accounts[0], self.address, use_nonce=True)
    278         tx = c.set_code(tx, data)
    279         (tx_hash_hex, o) = c.finalize(tx, TxFormat.JSONRPC)
    280         r = self.rpc.do(o)
    281         o = receipt(tx_hash_hex)
    282         r = self.conn.do(o)
    283         self.assertEqual(r['status'], 0)
    284 
    285 
    286     def test_transfer(self):
    287         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    288         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    289 
    290         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=0)
    291         self.rpc.do(o)
    292 
    293         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    294         self.rpc.do(o)
    295 
    296         int_of_foo = int(hash_of_foo, 16)
    297         nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
    298         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    299         (tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[1], self.accounts[2], int_of_foo)
    300         self.rpc.do(o)
    301         o = receipt(tx_hash_hex)
    302         r = self.conn.do(o)
    303         self.assertEqual(r['status'], 1)
    304 
    305         o = c.owner_of(self.address, int_of_foo, sender_address=self.accounts[0])
    306         r = self.rpc.do(o) 
    307         owner = strip_0x(r)
    308         self.assertTrue(is_same_address(owner[24:], self.accounts[2]))
    309 
    310 
    311     def test_transfer_batched(self):
    312         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    313         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    314 
    315         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10)
    316         self.rpc.do(o)
    317 
    318         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    319         self.rpc.do(o)
    320 
    321         expected_id = hash_of_foo[:64-16] + '0000000000000000'
    322         int_of_foo = int(expected_id, 16)
    323 
    324         nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
    325         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    326         (tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[1], self.accounts[2], int_of_foo)
    327         self.rpc.do(o)
    328         o = receipt(tx_hash_hex)
    329         r = self.conn.do(o)
    330         self.assertEqual(r['status'], 1)
    331 
    332 
    333     def test_fill_batches(self):
    334         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    335         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    336         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=6)
    337         self.rpc.do(o)
    338 
    339         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=8)
    340         self.rpc.do(o)
    341 
    342         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=4)
    343         self.rpc.do(o)
    344 
    345         for i in range(6+8+4):
    346             batch = c.batch_of(self.rpc, self.address, hash_of_foo, i, sender_address=self.accounts[0])
    347 
    348             (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[(i%7)+1], hash_of_foo, batch)
    349             r = self.rpc.do(o)
    350             o = receipt(tx_hash_hex)
    351             r = self.conn.do(o)
    352             self.assertEqual(r['status'], 1)
    353 
    354         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 2)
    355         r = self.rpc.do(o)
    356         o = receipt(tx_hash_hex)
    357         r = self.conn.do(o)
    358         self.assertEqual(r['status'], 0)
    359 
    360 
    361     def test_digest_single(self):
    362         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    363         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    364         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo)
    365         self.rpc.do(o)
    366 
    367         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    368         self.rpc.do(o)
    369 
    370         o = c.get_token_spec(self.address, hash_of_foo, 0, sender_address=self.accounts[0])
    371         r = self.rpc.do(o)
    372 
    373         o = c.get_token(self.address, hash_of_foo, sender_address=self.accounts[0])
    374         r = self.rpc.do(o)
    375 
    376         o = c.get_digest(self.address, hash_of_foo, sender_address=self.accounts[0])
    377         r = self.rpc.do(o)
    378         self.assertEqual(strip_0x(r), hash_of_foo)
    379 
    380 
    381 
    382     def test_digest_batch(self):
    383         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    384         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    385         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=2)
    386         self.rpc.do(o)
    387 
    388         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=3)
    389         self.rpc.do(o)
    390 
    391         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    392         self.conn.do(o)
    393 
    394         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 1)
    395         self.rpc.do(o)
    396 
    397         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 1)
    398         self.rpc.do(o)
    399 
    400         expected_id = hash_of_foo[:64-16] + '0000000000000000'
    401         o = c.get_digest(self.address, expected_id, sender_address=self.accounts[0])
    402         r = self.rpc.do(o)
    403         self.assertEqual(strip_0x(r), hash_of_foo)
    404 
    405         expected_id = hash_of_foo[:64-16] + '0001000000000000'
    406         o = c.get_token(self.address, expected_id, sender_address=self.accounts[0])
    407         self.rpc.do(o)
    408 
    409         o = c.get_digest(self.address, expected_id, sender_address=self.accounts[0])
    410         r = self.rpc.do(o)
    411         self.assertEqual(strip_0x(r), hash_of_foo)
    412 
    413         expected_id = hash_of_foo[:64-16] + '0001000000000001'
    414         o = c.get_digest(self.address, expected_id, sender_address=self.accounts[0])
    415         r = self.rpc.do(o)
    416         self.assertEqual(strip_0x(r), hash_of_foo)
    417 
    418 
    419     def test_multi(self):
    420         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    421         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    422 
    423         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=2)
    424         self.rpc.do(o)
    425 
    426         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=3)
    427         self.rpc.do(o)
    428  
    429         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_bar)
    430         self.rpc.do(o)
    431         o = receipt(tx_hash_hex)
    432         r = self.conn.do(o)
    433         self.assertEqual(r['status'], 1)
    434 
    435         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_bar, 0)
    436         self.rpc.do(o)
    437         o = receipt(tx_hash_hex)
    438         r = self.conn.do(o)
    439         self.assertEqual(r['status'], 1)
    440 
    441         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    442         self.rpc.do(o)
    443         o = receipt(tx_hash_hex)
    444         r = self.conn.do(o)
    445         self.assertEqual(r['status'], 1)
    446 
    447         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_bar, 0)
    448         self.rpc.do(o)
    449         o = receipt(tx_hash_hex)
    450         r = self.conn.do(o)
    451         self.assertEqual(r['status'], 0)
    452 
    453         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    454         self.rpc.do(o)
    455         o = receipt(tx_hash_hex)
    456         r = self.conn.do(o)
    457         self.assertEqual(r['status'], 1)
    458 
    459         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    460         self.rpc.do(o)
    461         o = receipt(tx_hash_hex)
    462         r = self.conn.do(o)
    463         self.assertEqual(r['status'], 0)
    464 
    465         expected_id = hash_of_foo[:64-16] + '0000000000000000'
    466         o = c.get_digest(self.address, expected_id, sender_address=self.accounts[0])
    467         r = self.rpc.do(o)
    468         self.assertEqual(strip_0x(r), hash_of_foo)
    469 
    470         o = c.get_digest(self.address, hash_of_bar, sender_address=self.accounts[0])
    471         r = self.rpc.do(o)
    472         self.assertEqual(strip_0x(r), hash_of_bar)
    473 
    474 
    475     def test_balance(self):
    476         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    477         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    478 
    479         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=3)
    480         self.rpc.do(o)
    481 
    482         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_bar, amount=0)
    483         self.rpc.do(o)
    484 
    485         o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
    486         r = self.rpc.do(o)
    487         balance = c.parse_balance(r)
    488         self.assertEqual(balance, 0)
    489 
    490         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    491         self.rpc.do(o)
    492 
    493         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo, 0)
    494         self.rpc.do(o)
    495 
    496         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_bar, 0)
    497         self.rpc.do(o)
    498 
    499         o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
    500         r = self.rpc.do(o)
    501         balance = c.parse_balance(r)
    502         self.assertEqual(balance, 3)
    503 
    504         nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
    505         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    506         expected_id = to_batch_key(hash_of_foo, 0, 1)
    507         (tx_hash_hex, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[1], self.accounts[2], int(expected_id, 16))
    508         self.rpc.do(o)
    509         o = receipt(tx_hash_hex)
    510         r = self.conn.do(o)
    511         self.assertEqual(r['status'], 1)
    512 
    513         o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
    514         r = self.rpc.do(o)
    515         balance = c.parse_balance(r)
    516         self.assertEqual(balance, 2)
    517 
    518         o = c.balance(self.address, self.accounts[2], sender_address=self.accounts[0])
    519         r = self.rpc.do(o)
    520         balance = c.parse_balance(r)
    521         self.assertEqual(balance, 1)
    522 
    523         (tx_hash_hex, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[1], self.accounts[3], int(hash_of_bar, 16))
    524         self.rpc.do(o)
    525         o = receipt(tx_hash_hex)
    526         r = self.conn.do(o)
    527         self.assertEqual(r['status'], 1)
    528 
    529         o = c.balance(self.address, self.accounts[1], sender_address=self.accounts[0])
    530         r = self.rpc.do(o)
    531         balance = c.parse_balance(r)
    532         self.assertEqual(balance, 1)
    533 
    534         o = c.balance(self.address, self.accounts[3], sender_address=self.accounts[0])
    535         r = self.rpc.do(o)
    536         balance = c.parse_balance(r)
    537         self.assertEqual(balance, 1)
    538 
    539 
    540     def test_mint_uncapped(self):
    541         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    542         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    543 
    544         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=-1)
    545         self.rpc.do(o)
    546         o = receipt(tx_hash_hex)
    547         r = self.conn.do(o)
    548         self.assertEqual(r['status'], 1)
    549 
    550         for i in range(5):
    551             (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1+i], hash_of_foo, 0)
    552             self.rpc.do(o)
    553             o = receipt(tx_hash_hex)
    554             r = self.conn.do(o)
    555             self.assertEqual(r['status'], 1)
    556  
    557         (tx_hash_hex, o) = c.set_cap(self.address, self.accounts[0], hash_of_foo, 0, 4)
    558         self.rpc.do(o)
    559         o = receipt(tx_hash_hex)
    560         r = self.conn.do(o)
    561         self.assertEqual(r['status'], 0)
    562 
    563         (tx_hash_hex, o) = c.set_cap(self.address, self.accounts[0], hash_of_foo, 0, 6)
    564         self.rpc.do(o)
    565         o = receipt(tx_hash_hex)
    566         r = self.conn.do(o)
    567         self.assertEqual(r['status'], 1)
    568 
    569         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1+i], hash_of_foo, 0)
    570         self.rpc.do(o)
    571         o = receipt(tx_hash_hex)
    572         r = self.conn.do(o)
    573         self.assertEqual(r['status'], 1)
    574 
    575         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], hash_of_foo, 0)
    576         self.rpc.do(o)
    577         o = receipt(tx_hash_hex)
    578         r = self.conn.do(o)
    579         self.assertEqual(r['status'], 0)
    580         
    581 
    582     def test_mint_cap_immediate(self):
    583         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    584         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    585 
    586         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=-1)
    587         self.rpc.do(o)
    588         o = receipt(tx_hash_hex)
    589         r = self.conn.do(o)
    590         self.assertEqual(r['status'], 1)
    591 
    592         for i in range(3):
    593             (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1+i], hash_of_foo, 0)
    594             self.rpc.do(o)
    595             o = receipt(tx_hash_hex)
    596             r = self.conn.do(o)
    597             self.assertEqual(r['status'], 1)
    598  
    599         (tx_hash_hex, o) = c.set_cap(self.address, self.accounts[0], hash_of_foo, 0, 0)
    600         self.rpc.do(o)
    601         o = receipt(tx_hash_hex)
    602         r = self.conn.do(o)
    603         self.assertEqual(r['status'], 1)
    604 
    605         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], hash_of_foo, 0)
    606         self.rpc.do(o)
    607         o = receipt(tx_hash_hex)
    608         r = self.conn.do(o)
    609         self.assertEqual(r['status'], 0)
    610 
    611 
    612 if __name__ == '__main__':
    613     unittest.main()