aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt9
-rw-r--r--CMakeLists.txt.user181
-rw-r--r--main.cpp139
3 files changed, 329 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..336ccd15
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_policy(SET CMP0015 NEW)
+
+aux_source_directory(. SRC_LIST)
+include_directories(../libethereum)
+link_directories(../libethereum)
+
+add_executable(testeth ${SRC_LIST})
+
+target_link_libraries(testeth libethereum)
diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user
new file mode 100644
index 00000000..6948bb79
--- /dev/null
+++ b/CMakeLists.txt.user
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE QtCreatorProject>
+<!-- Written by QtCreator 2.7.82, 2014-01-03T01:15:25. -->
+<qtcreator>
+ <data>
+ <variable>ProjectExplorer.Project.ActiveTarget</variable>
+ <value type="int">0</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.EditorSettings</variable>
+ <valuemap type="QVariantMap">
+ <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
+ <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
+ <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
+ <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
+ <value type="QString" key="language">Cpp</value>
+ <valuemap type="QVariantMap" key="value">
+ <value type="QString" key="CurrentPreferences">CppGlobal</value>
+ </valuemap>
+ </valuemap>
+ <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
+ <value type="QString" key="language">QmlJS</value>
+ <valuemap type="QVariantMap" key="value">
+ <value type="QString" key="CurrentPreferences">QmlJSGlobal</value>
+ </valuemap>
+ </valuemap>
+ <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
+ <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
+ <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
+ <value type="int" key="EditorConfiguration.IndentSize">4</value>
+ <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
+ <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
+ <value type="int" key="EditorConfiguration.PaddingMode">1</value>
+ <value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
+ <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
+ <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
+ <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
+ <value type="int" key="EditorConfiguration.TabSize">8</value>
+ <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
+ <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
+ <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
+ <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
+ <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
+ <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.PluginSettings</variable>
+ <valuemap type="QVariantMap"/>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Target.0</variable>
+ <valuemap type="QVariantMap">
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{0d0560e6-4479-432d-8a2c-23989b161c58}</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
+ <value type="QString" key="CMakeProjectManager.CMakeBuildConfiguration.BuildDirectory">/home/gav/Projects/cpp-ethereum-build</value>
+ <value type="bool" key="CMakeProjectManager.CMakeBuildConfiguration.UseNinja">false</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+ <value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
+ <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
+ <value type="QString">all</value>
+ </valuelist>
+ <value type="bool" key="CMakeProjectManager.MakeStep.Clean">false</value>
+ <value type="bool" key="CMakeProjectManager.MakeStep.UseNinja">false</value>
+ <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
+ </valuemap>
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+ <value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments">clean</value>
+ <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"/>
+ <value type="bool" key="CMakeProjectManager.MakeStep.Clean">true</value>
+ <value type="bool" key="CMakeProjectManager.MakeStep.UseNinja">false</value>
+ <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
+ <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
+ <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">all</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
+ <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
+ <value type="bool" key="Analyzer.Project.UseGlobal">true</value>
+ <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
+ <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
+ <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
+ <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
+ <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
+ <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
+ <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
+ <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
+ <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
+ <value type="int">0</value>
+ <value type="int">1</value>
+ <value type="int">2</value>
+ <value type="int">3</value>
+ <value type="int">4</value>
+ <value type="int">5</value>
+ <value type="int">6</value>
+ <value type="int">7</value>
+ <value type="int">8</value>
+ <value type="int">9</value>
+ <value type="int">10</value>
+ <value type="int">11</value>
+ <value type="int">12</value>
+ <value type="int">13</value>
+ <value type="int">14</value>
+ </valuelist>
+ <value type="QString" key="CMakeProjectManager.CMakeRunConfiguation.Title">ethereum</value>
+ <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.Arguments"></value>
+ <value type="bool" key="CMakeProjectManager.CMakeRunConfiguration.UseTerminal">false</value>
+ <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"></value>
+ <value type="int" key="PE.EnvironmentAspect.Base">2</value>
+ <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">ethereum</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.ethereum</value>
+ <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
+ <value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
+ <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
+ <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
+ <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
+ </valuemap>
+ <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.TargetCount</variable>
+ <value type="int">1</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
+ <value type="QByteArray">{2115e592-0090-43c3-97c5-38078516e87a}</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
+ <value type="int">12</value>
+ </data>
+</qtcreator>
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 00000000..e344a209
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,139 @@
+#include <random>
+#include "Common.h"
+#include "RLP.h"
+#include "PatriciaTree.h"
+#include "VirtualMachine.h"
+using namespace std;
+using namespace eth;
+
+std::string randomWord()
+{
+ static std::mt19937_64 s_eng(0);
+ std::string ret(uniform_int_distribution<int>(4, 10)(s_eng), ' ');
+ char const n[] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
+ uniform_int_distribution<int> d(0, sizeof(n) - 2);
+ for (char& c: ret)
+ c = n[d(s_eng)];
+ return ret;
+}
+
+int main()
+{
+ {
+ Trie t;
+ t.insert("dog", "puppy");
+ assert(t.sha256() == hash256({{"dog", "puppy"}}));
+ assert(t.at("dog") == "puppy");
+ t.insert("doe", "reindeer");
+ assert(t.sha256() == hash256({{"dog", "puppy"}, {"doe", "reindeer"}}));
+ assert(t.at("doe") == "reindeer");
+ assert(t.at("dog") == "puppy");
+ t.insert("dogglesworth", "cat");
+ assert(t.sha256() == hash256({{"doe", "reindeer"}, {"dog", "puppy"}, {"dogglesworth", "cat"}}));
+ assert(t.at("doe") == "reindeer");
+ assert(t.at("dog") == "puppy");
+ assert(t.at("dogglesworth") == "cat");
+ t.remove("dogglesworth");
+ t.remove("doe");
+ assert(t.at("doe").empty());
+ assert(t.at("dogglesworth").empty());
+ assert(t.at("dog") == "puppy");
+ assert(t.sha256() == hash256({{"dog", "puppy"}}));
+ t.insert("horse", "stallion");
+ t.insert("do", "verb");
+ t.insert("doge", "coin");
+ assert(t.sha256() == hash256({{"dog", "puppy"}, {"horse", "stallion"}, {"do", "verb"}, {"doge", "coin"}}));
+ assert(t.at("doge") == "coin");
+ assert(t.at("do") == "verb");
+ assert(t.at("horse") == "stallion");
+ assert(t.at("dog") == "puppy");
+ t.remove("horse");
+ t.remove("do");
+ t.remove("doge");
+ assert(t.sha256() == hash256({{"dog", "puppy"}}));
+ assert(t.at("dog") == "puppy");
+ t.remove("dog");
+
+ for (int a = 0; a < 20; ++a)
+ {
+ StringMap m;
+ for (int i = 0; i < 20; ++i)
+ {
+ auto k = randomWord();
+ auto v = toString(i);
+ m.insert(make_pair(k, v));
+ t.insert(k, v);
+ assert(hash256(m) == t.sha256());
+ }
+ while (!m.empty())
+ {
+ auto k = m.begin()->first;
+ t.remove(k);
+ m.erase(k);
+ assert(hash256(m) == t.sha256());
+ }
+ }
+ }
+
+ // int of value 15
+ assert(RLP("\x0f") == 15);
+ assert(rlp(15) == "\x0f");
+
+ // 3-character string
+ assert(RLP("\x43""dog") == "dog");
+ assert(rlp("dog") == "\x43""dog");
+
+ // 2-item list
+ RLP twoItemList("\x82\x0f\x43""dog");
+ assert(twoItemList.itemCount() == 2 && twoItemList[0] == 15 && twoItemList[1] == "dog");
+ assert(rlpList(15, "dog") == "\x82\x0f\x43""dog");
+
+ // 1-byte (8-bit) int
+ assert(RLP("\x18\x45") == 69);
+ assert(rlp(69) == "\x18\x45");
+
+ // 2-byte (16-bit) int
+ assert(RLP("\x19\x01\x01") == 257);
+ assert(rlp(257) == "\x19\x01\x01");
+
+ // 32-byte (256-bit) int
+ assert(RLP("\x37\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") == bigint("0x100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"));
+ assert(rlp(bigint("0x100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")) == "\x37\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f");
+
+ // 33-byte (264-bit) int
+ assert(RLP("\x38\x21\x20\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") == bigint("0x20100102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"));
+ assert(rlp(bigint("0x20100102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")) == "\x38\x21\x20\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f");
+
+ // 56-character string.
+ assert(RLP("\x78\x38""Lorem ipsum dolor sit amet, consectetur adipisicing elit") == "Lorem ipsum dolor sit amet, consectetur adipisicing elit");
+ assert(rlp("Lorem ipsum dolor sit amet, consectetur adipisicing elit") == "\x78\x38""Lorem ipsum dolor sit amet, consectetur adipisicing elit");
+
+ /*
+ * Hex-prefix Notation. First nibble has flags: oddness = 2^0 & termination = 2^1
+ * [0,0,1,2,3,4,5] 0x10012345
+ * [0,1,2,3,4,5] 0x00012345
+ * [1,2,3,4,5] 0x112345
+ * [0,0,1,2,3,4] 0x00001234
+ * [0,1,2,3,4] 0x101234
+ * [1,2,3,4] 0x001234
+ * [0,0,1,2,3,4,5,T] 0x30012345
+ * [0,0,1,2,3,4,T] 0x20001234
+ * [0,1,2,3,4,5,T] 0x20012345
+ * [1,2,3,4,5,T] 0x312345
+ * [1,2,3,4,T] 0x201234
+ */
+ assert(asHex(hexPrefixEncode({0, 0, 1, 2, 3, 4, 5}, false)) == "10012345");
+ assert(asHex(hexPrefixEncode({0, 1, 2, 3, 4, 5}, false)) == "00012345");
+ assert(asHex(hexPrefixEncode({1, 2, 3, 4, 5}, false)) == "112345");
+ assert(asHex(hexPrefixEncode({0, 0, 1, 2, 3, 4}, false)) == "00001234");
+ assert(asHex(hexPrefixEncode({0, 1, 2, 3, 4}, false)) == "101234");
+ assert(asHex(hexPrefixEncode({1, 2, 3, 4}, false)) == "001234");
+ assert(asHex(hexPrefixEncode({0, 0, 1, 2, 3, 4, 5}, true)) == "30012345");
+ assert(asHex(hexPrefixEncode({0, 0, 1, 2, 3, 4}, true)) == "20001234");
+ assert(asHex(hexPrefixEncode({0, 1, 2, 3, 4, 5}, true)) == "20012345");
+ assert(asHex(hexPrefixEncode({1, 2, 3, 4, 5}, true)) == "312345");
+ assert(asHex(hexPrefixEncode({1, 2, 3, 4}, true)) == "201234");
+
+ return 0;
+}
+