mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'upstream/develop' into moreTests
This commit is contained in:
commit
bbcba66443
@ -754,6 +754,10 @@ Options::Options()
|
||||
checkState = true;
|
||||
else if (arg == "--wallet")
|
||||
wallet = true;
|
||||
else if (arg == "--nonetwork")
|
||||
nonetwork = true;
|
||||
else if (arg == "--nodag")
|
||||
nodag = true;
|
||||
else if (arg == "--all")
|
||||
{
|
||||
performance = true;
|
||||
@ -761,7 +765,7 @@ Options::Options()
|
||||
memory = true;
|
||||
inputLimits = true;
|
||||
bigData = true;
|
||||
wallet= true;
|
||||
wallet = true;
|
||||
}
|
||||
else if (arg == "--singletest" && i + 1 < argc)
|
||||
{
|
||||
|
@ -223,6 +223,8 @@ public:
|
||||
bool inputLimits = false;
|
||||
bool bigData = false;
|
||||
bool wallet = false;
|
||||
bool nonetwork = false;
|
||||
bool nodag = false;
|
||||
/// @}
|
||||
|
||||
/// Get reference to options
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <thread>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <libdevcrypto/Common.h>
|
||||
#include <libtestutils/Common.h>
|
||||
#include <libtestutils/BlockChainLoader.h>
|
||||
#include <libtestutils/FixedClient.h>
|
||||
@ -116,3 +117,13 @@ void ParallelClientBaseFixture::enumerateClients(std::function<void(Json::Value
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
MoveNonceToTempDir::MoveNonceToTempDir()
|
||||
{
|
||||
crypto::Nonce::setSeedFilePath(m_dir.path() + "/seed");
|
||||
}
|
||||
|
||||
MoveNonceToTempDir::~MoveNonceToTempDir()
|
||||
{
|
||||
crypto::Nonce::reset();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
#include <libdevcore/TransientDirectory.h>
|
||||
#include <libethereum/BlockChain.h>
|
||||
#include <libethereum/ClientBase.h>
|
||||
|
||||
@ -78,5 +79,13 @@ struct JsonRpcFixture: public ClientBaseFixture
|
||||
|
||||
};
|
||||
|
||||
struct MoveNonceToTempDir
|
||||
{
|
||||
MoveNonceToTempDir();
|
||||
~MoveNonceToTempDir();
|
||||
private:
|
||||
TransientDirectory m_dir;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1726,7 +1726,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls)
|
||||
BOOST_CHECK(callContractFunction("callHelper(bytes2,bool)", string("\0a", 2), true) == encodeArgs(string("\0a\0\0\0", 5)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(constructor_arguments)
|
||||
BOOST_AUTO_TEST_CASE(constructor_arguments_internal)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Helper {
|
||||
@ -1749,8 +1749,28 @@ BOOST_AUTO_TEST_CASE(constructor_arguments)
|
||||
function getName() returns (bytes3 ret) { return h.getName(); }
|
||||
})";
|
||||
compileAndRun(sourceCode, 0, "Main");
|
||||
BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true));
|
||||
BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc"));
|
||||
BOOST_CHECK(callContractFunction("getFlag()") == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("getName()") == encodeArgs("abc"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(constructor_arguments_external)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Main {
|
||||
bytes3 name;
|
||||
bool flag;
|
||||
|
||||
function Main(bytes3 x, bool f) {
|
||||
name = x;
|
||||
flag = f;
|
||||
}
|
||||
function getName() returns (bytes3 ret) { return name; }
|
||||
function getFlag() returns (bool ret) { return flag; }
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "Main", encodeArgs("abc", true));
|
||||
BOOST_CHECK(callContractFunction("getFlag()") == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("getName()") == encodeArgs("abc"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(functions_called_by_constructor)
|
||||
@ -4166,7 +4186,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund)
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty());
|
||||
BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A").empty());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_integers_to_signed)
|
||||
@ -4243,9 +4263,9 @@ BOOST_AUTO_TEST_CASE(return_string)
|
||||
function get1() returns (string r) {
|
||||
return s;
|
||||
}
|
||||
// function get2() returns (string r) {
|
||||
// r = s;
|
||||
// }
|
||||
function get2() returns (string r) {
|
||||
r = s;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "Main");
|
||||
@ -4253,8 +4273,86 @@ BOOST_AUTO_TEST_CASE(return_string)
|
||||
bytes args = encodeArgs(u256(0x20), u256(s.length()), s);
|
||||
BOOST_REQUIRE(callContractFunction("set(string)", asString(args)) == encodeArgs());
|
||||
BOOST_CHECK(callContractFunction("get1()") == args);
|
||||
// BOOST_CHECK(callContractFunction("get2()") == args);
|
||||
// BOOST_CHECK(callContractFunction("s()") == args);
|
||||
BOOST_CHECK(callContractFunction("get2()") == args);
|
||||
BOOST_CHECK(callContractFunction("s()") == args);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(return_multiple_strings_of_various_sizes)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Main {
|
||||
string public s1;
|
||||
string public s2;
|
||||
function set(string _s1, uint x, string _s2) external returns (uint) {
|
||||
s1 = _s1;
|
||||
s2 = _s2;
|
||||
return x;
|
||||
}
|
||||
function get() returns (string r1, string r2) {
|
||||
r1 = s1;
|
||||
r2 = s2;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "Main");
|
||||
string s1(
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||
);
|
||||
string s2(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ"
|
||||
);
|
||||
vector<size_t> lengthes{0, 30, 32, 63, 64, 65, 210, 300};
|
||||
for (auto l1: lengthes)
|
||||
for (auto l2: lengthes)
|
||||
{
|
||||
bytes dyn1 = encodeArgs(u256(l1), s1.substr(0, l1));
|
||||
bytes dyn2 = encodeArgs(u256(l2), s2.substr(0, l2));
|
||||
bytes args = encodeArgs(u256(0x60), u256(l1), u256(0x60 + dyn1.size())) + dyn1 + dyn2;
|
||||
BOOST_REQUIRE(
|
||||
callContractFunction("set(string,uint256,string)", asString(args)) ==
|
||||
encodeArgs(u256(l1))
|
||||
);
|
||||
bytes result = encodeArgs(u256(0x40), u256(0x40 + dyn1.size())) + dyn1 + dyn2;
|
||||
BOOST_CHECK(callContractFunction("get()") == result);
|
||||
BOOST_CHECK(callContractFunction("s1()") == encodeArgs(0x20) + dyn1);
|
||||
BOOST_CHECK(callContractFunction("s2()") == encodeArgs(0x20) + dyn2);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(accessor_involving_strings)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Main {
|
||||
struct stringData { string a; uint b; string c; }
|
||||
mapping(uint => stringData[]) public data;
|
||||
function set(uint x, uint y, string a, uint b, string c) external returns (bool) {
|
||||
data[x].length = y + 1;
|
||||
data[x][y].a = a;
|
||||
data[x][y].b = b;
|
||||
data[x][y].c = c;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "Main");
|
||||
string s1("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||
string s2("ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ");
|
||||
bytes s1Data = encodeArgs(u256(s1.length()), s1);
|
||||
bytes s2Data = encodeArgs(u256(s2.length()), s2);
|
||||
u256 b = 765;
|
||||
u256 x = 7;
|
||||
u256 y = 123;
|
||||
bytes args = encodeArgs(x, y, u256(0xa0), b, u256(0xa0 + s1Data.size()), s1Data, s2Data);
|
||||
bytes result = encodeArgs(u256(0x60), b, u256(0x60 + s1Data.size()), s1Data, s2Data);
|
||||
BOOST_REQUIRE(callContractFunction("set(uint256,uint256,string,uint256,string)", asString(args)) == encodeArgs(true));
|
||||
BOOST_REQUIRE(callContractFunction("data(uint256,uint256)", x, y) == result);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(storage_array_ref)
|
||||
|
@ -190,6 +190,17 @@ BOOST_AUTO_TEST_CASE(struct_definition_indirectly_recursive)
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_not_really_recursive)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
struct s1 { uint a; }
|
||||
struct s2 { s1 x; s1 y; }
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
|
@ -77,13 +77,13 @@ BOOST_AUTO_TEST_CASE(storage_layout_mapping)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(storage_layout_arrays)
|
||||
{
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(1), 32).getStorageSize() == 1);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(1), 33).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(2), 31).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(7), 8).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(7), 9).getStorageSize() == 3);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(31), 9).getStorageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(1), 32).getStorageSize() == 1);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(1), 33).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(2), 31).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(7), 8).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(7), 9).getStorageSize() == 3);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(31), 9).getStorageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(DataLocation::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -42,19 +42,29 @@ class ExecutionFramework
|
||||
public:
|
||||
ExecutionFramework() { g_logVerbosity = 0; }
|
||||
|
||||
bytes const& compileAndRunWthoutCheck(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
|
||||
bytes const& compileAndRunWithoutCheck(
|
||||
std::string const& _sourceCode,
|
||||
u256 const& _value = 0,
|
||||
std::string const& _contractName = "",
|
||||
bytes const& _arguments = bytes()
|
||||
)
|
||||
{
|
||||
m_compiler.reset(false, m_addStandardSources);
|
||||
m_compiler.addSource("", _sourceCode);
|
||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
||||
bytes code = m_compiler.getBytecode(_contractName);
|
||||
sendMessage(code, true, _value);
|
||||
sendMessage(code + _arguments, true, _value);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
|
||||
bytes const& compileAndRun(
|
||||
std::string const& _sourceCode,
|
||||
u256 const& _value = 0,
|
||||
std::string const& _contractName = "",
|
||||
bytes const& _arguments = bytes()
|
||||
)
|
||||
{
|
||||
compileAndRunWthoutCheck(_sourceCode, _value, _contractName);
|
||||
compileAndRunWithoutCheck(_sourceCode, _value, _contractName, _arguments);
|
||||
BOOST_REQUIRE(!m_output.empty());
|
||||
return m_output;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user