From 29faf1b298030f23076e8322dafd87df2154b40f Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 3 Feb 2016 21:34:24 +0100 Subject: Index access for bytesXX. --- test/libsolidity/SolidityEndToEndTest.cpp | 36 ++++++++++++++++++++++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 13 ++++++++ 2 files changed, 49 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 73e2d662..c6e1b10d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -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() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 820fd7d0..d202942c 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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() } -- cgit v1.2.3