eth-erc721

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

commit 51e71ee6b514def57186e13a2edd5cf505842c84
parent 8649775406d3eccc030a78aac3deb8e7a3dad342
Author: nolash <dev@holbrook.no>
Date:   Fri,  7 May 2021 22:09:07 +0200

Parse token owner address

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

diff --git a/python/eth_devbadge/token.py b/python/eth_devbadge/token.py @@ -79,6 +79,24 @@ class BadgeToken(TxFactory): return tx + def transfer_from(self, contract_address, sender_address, holder_address, beneficiary_address, token_id, tx_format=TxFormat.JSONRPC): + enc = ABIContractEncoder() + enc.method('transferFrom') + enc.typ(ABIContractType.ADDRESS) + enc.typ(ABIContractType.ADDRESS) + enc.typ(ABIContractType.UINT256) + enc.address(holder_address) + enc.address(beneficiary_address) + enc.uint256(token_id) + data = enc.get() + tx = self.template(sender_address, contract_address, use_nonce=True) + tx = self.set_code(tx, data) + tx = self.finalize(tx, tx_format) + return tx + + + + def owner_of(self, contract_address, token_id, sender_address=ZERO_ADDRESS): o = jsonrpc_template() o['method'] = 'eth_call' diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -73,5 +73,18 @@ 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) + + (tx_hash_hex, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[1], self.accounts[2], token_id) + r = self.rpc.do(o) + + o = receipt(tx_hash_hex) + r = self.conn.do(o) + self.assertEqual(r['status'], 1) + + + if __name__ == '__main__': unittest.main()