Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_account_query_db.cpp File Reference
#include <sysio/chain/permission_object.hpp>
#include <boost/test/included/unit_test.hpp>
#include <sysio/testing/tester.hpp>
#include <sysio/chain/types.hpp>
#include <sysio/chain/block_state.hpp>
#include <sysio/chain_plugin/account_query_db.hpp>
Include dependency graph for test_account_query_db.cpp:

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   account_query_db
 
#define TESTER   validating_tester
 

Typedefs

using params = account_query_db::get_accounts_by_authorizers_params
 
using results = account_query_db::get_accounts_by_authorizers_result
 

Functions

bool find_account_name (results rst, account_name name)
 
bool find_account_auth (results rst, account_name name, permission_name perm)
 
 BOOST_FIXTURE_TEST_CASE (newaccount_test, TESTER)
 
 BOOST_FIXTURE_TEST_CASE (updateauth_test, TESTER)
 
 BOOST_AUTO_TEST_CASE (future_fork_test)
 
 BOOST_AUTO_TEST_CASE (fork_test)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   account_query_db

Definition at line 1 of file test_account_query_db.cpp.

◆ TESTER

#define TESTER   validating_tester

Definition at line 12 of file test_account_query_db.cpp.

Typedef Documentation

◆ params

◆ results

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( fork_test )

Definition at line 147 of file test_account_query_db.cpp.

147 { 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
An order-preserving dictionary of variants.
provides utility function to simplify the creation of unit tests
Definition tester.hpp:448
#define FC_LOG_AND_RETHROW()
std::shared_ptr< block_state > block_state_ptr
static action_name get_name()
bool find_account_auth(results rst, account_name name, permission_name perm)
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( future_fork_test )

Definition at line 100 of file test_account_query_db.cpp.

100 { 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
constexpr microseconds milliseconds(int64_t s)
Definition time.hpp:33
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [1/2]

BOOST_FIXTURE_TEST_CASE ( newaccount_test ,
TESTER  )

Definition at line 41 of file test_account_query_db.cpp.

41 { 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
auto get_public_key(chain::name keyname, std::string role="owner")
Immutable except for fc::from_variant.
Definition name.hpp:43
bool find_account_name(results rst, account_name name)
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [2/2]

BOOST_FIXTURE_TEST_CASE ( updateauth_test ,
TESTER  )

Definition at line 66 of file test_account_query_db.cpp.

66 { 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
Here is the call graph for this function:

◆ find_account_auth()

bool find_account_auth ( results rst,
account_name name,
permission_name perm )

Definition at line 31 of file test_account_query_db.cpp.

31 {
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}
Here is the caller graph for this function:

◆ find_account_name()

bool find_account_name ( results rst,
account_name name )

Definition at line 23 of file test_account_query_db.cpp.

23 {
24 for (const auto& acc : rst.accounts){
25 if (acc.account_name == name){
26 return true;
27 }
28 }
29 return false;
30}
Here is the caller graph for this function: