Merge pull request #1351 from ethereum/truncate_bit

Truncate a boolean from calldata into one bit
This commit is contained in:
chriseth
2016-12-08 16:15:35 +01:00
committed by GitHub
7 changed files with 89 additions and 5 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(location_test)
shared_ptr<string const> n = make_shared<string>("");
AssemblyItems items = compileContract(sourceCode);
vector<SourceLocation> locations =
vector<SourceLocation>(16, SourceLocation(2, 75, n)) +
vector<SourceLocation>(18, SourceLocation(2, 75, n)) +
vector<SourceLocation>(27, SourceLocation(20, 72, n)) +
vector<SourceLocation>{SourceLocation(42, 51, n), SourceLocation(65, 67, n)} +
vector<SourceLocation>(2, SourceLocation(58, 67, n)) +
+28
View File
@@ -4591,6 +4591,34 @@ BOOST_AUTO_TEST_CASE(super_overload)
BOOST_CHECK(callContractFunction("h()") == encodeArgs(2));
}
BOOST_AUTO_TEST_CASE(bool_conversion)
{
char const* sourceCode = R"(
contract C {
function f(bool _b) returns(uint) {
if (_b)
return 1;
else
return 0;
}
function g(bool _in) returns (bool _out) {
_out = _in;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f(bool)", 0) == encodeArgs(0));
BOOST_CHECK(callContractFunction("f(bool)", 1) == encodeArgs(1));
BOOST_CHECK(callContractFunction("f(bool)", 2) == encodeArgs(1));
BOOST_CHECK(callContractFunction("f(bool)", 3) == encodeArgs(1));
BOOST_CHECK(callContractFunction("f(bool)", 255) == encodeArgs(1));
BOOST_CHECK(callContractFunction("g(bool)", 0) == encodeArgs(0));
BOOST_CHECK(callContractFunction("g(bool)", 1) == encodeArgs(1));
BOOST_CHECK(callContractFunction("g(bool)", 2) == encodeArgs(1));
BOOST_CHECK(callContractFunction("g(bool)", 3) == encodeArgs(1));
BOOST_CHECK(callContractFunction("g(bool)", 255) == encodeArgs(1));
}
BOOST_AUTO_TEST_CASE(packed_storage_signed)
{
char const* sourceCode = R"(