eth-erc721

ERC-721 'NFT' token interface with example developer badge token contract
Info | Log | Files | Refs | LICENSE

enum.py (2473B)


      1 # external imports
      2 from hexathon import strip_0x
      3 from chainlib.eth.nonce import RPCNonceOracle
      4 # TODO: for mint, move to cic-contracts unittest
      5 from eth_badgetoken import BadgeToken 
      6 from chainlib.eth.tx import receipt
      7 
      8 # local imports
      9 from .base import TestInterface as TestInterfaceBase
     10 
     11 
     12 class TestInterface(TestInterfaceBase):
     13 
     14     def test_token_index(self):
     15         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     16         c = BadgeToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     17 
     18         token_bytes = b'\xee' * 32
     19         token_id_one = int.from_bytes(token_bytes, byteorder='big')
     20         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], token_id_one)
     21         r = self.rpc.do(o)
     22 
     23         token_bytes = b'\xee' * 32
     24         token_id_two = int.from_bytes(token_bytes, byteorder='big')
     25         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], token_id_two)
     26         r = self.rpc.do(o)
     27 
     28         o = c.token_by_index(self.address, 0, sender_address=self.accounts[0])
     29         r = self.rpc.do(o)
     30         token = c.parse_token_by_index(r)
     31         self.assertEqual(token_id_one, token)
     32 
     33         o = c.token_by_index(self.address, 1, sender_address=self.accounts[0])
     34         r = self.rpc.do(o)
     35         token = c.parse_token_by_index(r)
     36         self.assertEqual(token_id_two, token)
     37 
     38 
     39 
     40     def test_token_owner_index(self):
     41         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     42         c = BadgeToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     43 
     44         token_bytes = b'\xee' * 32
     45         token_id_one = int.from_bytes(token_bytes, byteorder='big')
     46         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], token_id_one)
     47         r = self.rpc.do(o)
     48 
     49         token_bytes = b'\xee' * 32
     50         token_id_two = int.from_bytes(token_bytes, byteorder='big')
     51         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], token_id_two)
     52         r = self.rpc.do(o)
     53 
     54         o = c.token_of_owner_by_index(self.address, self.accounts[1], 0, sender_address=self.accounts[0])
     55         r = self.rpc.do(o)
     56         token = c.parse_token_by_index(r)
     57         self.assertEqual(token_id_one, token)
     58 
     59         o = c.token_of_owner_by_index(self.address, self.accounts[2], 0, sender_address=self.accounts[0])
     60         r = self.rpc.do(o)
     61         token = c.parse_token_by_index(r)
     62         self.assertEqual(token_id_two, token)