From 14fd647b852146cd885426d04bffffbd1b7c08a0 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 9 Nov 2017 00:02:39 -0300 Subject: Fix event parsing. Refs #3175 --- test/libsolidity/SolidityEndToEndTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 9a837113..7082b702 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2953,7 +2953,7 @@ BOOST_AUTO_TEST_CASE(event_no_arguments) { char const* sourceCode = R"( contract ClientReceipt { - event Deposit; + event Deposit(); function deposit() { Deposit(); } @@ -2995,7 +2995,7 @@ BOOST_AUTO_TEST_CASE(events_with_same_name) { char const* sourceCode = R"( contract ClientReceipt { - event Deposit; + event Deposit(); event Deposit(address _addr); event Deposit(address _addr, uint _amount); function deposit() returns (uint) { @@ -3041,7 +3041,7 @@ BOOST_AUTO_TEST_CASE(events_with_same_name_inherited) { char const* sourceCode = R"( contract A { - event Deposit; + event Deposit(); } contract B { -- cgit v1.2.3 From 6807010dc7864500d89a833e4f6e7f338e58b948 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Nov 2017 12:58:04 +0100 Subject: Prevent libraries from being called. --- test/libsolidity/SolidityEndToEndTest.cpp | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f5f7e64a..5b98d979 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3543,6 +3543,39 @@ BOOST_AUTO_TEST_CASE(library_call_in_homestead) ABI_CHECK(callContractFunction("sender()"), encodeArgs(u160(m_sender))); } +BOOST_AUTO_TEST_CASE(library_call_protection) +{ + // This tests code that reverts a call if it is a direct call to a library + // as opposed to a delegatecall. + char const* sourceCode = R"( + library Lib { + struct S { uint x; } + // a direct call to this should revert + function np(S storage s) public returns (address) { s.x = 3; return msg.sender; } + // a direct call to this is fine + function v(S storage) public view returns (address) { return msg.sender; } + // a direct call to this is fine + function pu() public pure returns (uint) { return 2; } + } + contract Test { + Lib.S public s; + function np() public returns (address) { return Lib.np(s); } + function v() public view returns (address) { return Lib.v(s); } + function pu() public pure returns (uint) { return Lib.pu(); } + } + )"; + compileAndRun(sourceCode, 0, "Lib"); + ABI_CHECK(callContractFunction("np(Lib.S storage)"), encodeArgs()); + ABI_CHECK(callContractFunction("v(Lib.S storage)"), encodeArgs(u160(m_sender))); + ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("s()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("np()"), encodeArgs(u160(m_sender))); + ABI_CHECK(callContractFunction("s()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("v()"), encodeArgs(u160(m_sender))); + ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); +} + BOOST_AUTO_TEST_CASE(store_bytes) { // this test just checks that the copy loop does not mess up the stack -- cgit v1.2.3 From aea9e7fe549d93436a1eb355258ea1b11b5dfb22 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 13 Feb 2018 12:03:02 +0100 Subject: Add tests for selectors for public variables. --- test/libsolidity/SolidityEndToEndTest.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SolidityEndToEndTest.cpp') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 5b98d979..0611e71d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10219,24 +10219,29 @@ BOOST_AUTO_TEST_CASE(function_types_sig) { char const* sourceCode = R"( contract C { - function f() returns (bytes4) { + uint public x; + function f() pure returns (bytes4) { return this.f.selector; } function g() returns (bytes4) { - function () external returns (bytes4) fun = this.f; + function () pure external returns (bytes4) fun = this.f; return fun.selector; } function h() returns (bytes4) { - function () external returns (bytes4) fun = this.f; + function () pure external returns (bytes4) fun = this.f; var funvar = fun; return funvar.selector; } + function i() pure returns (bytes4) { + return this.x.selector; + } } )"; compileAndRun(sourceCode, 0, "C"); ABI_CHECK(callContractFunction("f()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); ABI_CHECK(callContractFunction("g()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); ABI_CHECK(callContractFunction("h()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); + ABI_CHECK(callContractFunction("i()"), encodeArgs(asString(FixedHash<4>(dev::keccak256("x()")).asBytes()))); } BOOST_AUTO_TEST_CASE(constant_string) -- cgit v1.2.3