From 765f30368837e3e930d6a221d870a277278e5c3f Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 3 Aug 2015 18:09:39 +0200 Subject: strings as mapping keys. --- libsolidity/SolidityEndToEndTest.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index d4454514..fc1d2eab 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -5099,6 +5099,39 @@ BOOST_AUTO_TEST_CASE(memory_structs_with_mappings) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0))); } +BOOST_AUTO_TEST_CASE(string_as_mapping_key) +{ + char const* sourceCode = R"( + contract Test { + mapping(string => uint) data; + function set(string _s, uint _v) { data[_s] = _v; } + function get(string _s) returns (uint) { return data[_s]; } + } + )"; + compileAndRun(sourceCode, 0, "Test"); + vector strings{ + "Hello, World!", + "Hello, World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111", + "", + "1" + }; + for (unsigned i = 0; i < strings.size(); i++) + BOOST_CHECK(callContractFunction( + "set(string,uint256)", + u256(0x40), + u256(7 + i), + u256(strings[i].size()), + strings[i] + ) == encodeArgs()); + for (unsigned i = 0; i < strings.size(); i++) + BOOST_CHECK(callContractFunction( + "get(string)", + u256(0x20), + u256(strings[i].size()), + strings[i] + ) == encodeArgs(u256(7 + i))); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit