craft-nft

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

test_supply.py (4161B)


      1 import os
      2 import unittest
      3 import json
      4 import logging
      5 
      6 # external imports
      7 from chainlib.eth.unittest.ethtester import EthTesterCase
      8 from chainlib.connection import RPCConnection
      9 from chainlib.eth.nonce import RPCNonceOracle
     10 from chainlib.eth.address import to_checksum_address
     11 from chainlib.eth.tx import (
     12         receipt,
     13         transaction,
     14         TxFormat,
     15         )
     16 from chainlib.eth.contract import (
     17         abi_decode_single,
     18         ABIContractType,
     19         )
     20 from chainlib.eth.address import is_same_address
     21 from chainlib.error import JSONRPCException
     22 from chainlib.eth.constant import ZERO_ADDRESS
     23 from hexathon import (
     24         add_0x,
     25         strip_0x,
     26         )
     27 from chainlib.eth.tx import TxFormat
     28 from chainlib.eth.contract import ABIContractEncoder
     29 from chainlib.eth.contract import ABIContractType
     30 
     31 
     32 # local imports
     33 from craft_nft import CraftNFT
     34 from craft_nft.unittest import TestCraftNFT
     35 from craft_nft.error import InvalidBatchError
     36 
     37 logging.basicConfig(level=logging.DEBUG)
     38 logg = logging.getLogger()
     39 
     40 testdir = os.path.dirname(__file__)
     41 
     42 hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
     43 hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
     44 
     45 
     46 class TestSupply(TestCraftNFT):
     47 
     48     def test_supply_single(self):
     49         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     50         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     51 
     52         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo)
     53         self.rpc.do(o)
     54 
     55         o = c.total_supply(self.address, sender_address=self.accounts[0])
     56         r = self.rpc.do(o)
     57         supply = c.parse_total_supply(r)
     58         self.assertEqual(supply, 0);
     59       
     60         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo)
     61         self.rpc.do(o)  
     62 
     63         o = c.total_supply(self.address, sender_address=self.accounts[0])
     64         r = self.rpc.do(o)
     65         supply = c.parse_total_supply(r)
     66         self.assertEqual(supply, 1);
     67 
     68     
     69     def test_supply_batch(self):
     70         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     71         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     72 
     73         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=9)
     74         self.rpc.do(o)
     75 
     76         o = c.total_supply(self.address, sender_address=self.accounts[0])
     77         r = self.rpc.do(o)
     78         supply = c.parse_total_supply(r)
     79         self.assertEqual(supply, 0);
     80      
     81         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo)
     82         self.rpc.do(o)
     83 
     84         o = c.total_supply(self.address, sender_address=self.accounts[0])
     85         r = self.rpc.do(o)
     86         supply = c.parse_total_supply(r)
     87         self.assertEqual(supply, 1);
     88 
     89 
     90     def test_supply_mixed(self):
     91         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     92         c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     93 
     94         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=0)
     95         self.rpc.do(o)
     96 
     97         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_bar, amount=10)
     98         self.rpc.do(o)
     99 
    100         (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_bar, amount=5)
    101         self.rpc.do(o)
    102 
    103         o = c.total_supply(self.address, sender_address=self.accounts[0])
    104         r = self.rpc.do(o)
    105         supply = c.parse_total_supply(r)
    106         self.assertEqual(supply, 0);
    107 
    108         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[3], hash_of_bar)
    109         self.rpc.do(o)
    110 
    111         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[2], hash_of_bar)
    112         self.rpc.do(o)
    113 
    114         (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], hash_of_foo)
    115         self.rpc.do(o)
    116 
    117         o = c.total_supply(self.address, sender_address=self.accounts[0])
    118         r = self.rpc.do(o)
    119         supply = c.parse_total_supply(r)
    120         self.assertEqual(supply, 3);
    121 
    122 
    123 if __name__ == '__main__':
    124     unittest.main()
    125