def test_approve_and_make_and_getters(self): # given assert self.otc.get_last_offer_id() == 0 # when self.otc.approve([self.token1], directly()) self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(1), want_token=self.token2.address, want_amount=Wad.from_number(2)).transact() # then assert self.otc.get_last_offer_id() == 1 # and assert self.otc.get_offer(1).offer_id == 1 assert self.otc.get_offer(1).sell_which_token == self.token1.address assert self.otc.get_offer(1).sell_how_much == Wad.from_number(1) assert self.otc.get_offer(1).buy_which_token == self.token2.address assert self.otc.get_offer(1).buy_how_much == Wad.from_number(2) assert self.otc.get_offer(1).owner == self.our_address assert self.otc.get_offer(1).timestamp != 0 # and assert self.otc.active_offers() == [self.otc.get_offer(1)]
def test_on_take(self): # given on_take_mock = Mock() self.otc.on_take(on_take_mock) # when self.otc.approve([self.token1], directly()) self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(1), want_token=self.token2.address, want_amount=Wad.from_number(2)).transact() # and self.otc.approve([self.token2], directly()) self.otc.take(1, Wad.from_number(0.5)).transact() # then on_take = wait_until_mock_called(on_take_mock)[0] assert on_take.id == 1 assert on_take.maker == self.our_address assert on_take.taker == self.our_address assert on_take.have_token == self.token1.address assert on_take.take_amount == Wad.from_number(0.5) assert on_take.want_token == self.token2.address assert on_take.give_amount == Wad.from_number(1) assert on_take.timestamp != 0
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.our_address = Address(self.web3.eth.defaultAccount) self.otc = SimpleMarket.deploy(self.web3) self.token1 = DSToken.deploy(self.web3, 'AAA') self.token1.mint(Wad.from_number(100)).transact() self.token2 = DSToken.deploy(self.web3, 'BBB') self.token2.mint(Wad.from_number(100)).transact()
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_approve(self): # given assert self.token1.allowance_of(self.our_address, self.tx.address) == Wad(0) assert self.token2.allowance_of(self.our_address, self.tx.address) == Wad(0) # when self.tx.approve([self.token1, self.token2], directly()) # then assert self.token1.allowance_of(self.our_address, self.tx.address) == Wad(2**256-1) assert self.token2.allowance_of(self.our_address, self.tx.address) == Wad(2**256-1)
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_execute(self): # given self.tx.approve([self.token1], directly()) # when self.tx.execute([self.token1.address], [self.token1.transfer(self.other_address, Wad.from_number(500)).invocation()]).transact() # then assert self.token1.balance_of(self.our_address) == Wad.from_number(999500) assert self.token1.balance_of(self.other_address) == Wad.from_number(500)
def test_deposit_and_withdraw_eth(self): # when self.etherdelta.deposit(Wad.from_number(2.5)).transact() # then assert self.etherdelta.balance_of(self.our_address) == Wad.from_number(2.5) # when self.etherdelta.withdraw(Wad.from_number(1.1)).transact() # then assert self.etherdelta.balance_of(self.our_address) == Wad.from_number(1.4)
def cups(self, cup_id: int) -> Cup: """Get the cup details. Args: cup_id: Id of the cup to get the details of. Returns: Class encapsulating cup details. """ assert isinstance(cup_id, int) array = self._contractTub.call().cups(int_to_bytes32(cup_id)) return Cup(cup_id, Address(array[0]), Wad(array[1]), Wad(array[2]))
def test_onchain_order_happy_path(self): # given self.etherdelta.approve([self.token1, self.token2], directly()) self.etherdelta.deposit_token(self.token1.address, Wad.from_number(10)).transact() self.etherdelta.deposit_token(self.token2.address, Wad.from_number(10)).transact() # when self.etherdelta.place_order_onchain(token_get=self.token2.address, amount_get=Wad.from_number(4), token_give=self.token1.address, amount_give=Wad.from_number(2), expires=100000000).transact() # then assert len(self.etherdelta.active_onchain_orders()) == 1 # and order = self.etherdelta.active_onchain_orders()[0] assert order.token_get == self.token2.address assert order.amount_get == Wad.from_number(4) assert order.token_give == self.token1.address assert order.amount_give == Wad.from_number(2) assert order.expires == 100000000 assert order.user == self.our_address # and assert self.etherdelta.amount_available(order) == Wad.from_number(4) assert self.etherdelta.amount_filled(order) == Wad.from_number(0) # and assert self.etherdelta.can_trade(order, Wad.from_number(1.5)) assert not self.etherdelta.can_trade(order, Wad.from_number(5.5))
def test_kill(self): # given self.otc.approve([self.token1], directly()) self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(1), want_token=self.token2.address, want_amount=Wad.from_number(2)).transact() # when self.otc.kill(1).transact() # then assert self.otc.get_offer(1) is None assert self.otc.active_offers() == [] assert self.otc.get_last_offer_id() == 1
def test_deposit_and_withdraw_token(self): # given self.etherdelta.approve([self.token1], directly()) # when self.etherdelta.deposit_token(self.token1.address, Wad.from_number(1.5)).transact() # then assert self.etherdelta.balance_of_token(self.token1.address, self.our_address) == Wad.from_number(1.5) # when self.etherdelta.withdraw_token(self.token1.address, Wad.from_number(0.2)).transact() # then assert self.etherdelta.balance_of_token(self.token1.address, self.our_address) == Wad.from_number(1.3)
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.our_address = Address(self.web3.eth.defaultAccount) self.etherdelta = EtherDelta.deploy( self.web3, admin=self.our_address, fee_account=self.our_address, account_levels_addr=self.our_address, fee_make=Wad(0), fee_take=Wad(0), fee_rebate=Wad(0), api_server='http://none.invalid') self.token1 = DSToken.deploy(self.web3, 'AAA') self.token1.mint(Wad.from_number(100)).transact()
def gap(self) -> Wad: """Get the spread, charged on `take()`. Returns: The current value of the spread. `1.0` means no spread. `1.02` means 2% spread. """ return Wad(self._contract.call().gap())
def ask(self) -> Wad: """Get the current price of SKR in SAI for `bust`. Returns: The SKR in SAI price that will be used on `bust()`. """ return Wad(self._contract.call().ask())
def bid(self) -> Wad: """Get the current price of SKR in SAI for `boom`. Returns: The SKR in SAI price that will be used on `boom()`. """ return Wad(self._contract.call().bid())
def pie(self) -> Wad: """Get the amount of raw collateral. Returns: The amount of raw collateral in GEM. """ return Wad(self._contractTub.call().pie())
def gap(self) -> Wad: """Get the current spread for `boom` and `bust`. Returns: The current spread for `boom` and `bust`. `1.0` means no spread, `1.01` means 1% spread. """ return Wad(self._contract.call().gap())
def pie(self) -> Wad: """Get the total pool value (in ref). Returns: The the total pool value (in ref). """ return Wad(self._contract.call().pie())
def woe(self) -> Wad: """Get the amount of bad debt. Returns: The amount of bad debt in SAI. """ return Wad(self._contract.call().woe())
def hat(self) -> Wad: """Get the debt ceiling. Returns: The debt ceiling in SAI. """ return Wad(self._contractTub.call().hat())
def jar_gap(self) -> Wad: """Get the current spread for `join` and `exit`. Returns: The current spread for `join` and `exit`. `1.0` means no spread, `1.01` means 1% spread. """ return Wad(self._contractJar.call().gap())
def air(self) -> Wad: """Get the amount of backing collateral. Returns: The amount of backing collateral in SKR. """ return Wad(self._contractTub.call().air())
def setup_method(self): self.web3 = Web3(EthereumTesterProvider()) self.web3.eth.defaultAccount = self.web3.eth.accounts[0] self.our_address = Address(self.web3.eth.defaultAccount) self.etherdelta = EtherDelta.deploy(self.web3, admin=Address('0x1111100000999998888877777666665555544444'), fee_account=Address('0x8888877777666665555544444111110000099999'), account_levels_addr=Address('0x6666655555444441111188888777770000099999'), fee_make=Wad.from_number(0.01), fee_take=Wad.from_number(0.02), fee_rebate=Wad.from_number(0.03), api_server=None) self.token1 = DSToken.deploy(self.web3, 'AAA') self.token1.mint(Wad.from_number(100)).transact() self.token2 = DSToken.deploy(self.web3, 'BBB') self.token2.mint(Wad.from_number(100)).transact()
def s2s(self) -> Wad: """Get the current SKR per SAI rate (for `boom` and `bust`). Returns: The current SKR per SAI rate. """ return Wad(self._contract.call().s2s())
def ice(self) -> Wad: """Get the amount of good debt. Returns: The amount of good debt in SAI. """ return Wad(self._contractTub.call().ice())
def fog(self) -> Wad: """Get the amount of SKR pending liquidation. Returns: The amount of SKR pending liquidation, in SKR. """ return Wad(self._contract.call().fog())
def test_take_partial(self): # given self.otc.approve([self.token1], directly()) self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(1), want_token=self.token2.address, want_amount=Wad.from_number(2)).transact() # when self.otc.approve([self.token2], directly()) self.otc.take(1, Wad.from_number(0.25)).transact() # then assert self.otc.get_offer(1).sell_how_much == Wad.from_number(0.75) assert self.otc.get_offer(1).buy_how_much == Wad.from_number(1.5) assert self.otc.active_offers() == [self.otc.get_offer(1)] assert self.otc.get_last_offer_id() == 1
def test_offer_comparison(self): # when self.otc.approve([self.token1], directly()) self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(1), want_token=self.token2.address, want_amount=Wad.from_number(2)).transact() # and self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(3), want_token=self.token2.address, want_amount=Wad.from_number(4)).transact() # then assert self.otc.get_last_offer_id() == 2 assert self.otc.get_offer(1) == self.otc.get_offer(1) assert self.otc.get_offer(1) != self.otc.get_offer(2)
def test_past_make(self): # when self.otc.approve([self.token1], directly()) self.otc.make(have_token=self.token1.address, have_amount=Wad.from_number(1), want_token=self.token2.address, want_amount=Wad.from_number(2)).transact() # then past_make = self.otc.past_make(PAST_BLOCKS) assert len(past_make) == 1 assert past_make[0].id == 1 assert past_make[0].maker == self.our_address assert past_make[0].have_token == self.token1.address assert past_make[0].have_amount == Wad.from_number(1) assert past_make[0].want_token == self.token2.address assert past_make[0].want_amount == Wad.from_number(2) assert past_make[0].timestamp != 0