def test_add_base_pool_already_exists(factory, base_pool, alice, fee_receiver, implementation_usd): with brownie.reverts("dev: pool exists"): factory.add_base_pool(base_pool, fee_receiver, 0, [implementation_usd] + [ZERO_ADDRESS] * 9, {"from": alice})
def test_below_min_amount(alice, swap, initial_amounts, n_coins, idx): min_amount = initial_amounts.copy() min_amount[idx] += 1 with brownie.reverts(): swap.remove_liquidity(n_coins * 10**24, min_amount, {'from': alice})
def test_incorrect_gauge_multiple(LiquidityGaugeMock, alice, registry, gauge_controller, liquidity_gauge, swap): gauge = LiquidityGaugeMock.deploy(swap, {"from": alice}) gauges = [liquidity_gauge, gauge] + [ZERO_ADDRESS] * 8 with brownie.reverts("dev: wrong token"): registry.set_liquidity_gauges(swap, gauges, {"from": alice})
def test_user_checkpoint_wrong_account(accounts, gauge): with brownie.reverts("dev: unauthorized"): gauge.user_checkpoint(accounts[2], {"from": accounts[1]})
def test_experimental_deployments(gov, rando, registry, Vault, create_token, create_vault): v1_vault = create_vault(version="1.0.0") registry.newRelease(v1_vault, {"from": gov}) # Anyone can make an experiment token = create_token() registry.newExperimentalVault(token, rando, rando, rando, "", "", {"from": rando}) # You can make as many experiments as you want with same api version experimental_vault = Vault.at( registry.newExperimentalVault(token, rando, rando, rando, "", "", { "from": rando }).return_value) # Experimental Vaults do not count towards deployments with brownie.reverts(): registry.latestVault(token) # You can't endorse a vault if governance isn't set properly with brownie.reverts(): registry.endorseVault(experimental_vault, {"from": gov}) experimental_vault.setGovernance(gov, {"from": rando}) experimental_vault.acceptGovernance({"from": gov}) # You can only endorse a vault if it creates an new deployment registry.endorseVault(experimental_vault, {"from": gov}) assert registry.latestVault(token) == experimental_vault # You can't endorse a vault if it would overwrite a current deployment experimental_vault = Vault.at( registry.newExperimentalVault(token, gov, gov, gov, "", "", { "from": rando }).return_value) with brownie.reverts(): registry.endorseVault(experimental_vault, {"from": gov}) # You can only endorse a vault if it creates a new deployment v2_vault = create_vault(version="2.0.0") registry.newRelease(v2_vault, {"from": gov}) experimental_vault = Vault.at( registry.newExperimentalVault(token, gov, gov, gov, "", "", { "from": rando }).return_value) registry.endorseVault(experimental_vault, {"from": gov}) assert registry.latestVault(token) == experimental_vault # Can create an experiment and endorse it targeting a previous version token = create_token() experimental_vault = Vault.at( registry.newExperimentalVault(token, gov, gov, gov, "", "", 1, { "from": rando }).return_value) registry.endorseVault(experimental_vault, 1, {"from": gov}) assert registry.latestVault(token) == experimental_vault # Only governance can endorse a Vault vault = create_vault() with brownie.reverts(): registry.endorseVault(vault, {"from": rando})
def test_withdrawal_without_any_deposit(fund_through_proxy, accounts): with brownie.reverts("Fund has no shares"): fund_through_proxy.withdraw(50, {'from': accounts[1]})
def test_double_initialize(TestStrategy, vault, other_vault, gov): strategy = gov.deploy(TestStrategy, vault) # Sholdn't be able to initialize twice with brownie.reverts(): strategy.initialize(other_vault, gov, gov, gov)
def test_crowdsale_withdraw_tokens_wrong_beneficiary(crowdsale, buy_tokens): beneficiary = accounts[2] token_buyer = accounts[1] with reverts(): crowdsale.withdrawTokens(beneficiary, {"from": token_buyer})
def test_crowdsale_buyTokensExtra(crowdsale): token_buyer = accounts[2] eth_to_transfer = crowdsale.goal() + 1 with reverts(): crowdsale.buyTokensEth(token_buyer, {"value": eth_to_transfer})
def test_apply_admin_only(voting_escrow, accounts): with brownie.reverts("dev: admin only"): voting_escrow.apply_transfer_ownership({'from': accounts[1]})
def test_crowdsale_withdraw_tokens_has_not_closed(crowdsale, buy_tokens): beneficiary = accounts[1] token_buyer = accounts[1] with reverts(): crowdsale.withdrawTokens(beneficiary, {"from": token_buyer})
def test_apply_without_commit(voting_escrow, accounts): with brownie.reverts("dev: admin not set"): voting_escrow.apply_transfer_ownership({'from': accounts[0]})
def test_get_underlying_balances(factory, swap, is_rebase_pool): with brownie.reverts("dev: pool is not a metapool"): factory.get_underlying_balances(swap) return
def test_add_existing_metapools_unknown_pool(swap, new_factory): with brownie.reverts("dev: pool not in old factory"): new_factory.add_existing_metapools([swap] + [ZERO_ADDRESS] * 9)
def test_apply_admin_only(ve_token, accounts): with brownie.reverts(): ve_token.apply_transfer_ownership({"from": accounts[1]})
def test_admin_only(registry_swap, bob, lp_token): with brownie.reverts("dev: admin-only function"): registry_swap.claim_balance(lp_token, {'from': bob})
def test_withdrawal_without_enough_shares(fund_through_proxy, accounts, token): token.mint(accounts[1], 100, {'from': accounts[0]}) token.approve(fund_through_proxy, 50, {'from': accounts[1]}) fund_through_proxy.deposit(50, {'from': accounts[1]}) with brownie.reverts('ERC20: burn amount exceeds balance'): fund_through_proxy.withdraw(100, {'from': accounts[1]})
def test_deposit_insufficient_balance(accounts, unit_gauge): with brownie.reverts(): unit_gauge.deposit(100000, {"from": accounts[1]})
def test_reject_ether(gov, vault): # These functions should reject any calls with value for func, args in [ ("setGovernance", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("setManagement", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("acceptGovernance", []), ("setRewards", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("setGuardian", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("setPerformanceFee", [0]), ("setManagementFee", [0]), ("setEmergencyShutdown", [True]), ("approve", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1]), ("transfer", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1]), ( "transferFrom", [ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1, ], ), ("deposit", []), ("withdraw", []), ("deposit", [1]), ("withdraw", [1]), ("deposit", [1, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("withdraw", [1, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("addStrategy", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1, 1, 1]), ("addStrategyToQueue", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("removeStrategyFromQueue", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("updateStrategyDebtRatio", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1]), ("updateStrategyRateLimit", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1]), ( "updateStrategyPerformanceFee", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1], ), ( "migrateStrategy", [ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", ], ), ("revokeStrategy", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("report", [1, 2, 3]), ("sweep", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]), ("sweep", ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 1]), ]: with brownie.reverts("Cannot send ether to nonpayable function"): # NOTE: gov can do anything getattr(vault, func)(*args, {"from": gov, "value": 1}) # Fallback fails too with brownie.reverts("Cannot send ether to nonpayable function"): gov.transfer(vault, 1) # NOTE: Just for coverage with brownie.reverts(): gov.transfer(vault, 0)
def test_deposit_with_zero_funds(vault, token, rando): assert token.balanceOf(rando) == 0 token.approve(vault, 2**256 - 1, {"from": rando}) with brownie.reverts(): vault.deposit({"from": rando})
def test_erc1400_transfer_not_enough_funds(erc1400_token): with reverts('ERC777: transfer amount exceeds balance'): erc1400_token.transfer(accounts[1], '1001 ether', {'from': accounts[0]})
def test_deposit_with_wrong_amount(vault, token, gov): balance = token.balanceOf(gov) + 1 token.approve(vault, balance, {"from": gov}) with brownie.reverts(): vault.deposit(balance, {"from": gov})
def test_only_admin_can_claim(staked_3pool, dai, accounts): with brownie.reverts("dev: Only Owner"): staked_3pool.claim_erc20(dai, {'from': accounts[1]})
def test_launcher_add_template_not_operator(launcher, pool_liquidity_template): with reverts(): launcher.addLiquidityLauncherTemplate(pool_liquidity_template, {"from": accounts[5]})
def test_amount_exceeds_balance(alice, swap, plain_pool_size): with brownie.reverts(): swap.remove_liquidity( swap.balanceOf(alice) + 1, [0] * plain_pool_size, {"from": alice})
def test_apply_without_commit(ve_token, accounts): with brownie.reverts(): ve_token.apply_transfer_ownership({"from": accounts[0]})
def test_amount_exceeds_balance(alice, swap, n_coins): with brownie.reverts(): swap.remove_liquidity(n_coins * 10**24 + 1, [0] * n_coins, {'from': alice})
def test_commit_admin_only(ve_token, accounts): with brownie.reverts(): ve_token.commit_transfer_ownership(accounts[1], {"from": accounts[1]})
def test_deadline_reverts(lgt, accounts): with brownie.reverts('dev: deadline passed'): lgt.addLiquidity(1, 1, 1, {'from': accounts[1], 'value': "0.008 ether"})
def test_get_coin_indices_reverts(factory, swap, base_lp_token, underlying_coins, idx): with brownie.reverts(): factory.get_coin_indices(swap, base_lp_token, underlying_coins[idx])