def test_check_balances(cp, share, cust, cptime): """check balances""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) rpc.sleep(110) for i in range(1, 6): assert cp.custodianBalanceAt(share, accounts[i], cust, cptime) == i * 1000
def test_computational_refund(): job = Job() provider = accounts[0] requester = accounts[1] register_provider(100) register_requester(requester) job.code_hashes = [ b"9b3e9babb65d9c1aceea8d606fc55403", b"9a4c0c1c9aadb203daf9367bd4df930b" ] job.cores = [1] job.run_time = [5] job.data_transfer_ins = [1, 1] job.data_transfer_out = 1 job.storage_ids = [StorageID.EUDAT.value, StorageID.EUDAT.value] job.cache_types = [CacheType.PUBLIC.value, CacheType.PUBLIC.value] job.storage_hours = [0, 0] job.data_prices_set_block_numbers = [0, 0] job_price, _cost = job.cost(provider, requester) provider_price_block_number = ebb.getProviderSetBlockNumbers( accounts[0])[-1] args = [ provider, provider_price_block_number, job.storage_ids, job.cache_types, job.data_prices_set_block_numbers, job.cores, job.run_time, job.data_transfer_out, ] tx = ebb.submitJob( job.code_hashes[0], job.data_transfer_ins, args, job.storage_hours, job.code_hashes, { "from": requester, "value": web3.toWei(job_price, "wei") }, ) index = 0 job_id = 0 start_time = 1579524978 tx = ebb.setJobStatusRunning(job.code_hashes[0], index, job_id, start_time, {"from": accounts[0]}) rpc.sleep(60) mine(5) args = [index, job_id, 1579524998, 2, 0, job.cores, [5], True] run_time = 1 tx = ebb.processPayment(job.code_hashes[0], args, run_time, zero_bytes32, {"from": accounts[0]}) received_sum = tx.events["LogProcessPayment"]["receivedWei"] refunded_sum = tx.events["LogProcessPayment"]["refundedWei"] log(f"{received_sum} {refunded_sum}") assert received_sum + refunded_sum == 505 assert received_sum == 104 and refunded_sum == 401 withdraw(accounts[0], received_sum) withdraw(requester, refunded_sum)
def test_time(nft): """Block transfers with range time lock""" nft.mint(accounts[1], 10000, rpc.time() + 20, "0x00", {"from": accounts[0]}) with pytest.reverts(): nft.transfer(accounts[2], 1000, {"from": accounts[1]}) rpc.sleep(21) nft.transfer(accounts[2], 1000, {"from": accounts[1]})
def test_time_exceptions(monkeypatch): with pytest.raises(TypeError): rpc.sleep("foo") with pytest.raises(TypeError): rpc.sleep(3.0) monkeypatch.setattr('brownie.rpc.is_active', lambda: False) with pytest.raises(SystemError): rpc.time()
def test_time(): assert rpc.time() == int(time.time()) rpc.sleep(25) rpc.snapshot() rpc.sleep(75) assert rpc.time() == int(time.time() + 100) rpc.revert() assert rpc.time() == int(time.time() + 25)
def rule_advance_time(self, st_sleep_duration): """ Advance the clock. """ rpc.sleep(st_sleep_duration * WEEK) # check the balance as a transaction, to ensure a block is mined after time travel self.token.balanceOf.transact(self.accounts[0], {'from': self.accounts[0]})
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_moved_after(cp, share, cptime): """moved after checkpoint""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) rpc.sleep(110) for i in range(1, 6): assert cp.balanceAt(share, accounts[i], cptime) == i * 1000 share.transfer(accounts[0], 1000, {"from": accounts[i]}) assert cp.balanceAt(share, accounts[i], cptime) == i * 1000
def test_vote(gov, cust): rpc.sleep(210) gov.voteOnProposal("0x1234", 1, {"from": accounts[1]}) gov.custodialVoteOnProposal("0x1234", cust, {"from": accounts[1]}) gov.voteOnProposal("0x1234", 1, {"from": accounts[4]}) gov.custodialVoteOnProposal("0x1234", cust, {"from": accounts[4]}) gov.voteOnProposal("0x1234", 1, {"from": accounts[8]}) gov.custodialVoteOnProposal("0x1234", cust, {"from": accounts[8]})
def test_single_vote_quorum_not_reached(gov, share): gov.newVote("0x1234", 5000, 6700, [share], [1], {"from": accounts[0]}) rpc.sleep(210) gov.voteOnProposal("0x1234", 1, {"from": accounts[1]}) gov.voteOnProposal("0x1234", 0, {"from": accounts[2]}) rpc.sleep(110) gov.closeProposal("0x1234", {"from": accounts[0]}) assert gov.getProposalState("0x1234") == 3 assert gov.getVotePct("0x1234", 0) == (5000, 6666)
def test_two_moved_after(cp, share, cptime): """two checkpoints - moved after""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 100, {"from": accounts[0]}) rpc.sleep(210) for i in range(1, 6): share.transfer(accounts[0], 1000, {"from": accounts[i]}) assert cp.balanceAt(share, accounts[i], cptime) == i * 1000 assert cp.balanceAt(share, accounts[i], cptime + 100) == i * 1000
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 dutch_auction(PetylDutchAuction, auction_factory, auction_token): startDate = rpc.time() +10 endDate = startDate + AUCTION_TIME wallet = accounts[1] tx = auction_token.approve(auction_factory, AUCTION_TOKENS, {'from': accounts[0]}) tx = auction_factory.deployDutchAuction(auction_token, AUCTION_TOKENS, startDate, endDate,ETH_ADDRESS, AUCTION_START_PRICE, AUCTION_RESERVE, wallet, {"from": accounts[0]}) dutch_auction = PetylDutchAuction.at(tx.return_value) assert dutch_auction.clearingPrice() == AUCTION_START_PRICE rpc.sleep(10) return dutch_auction
def test_single_vote_no_quorum_fail(gov, share): gov.newVote("0x1234", 5000, 0, [share], [1], {"from": accounts[0]}) rpc.sleep(210) gov.voteOnProposal("0x1234", 1, {"from": accounts[1]}) gov.voteOnProposal("0x1234", 0, {"from": accounts[2]}) gov.voteOnProposal("0x1234", 0, {"from": accounts[3]}) rpc.sleep(110) gov.closeProposal("0x1234", {"from": accounts[0]}) assert gov.getProposalState("0x1234") == 4 assert gov.getVotePct("0x1234", 0) == (3333, 0)
def test_frames_crowdsale_finalise(frames_crowdsale, frame_token): producer = accounts[7] with reverts(): tx = frames_crowdsale.finalise( producer,{'from': accounts[0]}) rpc.sleep(50001) tx = frames_crowdsale.finalise( producer, {'from': accounts[0]}) assert frames_crowdsale.finalised({'from': accounts[0]}) == True assert frame_token.balanceOf(producer, {'from': accounts[0]}) == PRODUCER_FRAMES * 10 ** 18 with reverts(): tx = frames_crowdsale.finalise( producer,{'from': accounts[0]})
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 test_time_partial(nft): """Partially block a transfer with range time lock""" nft.mint(accounts[1], 10000, 0, "0x00", {"from": accounts[0]}) nft.modifyRanges(102001, 106001, rpc.time() + 20, "0x00", {"from": accounts[0]}) assert nft.getRange(102001)["_stop"] == 106001 nft.transfer(accounts[2], 4000, {"from": accounts[1]}) assert nft.rangesOf(accounts[1]) == ((102001, 106001), (108001, 110001)) rpc.sleep(25) nft.transfer(accounts[2], 6000, {"from": accounts[1]}) assert nft.rangesOf(accounts[2]) == ((100001, 110001),)
def test_moved_before(cp, share, cust, cptime): """moved before checkpoint""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) for i in range(1, 6): cust.transferInternal(share, accounts[i], accounts[0], 1000, {"from": accounts[0]}) rpc.sleep(110) for i in range(1, 6): assert cp.custodianBalanceAt(share, accounts[i], cust, cptime) == (i - 1) * 1000
def test_two_moved_in_between(cp, share, cptime): """two checkpoints - moved in between""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 100, {"from": accounts[0]}) rpc.sleep(110) for i in range(1, 6): share.transfer(accounts[0], 1000, {"from": accounts[i]}) rpc.sleep(110) for i in range(1, 6): assert cp.balanceAt(share, accounts[i], cptime) == i * 1000 assert cp.balanceAt(share, accounts[i], cptime + 100) == (i - 1) * 1000
def test_two_checkpoints(cp, share, cptime): """check balances - two checkpoints""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 100, {"from": accounts[0]}) rpc.sleep(110) for i in range(1, 6): assert cp.balanceAt(share, accounts[i], cptime) == i * 1000 rpc.sleep(110) for i in range(1, 6): assert cp.balanceAt(share, accounts[i], cptime) == i * 1000 assert cp.balanceAt(share, accounts[i], cptime + 100) == i * 1000
def dutch_auction(DutchSwapAuction, auction_token): startDate = rpc.time() +10 endDate = startDate + AUCTION_TIME wallet = accounts[1] dutch_auction = DutchSwapAuction.deploy({'from': accounts[0]}) dutch_auction.initDutchAuction(auction_token, AUCTION_TOKENS, startDate, endDate, AUCTION_START_PRICE, AUCTION_RESERVE, wallet, {"from": accounts[0]}) auction_token.setMintOperator(dutch_auction, True, {"from": accounts[0]}) assert dutch_auction.auctionPrice() == AUCTION_START_PRICE rpc.sleep(10) return dutch_auction
def test_iso_mismatch(options, id1): """cannot change iso in same expiration period""" options.issueOptions(id1, 10, False, [100, 100], [1, 2], {"from": accounts[0]}) with pytest.reverts("dev: iso mismatch"): options.issueOptions(id1, 10, True, [100, 100], [1, 2], {"from": accounts[0]}) options.issueOptions(id1, 10, False, [100, 100], [1, 2], {"from": accounts[0]}) rpc.sleep(2592000) options.issueOptions(id1, 10, True, [100, 100], [1, 2], {"from": accounts[0]})
def test_multi_vote_quorum_pass(gov, share, share2): gov.newVote("0x1234", 5000, 6600, [share], [1], {"from": accounts[0]}) gov.newVote("0x1234", 5000, 6600, [share, share2], [1, 2], {"from": accounts[0]}) rpc.sleep(210) gov.voteOnProposal("0x1234", 0, {"from": accounts[2]}) gov.voteOnProposal("0x1234", 1, {"from": accounts[3]}) gov.voteOnProposal("0x1234", 0, {"from": accounts[4]}) rpc.sleep(110) gov.closeProposal("0x1234", {"from": accounts[0]}) assert gov.getProposalState("0x1234") == 5 assert gov.getVotePct("0x1234", 0) == (5000, 6666) assert gov.getVotePct("0x1234", 1) == (5000, 6666)
def test_three_before(cp, share, cptime): """three checkpoints - moved before""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 100, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 200, {"from": accounts[0]}) for i in range(1, 6): share.transfer(accounts[0], 1000, {"from": accounts[i]}) rpc.sleep(310) for i in range(1, 6): assert cp.balanceAt(share, accounts[i], cptime) == (i - 1) * 1000 assert cp.balanceAt(share, accounts[i], cptime + 100) == (i - 1) * 1000 assert cp.balanceAt(share, accounts[i], cptime + 200) == (i - 1) * 1000
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_three_between_second_third(cp, share, cptime): """three checkpoints - moved between second and third""" cp.newCheckpoint(share, cptime, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 100, {"from": accounts[0]}) cp.newCheckpoint(share, cptime + 200, {"from": accounts[0]}) rpc.sleep(210) for i in range(1, 6): share.transfer(accounts[0], 1000, {"from": accounts[i]}) rpc.sleep(110) for i in range(1, 6): assert cp.balanceAt(share, accounts[i], cptime) == i * 1000 assert cp.balanceAt(share, accounts[i], cptime + 100) == i * 1000 assert cp.balanceAt(share, accounts[i], cptime + 200) == (i - 1) * 1000
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_close_proposal_no_end_passing(gov, share3, cptime): gov.newProposal( "0xffff", cptime, cptime + 100, 0, "test proposal", "0" * 40, "0x", {"from": accounts[0]}, ) gov.newVote("0xffff", 5000, 0, [share3], [1], {"from": accounts[0]}) rpc.sleep(210) gov.voteOnProposal("0xffff", 1, {"from": accounts[5]}) gov.closeProposal("0xffff", {"from": accounts[0]})