aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-04-05 04:04:52 +0800
committerGav Wood <i@gavwood.com>2014-04-05 04:04:52 +0800
commit1b4718f7849c66135df98061ffc4929847826e41 (patch)
treeddd4b33324df5532ff56fcdef5c08339717b7c0f
parentdcb8b533bbfe00f557d094ccb748a82d75eed10f (diff)
parentda2f0e1d4a67dd25060274ac1e13118e2f1d38fa (diff)
downloaddexon-solidity-1b4718f7849c66135df98061ffc4929847826e41.tar.gz
dexon-solidity-1b4718f7849c66135df98061ffc4929847826e41.tar.zst
dexon-solidity-1b4718f7849c66135df98061ffc4929847826e41.zip
Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop
-rw-r--r--TestHelper.cpp9
-rw-r--r--TestHelper.h1
-rw-r--r--txTest.cpp81
3 files changed, 76 insertions, 15 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index e33c105b..54cb84cc 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -37,4 +37,13 @@ void mine(Client& c, int numBlocks)
c.stopMining();
}
+void connectClients(Client& c1, Client& c2)
+{
+ short c1Port = 20000;
+ short c2Port = 21000;
+ c1.startNetwork(c1Port);
+ c2.startNetwork(c2Port);
+ c2.connect("127.0.0.1", c1Port);
+}
+
}
diff --git a/TestHelper.h b/TestHelper.h
index 5860f7fa..748373ba 100644
--- a/TestHelper.h
+++ b/TestHelper.h
@@ -25,5 +25,6 @@ namespace eth
{
void mine(Client& c, int numBlocks);
+void connectClients(Client& c1, Client& c2);
}
diff --git a/txTest.cpp b/txTest.cpp
index 757c3df3..d1a5566d 100644
--- a/txTest.cpp
+++ b/txTest.cpp
@@ -29,38 +29,89 @@
using namespace std;
using namespace eth;
-BOOST_AUTO_TEST_CASE(mine_and_send_to_peer)
+BOOST_AUTO_TEST_CASE(mine_local_simple_tx)
{
KeyPair kp1 = KeyPair::create();
KeyPair kp2 = KeyPair::create();
- string c1DataDir = (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string();
- string c2DataDir = (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string();
+ Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
+
+ //mine some blocks so that client 1 has a balance
+ mine(c1, 1);
+ auto c1bal = c1.state().balance(kp1.address());
+ BOOST_REQUIRE(c1bal > 0);
+
+ //send c2 some eth from c1
+ auto txAmount = c1bal / 2u;
+ auto gasPrice = 10 * szabo;
+ auto gas = eth::c_callGas;
+ c1.transact(kp1.secret(), txAmount, gasPrice, gas, kp2.address(), bytes());
+
+ //mine some more to include the transaction on chain
+ mine(c1, 1);
+ auto c2bal = c1.state().balance(kp2.address());
+ BOOST_REQUIRE(c2bal > 0);
+ BOOST_REQUIRE(c2bal == txAmount);
+}
- Client c1("TestClient1", kp1.address(), c1DataDir);
- Client c2("TestClient2", kp2.address(), c2DataDir);
+BOOST_AUTO_TEST_CASE(mine_and_send_to_peer)
+{
+ KeyPair kp1 = KeyPair::create();
+ KeyPair kp2 = KeyPair::create();
- short c1Port = 20000;
- short c2Port = 21000;
+ Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
+ Client c2("TestClient2", kp2.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
- //connect the two clients up
- c1.startNetwork(c1Port);
- c2.startNetwork(c2Port);
- c2.connect("127.0.0.1", c1Port);
+ connectClients(c1, c2);
//mine some blocks so that client 1 has a balance
mine(c1, 1);
auto c1bal = c1.state().balance(kp1.address());
BOOST_REQUIRE(c1bal > 0);
-// BOOST_REQUIRE(c1bal > c1.state().fee());
//send c2 some eth from c1
-// auto txAmount = c1bal - c1.state().fee();
-// c1.transact(kp1.secret(), c2.address(), txAmount);
+ auto txAmount = c1bal / 2u;
+ auto gasPrice = 10 * szabo;
+ auto gas = eth::c_callGas;
+ c1.transact(kp1.secret(), txAmount, gasPrice, gas, kp2.address(), bytes());
//mine some more to include the transaction on chain
mine(c1, 1);
auto c2bal = c2.state().balance(kp2.address());
BOOST_REQUIRE(c2bal > 0);
-// BOOST_REQUIRE(c2bal == txAmount);
+ BOOST_REQUIRE(c2bal == txAmount);
+}
+
+BOOST_AUTO_TEST_CASE(mine_and_send_to_peer_fee_check)
+{
+ KeyPair kp1 = KeyPair::create();
+ KeyPair kp2 = KeyPair::create();
+
+ Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
+ Client c2("TestClient2", kp2.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
+
+ connectClients(c1, c2);
+
+ //mine some blocks so that client 1 has a balance
+ mine(c1, 1);
+
+ auto c1StartBalance = c1.state().balance(kp1.address());
+ auto c2StartBalance = c2.state().balance(kp2.address());
+ BOOST_REQUIRE(c1StartBalance > 0);
+ BOOST_REQUIRE(c2StartBalance == 0);
+
+ //send c2 some eth from c1
+ auto txAmount = c1StartBalance / 2u;
+ auto gasPrice = 10 * szabo;
+ auto gas = eth::c_callGas;
+ c1.transact(kp1.secret(), txAmount, gasPrice, gas, c2.address(), bytes());
+
+ //mine some more, this time with second client (so he can get fees from first client's tx)
+ mine(c2, 1);
+
+ auto c1EndBalance = c1.state().balance(kp1.address());
+ auto c2EndBalance = c2.state().balance(kp2.address());
+ BOOST_REQUIRE(c1EndBalance > 0);
+ BOOST_REQUIRE(c1EndBalance == c1StartBalance - txAmount - gasPrice * gas);
+ BOOST_REQUIRE(c2EndBalance > 0);
}