aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaweł Bylica <pawel.bylica@imapp.pl>2014-12-05 16:24:47 +0800
committerPaweł Bylica <pawel.bylica@imapp.pl>2014-12-05 16:24:47 +0800
commit20b6b30b999447e7770b062bf71741d2ba88d1fb (patch)
treefe47f1ad89bf2802dd2c25debeb7b9ae10be0981
parent29b1964cfbcc21bb16cbeddfb2662c22813056f0 (diff)
parent3c8a45cec4a36ebd4560d7f4ee718b60680b3010 (diff)
downloaddexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.tar
dexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.tar.gz
dexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.tar.bz2
dexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.tar.lz
dexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.tar.xz
dexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.tar.zst
dexon-solidity-20b6b30b999447e7770b062bf71741d2ba88d1fb.zip
Merge branch 'develop' into develop-evmcc
Conflicts: libevm/VM.h test/createRandomTest.cpp
-rw-r--r--TestHelper.cpp42
-rw-r--r--TestHelper.h2
-rw-r--r--createRandomTest.cpp28
-rw-r--r--solidityNameAndTypeResolution.cpp30
-rw-r--r--stExampleFiller.json37
-rw-r--r--stSystemOperationsTestFiller.json12
-rw-r--r--state.cpp3
-rw-r--r--vm.cpp6
-rw-r--r--vm.h4
9 files changed, 141 insertions, 23 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index ca0394b8..1ece875e 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -72,6 +72,7 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o
if (!isFiller)
{
importState(_o["post"].get_obj(), m_statePost);
+ m_environment.sub.logs = importLog(_o["logs"].get_obj());
}
}
@@ -148,6 +149,9 @@ void ImportTest::exportTest(bytes _output, State& _statePost)
// export output
m_TestObject["out"] = "0x" + toHex(_output);
+ // export logs
+ m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
+
// export post state
json_spirit::mObject postState;
@@ -255,6 +259,44 @@ bytes importCode(json_spirit::mObject& _o)
return code;
}
+LogEntries importLog(json_spirit::mObject& _o)
+{
+ LogEntries logEntries;
+ for (auto const& l: _o)
+ {
+ json_spirit::mObject o = l.second.get_obj();
+ // cant use BOOST_REQUIRE, because this function is used outside boost test (createRandomTest)
+ assert(o.count("address") > 0);
+ assert(o.count("topics") > 0);
+ assert(o.count("data") > 0);
+ LogEntry log;
+ log.address = Address(o["address"].get_str());
+ for (auto const& t: o["topics"].get_array())
+ log.topics.push_back(h256(t.get_str()));
+ log.data = importData(o);
+ logEntries.push_back(log);
+ }
+ return logEntries;
+}
+
+json_spirit::mObject exportLog(eth::LogEntries _logs)
+{
+ json_spirit::mObject ret;
+ if (_logs.size() == 0) return ret;
+ for (LogEntry const& l: _logs)
+ {
+ json_spirit::mObject o;
+ o["address"] = toString(l.address);
+ json_spirit::mArray topics;
+ for (auto const& t: l.topics)
+ topics.push_back(toString(t));
+ o["topics"] = topics;
+ o["data"] = "0x" + toHex(l.data);
+ ret[toString(l.bloom())] = o;
+ }
+ return ret;
+}
+
void checkOutput(bytes const& _output, json_spirit::mObject& _o)
{
int j = 0;
diff --git a/TestHelper.h b/TestHelper.h
index 7a2b8da5..c5c3a083 100644
--- a/TestHelper.h
+++ b/TestHelper.h
@@ -68,6 +68,8 @@ u256 toInt(json_spirit::mValue const& _v);
byte toByte(json_spirit::mValue const& _v);
bytes importCode(json_spirit::mObject& _o);
bytes importData(json_spirit::mObject& _o);
+eth::LogEntries importLog(json_spirit::mObject& _o);
+json_spirit::mObject exportLog(eth::LogEntries _logs);
void checkOutput(bytes const& _output, json_spirit::mObject& _o);
void checkStorage(std::map<u256, u256> _expectedStore, std::map<u256, u256> _resultStore, Address _expectedAddr);
void checkLog(eth::LogEntries _resultLogs, eth::LogEntries _expectedLogs);
diff --git a/createRandomTest.cpp b/createRandomTest.cpp
index 87bb1384..1647ce81 100644
--- a/createRandomTest.cpp
+++ b/createRandomTest.cpp
@@ -31,7 +31,6 @@
#include <json_spirit/json_spirit_writer_template.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
-#include <libethereum/VMFactory.h>
#include <libevmcore/Instruction.h>
#include <libevm/VM.h>
#include "vm.h"
@@ -122,16 +121,14 @@ void doMyTests(json_spirit::mValue& v)
{
for (auto& i: v.get_obj())
{
+ cnote << i.first;
mObject& o = i.second.get_obj();
assert(o.count("env") > 0);
assert(o.count("pre") > 0);
assert(o.count("exec") > 0);
-
- auto vmObj = eth::VMFactory::create(eth::VMFactory::Interpreter);
- auto& vm = *vmObj;
- test::FakeExtVM fev;
+ dev::test::FakeExtVM fev;
fev.importEnv(o["env"].get_obj());
fev.importState(o["pre"].get_obj());
@@ -144,17 +141,20 @@ void doMyTests(json_spirit::mValue& v)
fev.code = fev.thisTxCode;
}
- vm.reset(fev.gas);
bytes output;
+ eth::VM vm(fev.gas);
+
u256 gas;
+ bool vmExceptionOccured = false;
try
{
- output = vm.go(fev).toBytes();
+ output = vm.go(fev, fev.simpleTrace()).toBytes();
+ gas = vm.gas();
}
catch (eth::VMException const& _e)
{
cnote << "VM did throw an exception: " << diagnostic_information(_e);
- gas = 0;
+ vmExceptionOccured = true;
}
catch (Exception const& _e)
{
@@ -183,9 +183,13 @@ void doMyTests(json_spirit::mValue& v)
o["env"] = mValue(fev.exportEnv());
o["exec"] = mValue(fev.exportExec());
- o["post"] = mValue(fev.exportState());
- o["callcreates"] = fev.exportCallCreates();
- o["out"] = "0x" + toHex(output);
- fev.push(o, "gas", gas);
+ if (!vmExceptionOccured)
+ {
+ o["post"] = mValue(fev.exportState());
+ o["callcreates"] = fev.exportCallCreates();
+ o["out"] = "0x" + toHex(output);
+ fev.push(o, "gas", gas);
+ o["logs"] = mValue(test::exportLog(fev.sub.logs));
+ }
}
}
diff --git a/solidityNameAndTypeResolution.cpp b/solidityNameAndTypeResolution.cpp
index a19e7450..8804c519 100644
--- a/solidityNameAndTypeResolution.cpp
+++ b/solidityNameAndTypeResolution.cpp
@@ -244,6 +244,36 @@ BOOST_AUTO_TEST_CASE(balance_invalid)
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
}
+BOOST_AUTO_TEST_CASE(assignment_to_mapping)
+{
+ char const* text = "contract test {\n"
+ " struct str {\n"
+ " mapping(uint=>uint) map;\n"
+ " }\n"
+ " str data;"
+ " function fun() {\n"
+ " var a = data.map;\n"
+ " data.map = a;\n"
+ " }\n"
+ "}\n";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(assignment_to_struct)
+{
+ char const* text = "contract test {\n"
+ " struct str {\n"
+ " mapping(uint=>uint) map;\n"
+ " }\n"
+ " str data;"
+ " function fun() {\n"
+ " var a = data;\n"
+ " data = a;\n"
+ " }\n"
+ "}\n";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/stExampleFiller.json b/stExampleFiller.json
new file mode 100644
index 00000000..7acf695e
--- /dev/null
+++ b/stExampleFiller.json
@@ -0,0 +1,37 @@
+{
+ "add11" : {
+ "env" : {
+ "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
+ "currentDifficulty" : "256",
+ "currentGasLimit" : "1000000",
+ "currentNumber" : "0",
+ "currentTimestamp" : 1,
+ "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
+ },
+ "pre" : {
+ "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
+ "balance" : "1000000000000000000",
+ "code" : "0x6001600101600055",
+ "nonce" : "0",
+ "storage" : {
+ }
+ },
+ "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
+ "balance" : "1000000000000000000",
+ "code" : "0x",
+ "nonce" : "0",
+ "storage" : {
+ }
+ }
+ },
+ "transaction" : {
+ "data" : "",
+ "gasLimit" : "10000",
+ "gasPrice" : "1",
+ "nonce" : "0",
+ "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
+ "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
+ "value" : "100000"
+ }
+ }
+}
diff --git a/stSystemOperationsTestFiller.json b/stSystemOperationsTestFiller.json
index e6275308..edd80364 100644
--- a/stSystemOperationsTestFiller.json
+++ b/stSystemOperationsTestFiller.json
@@ -12,7 +12,7 @@
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000",
"nonce" : 0,
- "code" : "{ (MSTORE 0 0x601080600c6000396000f20060003554156009570060203560003555) [[ 0 ]] (CREATE 23 4 28) }",
+ "code" : "{ (MSTORE 0 0x601080600c6000396000f30060003554156009570060203560003555) [[ 0 ]] (CREATE 23 4 28) }",
"storage": {}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
@@ -46,7 +46,7 @@
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000",
"nonce" : 0,
- "code" : "{ (MSTORE 0 0x601080600c6000396000f20060003554156009570060203560003555) [[ 0 ]] (CREATE 1000 4 28) }",
+ "code" : "{ (MSTORE 0 0x601080600c6000396000f30060003554156009570060203560003555) [[ 0 ]] (CREATE 1000 4 28) }",
"storage": {}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
@@ -80,7 +80,7 @@
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000",
"nonce" : 0,
- "code" : "{ (MSTORE 0 0x601080600c6000396000f20060003554156009570060203560003555) [[ 0 ]] (CREATE 23 0xfffffffffff 28) }",
+ "code" : "{ (MSTORE 0 0x601080600c6000396000f30060003554156009570060203560003555) [[ 0 ]] (CREATE 23 0xfffffffffff 28) }",
"storage": {}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
@@ -114,7 +114,7 @@
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000",
"nonce" : 0,
- "code" : "{ (MSTORE 0 0x601080600c6000396000f20060003554156009570060203560003555) [[ 0 ]] (CREATE 23 4 0xfffffffffff) }",
+ "code" : "{ (MSTORE 0 0x601080600c6000396000f30060003554156009570060203560003555) [[ 0 ]] (CREATE 23 4 0xfffffffffff) }",
"storage": {}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
@@ -195,7 +195,7 @@
},
"945304eb96065b2a98b57a48a06ae28d285a71b5" : {
"balance" : "23",
- "code" : "0x6001600155603760005360026000f2",
+ "code" : "0x6001600155603760005360026000f3",
"nonce" : "0",
"storage" : {
}
@@ -321,7 +321,7 @@
},
"945304eb96065b2a98b57a48a06ae28d285a71b5" : {
"balance" : "23",
- "code" : "0x6001600155603760005360026000f2",
+ "code" : "0x6001600155603760005360026000f3",
"nonce" : "0",
"storage" : {
}
diff --git a/state.cpp b/state.cpp
index 8ee7b2e9..5fc23f14 100644
--- a/state.cpp
+++ b/state.cpp
@@ -81,6 +81,9 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
// check output
checkOutput(output, o);
+ // check logs
+ checkLog(theState.pending().size() ? theState.log(0) : LogEntries(), importer.m_environment.sub.logs);
+
// check addresses
auto expectedAddrs = importer.m_statePost.addresses();
auto resultAddrs = theState.addresses();
diff --git a/vm.cpp b/vm.cpp
index ce0fe080..354defe4 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -150,7 +150,7 @@ void FakeExtVM::importLog(mObject& _o)
LogEntry log;
log.address = Address(o["address"].get_str());
for (auto const& t: o["topics"].get_array())
- log.topics.insert(h256(t.get_str()));
+ log.topics.push_back(h256(t.get_str()));
log.data = importData(o);
sub.logs.push_back(log);
}
@@ -410,7 +410,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
o["callcreates"] = fev.exportCallCreates();
o["out"] = "0x" + toHex(output);
fev.push(o, "gas", gas);
- o["logs"] = mValue(fev.exportLog());
+ o["logs"] = mValue(exportLog(fev.sub.logs));
}
}
else
@@ -428,7 +428,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
dev::test::FakeExtVM test;
test.importState(o["post"].get_obj());
test.importCallCreates(o["callcreates"].get_array());
- test.importLog(o["logs"].get_obj());
+ test.sub.logs = importLog(o["logs"].get_obj());
checkOutput(output, o);
diff --git a/vm.h b/vm.h
index eb98aa0a..fb0346d5 100644
--- a/vm.h
+++ b/vm.h
@@ -66,14 +66,14 @@ public:
u256 doPosts();
json_spirit::mObject exportEnv();
void importEnv(json_spirit::mObject& _o);
- json_spirit::mObject exportLog();
- void importLog(json_spirit::mObject& _o);
json_spirit::mObject exportState();
void importState(json_spirit::mObject& _object);
json_spirit::mObject exportExec();
void importExec(json_spirit::mObject& _o);
json_spirit::mArray exportCallCreates();
void importCallCreates(json_spirit::mArray& _callcreates);
+ json_spirit::mObject exportLog();
+ void importLog(json_spirit::mObject& _o);
eth::OnOpFunc simpleTrace();