eth-faucet

Gas token gifter with controls from time intervals, amounts and access
Info | Log | Files | Refs | README

test_registry.py (2800B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import logging
      5 
      6 # external imports
      7 from chainlib.connection import RPCConnection
      8 from chainlib.eth.nonce import RPCNonceOracle
      9 from chainlib.eth.unittest.ethtester import EthTesterCase
     10 from chainlib.eth.tx import receipt
     11 from chainlib.eth.tx import TxFactory
     12 from chainlib.eth.address import to_checksum_address
     13 from chainlib.eth.gas import balance
     14 from chainlib.eth.gas import Gas
     15 from chainlib.eth.gas import OverrideGasOracle
     16 from chainlib.eth.contract import ABIContractEncoder
     17 from chainlib.eth.contract import ABIContractType
     18 from chainlib.eth.block import block_by_number
     19 from eth_accounts_index.registry import AccountRegistry
     20 
     21 # local imports
     22 from eth_faucet import EthFaucet
     23 from eth_faucet.unittest import TestFaucetRegistryBase
     24 
     25 logging.basicConfig(level=logging.DEBUG)
     26 logg = logging.getLogger()
     27 
     28 
     29 class TestFaucetRegistry(TestFaucetRegistryBase):
     30 
     31     def test_basic(self):
     32         nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
     33         c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     34         (tx_hash_hex, o) = c.give_to(self.address, self.accounts[0], self.accounts[2])
     35         self.conn.do(o)
     36         o = receipt(tx_hash_hex)
     37         r = self.conn.do(o)
     38         self.assertEqual(r['status'], 0)
     39 
     40         nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn)
     41         c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     42         (tx_hash_hex, o) = c.gimme(self.address, self.accounts[1])
     43         self.conn.do(o)
     44         o = receipt(tx_hash_hex)
     45         r = self.conn.do(o)
     46         self.assertEqual(r['status'], 1)
     47 
     48 
     49     def test_registry(self):
     50         nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
     51         c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     52         (tx_hash_hex, o) = c.give_to(self.address, self.accounts[0], self.accounts[2])
     53         self.conn.do(o)
     54         o = receipt(tx_hash_hex)
     55         r = self.conn.do(o)
     56         self.assertEqual(r['status'], 0)
     57 
     58         (tx_hash_hex, o) = c.give_to(self.address, self.accounts[0], self.accounts[1])
     59         self.conn.do(o)
     60         o = receipt(tx_hash_hex)
     61         r = self.conn.do(o)
     62         self.assertEqual(r['status'], 1)
     63 
     64 
     65     def test_transparent(self):
     66         nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
     67         c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     68         o = c.check(self.address, self.accounts[2], sender_address=self.accounts[0])
     69         r = self.conn.do(o)
     70         self.assertEqual(int(r, 16), 0)
     71 
     72         o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
     73         r = self.conn.do(o)
     74         self.assertEqual(int(r, 16), 1)
     75 
     76 
     77 if __name__ == '__main__':
     78     unittest.main()