Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_account_query_db.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE account_query_db
3#include <boost/test/included/unit_test.hpp>
8
9#ifdef NON_VALIDATING_TEST
10#define TESTER tester
11#else
12#define TESTER validating_tester
13#endif
14
15using namespace sysio;
16using namespace sysio::chain;
17using namespace sysio::testing;
18using namespace sysio::chain_apis;
19
22
24 for (const auto& acc : rst.accounts){
25 if (acc.account_name == name){
26 return true;
27 }
28 }
29 return false;
30}
32 for (const auto& acc : rst.accounts){
33 if (acc.account_name == name && acc.permission_name == perm)
34 return true;
35 }
36 return false;
37}
38
39BOOST_AUTO_TEST_SUITE(account_query_db_tests)
40
41BOOST_FIXTURE_TEST_CASE(newaccount_test, TESTER) { try {
42
43 // instantiate an account_query_db
44 auto aq_db = account_query_db(*control);
45
46 //link aq_db to the `accepted_block` signal on the controller
47 auto c2 = control->accepted_block.connect([&](const block_state_ptr& blk) {
48 aq_db.commit_block( blk);
49 });
50
51 produce_blocks(10);
52
53 account_name tester_account = "tester"_n;
54 const auto trace_ptr = create_account(tester_account);
55 aq_db.cache_transaction_trace(trace_ptr);
56 produce_block();
57
58 params pars;
59 pars.keys.emplace_back(get_public_key(tester_account, "owner"));
60 const auto results = aq_db.get_accounts_by_authorizers(pars);
61
62 BOOST_TEST_REQUIRE(find_account_name(results, tester_account) == true);
63
65
66BOOST_FIXTURE_TEST_CASE(updateauth_test, TESTER) { try {
67
68 // instantiate an account_query_db
69 auto aq_db = account_query_db(*control);
70
71 //link aq_db to the `accepted_block` signal on the controller
72 auto c = control->accepted_block.connect([&](const block_state_ptr& blk) {
73 aq_db.commit_block( blk);
74 });
75
76 produce_blocks(10);
77
78 const auto& tester_account = "tester"_n;
79 const string role = "first";
80 produce_block();
81 create_account(tester_account);
82
83 const auto trace_ptr = push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
84 ("account", tester_account)
85 ("permission", "role"_n)
86 ("parent", "active")
87 ("auth", authority(get_public_key(tester_account, role), 5))
88 );
89 aq_db.cache_transaction_trace(trace_ptr);
90 produce_block();
91
92 params pars;
93 pars.keys.emplace_back(get_public_key(tester_account, role));
94 const auto results = aq_db.get_accounts_by_authorizers(pars);
95
96 BOOST_TEST_REQUIRE(find_account_auth(results, tester_account, "role"_n) == true);
97
99
100BOOST_AUTO_TEST_CASE(future_fork_test) { try {
101 tester node_a(setup_policy::none);
102 tester node_b(setup_policy::none);
103
104 // instantiate an account_query_db
105 auto aq_db = account_query_db(*node_a.control);
106
107 //link aq_db to the `accepted_block` signal on the controller
108 auto c = node_a.control->accepted_block.connect([&](const block_state_ptr& blk) {
109 aq_db.commit_block( blk);
110 });
111
112 // create 10 blocks synced
113 for (int i = 0; i < 10; i++) {
114 node_b.push_block(node_a.produce_block());
115 }
116
117 // produce a block on node A with a new account and permission
118 const auto& tester_account = "tester"_n;
119 const string role = "first";
120 node_a.create_account(tester_account);
121
122 const auto trace_ptr = node_a.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
123 ("account", tester_account)
124 ("permission", "role"_n)
125 ("parent", "active")
126 ("auth", authority(node_a.get_public_key(tester_account, role), 5))
127 );
128 aq_db.cache_transaction_trace(trace_ptr);
129 node_a.produce_block();
130
131 params pars;
132 pars.keys.emplace_back(node_a.get_public_key(tester_account, role));
133
134 const auto pre_results = aq_db.get_accounts_by_authorizers(pars);
135 BOOST_TEST_REQUIRE(find_account_auth(pre_results, tester_account, "role"_n) == true);
136
137 // have node B take over from head-1 and produce "future" blocks to overtake
138 node_a.push_block(node_b.produce_block(fc::milliseconds(config::block_interval_ms * 100)));
139 node_a.push_block(node_b.produce_block());
140
141 // ensure the account was forked away
142 const auto post_results = aq_db.get_accounts_by_authorizers(pars);
143 BOOST_TEST_REQUIRE(post_results.accounts.size() == 0);
144
146
147BOOST_AUTO_TEST_CASE(fork_test) { try {
148 tester node_a(setup_policy::none);
149 tester node_b(setup_policy::none);
150
151 // instantiate an account_query_db
152 auto aq_db = account_query_db(*node_a.control);
153
154 //link aq_db to the `accepted_block` signal on the controller
155 auto c = node_a.control->accepted_block.connect([&](const block_state_ptr& blk) {
156 aq_db.commit_block( blk);
157 });
158
159 // create 10 blocks synced
160 for (int i = 0; i < 10; i++) {
161 node_b.push_block(node_a.produce_block());
162 }
163
164 // produce a block on node A with a new account and permission
165 const auto& tester_account = "tester"_n;
166 const auto& tester_account2 = "tester2"_n;
167 const string role = "first";
168 node_a.create_account(tester_account);
169 node_a.create_account(tester_account2);
170
171 const auto trace_ptr = node_a.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
172 ("account", tester_account)
173 ("permission", "role"_n)
174 ("parent", "active")
175 ("auth", authority(node_a.get_public_key(tester_account, role), 5)), 1
176 );
177 aq_db.cache_transaction_trace(trace_ptr);
178 const auto trace_ptr2 = node_a.push_action(config::system_account_name, updateauth::get_name(), tester_account2, fc::mutable_variant_object()
179 ("account", tester_account2)
180 ("permission", "role"_n)
181 ("parent", "active")
182 ("auth", authority(node_a.get_public_key(tester_account2, role), 5)), 2
183 );
184 aq_db.cache_transaction_trace(trace_ptr2);
185 node_a.produce_block();
186
187 params pars;
188 pars.keys.emplace_back(node_a.get_public_key(tester_account, role));
189
190 const auto pre_results = aq_db.get_accounts_by_authorizers(pars);
191 BOOST_TEST_REQUIRE(find_account_auth(pre_results, tester_account, "role"_n) == true);
192
193 // have node B take over from head-1 and also update permissions
194 node_b.create_account(tester_account);
195 node_b.create_account(tester_account2);
196
197 const auto trace_ptr3 = node_b.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
198 ("account", tester_account)
199 ("permission", "role"_n)
200 ("parent", "active")
201 ("auth", authority(node_b.get_public_key(tester_account, role), 6)), 1
202 );
203 aq_db.cache_transaction_trace(trace_ptr3);
204 const auto trace_ptr4 = node_b.push_action(config::system_account_name, updateauth::get_name(), tester_account2, fc::mutable_variant_object()
205 ("account", tester_account2)
206 ("permission", "role"_n)
207 ("parent", "active")
208 ("auth", authority(node_b.get_public_key(tester_account2, role), 6)), 2
209 );
210 aq_db.cache_transaction_trace(trace_ptr4);
211
212 // push b's onto a
213 node_a.push_block(node_b.produce_block());
214
215 const auto trace_ptr5 = node_b.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
216 ("account", tester_account)
217 ("permission", "role"_n)
218 ("parent", "active")
219 ("auth", authority(node_b.get_public_key(tester_account, role), 5)), 3
220 );
221 aq_db.cache_transaction_trace(trace_ptr5);
222 const auto trace_ptr6 = node_b.push_action(config::system_account_name, updateauth::get_name(), tester_account2, fc::mutable_variant_object()
223 ("account", tester_account2)
224 ("permission", "role"_n)
225 ("parent", "active")
226 ("auth", authority(node_b.get_public_key(tester_account2, role), 5)), 4
227 );
228 aq_db.cache_transaction_trace(trace_ptr6);
229
230 node_a.push_block(node_b.produce_block());
231
232 // ensure the account was forked away
233 const auto post_results = aq_db.get_accounts_by_authorizers(pars);
234
235 // verify correct account is in results
236 BOOST_TEST_REQUIRE(post_results.accounts.size() == 1);
237
239
240BOOST_AUTO_TEST_SUITE_END()
241
An order-preserving dictionary of variants.
action_result push_action(action &&cert_act, uint64_t authorizer)
Definition tester.cpp:609
transaction_trace_ptr create_account(account_name name, account_name creator=config::system_account_name, bool multisig=false, bool include_code=true)
Definition tester.cpp:516
void push_block(signed_block_ptr b)
Definition tester.cpp:323
unique_ptr< controller > control
Definition tester.hpp:436
static auto get_public_key(name keyname, string role="owner")
Definition tester.hpp:303
provides utility function to simplify the creation of unit tests
Definition tester.hpp:448
signed_block_ptr produce_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
Definition tester.hpp:494
#define FC_LOG_AND_RETHROW()
constexpr microseconds milliseconds(int64_t s)
Definition time.hpp:33
std::shared_ptr< block_state > block_state_ptr
Immutable except for fc::from_variant.
Definition name.hpp:43
static action_name get_name()
bool find_account_name(results rst, account_name name)
bool find_account_auth(results rst, account_name name, permission_name perm)
BOOST_AUTO_TEST_CASE(future_fork_test)
BOOST_FIXTURE_TEST_CASE(newaccount_test, TESTER)
#define TESTER