Fabcoin Core  0.16.2
P2P Digital Currency
txTest.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #include <boost/test/unit_test.hpp>
24 #include <boost/filesystem/operations.hpp>
25 
26 #include <libethereum/Client.h>
27 #include <libethereum/BlockChain.h>
29 #include "TestHelper.h"
30 using namespace std;
31 using namespace dev;
32 using namespace dev::eth;
33 
34 // Disabled since tests shouldn't block. Need a short cut to avoid real mining.
35 /*
36 BOOST_AUTO_TEST_CASE(mine_local_simple_tx)
37 {
38  KeyPair kp1 = KeyPair::create();
39  KeyPair kp2 = KeyPair::create();
40 
41  Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
42 
43  //mine some blocks so that client 1 has a balance
44  mine(c1, 1);
45  auto c1bal = c1.state().balance(kp1.address());
46  BOOST_REQUIRE(c1bal > 0);
47 
48  //send c2 some eth from c1
49  auto txAmount = c1bal / 2u;
50  auto gasPrice = 10 * szabo;
51  auto gas = eth::EVMSchedule().callGas;
52  c1.submitTransaction(kp1.secret(), txAmount, kp2.address(), bytes(), gas, gasPrice);
53 
54  //mine some more to include the transaction on chain
55  mine(c1, 1);
56  auto c2bal = c1.state().balance(kp2.address());
57  BOOST_REQUIRE(c2bal > 0);
58  BOOST_REQUIRE(c2bal == txAmount);
59 }
60 
61 BOOST_AUTO_TEST_CASE(mine_and_send_to_peer)
62 {
63  KeyPair kp1 = KeyPair::create();
64  KeyPair kp2 = KeyPair::create();
65 
66  Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
67  Client c2("TestClient2", kp2.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
68 
69  connectClients(c1, c2);
70 
71  //mine some blocks so that client 1 has a balance
72  mine(c1, 1);
73  auto c1bal = c1.state().balance(kp1.address());
74  BOOST_REQUIRE(c1bal > 0);
75 
76  //send c2 some eth from c1
77  auto txAmount = c1bal / 2u;
78  auto gasPrice = 10 * szabo;
79  auto gas = eth::EVMSchedule().callGas;
80  c1.submitTransaction(kp1.secret(), txAmount, kp2.address(), bytes(), gas, gasPrice);
81 
82  //mine some more to include the transaction on chain
83  mine(c1, 1);
84  auto c2bal = c2.state().balance(kp2.address());
85  BOOST_REQUIRE(c2bal > 0);
86  BOOST_REQUIRE(c2bal == txAmount);
87 }
88 
89 BOOST_AUTO_TEST_CASE(mine_and_send_to_peer_fee_check)
90 {
91  KeyPair kp1 = KeyPair::create();
92  KeyPair kp2 = KeyPair::create();
93 
94  Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
95  Client c2("TestClient2", kp2.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
96 
97  connectClients(c1, c2);
98 
99  //mine some blocks so that client 1 has a balance
100  mine(c1, 1);
101 
102  auto c1StartBalance = c1.state().balance(kp1.address());
103  auto c2StartBalance = c2.state().balance(kp2.address());
104  BOOST_REQUIRE(c1StartBalance > 0);
105  BOOST_REQUIRE(c2StartBalance == 0);
106 
107  //send c2 some eth from c1
108  auto txAmount = c1StartBalance / 2u;
109  auto gasPrice = 10 * szabo;
110  auto gas = eth::EVMSchedule().callGas;
111  c1.submitTransaction(kp1.secret(), txAmount, c2.address(), bytes(), gas, gasPrice);
112 
113  //mine some more, this time with second client (so he can get fees from first client's tx)
114  mine(c2, 1);
115 
116  auto c1EndBalance = c1.state().balance(kp1.address());
117  auto c2EndBalance = c2.state().balance(kp2.address());
118  BOOST_REQUIRE(c1EndBalance > 0);
119  BOOST_REQUIRE(c1EndBalance == c1StartBalance - txAmount - gasPrice * gas);
120  BOOST_REQUIRE(c2EndBalance > 0);
121 }
122 */
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::hash for asio::adress
Definition: Common.h:323
Helper functions to work with json::spirit and test files.