mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Decoding for constructor.
This commit is contained in:
parent
90ee186044
commit
1e8c26421b
@ -4457,26 +4457,52 @@ BOOST_AUTO_TEST_CASE(bytes_index_access_memory)
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bytes_in_constructors)
|
||||
BOOST_AUTO_TEST_CASE(bytes_in_constructors_unpacker)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Base {
|
||||
contract Test {
|
||||
uint public m_x;
|
||||
bytes public m_s;
|
||||
function Base(uint x, bytes s) {
|
||||
function Test(uint x, bytes s) {
|
||||
m_x = x;
|
||||
m_s = s;
|
||||
}
|
||||
}
|
||||
)";
|
||||
string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||
bytes dyn1 = encodeArgs(u256(s1.length()), s1);
|
||||
u256 x = 7;
|
||||
bytes args1 = encodeArgs(x, u256(0x40)) + dyn1;
|
||||
compileAndRun(sourceCode, 0, "Test", args1);
|
||||
BOOST_REQUIRE(callContractFunction("m_x()") == encodeArgs(x));
|
||||
BOOST_REQUIRE(callContractFunction("m_s()") == encodeArgs(u256(0x20)) + dyn1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Base {
|
||||
uint public m_x;
|
||||
bytes m_s;
|
||||
function Base(uint x, bytes s) {
|
||||
m_x = x;
|
||||
m_s = s;
|
||||
}
|
||||
function part(uint i) returns (byte) {
|
||||
return m_s[i];
|
||||
}
|
||||
}
|
||||
contract Main is Base {
|
||||
function Main(bytes s, uint x) Base(x, f(s)) {}
|
||||
function f(bytes s) returns (bytes) { return s; }
|
||||
function Main(bytes s, uint x) Base(x, s){}//f(s)) {}
|
||||
function f(bytes s) returns (bytes) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
contract Creator {
|
||||
function f(uint x, bytes s) returns (uint r, bytes b) {
|
||||
function f(uint x, bytes s) returns (uint r, byte ch) {
|
||||
var c = new Main(s, x);
|
||||
r = c.m_x();
|
||||
b = c.m_s();
|
||||
ch = c.part(x);
|
||||
}
|
||||
}
|
||||
)";
|
||||
@ -4487,7 +4513,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors)
|
||||
bytes args1 = encodeArgs(x, u256(0x40)) + dyn1;
|
||||
BOOST_REQUIRE(
|
||||
callContractFunction("f(uint256,bytes)", asString(args1)) ==
|
||||
encodeArgs(x, u256(0x40), dyn1)
|
||||
encodeArgs(x, string{s1[unsigned(x)]})
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1987,6 +1987,19 @@ BOOST_AUTO_TEST_CASE(mem_array_assignment_changes_base_type)
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function f(uint) returns (string);
|
||||
function g() {
|
||||
var x = this.f(2);
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user