Example #1
0
def test_minify_vyper():
    code = "@public\ndef foo(a: address) -> bool:    return True\n\n"
    foo = compile_source(code)["Vyper"]
    minified, _ = sources.minify(code, "Vyper")
    minifoo = compile_source(minified)["Vyper"]
    assert foo._build["bytecodeSha1"] == minifoo._build["bytecodeSha1"]
    assert foo._build["source"] != minifoo._build["source"]
Example #2
0
def test_compile():
    source = sources.get('BrownieTester')
    source = source.replace('BrownieTester', 'TempTester')
    source = source.replace('UnlinkedLib', 'TestLib')
    obj = project.compile_source(source)
    assert obj[0]._name == "TempTester"
    assert obj[1]._name == "TestLib"
def test_fixed_tuple_array(accounts):
    code = """
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;

contract Test {

struct Foo { uint256 a; string b; }

Foo[2][2] bar;

function foo() public returns (Foo[2][2] memory, Foo[2] memory) {
    bar[0][0].a = 42;
    bar[0][0].b = "hello";
    bar[1][1].a = 69;
    return (bar, bar[1]);
}

}
"""
    contract = compile_source(code).Test.deploy({"from": accounts[0]})

    assert contract.foo.call() == [
        ([(42, "hello"), (0, "")], [(0, ""), (69, "")]),
        [(0, ""), (69, "")],
    ]
def test_vyper_contract(capfd):
    code = vyper_natspec
    contract = compile_source(code).Vyper

    contract.info()

    out = capfd.readouterr()[0]
    for field in ("title", "author", "notice", "details"):
        assert f"@{field}" in out
def test_solc_contract(version, capfd):
    code = solc_natspec
    contract = compile_source(code, solc_version=f"0.{version}.0").Bugs

    contract.info()

    out = capfd.readouterr()[0]
    for field in ("title", "author", "notice", "details"):
        assert f"@{field}" in out
Example #6
0
def test_deployment_size_limit(accounts, console_mode):
    code = f"""
# @version 0.2.4

@external
def baz():
    assert msg.sender != ZERO_ADDRESS, '{'blah'*10000}'
    """
    tx = compile_source(code, vyper_version="0.2.4").Vyper.deploy({"from": accounts[0]})
    assert tx.revert_msg == "exceeds EIP-170 size limit"
Example #7
0
    def deploy(tx_params: Dict) -> Contract:
        """Deploy an instance of the `Multicall2` contract.

        Args:
            tx_params: parameters passed to the `deploy` method of the `Multicall2` contract
                container.
        """
        project = compile_source(MULTICALL2_SOURCE)
        deployment = project.Multicall2.deploy(tx_params)  # type: ignore
        CONFIG.active_network["multicall2"] = deployment.address
        return deployment
def test_vyper_function(capfd, accounts):
    code = vyper_natspec
    contract = compile_source(code).Vyper
    contract.deploy({"from": accounts[0]})

    contract[0].doesEat.info()

    out = capfd.readouterr()[0]
    for field in ("notice", "details"):
        assert f"@{field}" in out

    assert out.count("@param") == 2
    assert out.count("@return") == 2
Example #9
0
def test_final_stmt_revert_input_no_msg(console_mode, evmtester, accounts, expr, func):

    func = func.format(expr)
    code = f"""
pragma solidity >=0.4.22;
contract Foo {{
    {func}
}}
    """

    contract = compile_source(code).Foo.deploy({"from": accounts[0]})
    tx = contract.foo(4)
    assert tx.revert_msg == "dev: yuss"
Example #10
0
def test_solc_function(version, capfd, accounts):
    code = solc_natspec
    contract = compile_source(code, solc_version=f"0.{version}.0").Bugs
    contract.deploy({"from": accounts[0]})

    contract[0].doesEat.info()

    out = capfd.readouterr()[0]
    for field in ("notice", "details"):
        assert f"@{field}" in out

    assert out.count("@param") == 2
    assert out.count("@return") == 2 if version == 6 else 1
Example #11
0
def test_dev_revert_on_final_statement(console_mode, evmtester, accounts):

    code = """pragma solidity >=0.4.22;

contract foo {

    function foo1 () external returns (bool) {
        revert(); // dev: yuss
    }

    function foo2 () external returns (bool) {
        uint b = 33;
        revert(); // dev: yuss
    }

    function foo3 (uint a) external returns (bool) {
        if (a < 3) {
            return true;
        }
        revert(); // dev: yuss
    }

    function foo4 (uint a) external returns (bool) {
        require(a >= 3);
        revert(); // dev: yuss
    }

    function foo5 (uint a) external {
        require(a >= 3);
        revert(); // dev: yuss
    }
}"""

    contract = compile_source(code).foo.deploy({"from": accounts[0]})
    tx = contract.foo1()
    assert tx.revert_msg == "dev: yuss"
    tx = contract.foo2()
    assert tx.revert_msg == "dev: yuss"
    tx = contract.foo3(4)
    assert tx.revert_msg == "dev: yuss"
    tx = contract.foo4(4)
    assert tx.revert_msg == "dev: yuss"
    tx = contract.foo5(4)
    assert tx.revert_msg == "dev: yuss"
Example #12
0
def test_dynamic_tuple_array(accounts):
    code = """
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;

contract Test {

struct Foo { uint256 a; }

Foo[] bar;

function foo() public returns (Foo[] memory a) {
    bar.push(Foo(1));
    bar.push(Foo(6));
    return bar;
}

}
"""
    contract = compile_source(code).Test.deploy({"from": accounts[0]})

    assert contract.foo.call() == [(1,), (6,)]
Example #13
0
def BUSD(accounts):
    token = compile_source(ERC20).Token
    yield token.deploy("BUSD", "Binance USD", 18, {"from": accounts[0]})
Example #14
0
def SUSD(accounts):
    token = compile_source(ERC20).Token
    yield token.deploy("sUSD", "Synth sUSD", 18, {"from": accounts[0]})
Example #15
0
def USDT(accounts):
    token = compile_source(ERC20_NO_RETURN).Token
    yield token.deploy("USDT", "Tether USD", 6, {"from": accounts[0]})
Example #16
0
def Foo():
    yield compile_source(TEST_SOURCE).Foo
def solc_tester(accounts):
    container = compile_source(solidity_source).OverloadedTester
    yield container.deploy({"from": accounts[0]})
def vyper_tester(accounts):
    container = compile_source(vyper_source).Vyper
    yield container.deploy({"from": accounts[0]})
Example #19
0
def test_minify_solc(version):
    foo = compile_source(MINIFY_SOURCE, solc_version=version)["Foo"]
    minified, _ = sources.minify(MINIFY_SOURCE)
    minifoo = compile_source(minified, solc_version=version)["Foo"]
    assert foo._build["bytecodeSha1"] == minifoo._build["bytecodeSha1"]
    assert foo._build["source"] != minifoo._build["source"]
Example #20
0
def DAI(accounts):
    token = compile_source(ERC20).Token
    yield token.deploy("DAI", "DAI Stablecoin", 18, {"from": accounts[0]})
Example #21
0
def test_minify_compiles(solc5source):
    foo = compile_source(solc5source, solc_version="0.5.7")['Foo']
    minified, _ = sources.minify(solc5source)
    minifoo = compile_source(minified, solc_version="0.5.7")['Foo']
    assert foo._build['bytecodeSha1'] == minifoo._build['bytecodeSha1']
    assert foo._build['source'] != minifoo._build['source']
Example #22
0
def USDC(accounts):
    token = compile_source(ERC20).Token
    yield token.deploy("USDC", "USD//C", 6, {"from": accounts[0]})
Example #23
0
def test_import_from_package():
    install_package("brownie-mix/[email protected]")
    compile_source(code)
Example #24
0
def TUSD(accounts):
    token = compile_source(ERC20).Token
    yield token.deploy("TUSD", "TrueUSD", 18, {"from": accounts[0]})
Example #25
0
def test_import_fails_without_package_installed():
    with pytest.raises(CompilerError):
        compile_source(code)
Example #26
0
def test_deployment_size_limit(accounts, console_mode):
    code = f"@public\ndef baz():\n    assert msg.sender != ZERO_ADDRESS, '{'blah'*10000}'"
    tx = compile_source(code).Vyper.deploy({"from": accounts[0]})
    assert tx.revert_msg == "exceeds EIP-170 size limit"
Example #27
0
def test_minify_compiles(solc5source):
    foo = compile_source(solc5source, solc_version="0.5.7")["Foo"]
    minified, _ = sources.minify(solc5source)
    minifoo = compile_source(minified, solc_version="0.5.7")["Foo"]
    assert foo._build["bytecodeSha1"] == minifoo._build["bytecodeSha1"]
    assert foo._build["source"] != minifoo._build["source"]