eth-erc721

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

commit d093fdb3631e673cbd2e2c0ee6e6d88de77e1296
parent 691e6855460ad03a57f11dcb01040cd3ab8c88c6
Author: nolash <dev@holbrook.no>
Date:   Fri,  7 May 2021 22:21:23 +0200

Add token by owner index

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

diff --git a/python/eth_devbadge/token.py b/python/eth_devbadge/token.py @@ -125,6 +125,23 @@ class BadgeToken(TxFactory): return o + def token_of_owner_by_index(self, contract_address, holder_address, idx, sender_address=ZERO_ADDRESS): + o = jsonrpc_template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('tokenOfOwnerByIndex') + enc.typ(ABIContractType.ADDRESS) + enc.typ(ABIContractType.UINT256) + enc.address(holder_address) + 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 + + @classmethod def parse_owner_of(self, v): return abi_decode_single(ABIContractType.ADDRESS, v) @@ -133,3 +150,10 @@ class BadgeToken(TxFactory): @classmethod def parse_token_by_index(self, v): return abi_decode_single(ABIContractType.UINT256, v) + + + @classmethod + def parse_token_of_owner_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 @@ -73,7 +73,8 @@ class Test(EthTesterCase): def test_owner(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.owner_of(self.address, token_id, sender_address=self.accounts[0]) @@ -82,6 +83,10 @@ class Test(EthTesterCase): self.assertEqual(self.accounts[1], owner_address) + 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):