Skip to content

Commit

Permalink
Fix tests for short data
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Sep 19, 2017
1 parent 2c58ddb commit db4662d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions test/libsolidity/ABIDecoderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,14 @@ BOOST_AUTO_TEST_CASE(short_input_value_type)
{
string sourceCode = R"(
contract C {
function f(uint a) returns (uint) { return a; }
function f(uint a, uint b) returns (uint) { return a; }
}
)";
NEW_ENCODER(
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f(uint256)", 1) == encodeArgs(1));
BOOST_CHECK(callContractFunction("f(uint256)", bytes(31, 0)) == encodeArgs(0));
BOOST_CHECK(callContractFunction("f(uint256,uint256)", 1, 2) == encodeArgs(1));
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256,uint256)", bytes(64, 0)) == encodeArgs(0));
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256,uint256)", bytes(63, 0)) == encodeArgs());
)
}

Expand All @@ -334,23 +335,32 @@ BOOST_AUTO_TEST_CASE(short_input_array)
)";
NEW_ENCODER(
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f(uint256[])", 0x20, 0) == encodeArgs(7));
BOOST_CHECK(callContractFunction("f(uint256[])", 0x20, 1) == encodeArgs());
BOOST_CHECK(callContractFunction("f(uint256[])", 0x20, 2, 5, 6) == encodeArgs(7));
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 0)) == encodeArgs(7));
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1) + bytes(31, 0)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 1) + bytes(32, 0)) == encodeArgs(7));
BOOST_CHECK(callContractFunctionNoEncoding("f(uint256[])", encodeArgs(0x20, 2, 5, 6)) == encodeArgs(7));
)
}

BOOST_AUTO_TEST_CASE(short_input_bytes)
{
string sourceCode = R"(
contract C {
function e(bytes a) returns (uint) { return 7; }
function f(bytes[] a) returns (uint) { return 7; }
}
)";
NEW_ENCODER(
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f(bytes[])", 0x20, 1, 0x20, 7, bytes(7, 0)) == encodeArgs(7));
BOOST_CHECK(callContractFunction("f(bytes[])", 0x20, 1, 0x20, 7, bytes(6, 0)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("e(bytes)", encodeArgs(0x20, 7) + bytes(5, 0)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("e(bytes)", encodeArgs(0x20, 7) + bytes(6, 0)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("e(bytes)", encodeArgs(0x20, 7) + bytes(7, 0)) == encodeArgs(7));
BOOST_CHECK(callContractFunctionNoEncoding("e(bytes)", encodeArgs(0x20, 7) + bytes(8, 0)) == encodeArgs(7));
BOOST_CHECK(callContractFunctionNoEncoding("f(bytes[])", encodeArgs(0x20, 1, 0x40, 7) + bytes(5, 0)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("f(bytes[])", encodeArgs(0x20, 1, 0x40, 7) + bytes(6, 0)) == encodeArgs());
BOOST_CHECK(callContractFunctionNoEncoding("f(bytes[])", encodeArgs(0x20, 1, 0x40, 7) + bytes(7, 0)) == encodeArgs(7));
BOOST_CHECK(callContractFunctionNoEncoding("f(bytes[])", encodeArgs(0x20, 1, 0x40, 7) + bytes(8, 0)) == encodeArgs(7));
)
}

Expand Down Expand Up @@ -380,9 +390,6 @@ BOOST_AUTO_TEST_CASE(cleanup_int_inside_arrays)

// test decoding storage pointers

// test that byte arrays in pure calldata and properly decoded into memory
// are valid, even if they do not have padding (i.e. the length check does not throw)

// TODO: ridiculously sized arrays, also when the size comes from deeply nested "short" arrays

// check again in the code that "offset" is always compared to "end"
Expand Down

0 comments on commit db4662d

Please sign in to comment.