erc20-pool/python/erc20_pool/unittest/base.py

88 lines
3.2 KiB
Python
Raw Permalink Normal View History

# standard imports
import logging
import time
# external imports
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.connection import RPCConnection
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
from chainlib.eth.address import to_checksum_address
from giftable_erc20_token.unittest import TestGiftableToken
from eth_erc20 import ERC20
from chainlib.eth.block import block_latest
from eth_accounts_index.unittest import TestAccountsIndex
from eth_accounts_index.registry import AccountRegistry
from giftable_erc20_token import GiftableToken
2023-07-28 14:46:15 +02:00
from erc20_limiter.unittest import TestLimiter
# local imports
from erc20_pool import Pool
logg = logging.getLogger(__name__)
hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
2023-07-28 14:46:15 +02:00
#hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
#hash_of_baz = 'baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096'
2023-07-28 14:46:15 +02:00
class TestERC20PoolBase(TestGiftableToken):
expire = 0
def setUp(self):
2023-07-28 14:46:15 +02:00
super(TestERC20PoolBase, self).setUp()
self.foo_address = self.address
2023-07-28 14:46:15 +02:00
self.publish_tokens()
def publish_tokens(self):
self.bar_address = self.publish_giftable_token('Bar Token', 'BAR', 16)
self.baz_address = self.publish_giftable_token('Baz Token', 'BAZ', 16)
self.initial_supply_bar = 1 << 20
self.initial_supply_baz = 1 << 15
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.mint_to(self.bar_address, self.accounts[0], self.accounts[1], self.initial_supply_bar)
2023-07-27 08:45:15 +02:00
self.conn.do(o)
o = receipt(tx_hash)
r = self.conn.do(o)
self.assertEqual(r['status'], 1)
(tx_hash, o) = c.mint_to(self.baz_address, self.accounts[0], self.accounts[2], self.initial_supply_baz)
2023-07-27 08:45:15 +02:00
self.conn.do(o)
o = receipt(tx_hash)
r = self.conn.do(o)
self.assertEqual(r['status'], 1)
2023-07-28 14:46:15 +02:00
def publish_pool(self, token_registry=None, token_limiter=None):
2023-07-28 14:46:15 +02:00
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.constructor(self.accounts[0], "Big Pool", "BIG", 16, token_registry=token_registry, token_limiter=token_limiter)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
2023-07-27 08:45:15 +02:00
self.pool_address = to_checksum_address(r['contract_address'])
2023-07-27 09:01:16 +02:00
self.address = self.pool_address
logg.debug('published bar token {}, baz token {}'.format(self.bar_address, self.baz_address))
2023-07-27 08:45:15 +02:00
logg.debug('published pool on address {} with hash {}'.format(self.pool_address, tx_hash))
2023-07-28 14:46:15 +02:00
class TestERC20Pool(TestERC20PoolBase):
def setUp(self):
super(TestERC20Pool, self).setUp()
self.publish_pool()
class TestERC20PoolLimiter(TestERC20PoolBase, TestLimiter):
def setUp(self):
super(TestERC20PoolLimiter, self).setUp()
self.limiter_address = self.publish_limiter()
self.publish_pool(token_limiter=self.limiter_address)