-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauth_tests.cpp
More file actions
558 lines (431 loc) · 24.2 KB
/
auth_tests.cpp
File metadata and controls
558 lines (431 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
#include <boost/test/unit_test.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/chain/permission_object.hpp>
#include <eosio/chain/authorization_manager.hpp>
#include <eosio/chain/to_string.hpp>
#include <eosio/chain/resource_limits.hpp>
#include <eosio/chain/resource_limits_private.hpp>
#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif
using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
BOOST_AUTO_TEST_SUITE(auth_tests)
BOOST_FIXTURE_TEST_CASE( missing_sigs, TESTER ) { try {
create_accounts( {"alice"_n} );
produce_block();
BOOST_REQUIRE_THROW( push_reqauth( "alice"_n, {permission_level{"alice"_n, config::active_name}}, {} ), unsatisfied_authorization );
auto trace = push_reqauth("alice"_n, "owner");
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace->id));
} FC_LOG_AND_RETHROW() } /// missing_sigs
BOOST_FIXTURE_TEST_CASE( missing_multi_sigs, TESTER ) { try {
produce_block();
create_account("alice"_n, config::system_account_name, true);
produce_block();
BOOST_REQUIRE_THROW(push_reqauth("alice"_n, "owner"), unsatisfied_authorization); // without multisig
auto trace = push_reqauth("alice"_n, "owner", true); // with multisig
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace->id));
} FC_LOG_AND_RETHROW() } /// missing_multi_sigs
BOOST_FIXTURE_TEST_CASE( missing_auths, TESTER ) { try {
create_accounts( {"alice"_n, "bob"_n} );
produce_block();
/// action not provided from authority
BOOST_REQUIRE_THROW( push_reqauth( "alice"_n, {permission_level{"bob"_n, config::active_name}}, { get_private_key("bob"_n, "active") } ), missing_auth_exception);
} FC_LOG_AND_RETHROW() } /// transfer_test
/**
* This test case will attempt to allow one account to transfer on behalf
* of another account by updating the active authority.
*/
BOOST_FIXTURE_TEST_CASE( delegate_auth, TESTER ) { try {
create_accounts( {"alice"_n,"bob"_n});
produce_block();
auto delegated_auth = authority( 1, {},
{
{ .permission = {"bob"_n,config::active_name}, .weight = 1}
});
auto original_auth = static_cast<authority>(control->get_authorization_manager().get_permission({"alice"_n, config::active_name}).auth);
wdump((original_auth));
set_authority( "alice"_n, config::active_name, delegated_auth );
auto new_auth = static_cast<authority>(control->get_authorization_manager().get_permission({"alice"_n, config::active_name}).auth);
wdump((new_auth));
BOOST_CHECK_EQUAL((new_auth == delegated_auth), true);
produce_block();
produce_block();
auto auth = static_cast<authority>(control->get_authorization_manager().get_permission({"alice"_n, config::active_name}).auth);
wdump((auth));
BOOST_CHECK_EQUAL((new_auth == auth), true);
/// execute nonce from alice signed by bob
auto trace = push_reqauth("alice"_n, {permission_level{"alice"_n, config::active_name}}, { get_private_key("bob"_n, "active") } );
produce_block();
//todoBOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace->id));
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(update_auths) {
try {
TESTER chain;
chain.create_account(name("alice"));
chain.create_account(name("bob"));
// Deleting active or owner should fail
BOOST_CHECK_THROW(chain.delete_authority(name("alice"), name("active")), action_validate_exception);
BOOST_CHECK_THROW(chain.delete_authority(name("alice"), name("owner")), action_validate_exception);
// Change owner permission
const auto new_owner_priv_key = chain.get_private_key(name("alice"), "new_owner");
const auto new_owner_pub_key = new_owner_priv_key.get_public_key();
chain.set_authority(name("alice"), name("owner"), authority(new_owner_pub_key), {});
chain.produce_blocks();
// Ensure the permission is updated
permission_object::id_type owner_id;
{
auto obj = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("owner")));
BOOST_TEST(obj != nullptr);
BOOST_TEST(obj->owner == name("alice"));
BOOST_TEST(obj->name == name("owner"));
BOOST_TEST(obj->parent == 0);
owner_id = obj->id;
auto auth = obj->auth.to_authority();
BOOST_TEST(auth.threshold == 1u);
BOOST_TEST(auth.keys.size() == 1u);
BOOST_TEST(auth.accounts.size() == 0u);
BOOST_TEST(auth.keys[0].key == new_owner_pub_key);
BOOST_TEST(auth.keys[0].weight == 1);
}
// Change active permission, remember that the owner key has been changed
const auto new_active_priv_key = chain.get_private_key(name("alice"), "new_active");
const auto new_active_pub_key = new_active_priv_key.get_public_key();
chain.set_authority(name("alice"), name("active"), authority(new_active_pub_key), name("owner"),
{ permission_level{name("alice"), name("active")} }, { chain.get_private_key(name("alice"), "active") });
chain.produce_blocks();
{
auto obj = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("active")));
BOOST_TEST(obj != nullptr);
BOOST_TEST(obj->owner == name("alice"));
BOOST_TEST(obj->name == name("active"));
BOOST_TEST(obj->parent == owner_id);
auto auth = obj->auth.to_authority();
BOOST_TEST(auth.threshold == 1u);
BOOST_TEST(auth.keys.size() == 1u);
BOOST_TEST(auth.accounts.size() == 0u);
BOOST_TEST(auth.keys[0].key == new_active_pub_key);
BOOST_TEST(auth.keys[0].weight == 1u);
}
auto spending_priv_key = chain.get_private_key(name("alice"), "spending");
auto spending_pub_key = spending_priv_key.get_public_key();
auto trading_priv_key = chain.get_private_key(name("alice"), "trading");
auto trading_pub_key = trading_priv_key.get_public_key();
// Bob attempts to create new spending auth for Alice
BOOST_CHECK_THROW( chain.set_authority( name("alice"), name("spending"), authority(spending_pub_key), name("active"),
{ permission_level{name("bob"), name("active")} },
{ chain.get_private_key(name("bob"), "active") } ),
irrelevant_auth_exception );
// Create new spending auth
chain.set_authority(name("alice"), name("spending"), authority(spending_pub_key), name("active"),
{ permission_level{name("alice"), name("active")} }, { new_active_priv_key });
chain.produce_blocks();
{
auto obj = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("spending")));
BOOST_TEST(obj != nullptr);
BOOST_TEST(obj->owner == name("alice"));
BOOST_TEST(obj->name == name("spending"));
BOOST_TEST(chain.get<permission_object>(obj->parent).owner == name("alice"));
BOOST_TEST(chain.get<permission_object>(obj->parent).name == name("active"));
}
// Update spending auth parent to be its own, should fail
BOOST_CHECK_THROW(chain.set_authority(name("alice"), name("spending"), spending_pub_key, name("spending"),
{ permission_level{name("alice"), name("spending")} }, { spending_priv_key }), action_validate_exception);
// Update spending auth parent to be owner, should fail
BOOST_CHECK_THROW(chain.set_authority(name("alice"), name("spending"), spending_pub_key, name("owner"),
{ permission_level{name("alice"), name("spending")} }, { spending_priv_key }), action_validate_exception);
// Remove spending auth
chain.delete_authority(name("alice"), name("spending"), { permission_level{name("alice"), name("active")} }, { new_active_priv_key });
{
auto obj = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("spending")));
BOOST_TEST(obj == nullptr);
}
chain.produce_blocks();
// Create new trading auth
chain.set_authority(name("alice"), name("trading"), trading_pub_key, name("active"),
{ permission_level{name("alice"), name("active")} }, { new_active_priv_key });
// Recreate spending auth again, however this time, it's under trading instead of owner
chain.set_authority(name("alice"), name("spending"), spending_pub_key, name("trading"),
{ permission_level{name("alice"), name("trading")} }, { trading_priv_key });
chain.produce_blocks();
// Verify correctness of trading and spending
{
const auto* trading = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("trading")));
const auto* spending = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("spending")));
BOOST_TEST(trading != nullptr);
BOOST_TEST(spending != nullptr);
BOOST_TEST(trading->owner == name("alice"));
BOOST_TEST(spending->owner == name("alice"));
BOOST_TEST(trading->name == name("trading"));
BOOST_TEST(spending->name == name("spending"));
BOOST_TEST(spending->parent == trading->id);
BOOST_TEST(chain.get(trading->parent).owner == name("alice"));
BOOST_TEST(chain.get(trading->parent).name == name("active"));
}
// Delete trading, should fail since it has children (spending)
BOOST_CHECK_THROW(chain.delete_authority(name("alice"), name("trading"),
{ permission_level{name("alice"), name("active")} }, { new_active_priv_key }), action_validate_exception);
// Update trading parent to be spending, should fail since changing parent authority is not supported
BOOST_CHECK_THROW(chain.set_authority(name("alice"), name("trading"), trading_pub_key, name("spending"),
{ permission_level{name("alice"), name("trading")} }, { trading_priv_key }), action_validate_exception);
// Delete spending auth
chain.delete_authority(name("alice"), name("spending"), { permission_level{name("alice"), name("active")} }, { new_active_priv_key });
BOOST_TEST((chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("spending")))) == nullptr);
// Delete trading auth, now it should succeed since it doesn't have any children anymore
chain.delete_authority(name("alice"), name("trading"), { permission_level{name("alice"), name("active")} }, { new_active_priv_key });
BOOST_TEST((chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("trading")))) == nullptr);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(update_auth_unknown_private_key) {
try {
TESTER chain;
chain.create_account(name("alice"));
// public key with no corresponding private key
fc::ecc::public_key_data data;
data.data[0] = 0x80; // not necessary, 0 also works
fc::sha256 hash = fc::sha256::hash("unknown key");
std::memcpy(&data.data[1], hash.data(), hash.data_size() );
fc::ecc::public_key_shim shim(data);
fc::crypto::public_key new_owner_pub_key(std::move(shim));
chain.set_authority(name("alice"), name("owner"), authority(new_owner_pub_key), {});
chain.produce_blocks();
// Ensure the permission is updated
permission_object::id_type owner_id;
{
auto obj = chain.find<permission_object, by_owner>(boost::make_tuple(name("alice"), name("owner")));
BOOST_TEST(obj != nullptr);
BOOST_TEST(obj->owner == name("alice"));
BOOST_TEST(obj->name == name("owner"));
BOOST_TEST(obj->parent == 0);
owner_id = obj->id;
auto auth = obj->auth.to_authority();
BOOST_TEST(auth.threshold == 1u);
BOOST_TEST(auth.keys.size() == 1u);
BOOST_TEST(auth.accounts.size() == 0u);
BOOST_TEST(auth.keys[0].key == new_owner_pub_key);
BOOST_TEST(auth.keys[0].weight == 1);
}
} FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE(link_auths) { try {
TESTER chain;
chain.create_accounts({name("alice"),name("bob")});
const auto spending_priv_key = chain.get_private_key(name("alice"), "spending");
const auto spending_pub_key = spending_priv_key.get_public_key();
const auto scud_priv_key = chain.get_private_key(name("alice"), "scud");
const auto scud_pub_key = scud_priv_key.get_public_key();
chain.set_authority(name("alice"), name("spending"), spending_pub_key, name("active"));
chain.set_authority(name("alice"), name("scud"), scud_pub_key, name("spending"));
// Send req auth action with alice's spending key, it should fail
BOOST_CHECK_THROW(chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("spending")} }, { spending_priv_key }), irrelevant_auth_exception);
// Link authority for eosio reqauth action with alice's spending key
chain.link_authority(name("alice"), name("eosio"), name("spending"), name("reqauth"));
// Now, req auth action with alice's spending key should succeed
chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("spending")} }, { spending_priv_key });
chain.produce_block();
// Relink the same auth should fail
BOOST_CHECK_THROW( chain.link_authority(name("alice"), name("eosio"), name("spending"), name("reqauth")), action_validate_exception);
// Unlink alice with eosio reqauth
chain.unlink_authority(name("alice"), name("eosio"), name("reqauth"));
// Now, req auth action with alice's spending key should fail
BOOST_CHECK_THROW(chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("spending")} }, { spending_priv_key }), irrelevant_auth_exception);
chain.produce_block();
// Send req auth action with scud key, it should fail
BOOST_CHECK_THROW(chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("scud")} }, { scud_priv_key }), irrelevant_auth_exception);
// Link authority for any eosio action with alice's scud key
chain.link_authority(name("alice"), name("eosio"), name("scud"));
// Now, req auth action with alice's scud key should succeed
chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("scud")} }, { scud_priv_key });
// req auth action with alice's spending key should also be fine, since it is the parent of alice's scud key
chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("spending")} }, { spending_priv_key });
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(link_then_update_auth) { try {
TESTER chain;
chain.create_account(name("alice"));
const auto first_priv_key = chain.get_private_key(name("alice"), "first");
const auto first_pub_key = first_priv_key.get_public_key();
const auto second_priv_key = chain.get_private_key(name("alice"), "second");
const auto second_pub_key = second_priv_key.get_public_key();
chain.set_authority(name("alice"), name("first"), first_pub_key, name("active"));
chain.link_authority(name("alice"), name("eosio"), name("first"), name("reqauth"));
chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("first")} }, { first_priv_key });
chain.produce_blocks(13); // Wait at least 6 seconds for first push_reqauth transaction to expire.
// Update "first" auth public key
chain.set_authority(name("alice"), name("first"), second_pub_key, name("active"));
// Authority updated, using previous "first" auth should fail on linked auth
BOOST_CHECK_THROW(chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("first")} }, { first_priv_key }), unsatisfied_authorization);
// Using updated authority, should succeed
chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("first")} }, { second_priv_key });
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(create_account) {
try {
TESTER chain;
chain.create_account(name("joe"));
chain.produce_block();
// Verify account created properly
const auto& joe_owner_authority = chain.get<permission_object, by_owner>(boost::make_tuple(name("joe"), name("owner")));
BOOST_TEST(joe_owner_authority.auth.threshold == 1u);
BOOST_TEST(joe_owner_authority.auth.accounts.size() == 1u);
BOOST_TEST(joe_owner_authority.auth.keys.size() == 1u);
BOOST_TEST(joe_owner_authority.auth.keys[0].key.to_string() == chain.get_public_key(name("joe"), "owner").to_string());
BOOST_TEST(joe_owner_authority.auth.keys[0].weight == 1u);
const auto& joe_active_authority = chain.get<permission_object, by_owner>(boost::make_tuple(name("joe"), name("active")));
BOOST_TEST(joe_active_authority.auth.threshold == 1u);
BOOST_TEST(joe_active_authority.auth.accounts.size() == 1u);
BOOST_TEST(joe_active_authority.auth.keys.size() == 1u);
BOOST_TEST(joe_active_authority.auth.keys[0].key.to_string() == chain.get_public_key(name("joe"), "active").to_string());
BOOST_TEST(joe_active_authority.auth.keys[0].weight == 1u);
// Create duplicate name
BOOST_CHECK_EXCEPTION(chain.create_account(name("joe")), action_validate_exception,
fc_exception_message_is("Cannot create account named joe, as that name is already taken"));
// Creating account with name more than 12 chars
BOOST_CHECK_EXCEPTION(chain.create_account(name("aaaaaaaaaaaaa")), action_validate_exception,
fc_exception_message_is("account names can only be 12 chars long"));
// Creating account with eosio. prefix with privileged account
chain.create_account(name("eosio.test1"));
// Creating account with eosio. prefix with non-privileged account, should fail
BOOST_CHECK_EXCEPTION(chain.create_account(name("eosio.test2"), name("joe")), action_validate_exception,
fc_exception_message_is("only privileged accounts can have names that start with 'eosio.'"));
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( any_auth ) { try {
TESTER chain;
chain.create_accounts( {name("alice"), name("bob")} );
chain.produce_block();
const auto spending_priv_key = chain.get_private_key(name("alice"), "spending");
const auto spending_pub_key = spending_priv_key.get_public_key();
const auto bob_spending_pub_key = spending_priv_key.get_public_key();
chain.set_authority(name("alice"), name("spending"), spending_pub_key, name("active"));
chain.set_authority(name("bob"), name("spending"), bob_spending_pub_key, name("active"));
/// this should fail because spending is not active which is default for reqauth
BOOST_REQUIRE_THROW( chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("spending")} }, { spending_priv_key }),
irrelevant_auth_exception );
chain.produce_block();
//test.push_reqauth( "alice"_n, { permission_level{"alice"_n,"spending"} }, { spending_priv_key });
chain.link_authority( name("alice"), name("eosio"), name("eosio.any"), name("reqauth") );
chain.link_authority( name("bob"), name("eosio"), name("eosio.any"), name("reqauth") );
/// this should succeed because eosio::reqauth is linked to any permission
chain.push_reqauth(name("alice"), { permission_level{"alice"_n, name("spending")} }, { spending_priv_key });
/// this should fail because bob cannot authorize for alice, the permission given must be one-of alices
BOOST_REQUIRE_THROW( chain.push_reqauth(name("alice"), { permission_level{"bob"_n, name("spending")} }, { spending_priv_key }),
missing_auth_exception );
chain.produce_block();
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(no_double_billing) {
try {
fc::temp_directory tempdir;
validating_tester chain( tempdir, true );
chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios );
chain.produce_block();
account_name acc1 = "bill1"_n;
account_name acc2 = "bill2"_n;
account_name acc1a = "bill1a"_n;
chain.create_account(acc1);
chain.create_account(acc1a);
chain.produce_block();
const chainbase::database &db = chain.control->db();
using resource_usage_object = eosio::chain::resource_limits::resource_usage_object;
using by_owner = eosio::chain::resource_limits::by_owner;
auto create_acc = [&](account_name a) {
signed_transaction trx;
chain.set_transaction_headers(trx);
authority owner_auth = authority( chain.get_public_key( a, "owner" ) );
vector<permission_level> pls = {{acc1, name("active")}};
pls.push_back({acc1, name("owner")}); // same account but different permission names
pls.push_back({acc1a, name("owner")});
trx.actions.emplace_back( pls,
newaccount{
.creator = acc1,
.name = a,
.owner = owner_auth,
.active = authority( chain.get_public_key( a, "active" ) )
});
chain.set_transaction_headers(trx);
trx.sign( chain.get_private_key( acc1, "active" ), chain.control->get_chain_id() );
trx.sign( chain.get_private_key( acc1, "owner" ), chain.control->get_chain_id() );
trx.sign( chain.get_private_key( acc1a, "owner" ), chain.control->get_chain_id() );
return chain.push_transaction( trx );
};
create_acc(acc2);
const auto &usage = db.get<resource_usage_object,by_owner>(acc1);
const auto &usage2 = db.get<resource_usage_object,by_owner>(acc1a);
BOOST_TEST(usage.cpu_usage.average() > 0U);
BOOST_TEST(usage.net_usage.average() > 0U);
BOOST_REQUIRE_EQUAL(usage.cpu_usage.average(), usage2.cpu_usage.average());
BOOST_REQUIRE_EQUAL(usage.net_usage.average(), usage2.net_usage.average());
chain.produce_block();
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(stricter_auth) {
try {
TESTER chain;
chain.produce_block();
account_name acc1 = "acc1"_n;
account_name acc2 = "acc2"_n;
account_name acc3 = "acc3"_n;
account_name acc4 = "acc4"_n;
chain.create_account(acc1);
chain.produce_block();
auto create_acc = [&](account_name a, account_name creator, int threshold) {
signed_transaction trx;
chain.set_transaction_headers(trx);
authority invalid_auth = authority(threshold, {key_weight{chain.get_public_key( a, "owner" ), 1}}, {permission_level_weight{{creator, config::active_name}, 1}});
vector<permission_level> pls;
pls.push_back({creator, name("active")});
trx.actions.emplace_back( pls,
newaccount{
.creator = creator,
.name = a,
.owner = authority( chain.get_public_key( a, "owner" ) ),
.active = invalid_auth//authority( chain.get_public_key( a, "active" ) ),
});
chain.set_transaction_headers(trx);
trx.sign( chain.get_private_key( creator, "active" ), chain.control->get_chain_id() );
return chain.push_transaction( trx );
};
try {
create_acc(acc2, acc1, 0);
BOOST_FAIL("threshold can't be zero");
} catch (...) { }
try {
create_acc(acc4, acc1, 3);
BOOST_FAIL("threshold can't be more than total weight");
} catch (...) { }
create_acc(acc3, acc1, 1);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( linkauth_special ) { try {
TESTER chain;
const auto& tester_account = "tester"_n;
std::vector<transaction_id_type> ids;
chain.produce_blocks();
chain.create_account("currency"_n);
chain.produce_blocks();
chain.create_account("tester"_n);
chain.create_account("tester2"_n);
chain.produce_blocks();
chain.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")
("parent", "active")
("auth", authority(chain.get_public_key(tester_account, "first"), 5))
);
auto validate_disallow = [&] (const char *type) {
BOOST_REQUIRE_EXCEPTION(
chain.push_action(config::system_account_name, linkauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("code", "eosio")
("type", type)
("requirement", "first")),
action_validate_exception,
fc_exception_message_is(std::string("Cannot link eosio::") + std::string(type) + std::string(" to a minimum permission"))
);
};
validate_disallow("linkauth");
validate_disallow("unlinkauth");
validate_disallow("deleteauth");
validate_disallow("updateauth");
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()