mirror of
https://github.com/grassrootseconomics/erc20-pool.git
synced 2024-11-21 11:46:47 +01:00
Add limiter token registry
This commit is contained in:
parent
5219ca0385
commit
89b92ef7de
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"bytes32","name":"_declaration","type":"bytes32"},{"internalType":"address","name":"_tokenRegistry","type":"address"},{"internalType":"address","name":"_limitRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_final","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_sealState","type":"uint256"}],"name":"SealStateChange","type":"event"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"isSealed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","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":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeAddress","type":"address"}],"name":"setFeeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"address","name":"_inToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
|
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"bytes32","name":"_declaration","type":"bytes32"},{"internalType":"address","name":"_tokenRegistry","type":"address"},{"internalType":"address","name":"_tokenLimiter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_final","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_sealState","type":"uint256"}],"name":"SealStateChange","type":"event"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"isSealed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","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":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeAddress","type":"address"}],"name":"setFeeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"address","name":"_inToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -1 +1 @@
|
|||||||
{"compiler":{"version":"0.8.19+commit.7dd6d404"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"bytes32","name":"_declaration","type":"bytes32"},{"internalType":"address","name":"_tokenRegistry","type":"address"},{"internalType":"address","name":"_limitRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_final","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_sealState","type":"uint256"}],"name":"SealStateChange","type":"event"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"isSealed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","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":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeAddress","type":"address"}],"name":"setFeeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"address","name":"_inToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"SwapPool.sol":"SwapPool"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"SwapPool.sol":{"keccak256":"0x3c82726f2bc94fd37c90dd161143155eb73ea0d4ede9c414554641d02db38c05","license":"AGPL-3.0-or-later","urls":["bzz-raw://53756d11bf73951a4165e907429c5b5365cf7da530193cd75cace975e4dd1e2a","dweb:/ipfs/QmR7gMvYpfaWVQPT8ZhyPMCxqa1dhvrhRCTzbrCb7WpMBv"]}},"version":1}
|
{"compiler":{"version":"0.8.19+commit.7dd6d404"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"bytes32","name":"_declaration","type":"bytes32"},{"internalType":"address","name":"_tokenRegistry","type":"address"},{"internalType":"address","name":"_tokenLimiter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_final","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_sealState","type":"uint256"}],"name":"SealStateChange","type":"event"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"isSealed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","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":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeAddress","type":"address"}],"name":"setFeeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"address","name":"_inToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"SwapPool.sol":"SwapPool"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"SwapPool.sol":{"keccak256":"0x436bcba6d38310e5caa8a4a2a83f309f95016521e052a88139f4241f7fc1cab6","license":"AGPL-3.0-or-later","urls":["bzz-raw://056d060f236df6c0f325ff74a9299f767dd42236494e9e14065a7d5626de952e","dweb:/ipfs/QmTRDCaMKu84ZrJqrKk3mwfDBK6Cnt9G5zLgABGyNyY23F"]}},"version":1}
|
||||||
|
@ -37,29 +37,29 @@ class Pool(TxFactory):
|
|||||||
__abi = None
|
__abi = None
|
||||||
__bytecode = None
|
__bytecode = None
|
||||||
|
|
||||||
def constructor(self, sender_address, name, symbol, decimals, declaration=None, accounts_registry=None, limit_registry=None, tx_format=TxFormat.JSONRPC, version=None):
|
def constructor(self, sender_address, name, symbol, decimals, declaration=None, token_registry=None, token_limiter=None, tx_format=TxFormat.JSONRPC, version=None):
|
||||||
code = self.cargs(name, symbol, decimals, declaration=declaration, accounts_registry=accounts_registry, limit_registry=limit_registry, version=version)
|
code = self.cargs(name, symbol, decimals, declaration=declaration, token_registry=token_registry, token_limiter=token_limiter, version=version)
|
||||||
tx = self.template(sender_address, None, use_nonce=True)
|
tx = self.template(sender_address, None, use_nonce=True)
|
||||||
tx = self.set_code(tx, code)
|
tx = self.set_code(tx, code)
|
||||||
return self.finalize(tx, tx_format)
|
return self.finalize(tx, tx_format)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cargs(name, symbol, decimals, declaration=None, accounts_registry=None, limit_registry=None, version=None):
|
def cargs(name, symbol, decimals, declaration=None, token_registry=None, token_limiter=None, version=None):
|
||||||
if declaration == None:
|
if declaration == None:
|
||||||
declaration = ZERO_CONTENT
|
declaration = ZERO_CONTENT
|
||||||
if accounts_registry == None:
|
if token_registry == None:
|
||||||
accounts_registry = ZERO_ADDRESS
|
token_registry = ZERO_ADDRESS
|
||||||
if limit_registry == None:
|
if token_limiter == None:
|
||||||
limit_registry = ZERO_ADDRESS
|
token_limiter = ZERO_ADDRESS
|
||||||
code = Pool.bytecode(version=version)
|
code = Pool.bytecode(version=version)
|
||||||
enc = ABIContractEncoder()
|
enc = ABIContractEncoder()
|
||||||
enc.string(name)
|
enc.string(name)
|
||||||
enc.string(symbol)
|
enc.string(symbol)
|
||||||
enc.uint256(decimals)
|
enc.uint256(decimals)
|
||||||
enc.bytes32(declaration)
|
enc.bytes32(declaration)
|
||||||
enc.address(accounts_registry)
|
enc.address(token_registry)
|
||||||
enc.address(limit_registry)
|
enc.address(token_limiter)
|
||||||
args = enc.get()
|
args = enc.get()
|
||||||
code += args
|
code += args
|
||||||
logg.debug('constructor code: ' + args)
|
logg.debug('constructor code: ' + args)
|
||||||
|
@ -14,6 +14,7 @@ from chainlib.eth.block import block_latest
|
|||||||
from eth_accounts_index.unittest import TestAccountsIndex
|
from eth_accounts_index.unittest import TestAccountsIndex
|
||||||
from eth_accounts_index.registry import AccountRegistry
|
from eth_accounts_index.registry import AccountRegistry
|
||||||
from giftable_erc20_token import GiftableToken
|
from giftable_erc20_token import GiftableToken
|
||||||
|
from erc20_limiter.unittest import TestLimiter
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from erc20_pool import Pool
|
from erc20_pool import Pool
|
||||||
@ -21,18 +22,21 @@ from erc20_pool import Pool
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
|
hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
|
||||||
hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
|
#hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
|
||||||
hash_of_baz = 'baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096'
|
#hash_of_baz = 'baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096'
|
||||||
|
|
||||||
|
|
||||||
class TestERC20Pool(TestGiftableToken):
|
class TestERC20PoolBase(TestGiftableToken):
|
||||||
|
|
||||||
expire = 0
|
expire = 0
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestERC20Pool, self).setUp()
|
super(TestERC20PoolBase, self).setUp()
|
||||||
|
|
||||||
self.foo_address = self.address
|
self.foo_address = self.address
|
||||||
|
self.publish_tokens()
|
||||||
|
|
||||||
|
|
||||||
|
def publish_tokens(self):
|
||||||
self.bar_address = self.publish_giftable_token('Bar Token', 'BAR', 16)
|
self.bar_address = self.publish_giftable_token('Bar Token', 'BAR', 16)
|
||||||
self.baz_address = self.publish_giftable_token('Baz Token', 'BAZ', 16)
|
self.baz_address = self.publish_giftable_token('Baz Token', 'BAZ', 16)
|
||||||
self.initial_supply_bar = 1 << 20
|
self.initial_supply_bar = 1 << 20
|
||||||
@ -52,8 +56,11 @@ class TestERC20Pool(TestGiftableToken):
|
|||||||
r = self.conn.do(o)
|
r = self.conn.do(o)
|
||||||
self.assertEqual(r['status'], 1)
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
|
||||||
|
def publish_pool(self, declaration=hash_of_foo, token_registry=None, token_limiter=None):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||||
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
(tx_hash, o) = c.constructor(self.accounts[0], "Big Pool", "BIG", 16)
|
(tx_hash, o) = c.constructor(self.accounts[0], "Big Pool", "BIG", 16, declaration=declaration, token_registry=token_registry, token_limiter=token_limiter)
|
||||||
self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
o = receipt(tx_hash)
|
o = receipt(tx_hash)
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
@ -62,3 +69,19 @@ class TestERC20Pool(TestGiftableToken):
|
|||||||
self.address = self.pool_address
|
self.address = self.pool_address
|
||||||
logg.debug('published bar token {}, baz token {}'.format(self.bar_address, self.baz_address))
|
logg.debug('published bar token {}, baz token {}'.format(self.bar_address, self.baz_address))
|
||||||
logg.debug('published pool on address {} with hash {}'.format(self.pool_address, tx_hash))
|
logg.debug('published pool on address {} with hash {}'.format(self.pool_address, tx_hash))
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
eth_tester==0.5.0b3
|
eth_tester==0.5.0b3
|
||||||
py-evm==0.3.0a20
|
py-evm==0.3.0a20
|
||||||
eth-interface==0.1.1
|
eth-interface==0.1.1
|
||||||
eth-accounts-index~=0.5.3
|
erc20-limiter==0.0.2
|
||||||
|
@ -12,10 +12,6 @@ from giftable_erc20_token import GiftableToken
|
|||||||
# local imports
|
# local imports
|
||||||
from erc20_pool.unittest import TestERC20Pool
|
from erc20_pool.unittest import TestERC20Pool
|
||||||
from erc20_pool import Pool
|
from erc20_pool import Pool
|
||||||
#from evm_tokenvote.unittest.base import hash_of_foo
|
|
||||||
#from evm_tokenvote import Voter
|
|
||||||
#from evm_tokenvote import ProposalState
|
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
86
python/tests/test_token.py
Normal file
86
python/tests/test_token.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
# standard imports
|
||||||
|
import unittest
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
from chainlib.eth.block import block_latest
|
||||||
|
from hexathon import same as same_hex
|
||||||
|
from eth_erc20 import ERC20
|
||||||
|
from giftable_erc20_token import GiftableToken
|
||||||
|
from erc20_limiter import Limiter
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from erc20_pool.unittest import TestERC20PoolLimiter
|
||||||
|
from erc20_pool import Pool
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
class TestPoolLimit(TestERC20PoolLimiter):
|
||||||
|
|
||||||
|
def test_deposit_limit(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||||
|
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.approve(self.foo_address, self.accounts[0], self.pool_address, 1024)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 513)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.set_limit(self.limiter_address, self.accounts[0], self.foo_address, 512, holder_address=self.pool_address)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.limit_of(self.limiter_address, self.foo_address, self.pool_address, sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(int(r, 16), 512)
|
||||||
|
|
||||||
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 513)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 512)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
c = Limiter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.set_limit(self.limiter_address, self.accounts[0], self.foo_address, 513, holder_address=self.pool_address)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.deposit(self.pool_address, self.accounts[0], self.foo_address, 1)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -3,14 +3,14 @@ pragma solidity ^0.8.0;
|
|||||||
// Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
// Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
// File-Version: 1
|
// File-Version: 1
|
||||||
// Description: Voting contract using ERC20 tokens as shares
|
// Description: ACL-enabled ERC20 token swap for tokens with compatible properties.
|
||||||
|
|
||||||
contract SwapPool {
|
contract SwapPool {
|
||||||
// Implements EIP173
|
// Implements EIP173
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
address tokenRegistry;
|
address tokenRegistry;
|
||||||
address limitRegistry;
|
address tokenLimiter;
|
||||||
address quoter;
|
address quoter;
|
||||||
uint256 feePpm;
|
uint256 feePpm;
|
||||||
address feeAddress;
|
address feeAddress;
|
||||||
@ -36,12 +36,12 @@ contract SwapPool {
|
|||||||
// EIP173
|
// EIP173
|
||||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
||||||
|
|
||||||
constructor(string memory _name, string memory _symbol, uint8 _decimals, bytes32 _declaration, address _tokenRegistry, address _limitRegistry) {
|
constructor(string memory _name, string memory _symbol, uint8 _decimals, bytes32 _declaration, address _tokenRegistry, address _tokenLimiter) {
|
||||||
name = _name;
|
name = _name;
|
||||||
symbol = _symbol;
|
symbol = _symbol;
|
||||||
decimals = _decimals;
|
decimals = _decimals;
|
||||||
tokenRegistry = _tokenRegistry;
|
tokenRegistry = _tokenRegistry;
|
||||||
limitRegistry = _limitRegistry;
|
tokenLimiter = _tokenLimiter;
|
||||||
declaration = _declaration;
|
declaration = _declaration;
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
}
|
}
|
||||||
@ -200,12 +200,13 @@ contract SwapPool {
|
|||||||
uint256 limit;
|
uint256 limit;
|
||||||
uint256 balance;
|
uint256 balance;
|
||||||
|
|
||||||
if (limitRegistry == address(0)) {
|
if (tokenLimiter == address(0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(r, v) = limitRegistry.call(abi.encodeWithSignature("limitOf(address, address)", _token, this));
|
|
||||||
require(r, "ERR_TOKEN");
|
(r, v) = tokenLimiter.call(abi.encodeWithSignature("limitOf(address,address)", _token, this));
|
||||||
|
require(r, "ERR_LIMITER");
|
||||||
limit = abi.decode(v, (uint256));
|
limit = abi.decode(v, (uint256));
|
||||||
|
|
||||||
(r, v) = _token.call(abi.encodeWithSignature("balanceOf(address)", this));
|
(r, v) = _token.call(abi.encodeWithSignature("balanceOf(address)", this));
|
||||||
|
Loading…
Reference in New Issue
Block a user