diff --git a/TestHelper.cpp b/TestHelper.cpp
new file mode 100644
index 000000000..e33c105b7
--- /dev/null
+++ b/TestHelper.cpp
@@ -0,0 +1,40 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see .
+*/
+/** @file TestHelper.cpp
+ * @author Marko Simovic
+ * @date 2014
+ */
+
+#include
+#include
+#include
+#include "TestHelper.h"
+
+namespace eth
+{
+
+void mine(Client& c, int numBlocks)
+{
+ auto startBlock = c.blockChain().details().number;
+
+ c.startMining();
+ while(c.blockChain().details().number < startBlock + numBlocks)
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ c.stopMining();
+}
+
+}
diff --git a/TestHelper.h b/TestHelper.h
new file mode 100644
index 000000000..5860f7fa6
--- /dev/null
+++ b/TestHelper.h
@@ -0,0 +1,29 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see .
+*/
+/** @file TestHelper.h
+ * @author Marko Simovic
+ * @date 2014
+ */
+
+#pragma once
+
+namespace eth
+{
+
+void mine(Client& c, int numBlocks);
+
+}
diff --git a/fork.cpp b/fork.cpp
new file mode 100644
index 000000000..24e7be175
--- /dev/null
+++ b/fork.cpp
@@ -0,0 +1,56 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see .
+*/
+/** @file fork.cpp
+ * @author Marko Simovic
+ * @date 2014
+ * Tests for different forking behavior
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include "TestHelper.h"
+using namespace std;
+using namespace eth;
+
+BOOST_AUTO_TEST_CASE(simple_chain_fork)
+{
+ //start a client and mine a short chain
+ Client c1("TestClient1", KeyPair::create().address(),
+ (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
+ mine(c1, 4);
+
+ //start another client and mine a longer chain
+ Client c2("TestClient2", KeyPair::create().address(),
+ (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
+ mine(c2, 6);
+
+ //connect the two clients up to resolve chain
+ c1.startNetwork(20000);
+ c2.startNetwork(21000);
+ c2.connect("127.0.0.1", 20000);
+
+ //mine an extra block to cement it
+ mine(c1, 1);
+
+ //check the balances are where they should be
+ //c1's chain should have been clobbered by c2
+ BOOST_REQUIRE(c1.state().balance(c1.address()) == 0);
+ BOOST_REQUIRE(c2.state().balance(c2.address()) > 0);
+}
diff --git a/txTest.cpp b/txTest.cpp
index 1b8fdde95..4367b9036 100644
--- a/txTest.cpp
+++ b/txTest.cpp
@@ -25,19 +25,10 @@
#include
#include
#include
+#include "TestHelper.h"
using namespace std;
using namespace eth;
-void mine(Client &c, int numBlocks)
-{
- auto startBlock = c.blockChain().details().number;
-
- c.startMining();
- while(c.blockChain().details().number < startBlock + numBlocks)
- this_thread::sleep_for(chrono::milliseconds(1000));
- c.stopMining();
-}
-
BOOST_AUTO_TEST_CASE(mine_and_send_to_peer)
{
KeyPair kp1 = KeyPair::create();