eth-owned

EIP-173 interface and tools for chainlib-eth
git clone git://holbrook.no/eth-owned.git
Info | Log | Files | Refs

interface.py (5018B)


      1 # standard imports
      2 import unittest
      3 import os
      4 import logging
      5 
      6 # external imports
      7 from chainlib.eth.unittest.ethtester import EthTesterCase
      8 from chainlib.eth.nonce import RPCNonceOracle
      9 from chainlib.eth.gas import OverrideGasOracle
     10 from chainlib.connection import RPCConnection
     11 from chainlib.eth.tx import (
     12         TxFactory,
     13         receipt,
     14         )
     15 from hexathon import strip_0x
     16 
     17 # local imports
     18 from eth_owned.owned import ERC173
     19 
     20 logging.basicConfig(level=logging.DEBUG)
     21 logg = logging.getLogger()
     22 
     23 script_dir = os.path.realpath(os.path.dirname(__file__))
     24 
     25 
     26 class TestInterface: #(EthTesterCase):
     27 
     28     def test_owned(self):
     29         c = ERC173(self.chain_spec)
     30         o = c.owner(self.address, sender_address=self.accounts[0])
     31         r = self.conn.do(o)
     32         owner = c.parse_owner(r)
     33         self.assertEqual(owner, strip_0x(self.accounts[0]))
     34 
     35 
     36     def test_transfer_ownership(self):
     37         nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn)
     38         gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn)
     39         c = ERC173(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
     40         (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[2], self.accounts[1])
     41         r = self.conn.do(o)
     42 
     43         o = receipt(tx_hash_hex)
     44         r = self.conn.do(o)
     45         self.assertEqual(r['status'], 0)
     46         
     47         nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
     48         c = ERC173(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
     49         (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1])
     50         r = self.conn.do(o)
     51 
     52         o = receipt(tx_hash_hex)
     53         r = self.conn.do(o)
     54         self.assertEqual(r['status'], 1)
     55  
     56         o = c.owner(self.address, sender_address=self.accounts[0])
     57         r = self.conn.do(o)
     58         owner = c.parse_owner(r)
     59         self.assertEqual(owner, strip_0x(self.accounts[1]))
     60       
     61 
     62 #    def test_accept_ownership(self):
     63 #        nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
     64 #        gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn)
     65 #        c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
     66 #        (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1])
     67 #        r = self.conn.do(o)
     68 #
     69 #        nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn)
     70 #        c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
     71 #        (tx_hash_hex, o) = c.accept_ownership(self.address, self.accounts[2])
     72 #        r = self.conn.do(o)
     73 #
     74 #        o = receipt(tx_hash_hex)
     75 #        r = self.conn.do(o)
     76 #        self.assertEqual(r['status'], 0)
     77 #
     78 #        nonce_oracle = RPCNonceOracle(self.accounts[1], self.conn)
     79 #        c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
     80 #        (tx_hash_hex, o) = c.accept_ownership(self.address, self.accounts[1])
     81 #        r = self.conn.do(o)
     82 #
     83 #        o = receipt(tx_hash_hex)
     84 #        r = self.conn.do(o)
     85 #        self.assertEqual(r['status'], 1)
     86 #
     87 #        o = c.owner(self.address, sender_address=self.accounts[0])
     88 #        r = self.conn.do(o)
     89 #        owner = c.parse_owner(r)
     90 #        self.assertEqual(owner, strip_0x(self.accounts[1]))
     91 #
     92 #
     93 #    def test_take_ownership(self):
     94 #        nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
     95 #        gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn)
     96 #        c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
     97 #        (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.address)
     98 #        r = self.conn.do(o)
     99 #
    100 #        (tx_hash_hex, o) = c.take_ownership(self.address, self.accounts[0], self.address)
    101 #        r = self.conn.do(o)
    102 #
    103 #        o = receipt(tx_hash_hex)
    104 #        r = self.conn.do(o)
    105 #        self.assertEqual(r['status'], 1)
    106 #
    107 #        o = c.owner(self.address, sender_address=self.accounts[0])
    108 #        r = self.conn.do(o)
    109 #        owner = c.parse_owner(r)
    110 #        self.assertEqual(owner, strip_0x(self.address))
    111 #
    112 #
    113 #    def test_ownership_final(self):
    114 #        nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
    115 #        gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn)
    116 #        c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
    117 #        (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True)
    118 #        r = self.conn.do(o)
    119 #
    120 #        c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer)
    121 #        (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True)
    122 #        r = self.conn.do(o)
    123 #        o = receipt(tx_hash_hex)
    124 #        r = self.conn.do(o)
    125 #        self.assertEqual(r['status'], 0)
    126 
    127 if __name__ == '__main__':
    128     unittest.main()