eth-erc721

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

commit d5174a7acaad0a395bbbd48b4e8ab29176eed2ee
parent d093fdb3631e673cbd2e2c0ee6e6d88de77e1296
Author: nolash <dev@holbrook.no>
Date:   Fri,  7 May 2021 22:27:39 +0200

Add total supply, token index change test

Diffstat:
Mpython/eth_devbadge/token.py | 18++++++++++++++++++
Mpython/tests/test_app.py | 18++++++++++++++++--
2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/python/eth_devbadge/token.py b/python/eth_devbadge/token.py @@ -142,6 +142,19 @@ class BadgeToken(TxFactory): return o + def total_supply(self, contract_address, sender_address=ZERO_ADDRESS): + o = jsonrpc_template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('totalSupply') + data = add_0x(enc.get()) + tx = self.template(sender_address, contract_address) + tx = self.set_code(tx, data) + o['params'].append(self.normalize(tx)) + o['params'].append('latest') + return o + + @classmethod def parse_owner_of(self, v): return abi_decode_single(ABIContractType.ADDRESS, v) @@ -157,3 +170,8 @@ class BadgeToken(TxFactory): return abi_decode_single(ABIContractType.UINT256, v) + @classmethod + def parse_total_supply(self, v): + return abi_decode_single(ABIContractType.UINT256, v) + + diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -18,6 +18,7 @@ from chainlib.eth.contract import ( abi_decode_single, ABIContractType, ) +from chainlib.error import JSONRPCException from hexathon import ( add_0x, strip_0x, @@ -71,6 +72,12 @@ class Test(EthTesterCase): r = self.rpc.do(o) self.assertEqual(token_bytes.hex(), strip_0x(r)) + o = c.total_supply(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + supply = c.parse_total_supply(r) + + self.assertEqual(supply, 1) + def test_owner(self): token_bytes = b'\xee' * 32 @@ -85,12 +92,12 @@ class Test(EthTesterCase): o = c.token_of_owner_by_index(self.address, self.accounts[1], 0, sender_address=self.accounts[0]) r = self.rpc.do(o) - self.assertEqual(token_bytes.hex(), strip_0x(r)) def test_transfer(self): - token_id = int.from_bytes(b'\xee' * 32, byteorder='big') + token_bytes = b'\xee' * 32 + token_id = int.from_bytes(token_bytes, byteorder='big') c = self._mint(self.accounts[1], token_id) nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) @@ -102,7 +109,14 @@ class Test(EthTesterCase): r = self.conn.do(o) self.assertEqual(r['status'], 1) + o = c.token_of_owner_by_index(self.address, self.accounts[1], 0, sender_address=self.accounts[0]) + with self.assertRaises(JSONRPCException): + r = self.rpc.do(o) + o = c.token_of_owner_by_index(self.address, self.accounts[2], 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertEqual(token_bytes.hex(), strip_0x(r)) + if __name__ == '__main__': unittest.main()