Merge pull request #4489 from chase1745/use-explicit-data-locations-end-to-end-tests

Added default data locations to parameters for end to end tests.
This commit is contained in:
chriseth 2018-07-16 14:41:24 +02:00 committed by GitHub
commit 58667db8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 240 additions and 240 deletions

View File

@ -43,20 +43,20 @@ static char const* registrarCode = R"DELIMITER(
pragma solidity ^0.4.0;
contract NameRegister {
function addr(string _name) view returns (address o_owner);
function name(address _owner) view returns (string o_name);
function addr(string memory _name) view returns (address o_owner);
function name(address _owner) view returns (string memory o_name);
}
contract Registrar is NameRegister {
event Changed(string indexed name);
event PrimaryChanged(string indexed name, address indexed addr);
function owner(string _name) view returns (address o_owner);
function addr(string _name) view returns (address o_address);
function subRegistrar(string _name) view returns (address o_subRegistrar);
function content(string _name) view returns (bytes32 o_content);
function owner(string memory _name) view returns (address o_owner);
function addr(string memory _name) view returns (address o_address);
function subRegistrar(string memory _name) view returns (address o_subRegistrar);
function content(string memory _name) view returns (bytes32 o_content);
function name(address _owner) view returns (string o_name);
function name(address _owner) view returns (string memory o_name);
}
contract AuctionSystem {
@ -64,9 +64,9 @@ contract AuctionSystem {
event NewBid(string indexed _name, address _bidder, uint _value);
/// Function that is called once an auction ends.
function onAuctionEnd(string _name) internal;
function onAuctionEnd(string memory _name) internal;
function bid(string _name, address _bidder, uint _value) internal {
function bid(string memory _name, address _bidder, uint _value) internal {
Auction storage auction = m_auctions[_name];
if (auction.endDate > 0 && now > auction.endDate)
{
@ -116,7 +116,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
// TODO: Populate with hall-of-fame.
}
function onAuctionEnd(string _name) internal {
function onAuctionEnd(string memory _name) internal {
Auction storage auction = m_auctions[_name];
Record storage record = m_toRecord[_name];
address previousOwner = record.owner;
@ -150,18 +150,18 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
}
}
function requiresAuction(string _name) internal returns (bool) {
function requiresAuction(string memory _name) internal returns (bool) {
return bytes(_name).length < c_freeBytes;
}
modifier onlyrecordowner(string _name) { if (m_toRecord[_name].owner == msg.sender) _; }
modifier onlyrecordowner(string memory _name) { if (m_toRecord[_name].owner == msg.sender) _; }
function transfer(string _name, address _newOwner) onlyrecordowner(_name) {
function transfer(string memory _name, address _newOwner) onlyrecordowner(_name) {
m_toRecord[_name].owner = _newOwner;
emit Changed(_name);
}
function disown(string _name) onlyrecordowner(_name) {
function disown(string memory _name) onlyrecordowner(_name) {
if (stringsEqual(m_toName[m_toRecord[_name].primary], _name))
{
emit PrimaryChanged(_name, m_toRecord[_name].primary);
@ -171,7 +171,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
emit Changed(_name);
}
function setAddress(string _name, address _a, bool _primary) onlyrecordowner(_name) {
function setAddress(string memory _name, address _a, bool _primary) onlyrecordowner(_name) {
m_toRecord[_name].primary = _a;
if (_primary)
{
@ -180,11 +180,11 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
}
emit Changed(_name);
}
function setSubRegistrar(string _name, address _registrar) onlyrecordowner(_name) {
function setSubRegistrar(string memory _name, address _registrar) onlyrecordowner(_name) {
m_toRecord[_name].subRegistrar = _registrar;
emit Changed(_name);
}
function setContent(string _name, bytes32 _content) onlyrecordowner(_name) {
function setContent(string memory _name, bytes32 _content) onlyrecordowner(_name) {
m_toRecord[_name].content = _content;
emit Changed(_name);
}
@ -201,11 +201,11 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
return true;
}
function owner(string _name) view returns (address) { return m_toRecord[_name].owner; }
function addr(string _name) view returns (address) { return m_toRecord[_name].primary; }
function subRegistrar(string _name) view returns (address) { return m_toRecord[_name].subRegistrar; }
function content(string _name) view returns (bytes32) { return m_toRecord[_name].content; }
function name(address _addr) view returns (string o_name) { return m_toName[_addr]; }
function owner(string memory _name) view returns (address) { return m_toRecord[_name].owner; }
function addr(string memory _name) view returns (address) { return m_toRecord[_name].primary; }
function subRegistrar(string memory _name) view returns (address) { return m_toRecord[_name].subRegistrar; }
function content(string memory _name) view returns (bytes32) { return m_toRecord[_name].content; }
function name(address _addr) view returns (string memory o_name) { return m_toName[_addr]; }
mapping (address => string) m_toName;
mapping (string => Record) m_toRecord;

View File

@ -58,10 +58,10 @@ pragma solidity ^0.4.0;
contract Registrar {
event Changed(string indexed name);
function owner(string _name) view returns (address o_owner);
function addr(string _name) view returns (address o_address);
function subRegistrar(string _name) view returns (address o_subRegistrar);
function content(string _name) view returns (bytes32 o_content);
function owner(string memory _name) view returns (address o_owner);
function addr(string memory _name) view returns (address o_address);
function subRegistrar(string memory _name) view returns (address o_subRegistrar);
function content(string memory _name) view returns (bytes32 o_content);
}
contract FixedFeeRegistrar is Registrar {
@ -72,52 +72,52 @@ contract FixedFeeRegistrar is Registrar {
address owner;
}
modifier onlyrecordowner(string _name) { if (m_record(_name).owner == msg.sender) _; }
modifier onlyrecordowner(string memory _name) { if (m_record(_name).owner == msg.sender) _; }
function reserve(string _name) payable {
function reserve(string memory _name) payable {
Record storage rec = m_record(_name);
if (rec.owner == 0x0000000000000000000000000000000000000000 && msg.value >= c_fee) {
rec.owner = msg.sender;
emit Changed(_name);
}
}
function disown(string _name, address _refund) onlyrecordowner(_name) {
function disown(string memory _name, address _refund) onlyrecordowner(_name) {
delete m_recordData[uint(keccak256(bytes(_name))) / 8];
if (!_refund.send(c_fee))
throw;
emit Changed(_name);
}
function transfer(string _name, address _newOwner) onlyrecordowner(_name) {
function transfer(string memory _name, address _newOwner) onlyrecordowner(_name) {
m_record(_name).owner = _newOwner;
emit Changed(_name);
}
function setAddr(string _name, address _a) onlyrecordowner(_name) {
function setAddr(string memory _name, address _a) onlyrecordowner(_name) {
m_record(_name).addr = _a;
emit Changed(_name);
}
function setSubRegistrar(string _name, address _registrar) onlyrecordowner(_name) {
function setSubRegistrar(string memory _name, address _registrar) onlyrecordowner(_name) {
m_record(_name).subRegistrar = _registrar;
emit Changed(_name);
}
function setContent(string _name, bytes32 _content) onlyrecordowner(_name) {
function setContent(string memory _name, bytes32 _content) onlyrecordowner(_name) {
m_record(_name).content = _content;
emit Changed(_name);
}
function record(string _name) view returns (address o_addr, address o_subRegistrar, bytes32 o_content, address o_owner) {
function record(string memory _name) view returns (address o_addr, address o_subRegistrar, bytes32 o_content, address o_owner) {
Record storage rec = m_record(_name);
o_addr = rec.addr;
o_subRegistrar = rec.subRegistrar;
o_content = rec.content;
o_owner = rec.owner;
}
function addr(string _name) view returns (address) { return m_record(_name).addr; }
function subRegistrar(string _name) view returns (address) { return m_record(_name).subRegistrar; }
function content(string _name) view returns (bytes32) { return m_record(_name).content; }
function owner(string _name) view returns (address) { return m_record(_name).owner; }
function addr(string memory _name) view returns (address) { return m_record(_name).addr; }
function subRegistrar(string memory _name) view returns (address) { return m_record(_name).subRegistrar; }
function content(string memory _name) view returns (bytes32) { return m_record(_name).content; }
function owner(string memory _name) view returns (address) { return m_record(_name).owner; }
Record[2**253] m_recordData;
function m_record(string _name) view internal returns (Record storage o_record) {
function m_record(string memory _name) view internal returns (Record storage o_record) {
return m_recordData[uint(keccak256(bytes(_name))) / 8];
}
uint constant c_fee = 69 ether;

View File

@ -101,7 +101,7 @@ contract multiowned {
// constructor is given number of sigs required to do protected "onlymanyowners" transactions
// as well as the selection of addresses capable of confirming them.
constructor(address[] _owners, uint _required) {
constructor(address[] memory _owners, uint _required) {
m_numOwners = _owners.length + 1;
m_owners[1] = uint(msg.sender);
m_ownerIndex[uint(msg.sender)] = 1;
@ -369,7 +369,7 @@ contract Wallet is multisig, multiowned, daylimit {
// constructor - just pass on the owner array to the multiowned and
// the limit to daylimit
constructor(address[] _owners, uint _required, uint _daylimit) payable
constructor(address[] memory _owners, uint _required, uint _daylimit) payable
multiowned(_owners, _required) daylimit(_daylimit) {
}

View File

@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays)
{
string sourceCode = R"(
contract C {
function f(uint16[3] a, uint16[2][3] b, uint i, uint j, uint k)
function f(uint16[3] memory a, uint16[2][3] memory b, uint i, uint j, uint k)
public pure returns (uint, uint) {
return (a[i], b[j][k]);
}
@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(dynamic_arrays)
{
string sourceCode = R"(
contract C {
function f(uint a, uint16[] b, uint c)
function f(uint a, uint16[] memory b, uint c)
public pure returns (uint, uint, uint) {
return (b.length, b[a], c);
}
@ -178,7 +178,7 @@ BOOST_AUTO_TEST_CASE(dynamic_nested_arrays)
{
string sourceCode = R"(
contract C {
function f(uint a, uint16[][] b, uint[2][][3] c, uint d)
function f(uint a, uint16[][] memory b, uint[2][][3] memory c, uint d)
public pure returns (uint, uint, uint, uint, uint, uint, uint) {
return (a, b.length, b[1].length, b[1][1], c[1].length, c[1][1][1], d);
}
@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(byte_arrays)
{
string sourceCode = R"(
contract C {
function f(uint a, bytes b, uint c)
function f(uint a, bytes memory b, uint c)
public pure returns (uint, uint, byte, uint) {
return (a, b.length, b[3], c);
}
@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE(decode_from_memory_simple)
contract C {
uint public _a;
uint[] public _b;
constructor(uint a, uint[] b) public {
constructor(uint a, uint[] memory b) public {
_a = a;
_b = b;
}
@ -344,13 +344,13 @@ BOOST_AUTO_TEST_CASE(decode_function_type_array)
string sourceCode = R"(
contract D {
function () external returns (uint)[] public _a;
constructor(function () external returns (uint)[] a) public {
constructor(function () external returns (uint)[] memory a) public {
_a = a;
}
}
contract E {
function () external returns (uint)[3] public _a;
constructor(function () external returns (uint)[3] a) public {
constructor(function () external returns (uint)[3] memory a) public {
_a = a;
}
}
@ -364,10 +364,10 @@ BOOST_AUTO_TEST_CASE(decode_function_type_array)
function f3() public returns (uint) {
return 3;
}
function g(function () external returns (uint)[] _f, uint i) public returns (uint) {
function g(function () external returns (uint)[] memory _f, uint i) public returns (uint) {
return _f[i]();
}
function h(function () external returns (uint)[3] _f, uint i) public returns (uint) {
function h(function () external returns (uint)[3] memory _f, uint i) public returns (uint) {
return _f[i]();
}
// uses "decode from memory"
@ -412,7 +412,7 @@ BOOST_AUTO_TEST_CASE(decode_from_memory_complex)
uint public _a;
uint[] public _b;
bytes[2] public _c;
constructor(uint a, uint[] b, bytes[2] c) public {
constructor(uint a, uint[] memory b, bytes[2] memory c) public {
_a = a;
_b = b;
_c = c;
@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(short_input_array)
{
string sourceCode = R"(
contract C {
function f(uint[] a) public pure returns (uint) { return 7; }
function f(uint[] memory a) public pure returns (uint) { return 7; }
}
)";
BOTH_ENCODERS(
@ -476,7 +476,7 @@ BOOST_AUTO_TEST_CASE(short_dynamic_input_array)
{
string sourceCode = R"(
contract C {
function f(bytes[1] a) public pure returns (uint) { return 7; }
function f(bytes[1] memory a) public pure returns (uint) { return 7; }
}
)";
NEW_ENCODER(
@ -489,8 +489,8 @@ BOOST_AUTO_TEST_CASE(short_input_bytes)
{
string sourceCode = R"(
contract C {
function e(bytes a) public pure returns (uint) { return 7; }
function f(bytes[] a) public pure returns (uint) { return 7; }
function e(bytes memory a) public pure returns (uint) { return 7; }
function f(bytes[] memory a) public pure returns (uint) { return 7; }
}
)";
NEW_ENCODER(
@ -511,9 +511,9 @@ BOOST_AUTO_TEST_CASE(cleanup_int_inside_arrays)
string sourceCode = R"(
contract C {
enum E { A, B }
function f(uint16[] a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
function g(int16[] a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
function h(E[] a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
function f(uint16[] memory a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
function g(int16[] memory a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
function h(E[] memory a) public pure returns (uint r) { assembly { r := mload(add(a, 0x20)) } }
}
)";
NEW_ENCODER(
@ -569,7 +569,7 @@ BOOST_AUTO_TEST_CASE(struct_simple)
string sourceCode = R"(
contract C {
struct S { uint a; uint8 b; uint8 c; bytes2 d; }
function f(S s) public pure returns (uint a, uint b, uint c, uint d) {
function f(S memory s) public pure returns (uint a, uint b, uint c, uint d) {
a = s.a;
b = s.b;
c = s.c;
@ -588,7 +588,7 @@ BOOST_AUTO_TEST_CASE(struct_cleanup)
string sourceCode = R"(
contract C {
struct S { int16 a; uint8 b; bytes2 c; }
function f(S s) public pure returns (uint a, uint b, uint c) {
function f(S memory s) public pure returns (uint a, uint b, uint c) {
assembly {
a := mload(s)
b := mload(add(s, 0x20))
@ -611,7 +611,7 @@ BOOST_AUTO_TEST_CASE(struct_short)
string sourceCode = R"(
contract C {
struct S { int a; uint b; bytes16 c; }
function f(S s) public pure returns (S q) {
function f(S memory s) public pure returns (S memory q) {
q = s;
}
}
@ -638,7 +638,7 @@ BOOST_AUTO_TEST_CASE(struct_function)
string sourceCode = R"(
contract C {
struct S { function () external returns (uint) f; uint b; }
function f(S s) public returns (uint, uint) {
function f(S memory s) public returns (uint, uint) {
return (s.f(), s.b);
}
function test() public returns (uint, uint) {
@ -658,7 +658,7 @@ BOOST_AUTO_TEST_CASE(mediocre_struct)
string sourceCode = R"(
contract C {
struct S { C c; }
function f(uint a, S[2] s1, uint b) public returns (uint r1, C r2, uint r3) {
function f(uint a, S[2] memory s1, uint b) public returns (uint r1, C r2, uint r3) {
r1 = a;
r2 = s1[0].c;
r3 = b;
@ -679,7 +679,7 @@ BOOST_AUTO_TEST_CASE(mediocre2_struct)
string sourceCode = R"(
contract C {
struct S { C c; uint[] x; }
function f(uint a, S[2] s1, uint b) public returns (uint r1, C r2, uint r3) {
function f(uint a, S[2] memory s1, uint b) public returns (uint r1, C r2, uint r3) {
r1 = a;
r2 = s1[0].c;
r3 = b;
@ -707,7 +707,7 @@ BOOST_AUTO_TEST_CASE(complex_struct)
enum E {A, B, C}
struct T { uint x; E e; uint8 y; }
struct S { C c; T[] t;}
function f(uint a, S[2] s1, S[] s2, uint b) public returns
function f(uint a, S[2] memory s1, S[] memory s2, uint b) public returns
(uint r1, C r2, uint r3, uint r4, C r5, uint r6, E r7, uint8 r8) {
r1 = a;
r2 = s1[0].c;
@ -767,10 +767,10 @@ BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_simple)
string sourceCode = R"(
contract C {
function dyn() public returns (bytes) {
function dyn() public returns (bytes memory) {
return "1234567890123456789012345678901234567890";
}
function f() public returns (bytes) {
function f() public returns (bytes memory) {
return this.dyn();
}
}
@ -788,7 +788,7 @@ BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_advanced)
string sourceCode = R"(
contract C {
function dyn() public returns (bytes a, uint b, bytes20[] c, uint d) {
function dyn() public returns (bytes memory a, uint b, bytes20[] memory c, uint d) {
a = "1234567890123456789012345678901234567890";
b = uint(-1);
c = new bytes20[](4);
@ -796,7 +796,7 @@ BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_advanced)
c[3] = bytes20(6789);
d = 0x1234;
}
function f() public returns (bytes, uint, bytes20[], uint) {
function f() public returns (bytes memory, uint, bytes20[] memory, uint) {
return this.dyn();
}
}
@ -815,7 +815,7 @@ BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_out_of_range)
{
string sourceCode = R"(
contract C {
function dyn(uint x) public returns (bytes a) {
function dyn(uint x) public returns (bytes memory a) {
assembly {
mstore(0, 0x20)
mstore(0x20, 0x21)

View File

@ -417,7 +417,7 @@ BOOST_AUTO_TEST_CASE(structs)
struct T { uint64[2] x; }
S s;
event e(uint16, S);
function f() public returns (uint, S) {
function f() public returns (uint, S memory) {
uint16 x = 7;
s.a = 8;
s.b = 9;
@ -454,7 +454,7 @@ BOOST_AUTO_TEST_CASE(structs2)
enum E {A, B, C}
struct T { uint x; E e; uint8 y; }
struct S { C c; T[] t;}
function f() public returns (uint a, S[2] s1, S[] s2, uint b) {
function f() public returns (uint a, S[2] memory s1, S[] memory s2, uint b) {
a = 7;
b = 8;
s1[0].c = this;

View File

@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(complex_import)
CompilerStack c;
c.addSource("a", "contract A {} contract B {} contract C { struct S { uint a; } } pragma solidity >=0.0;");
c.addSource("b", "import \"a\" as x; import {B as b, C as c, C} from \"a\"; "
"contract D is b { function f(c.S var1, x.C.S var2, C.S var3) internal {} } pragma solidity >=0.0;");
"contract D is b { function f(c.S memory var1, x.C.S memory var2, C.S memory var3) internal {} } pragma solidity >=0.0;");
c.setEVMVersion(dev::test::Options::get().evmVersion());
BOOST_CHECK(c.compile());
}

View File

@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(warn_on_struct)
pragma experimental ABIEncoderV2;
contract C {
struct A { uint a; uint b; }
function f() public pure returns (A) {
function f() public pure returns (A memory) {
return A({ a: 1, b: 2 });
}
}

View File

@ -756,7 +756,7 @@ BOOST_AUTO_TEST_CASE(library_function)
char const* sourceCode = R"(
library test {
struct StructType { uint a; }
function f(StructType storage b, uint[] storage c, test d) public returns (uint[] e, StructType storage f) {}
function f(StructType storage b, uint[] storage c, test d) public returns (uint[] memory e, StructType storage f) {}
}
)";
@ -891,7 +891,7 @@ BOOST_AUTO_TEST_CASE(return_structs)
contract C {
struct S { uint a; T[] sub; }
struct T { uint[2] x; }
function f() public returns (uint x, S s) {
function f() public returns (uint x, S memory s) {
}
}
)";
@ -940,7 +940,7 @@ BOOST_AUTO_TEST_CASE(return_structs_with_contracts)
pragma experimental ABIEncoderV2;
contract C {
struct S { C[] x; C y; }
function f() public returns (S s, C c) {
function f() public returns (S memory s, C c) {
}
}
)";
@ -1042,7 +1042,7 @@ BOOST_AUTO_TEST_CASE(structs_in_libraries)
struct S { uint a; T[] sub; bytes b; }
struct T { uint[2] x; }
function f(L.S storage s) {}
function g(L.S s) {}
function g(L.S memory s) {}
}
)";
char const* interface = R"(

File diff suppressed because it is too large Load Diff

View File

@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(dynamic_return_types_not_possible)
{
char const* sourceCode = R"(
contract C {
function f(uint) public returns (string);
function f(uint) public returns (string memory);
function g() public {
string memory x = this.f(2);
// we can assign to x but it is not usable.

View File

@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(sequence_number_for_calls)
// to storage), so the sequence number should be incremented.
char const* sourceCode = R"(
contract test {
function f(string a, string b) public returns (bool) { return sha256(bytes(a)) == sha256(bytes(b)); }
function f(string memory a, string memory b) public returns (bool) { return sha256(bytes(a)) == sha256(bytes(b)); }
}
)";
compileBothVersions(sourceCode);
@ -619,7 +619,7 @@ BOOST_AUTO_TEST_CASE(optimise_multi_stores)
struct S { uint16 a; uint16 b; uint16[3] c; uint[] dyn; }
uint padding;
S[] s;
function f() public returns (uint16, uint16, uint16[3], uint) {
function f() public returns (uint16, uint16, uint16[3] memory, uint) {
uint16[3] memory c;
c[0] = 7;
c[1] = 8;