eth-erc721

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

commit 691e6855460ad03a57f11dcb01040cd3ab8c88c6
parent 51c986e6f1d8ed720f1f067fa7276d3d5599c94c
Author: nolash <dev@holbrook.no>
Date:   Fri,  7 May 2021 22:17:06 +0200

Add tokenindex lookup

Diffstat:
Mpython/eth_devbadge/token.py | 18++++++++++++++++++
Mpython/tests/test_app.py | 13++++++++++++-
2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/python/eth_devbadge/token.py b/python/eth_devbadge/token.py @@ -95,6 +95,19 @@ class BadgeToken(TxFactory): return tx + def token_by_index(self, contract_address, idx, sender_address=ZERO_ADDRESS): + o = jsonrpc_template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('tokenByIndex') + enc.typ(ABIContractType.UINT256) + enc.uint256(idx) + 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 def owner_of(self, contract_address, token_id, sender_address=ZERO_ADDRESS): @@ -115,3 +128,8 @@ class BadgeToken(TxFactory): @classmethod def parse_owner_of(self, v): return abi_decode_single(ABIContractType.ADDRESS, v) + + + @classmethod + def parse_token_by_index(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,11 @@ from chainlib.eth.contract import ( abi_decode_single, ABIContractType, ) +from hexathon import ( + add_0x, + strip_0x, + ) + # local imports from eth_devbadge.token import BadgeToken @@ -58,9 +63,14 @@ class Test(EthTesterCase): def test_mint(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) + o = c.token_by_index(self.address, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertEqual(token_bytes.hex(), strip_0x(r)) + def test_owner(self): token_id = int.from_bytes(b'\xee' * 32, byteorder='big') @@ -73,6 +83,7 @@ class Test(EthTesterCase): self.assertEqual(self.accounts[1], owner_address) + def test_transfer(self): token_id = int.from_bytes(b'\xee' * 32, byteorder='big') c = self._mint(self.accounts[1], token_id)