コード例 #1
0
    def rule_create_lock(self, st_account, st_value, st_lock_duration):
        unlock_time = (rpc.time() + st_lock_duration * WEEK) // WEEK * WEEK

        if st_value == 0:
            with brownie.reverts("dev: need non-zero value"):
                self.voting_escrow.create_lock(st_value, unlock_time, {'from': st_account})

        elif self.voting_balances[st_account]['value'] > 0:
            with brownie.reverts("Withdraw old tokens first"):
                self.voting_escrow.create_lock(st_value, unlock_time, {'from': st_account})

        elif unlock_time <= rpc.time():
            with brownie.reverts("Can only lock until time in the future"):
                self.voting_escrow.create_lock(st_value, unlock_time, {'from': st_account})

        elif unlock_time > rpc.time() + 86400 * 365 * 4:
            with brownie.reverts("Voting lock can be 4 years max"):
                self.voting_escrow.create_lock(st_value, unlock_time, {'from': st_account})

        else:
            tx = self.voting_escrow.create_lock(st_value, unlock_time, {'from': st_account})
            self.voting_balances[st_account] = {
                    'value': st_value,
                    'unlock_time': tx.events['Deposit']['locktime']
            }
コード例 #2
0
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()
コード例 #3
0
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)
コード例 #4
0
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]
コード例 #5
0
    def rule_increase_amount(self, st_account, st_value):
        if st_value == 0:
            with brownie.reverts("dev: need non-zero value"):
                self.voting_escrow.increase_amount(st_value, {
                    'from': st_account,
                    'gas': GAS_LIMIT
                })

        elif self.voting_balances[st_account]['value'] == 0:
            with brownie.reverts("No existing lock found"):
                self.voting_escrow.increase_amount(st_value, {
                    'from': st_account,
                    'gas': GAS_LIMIT
                })

        elif self.voting_balances[st_account]['unlock_time'] <= rpc.time():
            with brownie.reverts("Cannot add to expired lock. Withdraw"):
                self.voting_escrow.increase_amount(st_value, {
                    'from': st_account,
                    'gas': GAS_LIMIT
                })

        else:
            self.voting_escrow.increase_amount(st_value, {
                'from': st_account,
                'gas': GAS_LIMIT
            })
            self.voting_balances[st_account]['value'] += st_value
コード例 #6
0
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]})
コード例 #7
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_cancel_upgrade_without_enough_original_reserve(
        goldx, new_paxg, paxg, rpc, accounts):
    print(
        f'---------------- start to cancel upgrade without enough origianl reserve----------------\n'
    )
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})
    goldx.mint(accounts[1], 100.001e18, {'from': accounts[1]})

    print(f'previous unit is: {goldx.unit()}')

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)

    rpc_delay(rpc, interval + 1)

    goldx.removeReserve()

    should_add_new_reserve_amount = goldx.getOutstanding(
        new_paxg.address, upgradeUint)

    new_paxg.transfer(
        goldx.address,
        (should_add_new_reserve_amount + 10**new_paxg.decimals()))

    with brownie.reverts('cancelUpgrade: Add more current anchored asset!'):
        goldx.cancelUpgrade()
コード例 #8
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_cancel_upgrade_without_enough_new_reserve(goldx, new_paxg, paxg, rpc,
                                                   accounts):
    print(
        f'---------------- start to cancel upgrade without enough new reserve ----------------\n'
    )
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})
    goldx.mint(accounts[1], 100e18, {'from': accounts[1]})
    goldx.burn(accounts[1], 50e18, {'from': accounts[1]})

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)

    rpc_delay(rpc, interval + 1)

    goldx.removeReserve()

    with brownie.reverts('cancelUpgrade: Add more current anchored asset!'):
        goldx.cancelUpgrade()

    print(
        f'---------------- end to cancel upgrade without enough new reserve ----------------\n'
    )
コード例 #9
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_confirm_upgrade_when_do_not_reach_time(goldx, new_paxg, paxg, rpc,
                                                accounts):
    print(
        f'---------------- start to confirm upgrade but does not reach time ----------------\n'
    )
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})
    goldx.mint(accounts[1], 100e18, {'from': accounts[1]})
    goldx.burn(accounts[1], 50e18, {'from': accounts[1]})

    with brownie.reverts('confirmUpgrade:  Too early to confirm upgrading!'):
        goldx.confirmUpgrade()

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)
    with brownie.reverts('confirmUpgrade:  Too early to confirm upgrading!'):
        goldx.confirmUpgrade()
    print(f'owner is going to confirm upgrade but does not reach time')
    print(
        f'---------------- end to confirm upgrade but does not reach time ----------------\n'
    )
コード例 #10
0
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),)
コード例 #11
0
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
コード例 #12
0
    def rule_increase_unlock_time(self, st_account, st_lock_duration):
        unlock_time = (rpc.time() + st_lock_duration * WEEK) // WEEK * WEEK

        if self.voting_balances[st_account]['unlock_time'] <= rpc.time():
            with brownie.reverts("Lock expired"):
                self.voting_escrow.increase_unlock_time(
                    unlock_time, {
                        'from': st_account,
                        'gas': GAS_LIMIT
                    })

        elif self.voting_balances[st_account]['value'] == 0:
            with brownie.reverts("Nothing is locked"):
                self.voting_escrow.increase_unlock_time(
                    unlock_time, {
                        'from': st_account,
                        'gas': GAS_LIMIT
                    })

        elif unlock_time <= self.voting_balances[st_account]['unlock_time']:
            with brownie.reverts("Can only increase lock duration"):
                self.voting_escrow.increase_unlock_time(
                    unlock_time, {
                        'from': st_account,
                        'gas': GAS_LIMIT
                    })

        elif unlock_time > rpc.time() + 86400 * 365 * 4:
            with brownie.reverts("Voting lock can be 4 years max"):
                self.voting_escrow.increase_unlock_time(
                    unlock_time, {
                        'from': st_account,
                        'gas': GAS_LIMIT
                    })

        else:
            tx = self.voting_escrow.increase_unlock_time(
                unlock_time, {
                    'from': st_account,
                    'gas': GAS_LIMIT
                })
            self.voting_balances[st_account]['unlock_time'] = tx.events[
                'Deposit']['locktime']
コード例 #13
0
ファイル: conftest.py プロジェクト: cleancoindev/DutchSwap
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
コード例 #14
0
    def rule_withdraw(self, st_account):
        """
        Withdraw tokens from the voting escrow.
        """
        if self.voting_balances[st_account]['unlock_time'] > rpc.time():
            # fail path - before unlock time
            with brownie.reverts("The lock didn't expire"):
                self.voting_escrow.withdraw({'from': st_account})

        else:
            # success path - specific amount
            self.voting_escrow.withdraw({'from': st_account})
            self.voting_balances[st_account]['value'] = 0
コード例 #15
0
ファイル: test_random.py プロジェクト: joyalpha/goldX
def replace_underlying(goldx, new_paxg, paxg, rpc, accounts):
    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)

    rpc_delay(rpc, interval + 1)

    goldx.removeReserve()

    should_add_new_reserve_amount = goldx.getOutstanding(
        new_paxg.address, upgradeUint)

    new_paxg.transfer(
        goldx.address,
        (should_add_new_reserve_amount + 10**new_paxg.decimals()))

    goldx.confirmUpgrade()
コード例 #16
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_cancel_upgrade_when_upgrade_protocol(goldx, new_paxg, paxg, rpc,
                                              accounts):
    print(
        f'---------------- start to cancel upgrade when upgradeprotocol ----------------\n'
    )
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})
    goldx.mint(accounts[1], 100e18, {'from': accounts[1]})
    goldx.burn(accounts[1], 50e18, {'from': accounts[1]})

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)

    goldx.cancelUpgrade()

    print(
        f'---------------- end to cancel upgrade when upgradeprotocol ----------------\n'
    )
コード例 #17
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_upgrade_protocol_with_upgrade_token_is_zero_address(
        goldx, new_paxg, paxg, rpc, accounts):
    print(
        f'---------------- start to upgrade protocol with tokne is zero address ----------------\n'
    )
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})
    goldx.mint(accounts[1], 100e18, {'from': accounts[1]})
    goldx.burn(accounts[1], 50e18, {'from': accounts[1]})

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = zero_address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    print(f'owner is going to upgrade with tokne is zero address')
    with brownie.reverts(
            'upgradeProtocol: New anchored asset should not be zero address!'):
        goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                              upgradeMinMintAmount, upgradeMinBurnAmount)
    print(
        f'---------------- end to upgrade protocol with tokne is zero address ----------------\n'
    )
コード例 #18
0
def frames_crowdsale(DreamFramesCrowdsale, frame_token, price_feed,
                     bonus_list):
    wallet = accounts[9]
    startDate = rpc.time()
    endDate = startDate + 50000
    minFrames = 1
    maxFrames = 1000000
    producerFrames = 25000
    frameUsd = '100 ether'
    bonusOffList = 30
    bonusOnList = 40
    hardCapUsd = '3000000 ether'
    softCapUsd = '1500000 ether'
    frames_crowdsale = DreamFramesCrowdsale.deploy({"from": accounts[0]})
    frames_crowdsale.init(frame_token, price_feed, wallet, startDate, endDate,
                          minFrames, maxFrames, producerFrames, frameUsd,
                          bonusOffList, bonusOnList, hardCapUsd, softCapUsd,
                          {"from": accounts[0]})
    tx = frames_crowdsale.addOperator(accounts[1], {"from": accounts[0]})
    assert 'OperatorAdded' in tx.events
    tx = frame_token.setMinter(frames_crowdsale, {"from": accounts[0]})
    tx = frames_crowdsale.setBonusList(bonus_list, {"from": accounts[0]})

    return frames_crowdsale
コード例 #19
0
ファイル: conftest.py プロジェクト: zerolawtech/ZAP-Tech
def cptime():
    yield rpc.time() + 100
コード例 #20
0
def test_set_checkpoint_time(cp, share):
    """set a checkpoint - time already passed"""
    with pytest.reverts("dev: time"):
        cp.newCheckpoint(share, rpc.time() - 100, {"from": accounts[0]})
    with pytest.reverts("dev: time"):
        cp.newCheckpoint(share, rpc.time(), {"from": accounts[0]})
コード例 #21
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_upgrade_protocol(goldx, new_paxg, paxg, rpc, accounts):
    print(f'---------------- start to upgrade protocol ----------------\n')
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})

    check_diff(goldx, paxg, 'mint', 100.078e18, accounts[0], accounts[1])
    check_diff(goldx, paxg, 'burn', 50.56909e18, accounts[0], accounts[1])
    check_diff(goldx, new_paxg, 'transfer', 32.098e18, accounts[0],
               accounts[1], 0, accounts[2])

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e18
    upgradeMinBurnAmount = 0.001e18

    print(f'owner is going to set upgrading config for contract')
    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)

    rpc_delay(rpc, interval + 1)

    before_remove_goldx_amount = goldx.totalSupply()

    before_remove_owner_balance = paxg.balanceOf(accounts[0])

    before_remove_contract_reserve = paxg.balanceOf(goldx.address)

    transfer_paxg_fee = paxg.getFeeFor(before_remove_contract_reserve)

    print(f'owner is going to remove reserve of the contract\n')
    goldx.removeReserve()
    after_remove_owner_balance = paxg.balanceOf(accounts[0])

    after_remove_contract_reserve = paxg.balanceOf(goldx.address)

    assert after_remove_contract_reserve == 0
    # actually paxg and goldx should be the different owner, that is the owner should not get paxg transfering fee,
    # so it should be:
    assert after_remove_owner_balance == before_remove_owner_balance + before_remove_contract_reserve

    should_add_new_reserve_amount = goldx.getOutstanding(
        new_paxg.address, upgradeUint)

    decimal_diff = goldx.decimals() - new_paxg.decimals()

    expected_add_new_reserve_amount = div(
        rdiv(before_remove_goldx_amount, upgradeUint), 10**decimal_diff)

    print(
        f'expected contract adds new reserve amount is: {expected_add_new_reserve_amount}\n'
    )
    assert expected_add_new_reserve_amount == should_add_new_reserve_amount

    print(f'owner is going to add new reserve')
    new_paxg.transfer(
        goldx.address,
        (should_add_new_reserve_amount + 10**new_paxg.decimals()))

    print(f'owner is going to confirm upgrade')
    goldx.confirmUpgrade()

    new_paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})

    mint_amount = 100.123e18
    check_diff(goldx, new_paxg, 'mint', mint_amount, accounts[0], accounts[1],
               upgradeUint)

    burn_amount = 10.0098e18
    check_diff(goldx, new_paxg, 'burn', burn_amount, accounts[0], accounts[1],
               upgradeUint)

    transfer_amount = 10.459e18
    check_diff(goldx, new_paxg, 'transfer', transfer_amount, accounts[0],
               accounts[1], upgradeUint, accounts[2])

    goldx.approve(accounts[2], 100e18, {'from': accounts[1]})
    goldx.transferFrom(accounts[1], accounts[2], 10e18, {'from': accounts[2]})

    print(f'---------------- end to upgrade protocol ----------------\n')
コード例 #22
0
ファイル: test_upgrade.py プロジェクト: joyalpha/goldX
def test_upgrade_protocol_without_lower_decimal_reserve(
        goldx, new_paxg_6, paxg, rpc, accounts):
    print(
        f'---------------- start to upgrade protocol with lower decimal reserve ----------------\n'
    )
    paxg.approve(goldx.address, max_allowance, {'from': accounts[1]})
    goldx.mint(accounts[1], 100.001e18, {'from': accounts[1]})

    interval = 60
    upgradeTime = rpc.time() + interval
    upgradeToken = new_paxg_6.address
    upgradeUint = 1.05e18
    upgradeMinMintAmount = 0.001e6
    upgradeMinBurnAmount = 0.001e6

    goldx.upgradeProtocol(upgradeTime, upgradeToken, upgradeUint,
                          upgradeMinMintAmount, upgradeMinBurnAmount)
    rpc_delay(rpc, interval + 1)
    goldx.removeReserve()
    should_add_new_reserve_amount = goldx.getOutstanding(
        new_paxg_6.address, upgradeUint)
    new_paxg_6.transfer(
        goldx.address,
        (should_add_new_reserve_amount + 10**new_paxg_6.decimals()))
    goldx.confirmUpgrade()

    new_paxg_6.approve(goldx.address, max_allowance, {'from': accounts[1]})

    mint_amount = 100.123e6
    check_diff(goldx,
               new_paxg_6,
               'mint',
               mint_amount,
               accounts[0],
               accounts[1],
               upgradeUint,
               without_paxg_fee=1e18)

    burn_amount = 10.0098e6
    check_diff(goldx,
               new_paxg_6,
               'burn',
               burn_amount,
               accounts[0],
               accounts[1],
               upgradeUint,
               without_paxg_fee=1e18)

    transfer_amount = 10.459e6
    check_diff(goldx,
               new_paxg_6,
               'transfer',
               transfer_amount,
               accounts[0],
               accounts[1],
               upgradeUint,
               accounts[2],
               without_paxg_fee=1e18)

    goldx.approve(accounts[2], 100e6, {'from': accounts[1]})
    goldx.transferFrom(accounts[1], accounts[2], 10.59493e6,
                       {'from': accounts[2]})
コード例 #23
0
ファイル: conftest.py プロジェクト: zerolawtech/ZAP-Tech
def _sleep(months):
    now = int(rpc.time() // 2592000 + 1) * 2592000
    rpc.sleep(now - rpc.time() + 1 + 2592000 * (months - 1))
    rpc.mine()
コード例 #24
0
def test_frames_crowdsale_setStartDate(frames_crowdsale):
    tx = frames_crowdsale.setStartDate(rpc.time()+100, {'from': accounts[0]})
    assert 'StartDateUpdated' in tx.events
    with reverts("dev: Not owner"):
        frames_crowdsale.setStartDate(rpc.time()+100, {'from': accounts[3]})
コード例 #25
0
def _months(months):
    return int(rpc.time() // 2592000 + 1) * 2592000 + months * 2592000