mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Index access for bytesXX.
This commit is contained in:
@@ -6394,6 +6394,42 @@ BOOST_AUTO_TEST_CASE(inline_long_string_return)
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
BOOST_CHECK(callContractFunction("f()") == encodeDyn(strLong));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fixed_bytes_index_access)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
bytes16[] public data;
|
||||
function f(bytes32 x) returns (byte) {
|
||||
return x[2];
|
||||
}
|
||||
function g(bytes32 x) returns (uint) {
|
||||
data = [x[0], x[1], x[2]];
|
||||
data[0] = "12345";
|
||||
return uint(data[0][4]);
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
BOOST_CHECK(callContractFunction("f(bytes32)", "789") == encodeArgs("9"));
|
||||
BOOST_CHECK(callContractFunction("g(bytes32)", "789") == encodeArgs(u256(int('5'))));
|
||||
BOOST_CHECK(callContractFunction("data(uint256)", u256(1)) == encodeArgs("8"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fixed_bytes_length_access)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
byte a;
|
||||
function f(bytes32 x) returns (uint, uint, uint) {
|
||||
return (x.length, bytes16(2).length, a.length + 7);
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
BOOST_CHECK(callContractFunction("f(bytes32)", "789") == encodeArgs(u256(32), u256(16), u256(8)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
||||
@@ -3136,6 +3136,19 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types)
|
||||
BOOST_CHECK(success(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(index_access_for_bytes)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
bytes20 x;
|
||||
function f(bytes16 b) {
|
||||
b[uint(x[2])];
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK(success(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user