craft-nft

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

test_spec.py (2127B)


      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 chainlib.eth.contract import ABIContractType
     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 
     38 logging.basicConfig(level=logging.DEBUG)
     39 logg = logging.getLogger()
     40 
     41 testdir = os.path.dirname(__file__)
     42 
     43 hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
     44 hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
     45 
     46 
     47 class TestSpec(TestCraftNFT):
     48     
     49     def test_allocate_mint_spec(self):
     50         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     51         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     52 
     53         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=2)
     54         self.rpc.do(o)
     55 
     56         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=3)
     57         self.rpc.do(o)
     58        
     59         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 1)
     60         self.rpc.do(o)
     61 
     62         o = c.get_token_spec(self.address, hash_of_foo, 1, sender_address=self.accounts[0])
     63         r = self.rpc.do(o)
     64         spec = c.parse_token_spec(r) 
     65         self.assertEqual(spec.count, 3)
     66         self.assertEqual(spec.cursor, 1)
     67 
     68 
     69 if __name__ == '__main__':
     70     unittest.main()