mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow explicit conversions bytes <-> string.
This commit is contained in:
parent
765f303688
commit
45e6d94078
@ -5099,6 +5099,31 @@ BOOST_AUTO_TEST_CASE(memory_structs_with_mappings)
|
||||
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(string_bytes_conversion)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Test {
|
||||
string s;
|
||||
bytes b;
|
||||
function f(string _s, uint n) returns (byte) {
|
||||
b = bytes(_s);
|
||||
s = string(b);
|
||||
return bytes(s)[n];
|
||||
}
|
||||
function l() returns (uint) { return bytes(s).length; }
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "Test");
|
||||
BOOST_CHECK(callContractFunction(
|
||||
"f(string,uint256)",
|
||||
u256(0x40),
|
||||
u256(2),
|
||||
u256(6),
|
||||
string("abcdef")
|
||||
) == encodeArgs("c"));
|
||||
BOOST_CHECK(callContractFunction("l()") == encodeArgs(u256(6)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(string_as_mapping_key)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
@ -2149,6 +2149,23 @@ BOOST_AUTO_TEST_CASE(memory_structs_with_mappings)
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(string_bytes_conversion)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract Test {
|
||||
string s;
|
||||
bytes b;
|
||||
function h(string _s) external { bytes(_s).length; }
|
||||
function i(string _s) internal { bytes(_s).length; }
|
||||
function j() internal { bytes(s).length; }
|
||||
function k(bytes _b) external { string(_b); }
|
||||
function l(bytes _b) internal { string(_b); }
|
||||
function m() internal { string(b); }
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user