aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCJentzsch <jentzsch.software@gmail.com>2014-12-13 04:02:41 +0800
committerCJentzsch <jentzsch.software@gmail.com>2014-12-13 04:02:41 +0800
commitbdb3a6d9465a71dc7f73c7f538bdbef54388f6e6 (patch)
treea21841707593dd030e25f1b1781c92f098a79a1e
parent2a4e8228d7e912febdd6c4570a9143ea9bed11d9 (diff)
parent7d8ec26141546cd965a1833348e44cdaecd57c96 (diff)
downloaddexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.tar
dexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.tar.gz
dexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.tar.bz2
dexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.tar.lz
dexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.tar.xz
dexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.tar.zst
dexon-solidity-bdb3a6d9465a71dc7f73c7f538bdbef54388f6e6.zip
Merge remote-tracking branch 'upstream/develop' into fixTest
Conflicts: test/trie.cpp
-rw-r--r--createRandomTest.cpp8
-rw-r--r--jsonrpc.cpp2
-rw-r--r--solidityCompiler.cpp14
-rw-r--r--solidityEndToEndTest.cpp70
-rw-r--r--solidityNameAndTypeResolution.cpp8
-rw-r--r--solidityOptimizerTest.cpp19
-rw-r--r--trie.cpp17
-rw-r--r--vm.cpp8
-rw-r--r--whisperTopic.cpp5
9 files changed, 120 insertions, 31 deletions
diff --git a/createRandomTest.cpp b/createRandomTest.cpp
index caeeb6b6..a1168845 100644
--- a/createRandomTest.cpp
+++ b/createRandomTest.cpp
@@ -32,7 +32,7 @@
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
#include <libevmcore/Instruction.h>
-#include <libevm/VM.h>
+#include <libevm/VMFactory.h>
#include "vm.h"
using namespace std;
@@ -142,14 +142,14 @@ void doMyTests(json_spirit::mValue& v)
}
bytes output;
- eth::VM vm(fev.gas);
+ auto vm = eth::VMFactory::create(fev.gas);
u256 gas;
bool vmExceptionOccured = false;
try
{
- output = vm.go(fev, fev.simpleTrace()).toBytes();
- gas = vm.gas();
+ output = vm->go(fev, fev.simpleTrace()).toBytes();
+ gas = vm->gas();
}
catch (eth::VMException const& _e)
{
diff --git a/jsonrpc.cpp b/jsonrpc.cpp
index d17c5a59..20ffc6d5 100644
--- a/jsonrpc.cpp
+++ b/jsonrpc.cpp
@@ -19,7 +19,7 @@
* @date 2014
*/
-#if ETH_JSONRPC
+#if ETH_JSONRPC && 0
#include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp
index 004740b5..eae8f314 100644
--- a/solidityCompiler.cpp
+++ b/solidityCompiler.cpp
@@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(smoke_test)
"}\n";
bytes code = compileContract(sourceCode);
- unsigned boilerplateSize = 42;
+ unsigned boilerplateSize = 40;
bytes expectation({byte(Instruction::JUMPDEST),
byte(Instruction::PUSH1), 0x0, // initialize local variable x
byte(Instruction::PUSH1), 0x2,
@@ -107,8 +107,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers)
"}\n";
bytes code = compileContract(sourceCode);
- unsigned shift = 70;
- unsigned boilerplateSize = 83;
+ unsigned shift = 68;
+ unsigned boilerplateSize = 81;
bytes expectation({byte(Instruction::JUMPDEST),
byte(Instruction::PUSH1), 0x0, // initialize return variable d
byte(Instruction::DUP3),
@@ -158,8 +158,8 @@ BOOST_AUTO_TEST_CASE(ifStatement)
"}\n";
bytes code = compileContract(sourceCode);
- unsigned shift = 29;
- unsigned boilerplateSize = 42;
+ unsigned shift = 27;
+ unsigned boilerplateSize = 40;
bytes expectation({byte(Instruction::JUMPDEST),
byte(Instruction::PUSH1), 0x0,
byte(Instruction::DUP1),
@@ -200,8 +200,8 @@ BOOST_AUTO_TEST_CASE(loops)
"}\n";
bytes code = compileContract(sourceCode);
- unsigned shift = 29;
- unsigned boilerplateSize = 42;
+ unsigned shift = 27;
+ unsigned boilerplateSize = 40;
bytes expectation({byte(Instruction::JUMPDEST),
byte(Instruction::JUMPDEST),
byte(Instruction::PUSH1), 0x1,
diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp
index 3c77492a..af8b58ba 100644
--- a/solidityEndToEndTest.cpp
+++ b/solidityEndToEndTest.cpp
@@ -363,6 +363,48 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
testSolidityAgainstCpp(0, small_signed_types_cpp);
}
+BOOST_AUTO_TEST_CASE(strings)
+{
+ char const* sourceCode = "contract test {\n"
+ " function fixed() returns(string32 ret) {\n"
+ " return \"abc\\x00\\xff__\";\n"
+ " }\n"
+ " function pipeThrough(string2 small, bool one) returns(string16 large, bool oneRet) {\n"
+ " oneRet = one;\n"
+ " large = small;\n"
+ " }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+ bytes expectation(32, 0);
+ expectation[0] = byte('a');
+ expectation[1] = byte('b');
+ expectation[2] = byte('c');
+ expectation[3] = byte(0);
+ expectation[4] = byte(0xff);
+ expectation[5] = byte('_');
+ expectation[6] = byte('_');
+ BOOST_CHECK(callContractFunction(0, bytes()) == expectation);
+ expectation = bytes(17, 0);
+ expectation[0] = 0;
+ expectation[1] = 2;
+ expectation[16] = 1;
+ BOOST_CHECK(callContractFunction(1, bytes({0x00, 0x02, 0x01})) == expectation);
+}
+
+BOOST_AUTO_TEST_CASE(empty_string_on_stack)
+{
+ char const* sourceCode = "contract test {\n"
+ " function run(string0 empty, uint8 inp) returns(uint16 a, string0 b, string4 c) {\n"
+ " var x = \"abc\";\n"
+ " var y = \"\";\n"
+ " var z = inp;\n"
+ " a = z; b = y; c = x;"
+ " }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction(0, bytes({0x02})) == bytes({0x00, 0x02, 'a', 'b', 'c', 0x00}));
+}
+
BOOST_AUTO_TEST_CASE(state_smoke_test)
{
char const* sourceCode = "contract test {\n"
@@ -941,6 +983,34 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars)
BOOST_REQUIRE(callContractFunction(0, a, b) == toBigEndian(a * b + 9));
}
+BOOST_AUTO_TEST_CASE(strings_in_calls)
+{
+ char const* sourceCode = R"(
+ contract Helper {
+ function invoke(string3 x, bool stop) returns (string4 ret) {
+ return x;
+ }
+ }
+ contract Main {
+ Helper h;
+ function callHelper(string2 x, bool stop) returns (string5 ret) {
+ return h.invoke(x, stop);
+ }
+ function getHelper() returns (address addr) {
+ return address(h);
+ }
+ function setHelper(address addr) {
+ h = Helper(addr);
+ }
+ })";
+ compileAndRun(sourceCode, 0, "Helper");
+ u160 const helperAddress = m_contractAddress;
+ compileAndRun(sourceCode, 0, "Main");
+ BOOST_REQUIRE(callContractFunction(2, helperAddress) == bytes());
+ BOOST_REQUIRE(callContractFunction(1, helperAddress) == toBigEndian(helperAddress));
+ BOOST_CHECK(callContractFunction(0, bytes({0, 'a', 1})) == bytes({0, 'a', 0, 0, 0}));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/solidityNameAndTypeResolution.cpp b/solidityNameAndTypeResolution.cpp
index 78397229..03eaebb3 100644
--- a/solidityNameAndTypeResolution.cpp
+++ b/solidityNameAndTypeResolution.cpp
@@ -226,6 +226,14 @@ BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion)
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
}
+BOOST_AUTO_TEST_CASE(large_string_literal)
+{
+ char const* text = "contract test {\n"
+ " function f() { var x = \"123456789012345678901234567890123\"; }"
+ "}\n";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
BOOST_AUTO_TEST_CASE(balance)
{
char const* text = "contract test {\n"
diff --git a/solidityOptimizerTest.cpp b/solidityOptimizerTest.cpp
index f8d3b552..388e0579 100644
--- a/solidityOptimizerTest.cpp
+++ b/solidityOptimizerTest.cpp
@@ -48,7 +48,7 @@ public:
m_optimize = true;
bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName);
int sizeDiff = nonOptimizedBytecode.size() - optimizedBytecode.size();
- BOOST_CHECK_MESSAGE(sizeDiff >= _expectedSizeDecrease, "Bytecode did only shrink by "
+ BOOST_CHECK_MESSAGE(sizeDiff == int(_expectedSizeDecrease), "Bytecode did only shrink by "
+ boost::lexical_cast<string>(sizeDiff) + " bytes, expected: "
+ boost::lexical_cast<string>(_expectedSizeDecrease));
m_optimizedContract = m_contractAddress;
@@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(invariants)
return (((a + (1 - 1)) ^ 0) | 0) & (uint(0) - 1);
}
})";
- compileBothVersions(19, sourceCode);
+ compileBothVersions(28, sourceCode);
compareVersions(0, u256(0x12334664));
}
@@ -124,6 +124,21 @@ BOOST_AUTO_TEST_CASE(unused_expressions)
compareVersions(0);
}
+BOOST_AUTO_TEST_CASE(constant_folding_both_sides)
+{
+ // if constants involving the same associative and commutative operator are applied from both
+ // sides, the operator should be applied only once, because the expression compiler
+ // (even in non-optimized mode) pushes literals as late as possible
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint x) returns (uint y) {
+ return 98 ^ (7 * ((1 | (x | 1000)) * 40) ^ 102);
+ }
+ })";
+ compileBothVersions(31, sourceCode);
+ compareVersions(0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/trie.cpp b/trie.cpp
index b300de33..3f072a6d 100644
--- a/trie.cpp
+++ b/trie.cpp
@@ -59,22 +59,17 @@ BOOST_AUTO_TEST_CASE(trie_tests)
cnote << "Testing Trie...";
js::mValue v;
- string s = asString(contents(testPath + "/trietest.json"));
- BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
+ string s = asString(contents(testPath + "/trieanyorder.json"));
+ BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trieanyorder.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
for (auto& i: v.get_obj())
{
cnote << i.first;
js::mObject& o = i.second.get_obj();
vector<pair<string, string>> ss;
- for (auto& i: o["in"].get_array())
+ for (auto i: o["in"].get_obj())
{
- vector<string> values;
- for (auto& s: i.get_array())
- values.push_back(s.get_str());
-
- assert(values.size() == 2);
- ss.push_back(make_pair(values[0], values[1]));
+ ss.push_back(make_pair(i.first, i.second.get_str()));
if (!ss.back().first.find("0x"))
ss.back().first = asString(fromHex(ss.back().first.substr(2)));
if (!ss.back().second.find("0x"))
@@ -82,6 +77,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
}
for (unsigned j = 0; j < min(1000u, dev::test::fac((unsigned)ss.size())); ++j)
{
+ next_permutation(ss.begin(), ss.end());
MemoryDB m;
GenericTrieDB<MemoryDB> t(&m);
t.init();
@@ -93,13 +89,10 @@ BOOST_AUTO_TEST_CASE(trie_tests)
}
BOOST_REQUIRE(!o["root"].is_null());
BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray()));
- if (o["root"].get_str() != "0x" + toHex(t.root().asArray()))
- break;
}
}
}
-
inline h256 stringMapHash256(StringMap const& _s)
{
return hash256(_s);
diff --git a/vm.cpp b/vm.cpp
index 8fe378ce..d8e85383 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -21,6 +21,8 @@
*/
#include <boost/filesystem.hpp>
+#include <libethereum/Executive.h>
+#include <libevm/VMFactory.h>
#include "vm.h"
using namespace std;
@@ -298,14 +300,14 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
}
bytes output;
- VM vm(fev.gas);
+ auto vm = eth::VMFactory::create(fev.gas);
u256 gas;
bool vmExceptionOccured = false;
try
{
- output = vm.go(fev, fev.simpleTrace()).toBytes();
- gas = vm.gas();
+ output = vm->go(fev, fev.simpleTrace()).toBytes();
+ gas = vm->gas();
}
catch (VMException const& _e)
{
diff --git a/whisperTopic.cpp b/whisperTopic.cpp
index 941c790e..c5e59332 100644
--- a/whisperTopic.cpp
+++ b/whisperTopic.cpp
@@ -32,7 +32,8 @@ BOOST_AUTO_TEST_SUITE(whisper)
BOOST_AUTO_TEST_CASE(topic)
{
- g_logVerbosity = 20;
+ cnote << "Testing Whisper...";
+// g_logVerbosity = 0;
bool started = false;
unsigned result = 0;
@@ -80,7 +81,7 @@ BOOST_AUTO_TEST_CASE(topic)
}
listener.join();
- g_logVerbosity = 0;
+// g_logVerbosity = 0;
BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81);
}