erc20-pool

Permissioned ERC20 swap pool for EVM
Info | Log | Files | Refs | README

test_quoter.py (2223B)


      1 # standard imports
      2 import unittest
      3 import logging
      4 import os
      5 from chainlib.eth.nonce import RPCNonceOracle
      6 from chainlib.eth.tx import receipt
      7 from chainlib.eth.block import block_latest
      8 from hexathon import same as same_hex
      9 from eth_erc20 import ERC20
     10 from giftable_erc20_token import GiftableToken
     11 from erc20_limiter import Limiter
     12 
     13 # local imports
     14 from erc20_pool.quote import DecimalQuote
     15 from erc20_pool.unittest.quote import TestDecimalQuote
     16 
     17 logging.basicConfig(level=logging.DEBUG)
     18 logg = logging.getLogger()
     19 
     20 class TestQuote(TestDecimalQuote):
     21 
     22     def setUp(self):
     23         super(TestQuote, self).setUp()
     24         self.tokens = {}
     25         self.publish_token('Foo token', 'FOO', 14)
     26         self.publish_token('Bar token', 'BAR', 18)
     27         self.publish_token('Baz token', 'BAZ', 11)
     28 
     29     def publish_token(self, name, symbol, decimals):
     30         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     31         c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     32         self.symbol = name
     33         self.name = symbol
     34         self.decimals = decimals
     35         (tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, expire=0)
     36         self.rpc.do(o)
     37         o = receipt(tx_hash)
     38         r = self.rpc.do(o)
     39         self.assertEqual(r['status'], 1)
     40         address = r['contract_address'] 
     41         logg.debug('published "{}" ("{}") on address {} with hash {}'.format(name, symbol, address, tx_hash))
     42         self.tokens[symbol] = address
     43 
     44 
     45     def test_quote(self):
     46         c = DecimalQuote(self.chain_spec)
     47         o = c.value_for(self.quoter_address, self.tokens['FOO'], self.tokens['FOO'], 10**18, sender_address=self.accounts[0])
     48         r = self.rpc.do(o)
     49         self.assertEqual(int(r, 16), 10**18)
     50 
     51         o = c.value_for(self.quoter_address, self.tokens['FOO'], self.tokens['BAR'], 10**18, sender_address=self.accounts[0])
     52         r = self.rpc.do(o)
     53         self.assertEqual(int(r, 16), 10**14)
     54 
     55         o = c.value_for(self.quoter_address, self.tokens['FOO'], self.tokens['BAZ'], 10**18, sender_address=self.accounts[0])
     56         r = self.rpc.do(o)
     57         self.assertEqual(int(r, 16), 10**21)
     58 
     59 
     60 if __name__ == '__main__':
     61     unittest.main()