eth-address-index

signed metadata declarations for ethereum addresses
Info | Log | Files | Refs

test_tokenindex.py (1502B)


      1 import logging
      2 import os
      3 import json
      4 import hashlib
      5 
      6 import web3
      7 import eth_tester
      8 
      9 logging.basicConfig(level=logging.DEBUG)
     10 logg = logging.getLogger()
     11 
     12 
     13 eth_params = eth_tester.backends.pyevm.main.get_default_genesis_params({
     14     'gas_limit': 9000000,
     15     })
     16 backend = eth_tester.PyEVMBackend(eth_params)
     17 instance = eth_tester.EthereumTester(backend)
     18 provider = web3.Web3.EthereumTesterProvider(instance)
     19 w3 = web3.Web3(provider)
     20 
     21 
     22 f = open('TokenUniqueSymbolIndex.bin', 'r')
     23 bytecode = f.read()
     24 f.close()
     25 
     26 f = open('TokenUniqueSymbolIndex.json', 'r')
     27 abi = json.load(f)
     28 f.close()
     29 
     30 token_address = web3.Web3.toChecksumAddress('0x' + os.urandom(20).hex())
     31 
     32 c = w3.eth.contract(abi=abi, bytecode=bytecode)
     33 tx_hash = c.constructor().transact({'from': w3.eth.accounts[0]})
     34 r = w3.eth.getTransactionReceipt(tx_hash)
     35 logg.debug('contract {}'.format(r.contractAddress))
     36 
     37 c = w3.eth.contract(abi=abi, address=r.contractAddress)
     38 d = '0x' + os.urandom(32).hex()
     39 
     40 # Initial token will fail in any case
     41 h =hashlib.new('sha256')
     42 h.update('FOO'.encode('utf-8'))
     43 z = h.digest()
     44 foo_symbol = z.hex()
     45 
     46 fail = False
     47 try:
     48     c.functions.register(foo_symbol, token_address).transact({'from':w3.eth.accounts[0]})
     49 except:
     50     fail = True
     51     pass
     52 
     53 if not fail:
     54     raise RuntimeError('expected fail on register same token to same address')
     55 
     56 assert(c.functions.supportsInterface('0x325d15e2').call())
     57 assert(c.functions.supportsInterface('0x01ffc9a7').call())
     58 assert(not c.functions.supportsInterface('0xffffffff').call())