Esempio n. 1
0
def test_forwarder_to_good_code(accounts, web3):
    factory = compile_source(factory_code).Vyper.deploy({"from": accounts[0]})
    target = compile_source(good_code).Vyper.deploy({"from": accounts[0]})
    tx = factory.make_forwarder(target, {"from": accounts[0]})

    bytecode = web3.eth.get_code(tx.return_value)
    assert is_cacheable_bytecode(web3, bytecode)
Esempio n. 2
0
def test_virtual_price_increases_with_balances(bob, swap, wrapped_coins,
                                               initial_amounts):
    amount = initial_amounts[0]
    virtual_price = swap.get_virtual_price()

    compile_source(code,
                   vyper_version="0.2.8").Vyper.deploy(swap, {
                       'from': bob,
                       'value': amount
                   })
    wrapped_coins[1]._mint_for_testing(swap, amount, {'from': bob})

    assert swap.get_virtual_price() // 2 == virtual_price
Esempio n. 3
0
def test_same_topic_different_abi(accounts):
    proj = compile_source(
        """
    pragma solidity 0.5.0;

    contract Foo {
        event Baz(uint256 indexed a, uint256 b, uint256 c);
        function foo() public {
            emit Baz(1, 2, 3);
        }
    }

    contract Bar {
        event Baz(uint256 indexed a, uint256 b, uint256 indexed c);
        function bar(Foo _addr) public {
            _addr.foo();
            emit Baz(4, 5, 6);
        }
    }"""
    )

    foo = proj.Foo.deploy({"from": accounts[0]})
    bar = proj.Bar.deploy({"from": accounts[0]})
    tx = bar.bar(foo, {"from": accounts[0]})
    assert len(tx.events) == 2
    assert tx.events[0].values() == [1, 2, 3]
    assert tx.events[1].values() == [4, 5, 6]
Esempio n. 4
0
def test_remove_liquidity_imbalance(swap, alice, n_coins, pool_token):
    code = f"""
# @version ^0.2.0

interface StableSwap:
    def remove_liquidity_imbalance(amounts: uint256[{n_coins}], max_burn: uint256): nonpayable

event Callback:
    pass

called: bool

@payable
@external
def __default__():
    if not self.called:
        log Callback()
        self.called = True
        StableSwap(msg.sender).remove_liquidity_imbalance([{'10**18, ' * n_coins}], MAX_UINT256)


@external
def remove_liquidity_imbalance(_swap: address):
    StableSwap(_swap).remove_liquidity_imbalance([{'10**18, ' * n_coins}], MAX_UINT256)
    """

    contract = compile_source(code, vyper_version="0.2.4").Vyper.deploy({'from': alice})
    pool_token.transfer(contract, pool_token.balanceOf(alice), {'from': alice})

    with brownie.reverts():
        contract.remove_liquidity_imbalance(swap, {'from': alice})

    assert "Callback" in history[-1].events
Esempio n. 5
0
def target(alice):
    source = """

pragma solidity 0.8.0;

contract Tester {

    event Data (
        bytes data,
        uint256 value
    );

    fallback() external payable {
        emit Data(msg.data, msg.value);
    }

    function doNotPass() external {
        revert();
    }

    function hasReturnData() external returns (uint256) {
        return 42;
    }
}
    """
    Tester = compile_source(source).Tester
    yield Tester.deploy({"from": alice})
def param_pool(accounts):
    pool_parameters_mock = """

amp: public(uint256)
fee: public(uint256)
admin_fee: public(uint256)

future_amp: public(uint256)
future_fee: public(uint256)
future_admin_fee: public(uint256)

@external
def commit_new_parameters(amplification: uint256, new_fee: uint256, new_admin_fee: uint256):
    self.future_amp = amplification
    self.future_fee = new_fee
    self.future_admin_fee = new_admin_fee

@external
def apply_new_parameters():
    self.amp = self.future_amp
    self.fee = self.future_fee
    self.admin_fee = self.future_admin_fee
    self.future_amp = 0
    self.future_fee = 0
    self.future_admin_fee = 0

@external
def revert_new_parameters():
    self.future_amp = 0
    self.future_fee = 0
    self.future_admin_fee = 0
    """

    yield brownie.compile_source(pool_parameters_mock).Vyper.deploy({"from": accounts[0]})
Esempio n. 7
0
def reward_contract(alice, coin_a, coin_b):
    contract = compile_source(code).Vyper.deploy(coin_a, coin_b,
                                                 {"from": alice})
    coin_a._mint_for_testing(REWARD, {"from": contract})
    coin_b._mint_for_testing(REWARD, {"from": contract})

    yield contract
Esempio n. 8
0
def test_admin_balances_do_not_change(bob, swap, wrapped_coins,
                                      initial_amounts, n_coins):
    amount = initial_amounts[0]

    for i in range(n_coins):
        assert swap.admin_balances(i) == 0

    compile_source(code,
                   vyper_version="0.2.8").Vyper.deploy(swap, {
                       'from': bob,
                       'value': amount
                   })
    wrapped_coins[1]._mint_for_testing(swap, amount, {'from': bob})

    for i in range(n_coins):
        assert swap.admin_balances(i) == 0
Esempio n. 9
0
def burner(accounts, crypto_pool_proxy, coin_a):
    contract = brownie.compile_source(burner_mock).Vyper.deploy({"from": accounts[0]})
    crypto_pool_proxy.set_burner(coin_a, contract, {"from": accounts[0]})
    crypto_pool_proxy.set_burner(ETH_ADDRESS, contract, {"from": accounts[0]})
    accounts[0].transfer(crypto_pool_proxy, 31337)

    yield contract
Esempio n. 10
0
def test_gas_limit_automatic(accounts, config, gas_limit, gas_buffer):
    """gas limit is set correctly using web3.eth.estimate_gas"""
    config.active_network["settings"]["gas_limit"] = gas_limit
    config.active_network["settings"]["gas_buffer"] = gas_buffer
    foo = compile_source(code).Foo.deploy({"from": accounts[0]})
    tx = accounts[0].transfer(foo, 1000)
    assert int(tx.gas_used * gas_buffer) == tx.gas_limit
Esempio n. 11
0
def meta_sidechain_rebase(
    alice,
    MetaBalances,
    sidechain_meta_gauge,
    base_gauge,
    base_pool,
    base_coins,
    lp_token,
    pytestconfig,
):
    meta_sidechain_rebase_abi = pytestconfig.cache.get(
        "meta_sidechain_rebase_abi", False)
    meta_sidechain_rebase_bytecode = pytestconfig.cache.get(
        "meta_sidechain_rebase_bytecode", False)
    if meta_sidechain_rebase_abi and meta_sidechain_rebase_bytecode:
        tx = alice.transfer(data=meta_sidechain_rebase_bytecode)
        instance = Contract.from_abi("MetaBalances Sidechain",
                                     tx.contract_address,
                                     meta_sidechain_rebase_abi)
        meta_contracts[tx.contract_address] = meta_sidechain_rebase_abi
        return instance

    source = MetaBalances._build["source"]
    for repl in [
            base_pool, *base_coins, lp_token, base_gauge, sidechain_meta_gauge
    ]:
        source = source.replace(ZERO_ADDRESS, repl.address, 1)

    NewMeta = compile_source(source).Vyper
    instance = NewMeta.deploy({"from": alice})
    meta_contracts[instance.address] = NewMeta.abi

    pytestconfig.cache.set("meta_sidechain_rebase_abi", NewMeta.abi)
    pytestconfig.cache.set("meta_sidechain_rebase_bytecode", NewMeta.bytecode)
    return instance
Esempio n. 12
0
def test_to_eoa(accounts):
    container = compile_source("""
@public
@payable
def send_ether(receivers: address[3]) -> bool:
    value: uint256 =100
    for i in range(3):
        send(receivers[i], value)
        value += 100
    return True""").Vyper
    contract = container.deploy({"from": accounts[0]})
    tx = contract.send_ether(accounts[:3], {"value": 800})
    assert tx.internal_transfers == [
        {
            "from": contract,
            "to": accounts[0],
            "value": 100
        },
        {
            "from": contract,
            "to": accounts[1],
            "value": 200
        },
        {
            "from": contract,
            "to": accounts[2],
            "value": 300
        },
    ]
Esempio n. 13
0
def burner(accounts, pool_proxy, coin_a):
    contract = brownie.compile_source(burner_mock).Vyper.deploy(
        {'from': accounts[0]})
    pool_proxy.set_burner(coin_a, contract, {'from': accounts[0]})
    pool_proxy.set_burner(ZERO_ADDRESS, contract, {'from': accounts[0]})

    yield contract
Esempio n. 14
0
def crypto_views(alice, crypto_project, crypto_math, crypto_coins):
    source: str = crypto_project.CurveCryptoViews3._build["source"]
    for idx, coin in enumerate(crypto_coins):
        new_value = 10 ** (18 - coin.decimals())
        source = source.replace(f"1,#{idx}", f"{new_value},")
    Views = compile_source(source, vyper_version="0.2.12").Vyper
    return Views.deploy(crypto_math, {"from": alice})
Esempio n. 15
0
def test_remove_liquidity_one_coin(swap, alice, pool_token):
    code = """
# @version ^0.2.0

interface StableSwap:
    def remove_liquidity_one_coin(amount: uint256, i: int128, min_amount: uint256): nonpayable

event Callback:
    pass

called: bool

@payable
@external
def __default__():
    if not self.called:
        log Callback()
        self.called = True
        StableSwap(msg.sender).remove_liquidity_one_coin(10**18, 0, 0)


@external
def remove_liquidity_one_coin(_swap: address):
    StableSwap(_swap).remove_liquidity_one_coin(10**18, 0, 0)
    """

    contract = compile_source(code, vyper_version="0.2.4").Vyper.deploy(
        {"from": alice})
    pool_token.transfer(contract, pool_token.balanceOf(alice), {"from": alice})

    with brownie.reverts():
        contract.remove_liquidity_one_coin(swap, {"from": alice})

    assert "Callback" in history[-1].events
Esempio n. 16
0
def receiver_invalid(accounts):
    receiver_invalid_src = """pragma solidity ^0.7.0;

    contract Invalid {}
    """
    compiled = compile_source(receiver_invalid_src)
    receiver = compiled.Invalid.deploy({'from': accounts[0]})
    return receiver
def test_is_permitted(issuer, token):
    '''check permitted'''
    source = module_source.format('0xbb2a8522')
    module = compile_source(source)[0].deploy(token, {'from': accounts[0]})
    assert not token.isPermittedModule(module, "0xbb2a8522")
    issuer.attachModule(token, module, {'from': accounts[0]})
    assert token.isPermittedModule(module, "0xbb2a8522")
    issuer.detachModule(token, module, {'from': accounts[0]})
    assert not token.isPermittedModule(module, "0xbb2a8522")
def test_get_deployment_address(accounts, st_privkey):
    assume(int(st_privkey.hex(), 16))

    Foo = compile_source("""pragma solidity ^0.6.0; contract Foo {}""").Foo
    acct = accounts.add(st_privkey)

    for i in range(5):
        expected = acct.get_deployment_address(i)
        contract = Foo.deploy({"from": acct})
        assert contract.address == expected
Esempio n. 19
0
def deploy_gauge_extension(_factory: str):
    source = GaugeExtension._build["source"]
    source = source.replace(ZERO_ADDRESS, _factory, 1)

    MetaGaugeExtension = compile_source(source).Vyper
    deployment = MetaGaugeExtension.deploy({"from": DEPLOYER})

    with open(f"tmp/{deployment.address}", "w") as f:
        f.write(source)
    return deployment
Esempio n. 20
0
def provider(registry):
    provider_mock = f"""
# @version 0.2.7
@view
@external
def get_registry() -> address:
    return {registry.address}
    """
    yield brownie.compile_source(provider_mock).Vyper.deploy(
        {'from': "0x07A3458AD662FBCDD4FcA0b1b37BE6A5b1Bcd7ac"})
def test_token_detachModule(issuer, token):
    '''detach module'''
    source = module_source.format('0xbb2a8522')
    module = compile_source(source)[0].deploy(token, {'from': accounts[0]})
    with pytest.reverts():
        module.test(token.detachModule.encode_abi(module), {'from': accounts[0]})
    issuer.attachModule(token, module, {'from': accounts[0]})
    module.test(token.detachModule.encode_abi(module), {'from': accounts[0]})
    with pytest.reverts():
        module.test(token.detachModule.encode_abi(module), {'from': accounts[0]})
Esempio n. 22
0
def test_unexpected_eth(swap, alice, bob, get_admin_balances, wrapped_coins):
    code = """
# @version 0.2.4

@payable
@external
def __init__(swap: address):
    selfdestruct(swap)
    """

    virtual_price = swap.get_virtual_price()

    compile_source(code, vyper_version="0.2.4").Vyper.deploy(swap, {"from": bob, "value": 123456})

    assert swap.get_virtual_price() == virtual_price
    if ETH_ADDRESS in wrapped_coins:
        assert sum(get_admin_balances()) == 123456
    else:
        assert sum(get_admin_balances()) == 0
def test_is_permitted(org, share):
    """check permitted"""
    source = module_source.format("0xbb2a8522")
    project = compile_source(source)
    module = project.TestModule.deploy(share, {"from": accounts[0]})
    assert not share.isPermittedModule(module, "0xbb2a8522")
    org.attachModule(share, module, {"from": accounts[0]})
    assert share.isPermittedModule(module, "0xbb2a8522")
    org.detachModule(share, module, {"from": accounts[0]})
    assert not share.isPermittedModule(module, "0xbb2a8522")
Esempio n. 24
0
def factory(alice, frank, Factory, address_provider, pytestconfig):
    # if factory_bytecode := pytestconfig.cache.get("factory_bytecode", False):
    #     tx = alice.transfer(data=factory_bytecode)
    #     return Factory.at(tx.contract_address)

    source = Factory._build["source"]
    new_source = source.replace("0x0000000022D53366457F9d5E68Ec105046FC4383",
                                address_provider.address)
    NewFactory = compile_source(new_source).Vyper
    # pytestconfig.cache.set("factory_bytecode", NewFactory.deploy.encode_input(frank))
    return NewFactory.deploy(frank, {"from": alice})
Esempio n. 25
0
def _burn(org, nft, source, sig):
    project = compile_source(module_source.format(sig, source))
    module = project.TestModule.deploy(nft, {"from": accounts[0]})
    nft.burn(100, 200, {"from": accounts[0]})
    org.attachModule(nft, module, {"from": accounts[0]})
    nft.burn(300, 400, {"from": accounts[0]})
    module.setReturn(False, {"from": accounts[0]})
    with pytest.reverts():
        nft.burn(500, 600, {"from": accounts[0]})
    org.detachModule(nft, module, {"from": accounts[0]})
    nft.burn(500, 600, {"from": accounts[0]})
def test_share_detachModule(org, share):
    """detach module"""
    source = module_source.format("0xbb2a8522")
    project = compile_source(source)
    module = project.TestModule.deploy(share, {"from": accounts[0]})
    with pytest.reverts():
        module.test(share.detachModule.encode_input(module), {"from": accounts[0]})
    org.attachModule(share, module, {"from": accounts[0]})
    module.test(share.detachModule.encode_input(module), {"from": accounts[0]})
    with pytest.reverts():
        module.test(share.detachModule.encode_input(module), {"from": accounts[0]})
Esempio n. 27
0
def _burn(issuer, nft, source, sig):
    module = compile_source(module_source.format(sig, source))[0].deploy(
        nft, {'from': accounts[0]})
    nft.burn(100, 200, {'from': accounts[0]})
    issuer.attachModule(nft, module, {'from': accounts[0]})
    nft.burn(300, 400, {'from': accounts[0]})
    module.setReturn(False, {'from': accounts[0]})
    with pytest.reverts():
        nft.burn(500, 600, {'from': accounts[0]})
    issuer.detachModule(nft, module, {'from': accounts[0]})
    nft.burn(500, 600, {'from': accounts[0]})
Esempio n. 28
0
def test_selfdestruct_during_deploy(accounts):
    foo = compile_source("""
pragma solidity 0.5.0;

contract Foo {
    constructor () public { selfdestruct(address(0)); }
}
    """).Foo

    result = foo.deploy({"from": accounts[0]})
    assert isinstance(result, TransactionReceipt)
Esempio n. 29
0
def oracle(alice):
    yield compile_source("""
pragma solidity 0.7.6;
contract Oracle {

    int256 public latestAnswer;

    function setAnswer(int256 answer) external {
        latestAnswer = answer;
    }
}
    """).Oracle.deploy({'from': alice})
def _hook(cust, fn, args, source, sig):
    args = list(args) + [{'from': accounts[0]}]
    source = module_source.format(sig, source)
    module = compile_source(source)[0].deploy(cust, {'from': accounts[0]})
    fn(*args)
    cust.attachModule(module, {'from': accounts[0]})
    fn(*args)
    module.setReturn(False, {'from': accounts[0]})
    with pytest.reverts():
        fn(*args)
    cust.detachModule(module, {'from': accounts[0]})
    fn(*args)