erc20-transfer-authorization

Simple approval escrow for ERC20 spending
Info | Log | Files | Refs

test_basic.py (4270B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import logging
      5 
      6 # external imports
      7 from chainlib.eth.nonce import RPCNonceOracle
      8 from chainlib.eth.tx import receipt
      9 
     10 # local imports
     11 from erc20_transfer_authorization import TransferAuthorization
     12 from erc20_transfer_authorization.unittest import TestBase
     13 
     14 logg = logging.getLogger()
     15 
     16 testdir = os.path.dirname(__file__)
     17 
     18 
     19 class TestBasic(TestBase):
     20 
     21     def setUp(self):
     22         super(TestBasic, self).setUp()
     23         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     24         self.c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     25         (tx_hash_hex, o) = self.c.add_writer(self.address, self.accounts[0], self.accounts[1])
     26         self.rpc.do(o)
     27         o = receipt(tx_hash_hex)
     28         r = self.rpc.do(o)
     29         self.assertEqual(r['status'], 1)
     30 
     31         (tx_hash_hex, o) = self.c.add_writer(self.address, self.accounts[0], self.accounts[2])
     32         self.rpc.do(o)
     33         o = receipt(tx_hash_hex)
     34         r = self.rpc.do(o)
     35         self.assertEqual(r['status'], 1)
     36 
     37 
     38     def test_basic(self):
     39         c = TransferAuthorization(self.chain_spec)
     40 
     41         o = c.is_writer(self.address, self.accounts[0], sender_address=self.accounts[0])
     42         r = self.rpc.do(o)
     43         self.assertTrue(c.parse_signers(r))
     44 
     45         o = c.is_writer(self.address, self.accounts[1], sender_address=self.accounts[0])
     46         r = self.rpc.do(o)
     47         self.assertTrue(c.parse_signers(r))
     48 
     49         o = c.is_writer(self.address, self.accounts[2], sender_address=self.accounts[0])
     50         r = self.rpc.do(o)
     51         self.assertTrue(c.parse_signers(r))
     52 
     53         o = c.is_writer(self.address, self.accounts[3], sender_address=self.accounts[0])
     54         r = self.rpc.do(o)
     55         self.assertFalse(c.parse_signers(r))
     56 
     57         o = c.signer_count(self.address, sender_address=self.accounts[0])
     58         r = self.rpc.do(o)
     59         count = c.parse_count(r)
     60         self.assertEqual(count, 3)
     61 
     62 
     63 #    def test_limit(self):
     64 #        nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
     65 #        c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     66 #        
     67 #        (tx_hash_hex, o) = c.create_request(self.address, self.accounts[0], self.accounts[1], self.accounts[2], self.token_address, 1024)
     68 #        self.rpc.do(o)
     69 #        o = receipt(tx_hash_hex)
     70 #        r = self.rpc.do(o)
     71 #        self.assertEqual(r['status'], 1)
     72 #
     73 #        (tx_hash_hex, o) = c.create_request(self.address, self.accounts[0], self.accounts[1], self.accounts[2], self.token_address, 1024)
     74 #        self.rpc.do(o)
     75 #        o = receipt(tx_hash_hex)
     76 #        r = self.rpc.do(o)
     77 #        self.assertEqual(r['status'], 1)
     78 #
     79 #        (tx_hash_hex, o) = c.yay(self.address, self.accounts[0], 1)
     80 #        self.rpc.do(o)
     81 #        o = receipt(tx_hash_hex)
     82 #        r = self.rpc.do(o)
     83 #        self.assertEqual(r['status'], 1)
     84 #
     85 #        (tx_hash_hex, o) = c.yay(self.address, self.accounts[0], 2)
     86 #        self.rpc.do(o)
     87 #        o = receipt(tx_hash_hex)
     88 #        r = self.rpc.do(o)
     89 #        self.assertEqual(r['status'], 1)
     90 #
     91 #        (tx_hash_hex, o) = c.check_result(self.address, self.accounts[0], 1)
     92 #        self.rpc.do(o)
     93 #        o = receipt(tx_hash_hex)
     94 #        r = self.rpc.do(o)
     95 #        self.assertEqual(r['status'], 1)
     96 #
     97 #        o = c.requests(self.address, 1, sender_address=self.accounts[0])
     98 #        r = self.rpc.do(o)
     99 #        request = self.c.parse_request(r)
    100 #        logg.debug('request {}'.format(request))
    101 #        self.assertTrue(request.is_accepted())
    102 
    103 
    104     def test_serial(self):
    105         nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
    106         c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
    107         for i in range(5):
    108             (tx_hash_hex, o) = c.create_request(self.address, self.accounts[0], self.accounts[i], self.accounts[i+1], self.token_address, 1024 * i)
    109             self.rpc.do(o)
    110             o = receipt(tx_hash_hex)
    111             r = self.rpc.do(o)
    112             self.assertEqual(r['status'], 1)
    113 
    114         o = c.count(self.address, sender_address=self.accounts[0])
    115         r = self.rpc.do(o)
    116         count = c.parse_count(r)
    117         self.assertEqual(count, 5)
    118 
    119 
    120 if __name__ == '__main__':
    121     unittest.main()