18
18
#include < graphene/app/application.hpp>
19
19
#include < graphene/app/plugin.hpp>
20
20
21
+ #include < graphene/chain/balance_object.hpp>
22
+
21
23
#include < graphene/time/time.hpp>
22
24
23
25
#include < graphene/utilities/tempdir.hpp>
@@ -38,19 +40,22 @@ BOOST_AUTO_TEST_CASE( two_node_network )
38
40
using namespace graphene ::chain;
39
41
using namespace graphene ::app;
40
42
try {
43
+ BOOST_TEST_MESSAGE ( " Creating temporary files" );
44
+
41
45
fc::temp_directory app_dir ( graphene::utilities::temp_directory_path () );
42
46
fc::temp_directory app2_dir ( graphene::utilities::temp_directory_path () );
43
47
fc::temp_file genesis_json;
44
48
45
- // TODO: Time should be read from the blockchain
46
- fc::time_point_sec now ( 1431700000 );
49
+ BOOST_TEST_MESSAGE ( " Creating and initializing app1" );
47
50
48
51
graphene::app::application app1;
49
52
app1.register_plugin <graphene::account_history::account_history_plugin>();
50
53
boost::program_options::variables_map cfg;
51
54
cfg.emplace (" p2p-endpoint" , boost::program_options::variable_value (string (" 127.0.0.1:3939" ), false ));
52
55
app1.initialize (app_dir.path (), cfg);
53
56
57
+ BOOST_TEST_MESSAGE ( " Creating and initializing app2" );
58
+
54
59
graphene::app::application app2;
55
60
app2.register_plugin <account_history::account_history_plugin>();
56
61
auto cfg2 = cfg;
@@ -59,42 +64,82 @@ BOOST_AUTO_TEST_CASE( two_node_network )
59
64
cfg2.emplace (" seed-node" , boost::program_options::variable_value (vector<string>{" 127.0.0.1:3939" }, false ));
60
65
app2.initialize (app2_dir.path (), cfg2);
61
66
62
- app1.startup ();
67
+ BOOST_TEST_MESSAGE ( " Starting app1 and waiting 500 ms" );
68
+ app1.startup ();
69
+ fc::usleep (fc::milliseconds (500 ));
70
+ BOOST_TEST_MESSAGE ( " Starting app2 and waiting 500 ms" );
63
71
app2.startup ();
64
72
fc::usleep (fc::milliseconds (500 ));
65
73
66
74
BOOST_REQUIRE_EQUAL (app1.p2p_node ()->get_connection_count (), 1 );
67
75
BOOST_CHECK_EQUAL (std::string (app1.p2p_node ()->get_connected_peers ().front ().host .get_address ()), " 127.0.0.1" );
68
- ilog ( " Connected! " );
76
+ BOOST_TEST_MESSAGE ( " app1 and app2 successfully connected " );
69
77
70
- fc::ecc::private_key nathan_key = fc::ecc::private_key::generate ();
71
- fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate (fc::sha256::hash (string (" nathan" )));
72
- graphene::chain::signed_transaction trx;
73
- trx.set_expiration (now + fc::seconds (30 ));
78
+ std::shared_ptr<chain::database> db1 = app1.chain_database ();
74
79
std::shared_ptr<chain::database> db2 = app2.chain_database ();
75
80
76
- assert_operation op;
77
- op.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
78
- op.predicates .push_back ( graphene::chain::asset_symbol_eq_lit_predicate{ asset_id_type (), " CORE" } );
79
-
80
- trx.operations .push_back ( std::move ( op ) );
81
+ BOOST_CHECK_EQUAL ( db1->get_balance ( GRAPHENE_NULL_ACCOUNT, asset_id_type () ).amount .value , 0 );
82
+ BOOST_CHECK_EQUAL ( db2->get_balance ( GRAPHENE_NULL_ACCOUNT, asset_id_type () ).amount .value , 0 );
81
83
82
- trx.validate ();
83
- processed_transaction ptrx = app1.chain_database ()->push_transaction (trx);
84
+ BOOST_TEST_MESSAGE ( " Creating transfer tx" );
85
+ graphene::chain::signed_transaction trx;
86
+ {
87
+ account_id_type nathan_id = db2->get_index_type <account_index>().indices ().get <by_name>().find ( " nathan" )->id ;
88
+ fc::ecc::private_key nathan_key = fc::ecc::private_key::regenerate (fc::sha256::hash (string (" nathan" )));
89
+
90
+ balance_claim_operation claim_op;
91
+ balance_id_type bid = balance_id_type ();
92
+ claim_op.deposit_to_account = nathan_id;
93
+ claim_op.balance_to_claim = bid;
94
+ claim_op.balance_owner_key = nathan_key.get_public_key ();
95
+ claim_op.total_claimed = bid (*db1).balance ;
96
+ trx.operations .push_back ( claim_op );
97
+ db1->current_fee_schedule ().set_fee ( trx.operations .back () );
98
+
99
+ transfer_operation xfer_op;
100
+ xfer_op.from = nathan_id;
101
+ xfer_op.to = GRAPHENE_NULL_ACCOUNT;
102
+ xfer_op.amount = asset ( 1000000 );
103
+ trx.operations .push_back ( xfer_op );
104
+ db1->current_fee_schedule ().set_fee ( trx.operations .back () );
105
+
106
+ trx.set_expiration ( db1->get_slot_time ( 10 ) );
107
+ trx.sign ( nathan_key );
108
+ trx.validate ();
109
+ }
110
+
111
+ BOOST_TEST_MESSAGE ( " Pushing tx locally on db1" );
112
+ processed_transaction ptrx = db1->push_transaction (trx);
113
+
114
+ BOOST_CHECK_EQUAL ( db1->get_balance ( GRAPHENE_NULL_ACCOUNT, asset_id_type () ).amount .value , 1000000 );
115
+ BOOST_CHECK_EQUAL ( db2->get_balance ( GRAPHENE_NULL_ACCOUNT, asset_id_type () ).amount .value , 0 );
116
+
117
+ BOOST_TEST_MESSAGE ( " Broadcasting tx" );
84
118
app1.p2p_node ()->broadcast (graphene::net::trx_message (trx));
85
119
86
- fc::usleep (fc::milliseconds (250 ));
87
- ilog (" Pushed transaction" );
120
+ fc::usleep (fc::milliseconds (500 ));
121
+
122
+ BOOST_CHECK_EQUAL ( db1->get_balance ( GRAPHENE_NULL_ACCOUNT, asset_id_type () ).amount .value , 1000000 );
123
+ BOOST_CHECK_EQUAL ( db2->get_balance ( GRAPHENE_NULL_ACCOUNT, asset_id_type () ).amount .value , 1000000 );
88
124
89
- now += GRAPHENE_DEFAULT_BLOCK_INTERVAL;
90
- app2.p2p_node ()->broadcast (graphene::net::block_message (db2->generate_block (now,
91
- db2->get_scheduled_witness (1 ).first ,
92
- committee_key,
93
- database::skip_nothing)));
125
+ BOOST_TEST_MESSAGE ( " Generating block on db2" );
126
+ fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate (fc::sha256::hash (string (" nathan" )));
127
+
128
+ auto block_1 = db2->generate_block (
129
+ db2->get_slot_time (1 ),
130
+ db2->get_scheduled_witness (1 ).first ,
131
+ committee_key,
132
+ database::skip_nothing);
133
+
134
+ BOOST_TEST_MESSAGE ( " Broadcasting block" );
135
+ app2.p2p_node ()->broadcast (graphene::net::block_message ( block_1 ));
94
136
95
137
fc::usleep (fc::milliseconds (500 ));
138
+ BOOST_TEST_MESSAGE ( " Verifying nodes are still connected" );
96
139
BOOST_CHECK_EQUAL (app1.p2p_node ()->get_connection_count (), 1 );
97
140
BOOST_CHECK_EQUAL (app1.chain_database ()->head_block_num (), 1 );
141
+
142
+ BOOST_TEST_MESSAGE ( " Checking GRAPHENE_NULL_ACCOUNT has balance" );
98
143
} catch ( fc::exception & e ) {
99
144
edump ((e.to_detail_string ()));
100
145
throw ;
0 commit comments