def test_convert(self): # two chain_amount = Wad(20000) assert self.token.normalize_amount(chain_amount) == Wad.from_number(2) # three normalized_amount = Wad.from_number(3) assert self.token.unnormalize_amount(normalized_amount) == Wad(30000)
def test_get_orders(self, mocker): pair = "ETH-KRW" mocker.patch("requests.request", side_effect=self.binaceUsMockServer.handle_request) response = self.binance_us.get_orders(pair) assert (len(response) > 0) for order in response: assert (isinstance(order.is_sell, bool)) assert (Wad(order.price) > Wad(0)) TestBinanceUs.check_orders(response)
def test_get_orders(self, mocker): instrument_id = "WETH-DAI" mocker.patch("dydx.client.Client.get_my_orders", side_effect=DydxMockServer.handle_get_orders) response = self.dydx.get_orders(instrument_id) assert (len(response) > 0) for order in response: assert(isinstance(order.is_sell, bool)) assert(Wad(order.price) > Wad(0)) TestDydx.check_orders(response)
def test_direct_approval_should_not_approve_if_already_approved(): # given global web3, our_address, second_address, token token.approve(second_address, Wad(2**248 + 17)).transact() # when directly()(token, second_address, "some-name") # then assert token.allowance_of(our_address, second_address) == Wad(2**248 + 17)
def test_via_tx_manager_approval_should_not_approve_if_already_approved(): # given global web3, our_address, second_address, token tx = TxManager.deploy(web3) tx.execute([], [token.approve(second_address, Wad(2**248 + 19)).invocation() ]).transact() # when via_tx_manager(tx)(token, second_address, "some-name") # then assert token.allowance_of(tx.address, second_address) == Wad(2**248 + 19)
def test_min_amount(self): assert self.token.min_amount == Wad.from_number(0.0001) assert float(self.token.min_amount) == 0.0001 assert self.token.unnormalize_amount(self.token.min_amount) == Wad(1) assert Wad.from_number(0.0004) > self.token.min_amount assert Wad.from_number(0.00005) < self.token.min_amount assert self.token.unnormalize_amount( Wad.from_number(0.0006)) > self.token.unnormalize_amount( self.token.min_amount) assert self.token.unnormalize_amount( Wad.from_number(0.00007)) < self.token.unnormalize_amount( self.token.min_amount) assert self.token.unnormalize_amount( Wad.from_number(0.00008)) == Wad(0)
def main(self): self.startup() pending_txes = get_pending_transactions(web3) pprint( list( map(lambda t: f"{t.name()} with gas {t.current_gas}", pending_txes))) if len(pending_txes) > 0: while len(pending_txes) > 0: pending_txes[0].cancel(gas_price=increasing_gas) # After the synchronous cancel, wait to see if subsequent transactions get mined time.sleep(15) pending_txes = get_pending_transactions(web3) else: logging.info( f"No pending transactions were found; submitting {stuck_txes_to_submit}" ) for i in range(1, stuck_txes_to_submit + 1): self._run_future( weth.deposit(Wad(i)).transact_async( gas_price=FixedGasPrice(int(0.4 * i * GWEI)))) time.sleep(2) self.shutdown()
def test_direct_approval(): # given global web3, our_address, second_address, token # when directly()(token, second_address, "some-name") # then assert token.allowance_of(our_address, second_address) == Wad(2**256 - 1)
def test_via_tx_manager_approval(): # given global web3, our_address, second_address, token tx = TxManager.deploy(web3) # when via_tx_manager(tx)(token, second_address, "some-name") # then assert token.allowance_of(tx.address, second_address) == Wad(2**256 - 1)
def test_direct_approval_should_obey_from_address(): # given global web3, our_address, second_address, third_address, token # and # [there is already approval from the `defaultAccount`] # [so that we make sure we check for the existing approval properly] directly()(token, second_address, "some-name") # when directly(from_address=third_address)(token, second_address, "some-name") # then assert token.allowance_of(third_address, second_address) == Wad(2**256 - 1)
def get_approvals(self, address) -> Wad: return Wad(self._contract.functions.approvals(address).call())
def get_deposits(self, address) -> Wad: return Wad(self._contract.functions.deposits(address).call())
def test_empty_tx(self): empty_tx = Transact(self, self.web3, None, self.keeper_address, None, None, [self.keeper_address, Wad(0)]) empty_tx.transact()
def get_minimum_liquidity(self) -> Wad: return Wad( self._pair_contract.functions.MINIMUM_LIQUIDITY( self.account_address.address).call())
def get_account_eth_balance(self): return Wad(self.web3.eth.getBalance(self.account_address.address))
def get_current_liquidity(self) -> Wad: return Wad( self._pair_contract.functions.balanceOf( self.account_address.address).call())
def get_total_liquidity(self) -> Wad: return Wad(self._pair_contract.functions.totalSupply().call())
def get_eth_exchange_balance(self): return Wad(self.web3.eth.getBalance(self.exchange.address))
def get_eth_token_input_price(self, amount: Wad): assert (isinstance(amount, Wad)) return Wad( self._contract.functions.getEthToTokenInputPrice( amount.value).call())
def get_token_eth_output_price(self, amount: Wad): assert (isinstance(amount, Wad)) return Wad( self._contract.functions.getTokenToEthOutputPrice( amount.value).call())