def test_dutch_auction_claim_not_enough(dutch_auction): token_buyer = accounts[2] eth_to_transfer = 0.01 * TENPOW18 token_buyer.transfer(dutch_auction, eth_to_transfer) rpc.sleep(AUCTION_TIME + 100) rpc.mine() dutch_auction.withdrawTokens({'from': token_buyer})
def test_dutch_auction_tokensClaimable(dutch_auction): assert dutch_auction.tokensClaimable(accounts[2]) == 0 token_buyer = accounts[2] eth_to_transfer = 20 * TENPOW18 token_buyer.transfer(dutch_auction, eth_to_transfer) rpc.sleep(AUCTION_TIME + 100) rpc.mine() assert dutch_auction.tokensClaimable(accounts[2]) == "1000 ether"
def test_dutch_auction_clearingPrice(dutch_auction): rpc.sleep(100) rpc.mine() assert dutch_auction.clearingPrice() <= AUCTION_START_PRICE assert dutch_auction.clearingPrice() > AUCTION_RESERVE rpc.sleep(AUCTION_TIME) rpc.mine() assert dutch_auction.clearingPrice() == AUCTION_RESERVE
def test_dutch_auction_erc20_clearingPrice(dutch_auction_erc20, currency_token): rpc.sleep(100) rpc.mine() assert dutch_auction_erc20.clearingPrice() <= AUCTION_START_PRICE assert dutch_auction_erc20.clearingPrice() > AUCTION_RESERVE rpc.sleep(AUCTION_TIME) rpc.mine() assert dutch_auction_erc20.clearingPrice() == AUCTION_RESERVE
def _check(options, id1, sorted_totals, at_price, get_options): for i in range(len(sorted_totals) - 1): now = int(rpc.time() // 2592000 + 1) * 2592000 rpc.sleep(now - rpc.time() - 5) rpc.mine() assert options.getSortedTotals() == sorted_totals[i] assert options.getTotalOptionsAtPrice(10) == at_price[i] assert options.getOptions(id1) == get_options[i] rpc.sleep(10) rpc.mine() assert options.getSortedTotals() == sorted_totals[i + 1] assert options.getTotalOptionsAtPrice(10) == at_price[i + 1] assert options.getOptions(id1) == get_options[i + 1]
def test_dutch_auction_erc20_tokensClaimable(dutch_auction_erc20, currency_token): assert dutch_auction_erc20.tokensClaimable(accounts[2]) == 0 token_buyer = accounts[2] tokens_to_transfer = 20 * TENPOW18 currency_token.approve(dutch_auction_erc20, tokens_to_transfer, {'from': token_buyer}) tx = dutch_auction_erc20.commitTokens(tokens_to_transfer, {'from': token_buyer}) #assert len(tx.events) == 3 rpc.sleep(AUCTION_TIME + 100) rpc.mine() assert dutch_auction_erc20.tokensClaimable(accounts[2]) == "1000 ether"
def test_dutch_auction_erc20_claim_not_enough(dutch_auction_erc20, currency_token): token_buyer = accounts[2] tokens_to_transfer = 0.01 * TENPOW18 currency_token.approve(dutch_auction_erc20, tokens_to_transfer, {'from': token_buyer}) tx = dutch_auction_erc20.commitTokens(tokens_to_transfer, {'from': token_buyer}) #assert len(tx.events) == 3 rpc.sleep(AUCTION_TIME + 100) rpc.mine() dutch_auction_erc20.withdrawTokens({'from': token_buyer})
def test_dutch_auction_claim(dutch_auction): token_buyer = accounts[2] eth_to_transfer = 100 * TENPOW18 dutch_auction.withdrawTokens({'from': accounts[0]}) token_buyer.transfer(dutch_auction, eth_to_transfer) with reverts(): dutch_auction.finaliseAuction({'from': accounts[0]}) rpc.sleep(AUCTION_TIME + 100) rpc.mine() dutch_auction.withdrawTokens({'from': token_buyer}) dutch_auction.withdrawTokens({'from': accounts[0]}) assert dutch_auction.auctionSuccessful({'from': accounts[0]}) == True dutch_auction.finaliseAuction({'from': accounts[0]})
def test_dutch_auction_claim(dutch_auction): token_buyer = accounts[2] eth_to_transfer = 100 * TENPOW18 dutch_auction.withdrawTokens({'from': accounts[0]}) dutch_auction.finaliseAuction({'from': accounts[0]}) assert dutch_auction.finalised({'from': accounts[0]}) == False token_buyer.transfer(dutch_auction, eth_to_transfer) ## AG: Test cases before auction ends above and below reserve rpc.sleep(AUCTION_TIME + 100) rpc.mine() dutch_auction.withdrawTokens({'from': token_buyer}) dutch_auction.withdrawTokens({'from': accounts[0]}) assert dutch_auction.auctionSuccessful({'from': accounts[0]}) == True dutch_auction.finaliseAuction({'from': accounts[0]}) assert dutch_auction.finalised({'from': accounts[0]}) == True
def test_dutch_auction_erc20_claim(dutch_auction_erc20, currency_token): token_buyer = accounts[2] tokens_to_transfer = 100 * TENPOW18 dutch_auction_erc20.finaliseAuction({'from': accounts[0]}) assert dutch_auction_erc20.finalised({'from': accounts[0]}) == False # dutch_auction_erc20.withdrawTokens({'from': accounts[0]}) currency_token.approve(dutch_auction_erc20, tokens_to_transfer, {'from': token_buyer}) tx = dutch_auction_erc20.commitTokens(tokens_to_transfer, {'from': token_buyer}) #assert len(tx.events) == 3 ## AG: Test cases before auction ends above and below reserve rpc.sleep(AUCTION_TIME + 100) rpc.mine() dutch_auction_erc20.withdrawTokens({'from': token_buyer}) dutch_auction_erc20.withdrawTokens({'from': accounts[0]}) assert dutch_auction_erc20.auctionSuccessful({'from': accounts[0]}) == True dutch_auction_erc20.finaliseAuction({'from': accounts[0]}) assert dutch_auction_erc20.finalised({'from': accounts[0]}) == True
def test_dutch_auction_ended(dutch_auction): assert dutch_auction.auctionEnded({'from': accounts[0]}) == False rpc.sleep(AUCTION_TIME) rpc.mine() assert dutch_auction.auctionEnded({'from': accounts[0]}) == True
def test_mine(): height = web3.eth.blockNumber rpc.mine() assert web3.eth.blockNumber == height + 1 rpc.mine(5) assert web3.eth.blockNumber == height + 6
def _sleep(months): now = int(rpc.time() // 2592000 + 1) * 2592000 rpc.sleep(now - rpc.time() + 1 + 2592000 * (months - 1)) rpc.mine()
def test_request_exceptions(noweb3, monkeypatch): with pytest.raises(RPCRequestError): rpc.mine() monkeypatch.setattr('brownie.rpc.is_active', lambda: False) with pytest.raises(SystemError): rpc.mine()
def test_mine_exceptions(): with pytest.raises(TypeError): rpc.mine("foo") with pytest.raises(TypeError): rpc.mine(3.0)
def test_gauge_weight_vote(accounts, gauge_controller, three_gauges, voting_escrow, st_deposits, st_length, st_votes): """ Test that gauge weights correctly adjust over time. Strategies --------- st_deposits : [int, int, int] Number of coins to be deposited per account st_length : [int, int, int] Policy duration in weeks st_votes : [(int, int), (int, int), (int, int)] (vote for gauge 0, vote for gauge 1) for each account, in units of 10% """ # Deposit for voting timestamp = history[-1].timestamp for i, acct in enumerate(accounts[:3]): voting_escrow.create_lock(st_deposits[i], timestamp + (st_length[i] * WEEK), {'from': acct}) # Place votes votes = [] for i, acct in enumerate(accounts[:3]): votes.append([x * 1000 for x in st_votes[i]]) votes[-1].append( 10000 - sum(votes[-1])) # XXX what if votes are not used up to 100%? # Now votes are [[vote_gauge_0, vote_gauge_1, vote_gauge_2], ...] for x in range(3): gauge_controller.vote_for_gauge_weights(three_gauges[x], votes[-1][x], {'from': acct}) # Vote power assertions - everyone used all voting power for acct in accounts[:3]: assert gauge_controller.vote_user_power(acct) == 10000 # Calculate slope data, build model functions slope_data = [] for i, acct in enumerate(accounts[:3]): initial_bias = voting_escrow.get_last_user_slope(acct) * ( voting_escrow.locked(acct)[1] - timestamp) duration = ( timestamp + st_length[i] * WEEK ) // WEEK * WEEK - timestamp # <- endtime rounded to whole weeks slope_data.append((initial_bias, duration)) max_duration = max(duration for bias, duration in slope_data) def models(idx, relative_time): bias, duration = slope_data[idx] return max(bias * (1 - relative_time * max_duration / duration), 0) rpc.sleep(WEEK * 4) rpc.mine() # advance clock a month at a time and compare theoretical weight to actual weights while history[-1].timestamp < timestamp + 1.5 * max_duration: for i in range(3): # XXX what happens if not enacted? 0 or old? gauge_controller.enact_vote(three_gauges[i], {'from': accounts[4]}) relative_time = (history[-1].timestamp // WEEK * WEEK - timestamp) / max_duration weights = [ gauge_controller.gauge_relative_weight(three_gauges[i]) / 1e18 for i in range(3) ] if relative_time < 1: theoretical_weights = [ sum((votes[i][0] / 10000) * models(i, relative_time) for i in range(3)), sum((votes[i][1] / 10000) * models(i, relative_time) for i in range(3)), sum((votes[i][2] / 10000) * models(i, relative_time) for i in range(3)), ] theoretical_weights = [ w and (w / sum(theoretical_weights)) for w in theoretical_weights ] else: theoretical_weights = [0] * 3 print(relative_time, weights, theoretical_weights) if relative_time != 1: # XXX 1 is odd: let's look at it separately for i in range(3): assert abs(weights[i] - theoretical_weights[i] ) <= (history[-1].timestamp - timestamp) / WEEK + 1 # 1 s per week? rpc.sleep(WEEK * 4) rpc.mine()
def _sleep(seconds): rpc.sleep(seconds) rpc.mine()
def rpc_delay(rpc, interval): rpc.sleep(interval) rpc.mine(interval)