test_numbered.py (5240B)
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 Test(TestCraftNFT): 48 49 50 def test_set_numbered(self): 51 nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) 52 c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 53 54 (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=2) 55 self.rpc.do(o) 56 57 o = c.get_token_spec(self.address, hash_of_foo, 0, sender_address=self.accounts[0]) 58 r = self.rpc.do(o) 59 spec = c.parse_token_spec(r) 60 61 62 def test_mint_number(self): 63 nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) 64 c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 65 66 (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=1000) 67 self.rpc.do(o) 68 69 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=666) 70 self.rpc.do(o) 71 o = receipt(tx_hash_hex) 72 r = self.conn.do(o) 73 self.assertEqual(r['status'], 1) 74 75 expected_id = hash_of_foo[:64-16] + '000000000000029a' 76 o = c.get_token(self.address, expected_id, sender_address=self.accounts[0]) 77 r = self.rpc.do(o) 78 content = c.parse_token(r, expected_id) 79 self.assertEqual(content.token_id, hash_of_foo); 80 81 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=666) 82 self.rpc.do(o) 83 o = receipt(tx_hash_hex) 84 r = self.conn.do(o) 85 self.assertEqual(r['status'], 0) 86 87 88 def test_mint_auto_after_number(self): 89 nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) 90 c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 91 92 (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=10) 93 self.rpc.do(o) 94 95 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=2) 96 self.rpc.do(o) 97 98 expected_id = hash_of_foo[:64-10] + '000000029a' 99 o = c.get_token(self.address, expected_id, sender_address=self.accounts[0]) 100 r = self.rpc.do(o) 101 content = c.parse_token(r, hash_of_foo) 102 103 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0) 104 self.rpc.do(o) 105 o = receipt(tx_hash_hex) 106 r = self.conn.do(o) 107 self.assertEqual(r['status'], 0) 108 109 110 def test_complete_number(self): 111 nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) 112 c = CraftNFT(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 113 114 (tx_hash_hex, o) = c.allocate(self.address, self.accounts[0], hash_of_foo, amount=3) 115 self.rpc.do(o) 116 117 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=1) 118 self.rpc.do(o) 119 o = receipt(tx_hash_hex) 120 r = self.conn.do(o) 121 self.assertEqual(r['status'], 1) 122 123 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=2) 124 self.rpc.do(o) 125 o = receipt(tx_hash_hex) 126 r = self.conn.do(o) 127 self.assertEqual(r['status'], 1) 128 129 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=0) 130 self.rpc.do(o) 131 o = receipt(tx_hash_hex) 132 r = self.conn.do(o) 133 self.assertEqual(r['status'], 1) 134 135 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=3) 136 self.rpc.do(o) 137 o = receipt(tx_hash_hex) 138 r = self.conn.do(o) 139 self.assertEqual(r['status'], 0) 140 141 (tx_hash_hex, o) = c.mint_to(self.address, self.accounts[0], self.accounts[9], hash_of_foo, 0, index=2) 142 self.rpc.do(o) 143 o = receipt(tx_hash_hex) 144 r = self.conn.do(o) 145 self.assertEqual(r['status'], 0) 146 147 148 if __name__ == '__main__': 149 unittest.main()