def get_rate(target): getcontext().prec = 6 if target == "mnt": return async_stubber( Decimal(2.2575782374764977).quantize(WEI_VALUE, context=Context(prec=40))) if target == "usd": return async_stubber( Decimal(0.0008393768466290626).quantize(WEI_VALUE, context=Context(prec=40))) if target == "xdr": return async_stubber( Decimal(0.0006094236838571045).quantize(WEI_VALUE, context=Context(prec=40)))
def test_fetch_coinone_krw(http_mock, exchange_coinone): http_mock.return_value = async_stubber(get_orderbook_200()) loop = asyncio.get_event_loop() result = loop.run_until_complete( fetch_coinone_krw() ) assert str(result) == "263.563000000000000000"
def test_fetch_coinone_krw_error(http_mock, exchange_coinone): http_mock.return_value = async_stubber({"errorCode":"51"}) loop = asyncio.get_event_loop() with pytest.raises(ExchangeErr): loop.run_until_complete( fetch_coinone_krw() )
def test_derive_rate_error(http_mock): http_mock.return_value = async_stubber(None) loop = asyncio.get_event_loop() result = loop.run_until_complete( derive_rate("mnt") ) assert str(result) == "-1.000000000000000000"
def test_sync_state_exception(LCDNodeMock): acc_addr = "terra1kk2gcmy6d444jpsg3hyf84lxd3dx0naud0236f" LCDNodeMock.get_account.return_value = async_stubber( mock_account_info(acc_addr, "public_key", "0", 0, 0)) cli_wallet = CLIWallet("feeder", "", acc_addr, LCDNodeMock) loop = asyncio.get_event_loop() with pytest.raises(ValueError): loop.run_until_complete(cli_wallet.sync_state())
def test_get_account(http_mock, lcd_node): http_mock.return_value = async_stubber("") loop = asyncio.get_event_loop() loop.run_until_complete( lcd_node.get_account("terra1tngw4yusyas9ujlcmxdn7xkx6az07hej72rssm") ) http_mock.assert_called_once_with( "http://127.0.0.1:1317/auth/accounts/terra1tngw4yusyas9ujlcmxdn7xkx6az07hej72rssm", params={})
def test_get_latest_block(http_mock, lcd_node): http_mock.return_value = async_stubber("") loop = asyncio.get_event_loop() loop.run_until_complete( lcd_node.get_latest_block() ) http_mock.assert_called_once_with( "http://127.0.0.1:1317/blocks/latest", params={})
def block_data(): return async_stubber( mock_block_data( height, "92ABADC153FAE3419744FD618F6FBD2211AB34467C605D53F2D09177BA24BF6D", "0A47AE25572A567978F990362D13E3968A9EF147E74B22000CAFD01491558795", "soju-0013", ))
def test_get_oracle_active_denoms(http_mock, lcd_node): http_mock.return_value = async_stubber("") loop = asyncio.get_event_loop() loop.run_until_complete( lcd_node.get_oracle_active_denoms() ) http_mock.assert_called_once_with( "http://127.0.0.1:1317/oracle/denoms/actives", params={})
def block_data(): return async_stubber( mock_block_data( height, "666880A87813145B22B0BD2EC064B652C3D94E91E6DB31BDB855CDAA88BEF7A1", "26339D064BF56950F46E0894FC54AAAAF83A48C10219567845D0E839B43DB0D0", "soju-0013", ))
def block_data(): return async_stubber( mock_block_data( height, "C0006E180BA9BFAAD01020477E7CD8A45A4B428684C69D2992E57887715479EE", "666880A87813145B22B0BD2EC064B652C3D94E91E6DB31BDB855CDAA88BEF7A1", "soju-0013", ))
def test_derive_rate(http_mock): http_mock.return_value = async_stubber([[1578626600000, 2.3255122144959466], [1578626659000, 2.32551221449594322]]) loop = asyncio.get_event_loop() result = loop.run_until_complete( derive_rate("mnt") ) http_mock.assert_called_with( "https://api.ukfx.co.uk/pairs/krw/mnt/livehistory/chart?t=1") assert str(result) == "2.325512214495943031"
def test_get_oracle_votes_validator(http_mock, lcd_node): http_mock.return_value = async_stubber("") loop = asyncio.get_event_loop() loop.run_until_complete( lcd_node.get_oracle_votes_validator( "mnt", "terravaloper1lsgzqmtyl99cxjs2rdrwvda3g6g6z8d3g8tfzu") ) http_mock.assert_called_once_with( "http://127.0.0.1:1317/oracle/denoms/mnt/votes/terravaloper1lsgzqmtyl99cxjs2rdrwvda3g6g6z8d3g8tfzu", params={})
def onchain_rates(): return async_stubber( mock_onchain_rates( height, ukrw="300.000000000000000000", umnt="684.542466258089234543", usdr="0.182737050935369655", uusd="0.251817321037518416", ))
def test_get_tx(http_mock, lcd_node): http_mock.return_value = async_stubber("get_tx") loop = asyncio.get_event_loop() result = loop.run_until_complete( lcd_node.get_tx( "36F6ABBE0A686D4DAC5F557EE562B421D7C47AB6DE77B986AA6D925E41645AFA") ) http_mock.assert_called_once_with( "http://127.0.0.1:1317/txs/36F6ABBE0A686D4DAC5F557EE562B421D7C47AB6DE77B986AA6D925E41645AFA", params={}) assert result == "get_tx"
def chain_prevotes(validator_addr, call_number): if call_number == 1: return async_stubber( mock_chain_prevotes( validator_addr, height, "umnt", submit_hash="4b5117103540e7869ecc291f6a81ee27b7bf08f0", submit_height=18553, )) if call_number == 2: return async_stubber( mock_chain_prevotes( validator_addr, height, "uusd", submit_hash="b68ecde518d56f237bbf38e2438e5f0451520d7e", submit_height=18553, )) if call_number == 3: return async_stubber( mock_chain_prevotes( validator_addr, height, "usdr", submit_hash="f9cd1971df0169b59fdb4d0bccf57d1c61ac49a0", submit_height=18553, )) if call_number == 4: return async_stubber( mock_chain_prevotes( validator_addr, height, "ukrw", submit_hash="2cd0e2c4963b68ef880bcedd5ded8743b2dfa9dd", submit_height=18553, ))
def chain_prevotes(validator_addr, call_number): if call_number == 1: return async_stubber( mock_chain_prevotes( validator_addr, height, "umnt", submit_hash="aebad352c771ac5797ad497043fee2c7856a6f75", submit_height=18547, )) if call_number == 2: return async_stubber( mock_chain_prevotes( validator_addr, height, "uusd", submit_hash="a883e3eb0602b0261fe7de798513d4ce478dfedc", submit_height=18547, )) if call_number == 3: return async_stubber( mock_chain_prevotes( validator_addr, height, "usdr", submit_hash="4f487244e40107f0b29211c4983de858c0f6a65f", submit_height=18547, )) if call_number == 4: return async_stubber( mock_chain_prevotes( validator_addr, height, "ukrw", submit_hash="3682c685b9130b65952f0dbd311b163fcefd247c", submit_height=18547, ))
async def handle_broadcast_error( CLIWalletMock, LCDNodeMock, vote_period, ): stub_lcd_node(18549, LCDNodeMock, cli_accounts) stub_wallet(18549, CLIWalletMock) oracle = Oracle( vote_period=vote_period, lcd_node=LCDNodeMock, validator_addr=cli_accounts[0], wallet=CLIWalletMock, ) stub_oracle(18549, oracle) await oracle.retrieve_height() stub_lcd_node(18550, LCDNodeMock, cli_accounts) LCDNodeMock.get_tx.return_value = async_stubber( mock_query_tx_error( 18549, "36F6ABBE0A686D4DAC5F557EE562B421D7C47AB6DE77B986AA6D925E41645AFA") ) stub_wallet(18550, CLIWalletMock) stub_oracle(18550, oracle) await oracle.retrieve_height()
def get_coinone(): getcontext().prec = 6 return async_stubber( Decimal("300.396").quantize(WEI_VALUE, context=Context(prec=40)))
def account_info(feeder_addr): acc_pubkey = "AmKCbdsbJT9+JakXdH0s0c1SWuaFMpDrxLWdGRivYP6S" acc_num = "52" # Prepare Stubs return async_stubber( mock_account_info(feeder_addr, acc_pubkey, acc_num, height, 77))
def test_get_orderbook_error(http_mock, exchange_coinone): http_mock.return_value = async_stubber({"errorCode": 400}) loop = asyncio.get_event_loop() error, _ = loop.run_until_complete(exchange_coinone.get_orderbook("LUNA")) assert error is 400
def sync_state(height, wallet): w = ok_sync_state[str(height)] type(wallet).account_num = PropertyMock(return_value=w["account_num"]) type(wallet).account_seq = PropertyMock(return_value=w["account_sequence"]) type(wallet).account_balance = PropertyMock(return_value=w["balance"]) return async_stubber(None)
def query_tx(): return async_stubber(None)
def broadcast_tx(txhash): return async_stubber(mock_broadcast_tx(txhash))
def query_tx(height, txhash): return async_stubber(mock_query_tx(height, txhash))
def active_denoms(): return async_stubber(mock_active_denoms(height))