aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsubtly <subtly@users.noreply.github.com>2014-10-28 23:23:34 +0800
committersubtly <subtly@users.noreply.github.com>2014-10-28 23:23:34 +0800
commit0466f758ddd5a3645fa066ad12bd124c46f2081f (patch)
treed86977548403156e4f1df0d6ac7c6fe327f682c5
parentfb5248b27c242ecda40ff3a462c74f45e3290067 (diff)
parentf59a8f58240f333a24c7f654171cdf7083d21aca (diff)
downloaddexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.tar
dexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.tar.gz
dexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.tar.bz2
dexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.tar.lz
dexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.tar.xz
dexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.tar.zst
dexon-solidity-0466f758ddd5a3645fa066ad12bd124c46f2081f.zip
Merge branch 'develop' into crypto
-rw-r--r--genesis.cpp13
-rw-r--r--hexPrefix.cpp13
-rw-r--r--main.cpp2
-rw-r--r--rlp.cpp13
-rw-r--r--trie.cpp13
-rw-r--r--vm.cpp38
-rw-r--r--vm.h36
7 files changed, 116 insertions, 12 deletions
diff --git a/genesis.cpp b/genesis.cpp
index 5f17d276..16ffb185 100644
--- a/genesis.cpp
+++ b/genesis.cpp
@@ -35,9 +35,20 @@ namespace js = json_spirit;
BOOST_AUTO_TEST_CASE(genesis_tests)
{
+ const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
+ string testPath;
+
+ if (ptestPath == NULL)
+ {
+ cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
+ testPath = "../../../tests";
+ }
+ else
+ testPath = ptestPath;
+
cnote << "Testing Genesis block...";
js::mValue v;
- string s = asString(contents("../../../tests/genesishashestest.json"));
+ string s = asString(contents(testPath + "/genesishashestest.json"));
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'genesishashestest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
diff --git a/hexPrefix.cpp b/hexPrefix.cpp
index fb2fbc82..99207ab9 100644
--- a/hexPrefix.cpp
+++ b/hexPrefix.cpp
@@ -33,9 +33,20 @@ namespace js = json_spirit;
BOOST_AUTO_TEST_CASE(hexPrefix_test)
{
+ const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
+ string testPath;
+
+ if (ptestPath == NULL)
+ {
+ cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
+ testPath = "../../../tests";
+ }
+ else
+ testPath = ptestPath;
+
cnote << "Testing Hex-Prefix-Encode...";
js::mValue v;
- string s = asString(contents("../../../tests/hexencodetest.json"));
+ string s = asString(contents(testPath + "/hexencodetest.json"));
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content from 'hexencodetest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
for (auto& i: v.get_obj())
diff --git a/main.cpp b/main.cpp
index ef009e29..3f8860d7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -44,7 +44,7 @@ using namespace dev::eth;
BOOST_AUTO_TEST_CASE(basic_tests)
{
/* RLPStream s;
- BlockInfo::genesis().fillStream(s, false);
+ BlockInfo::genesis().streamRLP(s, false);
std::cout << RLP(s.out()) << std::endl;
std::cout << toHex(s.out()) << std::endl;
std::cout << sha3(s.out()) << std::endl;*/
diff --git a/rlp.cpp b/rlp.cpp
index 69360ad6..608a8499 100644
--- a/rlp.cpp
+++ b/rlp.cpp
@@ -61,7 +61,18 @@ namespace dev
static void getRLPTestCases(js::mValue& v)
{
- string s = asString(contents("../../../tests/rlptest.json"));
+ const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
+ string testPath;
+
+ if (ptestPath == NULL)
+ {
+ cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
+ testPath = "../../../tests";
+ }
+ else
+ testPath = ptestPath;
+
+ string s = asString(contents(testPath + "/rlptest.json"));
BOOST_REQUIRE_MESSAGE( s.length() > 0,
"Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
diff --git a/trie.cpp b/trie.cpp
index 899eb1f6..f8ebd10c 100644
--- a/trie.cpp
+++ b/trie.cpp
@@ -49,9 +49,20 @@ static unsigned fac(unsigned _i)
BOOST_AUTO_TEST_CASE(trie_tests)
{
+ const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
+ string testPath;
+
+ if (ptestPath == NULL)
+ {
+ cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
+ testPath = "../../../tests";
+ }
+ else
+ testPath = ptestPath;
+
cnote << "Testing Trie...";
js::mValue v;
- string s = asString(contents("../../../tests/trietest.json"));
+ 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?");
js::read_string(s, v);
for (auto& i: v.get_obj())
diff --git a/vm.cpp b/vm.cpp
index fe486304..40a0a862 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -20,9 +20,8 @@
* vm test functions.
*/
-#include "vm.h"
-#include <libdevcore/CommonIO.h>
#include <boost/filesystem/path.hpp>
+#include "vm.h"
//#define FILL_TESTS
@@ -131,7 +130,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
m_ms.internal.resize(m_ms.internal.size() + 1);
- auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), OnOpFunc(), 1);
+ auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), simpleTrace<ExtVM>(), 1);
if (!m_ms.internal.back().from)
m_ms.internal.pop_back();
@@ -487,8 +486,6 @@ h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _end
return _newAddress;
}
-
-
namespace dev { namespace test {
void doTests(json_spirit::mValue& v, bool _fillin)
@@ -520,7 +517,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
VM vm(fev.gas);
try
{
- output = vm.go(fev).toVector();
+ output = vm.go(fev, fev.simpleTrace<FakeExtVM>()).toVector();
}
catch (Exception const& _e)
{
@@ -756,3 +753,32 @@ BOOST_AUTO_TEST_CASE(vmSystemOperationsTest)
{
dev::test::executeTests("vmSystemOperationsTest");
}
+
+BOOST_AUTO_TEST_CASE(userDefinedFile)
+{
+
+ if (boost::unit_test::framework::master_test_suite().argc == 2)
+ {
+ string filename = boost::unit_test::framework::master_test_suite().argv[1];
+ int currentVerbosity = g_logVerbosity;
+ g_logVerbosity = 12;
+ try
+ {
+ cnote << "Testing VM..." << "user defined test";
+ json_spirit::mValue v;
+ string s = asString(contents(filename));
+ BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
+ json_spirit::read_string(s, v);
+ dev::test::doTests(v, false);
+ }
+ catch (Exception const& _e)
+ {
+ BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e));
+ }
+ catch (std::exception const& _e)
+ {
+ BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
+ }
+ g_logVerbosity = currentVerbosity;
+ }
+}
diff --git a/vm.h b/vm.h
index 58ff58cd..f3aae694 100644
--- a/vm.h
+++ b/vm.h
@@ -28,6 +28,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
#include <boost/test/unit_test.hpp>
#include "JsonSpiritHeaders.h"
#include <libdevcore/Log.h>
+#include <libdevcore/CommonIO.h>
#include <libevmface/Instruction.h>
#include <libevm/ExtVMFace.h>
#include <libevm/VM.h>
@@ -44,7 +45,7 @@ class FakeState: public eth::State
{
public:
/// Execute a contract-creation transaction.
- h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, eth::SubState* o_suicides = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0);
+ h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, eth::SubState* o_sub = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0);
};
class FakeExtVM: public eth::ExtVMFace
@@ -80,6 +81,11 @@ public:
json_spirit::mArray exportCallCreates();
void importCallCreates(json_spirit::mArray& _callcreates);
+ template<typename ExtVMType>
+ eth::OnOpFunc simpleTrace();
+
+ FakeState state() const { return m_s; }
+
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
eth::Transactions callcreates;
bytes thisTxData;
@@ -91,4 +97,32 @@ private:
eth::Manifest m_ms;
};
+template<typename ExtVMType>
+eth::OnOpFunc FakeExtVM::simpleTrace()
+{
+ return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt)
+ {
+ ExtVMType const& ext = *(ExtVMType const*)voidExt;
+ eth::VM& vm = *(eth::VM*)voidVM;
+
+ std::ostringstream o;
+ o << std::endl << " STACK" << std::endl;
+ for (auto i: vm.stack())
+ o << (h256)i << std::endl;
+ o << " MEMORY" << std::endl << memDump(vm.memory());
+ o << " STORAGE" << std::endl;
+ for (auto const& i: ext.state().storage(ext.myAddress))
+ o << std::showbase << std::hex << i.first << ": " << i.second << std::endl;
+ dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str();
+ dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]";
+
+ if (eth::VMTraceChannel::verbosity <= g_logVerbosity)
+ {
+ std::ofstream f;
+ f.open("./vmtrace.log", std::ofstream::app);
+ f << o.str();
+ f << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32";
+ }
+ };
+}
} } // Namespace Close