mirror of
git://holbrook.no/eth-faucet
synced 2024-12-12 07:56:11 +01:00
Fix inverted balance check in period, faucet main
This commit is contained in:
parent
89b10e3192
commit
2c77976df8
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
{"compiler":{"version":"0.8.18+commit.87f61d96"},"language":"Solidity","output":{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"FaucetAmountChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Give","type":"event"},{"anonymous":false,"inputs":[],"name":"ImNotGassy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_sealState","type":"uint256"},{"indexed":false,"internalType":"address","name":"_registry","type":"address"},{"indexed":false,"internalType":"address","name":"_periodChecker","type":"address"}],"name":"SealStateChange","type":"event"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"check","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"gimme","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"giveTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"nextTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodChecker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"seal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_v","type":"uint256"}],"name":"setAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_checker","type":"address"}],"name":"setPeriodChecker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_registry","type":"address"}],"name":"setRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"tokenAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"EthFaucet.sol":"EthFacuet"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"EthFaucet.sol":{"keccak256":"0x4eee39d6ae6437809f3dc9a38a6541224c66586a6e1735411946386af156efc5","license":"GPL-3.0-or-later","urls":["bzz-raw://ffb6836ece8743ce991344bb7cbfe615c5193cc8976e334bbc87c545a502a76c","dweb:/ipfs/QmcromwDBMiPDKJKRA4ygWDwF9t3MvE4BNdgmQMYcERX6R"]}},"version":1}
|
||||
{"compiler":{"version":"0.8.18+commit.87f61d96"},"language":"Solidity","output":{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"FaucetAmountChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Give","type":"event"},{"anonymous":false,"inputs":[],"name":"ImNotGassy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_sealState","type":"uint256"},{"indexed":false,"internalType":"address","name":"_registry","type":"address"},{"indexed":false,"internalType":"address","name":"_periodChecker","type":"address"}],"name":"SealStateChange","type":"event"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"check","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"gimme","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"giveTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"nextTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodChecker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"seal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_v","type":"uint256"}],"name":"setAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_checker","type":"address"}],"name":"setPeriodChecker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_registry","type":"address"}],"name":"setRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"tokenAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"EthFaucet.sol":"EthFacuet"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"EthFaucet.sol":{"keccak256":"0x914fa90608a36d5d6082a1bdba168c849a3ea34d70d3dd6e1fef143554840f19","license":"GPL-3.0-or-later","urls":["bzz-raw://b4efbed22465930f683933bd5b4f74a74d1f53c0c34a1231fbedcff92a3eeba2","dweb:/ipfs/QmT6szY5nAEs1megXscAsYkM9rke8M8VLj3MrQEP5hTekn"]}},"version":1}
|
||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
{"compiler":{"version":"0.8.18+commit.87f61d96"},"language":"Solidity","output":{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"BalanceThresholdChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"PeriodChange","type":"event"},{"inputs":[],"name":"balanceThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"check","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastUsed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"next","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"period","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"poke","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"poker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"setBalanceThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"setPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_poker","type":"address"}],"name":"setPoker","outputs":[],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"PeriodSimple.sol":"PeriodSimple"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"PeriodSimple.sol":{"keccak256":"0xaa53391796f933e59e3c6809d3a19e35623f78ca90f20386c14d3b4845df62d3","license":"GPL-3.0-or-later","urls":["bzz-raw://e8ab3b6c5568c7907c2e515e43c68da038629f5adcb576083a73ede9a4879661","dweb:/ipfs/QmUSY345fKi8Neq2pkKPGbyMYV9bmHALFtj3QviodprEQr"]}},"version":1}
|
||||
{"compiler":{"version":"0.8.18+commit.87f61d96"},"language":"Solidity","output":{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"BalanceThresholdChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"PeriodChange","type":"event"},{"inputs":[],"name":"balanceThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"check","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastUsed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"next","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"period","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"poke","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"poker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"setBalanceThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"setPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_poker","type":"address"}],"name":"setPoker","outputs":[],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"PeriodSimple.sol":"PeriodSimple"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"PeriodSimple.sol":{"keccak256":"0x45faa9b0307c14cd87913aa6719092b693d47962285f659d1d01680ee9820527","license":"GPL-3.0-or-later","urls":["bzz-raw://29186cc92b9f6324e2043abe9ac74787866992c00ffeb0e3fc81d345d8c04ed1","dweb:/ipfs/QmXJaGaWBBFbdyQWaAicjXN6aC2w5Yvr97kXVVimHWAN7i"]}},"version":1}
|
||||
|
1
python/eth_faucet/unittest/__init__.py
Normal file
1
python/eth_faucet/unittest/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .base import *
|
190
python/eth_faucet/unittest/base.py
Normal file
190
python/eth_faucet/unittest/base.py
Normal file
@ -0,0 +1,190 @@
|
||||
# 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.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.tx import TxFactory
|
||||
from chainlib.eth.contract import ABIContractType
|
||||
from chainlib.eth.block import block_by_number
|
||||
from eth_accounts_index.registry import AccountRegistry
|
||||
|
||||
# local import
|
||||
from eth_faucet import EthFaucet
|
||||
from eth_faucet.period import PeriodSimple
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
class TestFaucetBase(EthTesterCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucetBase, self).setUp()
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
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.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))
|
||||
|
||||
|
||||
class TestFaucetRegistryBase(TestFaucetBase):
|
||||
|
||||
def setUpRegistry(self):
|
||||
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.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 setUp(self):
|
||||
super(TestFaucetRegistryBase, self).setUp()
|
||||
self.setUpRegistry()
|
||||
|
||||
|
||||
class TestFaucetPeriodBase(TestFaucetBase):
|
||||
|
||||
def setUpPeriod(self):
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = PeriodSimple(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
|
||||
f = open(os.path.join(datadir, 'PeriodSimple.bin'))
|
||||
period_store_bytecode = f.read()
|
||||
f.close()
|
||||
enc = ABIContractEncoder()
|
||||
code = enc.get()
|
||||
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
tx = c.template(self.accounts[0], None, use_nonce=True)
|
||||
tx = c.set_code(tx, period_store_bytecode)
|
||||
(tx_hash_hex, o) = c.build(tx)
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
self.period_store_address = r['contract_address']
|
||||
|
||||
o = block_by_number(r['block_number'])
|
||||
r = self.conn.do(o)
|
||||
|
||||
try:
|
||||
self.start_time = int(r['timestamp'], 16)
|
||||
except TypeError:
|
||||
self.start_time = int(r['timestamp'])
|
||||
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(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)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setPoker')
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(self.address)
|
||||
data = enc.get()
|
||||
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)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.period = 0
|
||||
self.threshold = 0
|
||||
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucetPeriodBase, self).setUp()
|
||||
self.setUpPeriod()
|
||||
|
||||
|
||||
def set_period(self, period):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setPeriod')
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(period)
|
||||
data = enc.get()
|
||||
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)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
self.period = period
|
||||
|
||||
|
||||
def set_threshold(self, threshold):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setBalanceThreshold')
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(threshold)
|
||||
data = enc.get()
|
||||
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)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.threshold = threshold
|
||||
|
||||
|
||||
class TestFaucetFullBase(TestFaucetRegistryBase, TestFaucetPeriodBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucetFullBase, self).setUp()
|
||||
self.setUpPeriod()
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = eth-faucet
|
||||
version = 0.3.1
|
||||
version = 0.3.2
|
||||
description = Gas token gifter with controls from time intervals, amounts and access.
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -15,26 +15,13 @@ from chainlib.eth.gas import OverrideGasOracle
|
||||
|
||||
# local import
|
||||
from eth_faucet import EthFaucet
|
||||
from eth_faucet.unittest import TestFaucetBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestFaucet(EthTesterCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucet, self).setUp()
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
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.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))
|
||||
|
||||
class TestFaucet(TestFaucetBase):
|
||||
|
||||
def test_basic(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
@ -55,6 +42,10 @@ class TestFaucet(EthTesterCase):
|
||||
|
||||
|
||||
def test_basic_funding(self):
|
||||
o = balance(self.accounts[2])
|
||||
r = self.conn.do(o)
|
||||
prebalance = int(r, 16)
|
||||
|
||||
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])
|
||||
@ -63,28 +54,18 @@ class TestFaucet(EthTesterCase):
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = balance(self.accounts[9])
|
||||
r = self.conn.do(o)
|
||||
prebalance = int(r, 16)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = balance(self.accounts[2])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), prebalance)
|
||||
|
||||
(tx_hash, o) = c.set_amount(self.address, self.accounts[0], 1000)
|
||||
r = self.conn.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
(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)
|
||||
@ -146,6 +127,7 @@ class TestFaucet(EthTesterCase):
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), prebalance - cost + 1000)
|
||||
|
||||
|
||||
def test_payable_with_tx_data(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
@ -169,5 +151,7 @@ class TestFaucet(EthTesterCase):
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), prebalance - cost)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
82
python/tests/test_check.py
Normal file
82
python/tests/test_check.py
Normal file
@ -0,0 +1,82 @@
|
||||
# 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.address import to_checksum_address
|
||||
from chainlib.eth.gas import balance
|
||||
from chainlib.eth.gas import Gas
|
||||
from chainlib.eth.gas import OverrideGasOracle
|
||||
|
||||
# local import
|
||||
from eth_faucet import EthFaucet
|
||||
from eth_faucet.unittest import TestFaucetFullBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestFaucet(TestFaucetFullBase):
|
||||
|
||||
def test_check_registry(self):
|
||||
c = EthFaucet(self.chain_spec)
|
||||
o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 1)
|
||||
|
||||
o = c.check(self.address, self.accounts[2], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 0)
|
||||
|
||||
|
||||
def test_check_period_time(self):
|
||||
self.set_period(100)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], self.conn)
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
|
||||
o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 1)
|
||||
|
||||
(tx_hash_hex, o) = c.gimme(self.address, self.accounts[1])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 0)
|
||||
|
||||
|
||||
def test_check_period_balance(self):
|
||||
o = balance(self.accounts[1])
|
||||
r = self.conn.do(o)
|
||||
prebalance = int(r, 16)
|
||||
|
||||
c = EthFaucet(self.chain_spec)
|
||||
o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 1)
|
||||
|
||||
self.set_threshold(prebalance + 1)
|
||||
|
||||
o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 1)
|
||||
|
||||
self.set_threshold(prebalance)
|
||||
|
||||
o = c.check(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(int(r, 16), 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -20,82 +20,16 @@ from chainlib.eth.block import block_by_number
|
||||
# local imports
|
||||
from eth_faucet import EthFaucet
|
||||
from eth_faucet.period import PeriodSimple
|
||||
from eth_faucet.unittest import TestFaucetPeriodBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'eth_faucet', 'data')
|
||||
|
||||
|
||||
class TestFaucetPeriod(EthTesterCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFaucetPeriod, self).setUp()
|
||||
# DRY
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = PeriodSimple(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0])
|
||||
r = self.conn.do(o)
|
||||
|
||||
f = open(os.path.join(datadir, 'PeriodSimple.bin'))
|
||||
period_store_bytecode = f.read()
|
||||
f.close()
|
||||
enc = ABIContractEncoder()
|
||||
code = enc.get()
|
||||
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
tx = c.template(self.accounts[0], None, use_nonce=True)
|
||||
tx = c.set_code(tx, period_store_bytecode)
|
||||
(tx_hash_hex, o) = c.build(tx)
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
self.period_store_address = r['contract_address']
|
||||
|
||||
o = block_by_number(r['block_number'])
|
||||
r = self.conn.do(o)
|
||||
|
||||
try:
|
||||
self.start_time = int(r['timestamp'], 16)
|
||||
except TypeError:
|
||||
self.start_time = int(r['timestamp'])
|
||||
|
||||
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_period_checker(self.address, self.accounts[0], self.period_store_address)
|
||||
self.conn.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setPoker')
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(self.address)
|
||||
data = enc.get()
|
||||
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)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
class TestFaucetPeriod(TestFaucetPeriodBase):
|
||||
|
||||
def test_period_basic(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
@ -155,51 +89,23 @@ class TestFaucetPeriod(EthTesterCase):
|
||||
|
||||
|
||||
def test_balance(self):
|
||||
o = balance(self.accounts[2])
|
||||
o = balance(self.accounts[1])
|
||||
r = self.conn.do(o)
|
||||
prebalance = int(r, 16)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setBalanceThreshold')
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(prebalance + 1)
|
||||
data = enc.get()
|
||||
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)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn)
|
||||
self.set_threshold(prebalance / 2)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], self.conn)
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.gimme(self.address, self.accounts[2])
|
||||
(tx_hash_hex, o) = c.gimme(self.address, self.accounts[1])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 0)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('setBalanceThreshold')
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(1)
|
||||
data = enc.get()
|
||||
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)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
self.set_threshold(prebalance)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[2], self.conn)
|
||||
c = EthFaucet(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.gimme(self.address, self.accounts[2])
|
||||
(tx_hash_hex, o) = c.gimme(self.address, self.accounts[1])
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.conn.do(o)
|
||||
|
@ -20,55 +20,13 @@ from eth_accounts_index.registry import AccountRegistry
|
||||
|
||||
# local imports
|
||||
from eth_faucet import EthFaucet
|
||||
from eth_faucet.unittest import TestFaucetRegistryBase
|
||||
|
||||
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)
|
||||
|
||||
class TestFaucetRegistry(TestFaucetRegistryBase):
|
||||
|
||||
def test_basic(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||
|
@ -85,7 +85,7 @@ contract EthFacuet {
|
||||
}
|
||||
|
||||
function checkBalance() private view returns(bool) {
|
||||
return amount >= address(this).balance;
|
||||
return amount <= address(this).balance;
|
||||
}
|
||||
|
||||
function check(address _recipient) public returns(bool) {
|
||||
|
@ -39,7 +39,9 @@ contract PeriodSimple {
|
||||
}
|
||||
|
||||
function check(address _subject) external view returns(bool) {
|
||||
require(_subject.balance >= balanceThreshold);
|
||||
if (balanceThreshold > 0 && _subject.balance >= balanceThreshold) {
|
||||
return false;
|
||||
}
|
||||
if (lastUsed[_subject] == 0) {
|
||||
return true;
|
||||
}
|
||||
@ -48,7 +50,9 @@ contract PeriodSimple {
|
||||
|
||||
function poke(address _subject) external returns(bool) {
|
||||
require(msg.sender == owner || msg.sender == poker, 'ERR_ACCESS');
|
||||
require(this.check(_subject), 'ERR_PREMATURE');
|
||||
if (!this.check(_subject)) {
|
||||
return false;
|
||||
}
|
||||
lastUsed[_subject] = block.timestamp;
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user