mirror of
git://holbrook.no/eth-faucet
synced 2025-01-06 00:57:33 +01:00
Add regsitry test
This commit is contained in:
parent
66c261d692
commit
cefdc5c00b
File diff suppressed because one or more lines are too long
@ -74,3 +74,15 @@ class EthFaucet(Faucet):
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
def set_registry(self, contract_address, sender_address, checker_address, tx_format=TxFormat.JSONRPC):
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setRegistry')
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(checker_address)
|
||||
data = enc.get()
|
||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
@ -1,3 +1,3 @@
|
||||
eth_tester==0.5.0b3
|
||||
py-evm==0.3.0a20
|
||||
eth-erc20~=0.1.2a1
|
||||
accounts_index~=0.3.0
|
||||
|
@ -29,10 +29,10 @@ moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'eth_faucet', 'data')
|
||||
|
||||
|
||||
class TestFaucet(EthTesterCase):
|
||||
class TestFaucetPeriod(EthTesterCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucet, self).setUp()
|
||||
super(TestFaucetPeriod, self).setUp()
|
||||
# DRY
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
@ -51,7 +51,7 @@ class TestFaucet(EthTesterCase):
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
self.period_store_contract = r['contract_address']
|
||||
self.period_store_address = r['contract_address']
|
||||
|
||||
o = block_by_number(r['block_number'])
|
||||
r = self.conn.do(o)
|
||||
@ -70,7 +70,7 @@ class TestFaucet(EthTesterCase):
|
||||
self.address = to_checksum_address(r['contract_address'])
|
||||
logg.debug('faucet contract {}'.format(self.address))
|
||||
|
||||
(tx_hash_hex, o) = c.set_period_checker(self.address, self.accounts[0], self.period_store_contract)
|
||||
(tx_hash_hex, o) = c.set_period_checker(self.address, self.accounts[0], self.period_store_address)
|
||||
self.conn.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
@ -86,7 +86,7 @@ class TestFaucet(EthTesterCase):
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(100)
|
||||
data = enc.get()
|
||||
tx = c.template(self.accounts[0], self.period_store_contract, use_nonce=True)
|
||||
tx = c.template(self.accounts[0], self.period_store_address, use_nonce=True)
|
||||
tx = c.set_code(tx, data)
|
||||
(tx_hash_hex, o) = c.finalize(tx)
|
||||
self.conn.do(o)
|
||||
@ -101,7 +101,7 @@ class TestFaucet(EthTesterCase):
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(self.address)
|
||||
data = enc.get()
|
||||
tx = c.template(self.accounts[0], self.period_store_contract, use_nonce=True)
|
||||
tx = c.template(self.accounts[0], self.period_store_address, use_nonce=True)
|
||||
tx = c.set_code(tx, data)
|
||||
(tx_hash_hex, o) = c.finalize(tx)
|
||||
self.conn.do(o)
|
||||
|
90
python/tests/test_registry.py
Normal file
90
python/tests/test_registry.py
Normal file
@ -0,0 +1,90 @@
|
||||
# standard imports
|
||||
import os
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from chainlib.connection import RPCConnection
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.unittest.ethtester import EthTesterCase
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.tx import TxFactory
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.gas import balance
|
||||
from chainlib.eth.gas import Gas
|
||||
from chainlib.eth.gas import OverrideGasOracle
|
||||
from chainlib.eth.contract import ABIContractEncoder
|
||||
from chainlib.eth.contract import ABIContractType
|
||||
from chainlib.eth.block import block_by_number
|
||||
from eth_accounts_index.registry import AccountRegistry
|
||||
|
||||
# local imports
|
||||
from eth_faucet.faucet import EthFaucet
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestFaucetRegistry(EthTesterCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucetRegistry, self).setUp()
|
||||
# DRY
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
|
||||
c = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash, o) = c.constructor(self.accounts[0])
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
r = self.conn.do(o)
|
||||
|
||||
o = receipt(r)
|
||||
r = self.conn.do(o)
|
||||
self.registry_address = to_checksum_address(r['contract_address'])
|
||||
|
||||
(tx_hash_hex, o) = c.add_writer(self.registry_address, self.accounts[0], self.accounts[0])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
(tx_hash_hex, o) = c.add(self.registry_address, self.accounts[0], self.accounts[1])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
|
||||
o = receipt(r)
|
||||
r = self.conn.do(o)
|
||||
self.address = to_checksum_address(r['contract_address'])
|
||||
logg.debug('faucet contract {}'.format(self.address))
|
||||
|
||||
(tx_hash_hex, o) = c.set_registry(self.address, self.accounts[0], self.registry_address)
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
|
||||
def test_registry(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.give_to(self.address, self.accounts[0], self.accounts[2])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 0)
|
||||
|
||||
(tx_hash_hex, o) = c.give_to(self.address, self.accounts[0], self.accounts[1])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -60,16 +60,18 @@ contract EthFacuet {
|
||||
|
||||
(_ok, _result) = periodChecker.call(abi.encodeWithSignature("check(address)", _recipient));
|
||||
if (!_ok) {
|
||||
emit FaucetFail(_recipient, address(0), amount);
|
||||
revert('ERR_PERIOD_BACKEND_ERROR');
|
||||
}
|
||||
if (_result[31] == 0) {
|
||||
emit FaucetFail(_recipient, address(0), amount);
|
||||
revert('ERR_PERIOD_CHECK');
|
||||
}
|
||||
|
||||
(_ok, _result) = periodChecker.call(abi.encodeWithSignature("poke(address)", _recipient));
|
||||
if (!_ok) {
|
||||
emit FaucetFail(_recipient, address(0), amount);
|
||||
revert('ERR_PERIOD_CHECK_REGISTER');
|
||||
revert('ERR_REGISTRY_BACKEND_ERROR');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -83,7 +85,11 @@ contract EthFacuet {
|
||||
emit FaucetFail(_recipient, address(0), amount);
|
||||
revert('ERR_TRANSFER');
|
||||
}
|
||||
|
||||
if (_result[31] == 0) {
|
||||
emit FaucetFail(_recipient, address(0), amount);
|
||||
revert('ERR_REGISTRY_CHECK');
|
||||
}
|
||||
|
||||
emit FaucetUsed(_recipient, address(0), amount);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user