eth-erc712

ERC712 typed data sign material builder
Info | Log | Files | Refs

base.py (1780B)


      1 # standard imports
      2 import os
      3 import logging
      4 
      5 # external imports
      6 from chainlib.eth.unittest.ethtester import EthTesterCase
      7 from chainlib.eth.address import to_checksum_address
      8 from chainlib.connection import RPCConnection
      9 from chainlib.eth.nonce import RPCNonceOracle
     10 from chainlib.eth.gas import OverrideGasOracle
     11 from chainlib.eth.gas import Gas
     12 from chainlib.eth.tx import receipt
     13 
     14 # local imports
     15 from eth_erc712 import EIP712Domain
     16 
     17 script_dir = os.path.realpath(os.path.dirname(__file__))
     18 data_dir = os.path.join(script_dir, '..', 'data')
     19 
     20 logg = logging.getLogger(__name__)
     21 
     22 
     23 class TestERC712(EthTesterCase):
     24 
     25     def setUp(self):
     26         super(TestERC712, self).setUp()
     27         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     28         gas_oracle = OverrideGasOracle(limit=1000000)
     29         fp = os.path.join(data_dir, 'ERC712Example.bin')
     30         f = open(fp, 'r')
     31         bytecode = f.read()
     32         f.close()
     33         c = Gas(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
     34         self.conn = RPCConnection.connect(self.chain_spec, 'default')
     35         (tx_hash, o) = c.create(self.accounts[0], None, 0, data=bytecode)
     36         r = self.conn.do(o)
     37         o = receipt(r)
     38         r = self.conn.do(o)
     39         self.address = to_checksum_address(r['contract_address'])
     40         logg.debug('erc712 example smart contract published with hash {} address {}'.format(r, self.address))
     41 
     42         address = os.urandom(20).hex()
     43         salt = os.urandom(32).hex()
     44         self.domain = EIP712Domain(
     45                 name='Ether Mail',
     46                 version='1',
     47                 chain_id=42,
     48                 verifying_contract=to_checksum_address('0xcccccccccccccccccccccccccccccccccccccccc'),
     49                 salt=salt,
     50                 )