COOPENOMICS  v1
Кооперативная Экономика
eosio.system_tester.hpp
См. документацию.
1#pragma once
2
3#include <eosio/testing/tester.hpp>
4#include <eosio/chain/abi_serializer.hpp>
5#include <eosio/chain/resource_limits.hpp>
6#include "contracts.hpp"
7#include "test_symbol.hpp"
8
9#include <fc/variant_object.hpp>
10#include <fstream>
11
12using namespace eosio::chain;
13using namespace eosio::testing;
14using namespace fc;
15
16using mvo = fc::mutable_variant_object;
17
18#ifndef TESTER
19#ifdef NON_VALIDATING_TEST
20#define TESTER tester
21#else
22#define TESTER validating_tester
23#endif
24#endif
25
26
27static constexpr eosio::chain::name _provider = "voskhod"_n;
28static constexpr eosio::chain::name _provider_chairman = "ant"_n;
29
30static constexpr eosio::chain::name _ano = "ano"_n;
31static constexpr eosio::chain::name _gateway = "gateway"_n;
32static constexpr eosio::chain::name _draft = "draft"_n;
33static constexpr eosio::chain::name _marketplace = "marketplace"_n;
34static constexpr eosio::chain::name _soviet = "soviet"_n;
35static constexpr eosio::chain::name _registrator = "registrator"_n;
36static constexpr eosio::chain::name _system = "eosio"_n;
37static constexpr eosio::chain::name _fund = "fund"_n;
38static constexpr eosio::chain::name _power_account = "eosio.power"_n;
39static constexpr eosio::chain::name _saving_account = "eosio.saving"_n;
40
41
42namespace eosio_system {
43
44
46public:
47
48 void basic_setup() {
49 produce_blocks( 2 );
50
51 create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
52 "eosio.bpay"_n, "eosio.vpay"_n, "eosio.saving"_n, "eosio.names"_n, "eosio.rex"_n,
53 "eosio.power"_n, "soviet"_n, "registrator"_n, "gateway"_n, "fund"_n, "marketplace"_n, "draft"_n});
54
55 produce_blocks( 100 );
56
57 set_code( "eosio.token"_n, contracts::token_wasm());
58 set_abi( "eosio.token"_n, contracts::token_abi().data() );
59
60 {
61 const auto& accnt = control->db().get<account_object,by_name>( "eosio.token"_n );
62 abi_def abi;
63 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
64 token_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
65 }
66
67 set_code("soviet"_n, contracts::soviet_wasm());
68 set_abi("soviet"_n, contracts::soviet_abi().data());
69
70 {
71 const auto& accnt = control->db().get<account_object,by_name>( _soviet );
72 abi_def abi;
73 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
74 soviet_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
75 }
76
77
78 set_code("fund"_n, contracts::fund_wasm());
79 set_abi("fund"_n, contracts::fund_abi().data());
80
81 {
82 const auto& accnt = control->db().get<account_object,by_name>( _fund );
83 abi_def abi;
84 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
85 fund_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
86 }
87
88 set_code("gateway"_n, contracts::gateway_wasm());
89 set_abi("gateway"_n, contracts::gateway_abi().data());
90
91 {
92 const auto& accnt = control->db().get<account_object,by_name>( _gateway );
93 abi_def abi;
94 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
95 gateway_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
96 }
97
98
99 set_code("registrator"_n, contracts::registrator_wasm());
100 set_abi("registrator"_n, contracts::registrator_abi().data());
101
102 {
103 const auto& accnt = control->db().get<account_object,by_name>( _registrator );
104 abi_def abi;
105 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
106 registrator_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
107 }
108
109 set_code("marketplace"_n, contracts::marketplace_wasm());
110 set_abi("marketplace"_n, contracts::marketplace_abi().data());
111
112 {
113 const auto& accnt = control->db().get<account_object,by_name>( _marketplace );
114 abi_def abi;
115 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
116 marketplace_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
117 }
118
119 set_code("draft"_n, contracts::draft_wasm());
120 set_abi("draft"_n, contracts::draft_abi().data());
121
122 {
123 const auto& accnt = control->db().get<account_object,by_name>( _draft );
124 abi_def abi;
125 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
126 draft_abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
127 }
128
129 }
130
131 void create_core_token( symbol core_symbol = symbol{CORE_SYM} ) {
132 FC_ASSERT( core_symbol.decimals() == 4, "create_core_token assumes core token has 4 digits of precision" );
133 create_currency( "eosio.token"_n, config::system_account_name, asset(100000000000000, core_symbol) );
134 issue( asset(10000000000000, core_symbol) );
135 BOOST_REQUIRE_EQUAL( asset(10000000000000, core_symbol), get_balance( "eosio", core_symbol ) );
136 }
137
138 void deploy_system_contract( bool call_init = true ) {
139 set_code( config::system_account_name, contracts::system_wasm() );
140 set_abi( config::system_account_name, contracts::system_abi().data() );
141
142 if( call_init ) {
143 base_tester::push_action(config::system_account_name, "init"_n,
144 config::system_account_name, mutable_variant_object()
145 ("version", 0)
146 ("core", CORE_SYM_STR)
147 );
148
149 }
150
151 {
152 const auto& accnt = control->db().get<account_object,by_name>( config::system_account_name );
153 abi_def abi;
154 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
155 abi_ser.set_abi(abi, abi_serializer::create_yield_function(abi_serializer_max_time));
156 }
157 }
158
159
162
163 // Assumes previous setup steps were done with core token symbol set to CORE_SYM
164 create_account_with_resources( "alice1111111"_n, config::system_account_name, core_sym::from_string("1.0000"), false );
165 create_account_with_resources( "bob111111111"_n, config::system_account_name, core_sym::from_string("0.4500"), false );
166 create_account_with_resources( "carol1111111"_n, config::system_account_name, core_sym::from_string("1.0000"), false );
167
168 BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") );
169 }
170
171 enum class setup_level {
172 none,
173 minimal,
174 core_token,
176 full
177 };
178
180 if( l == setup_level::none ) return;
181
182 basic_setup();
183 if( l == setup_level::minimal ) return;
185 if( l == setup_level::core_token ) return;
187 if( l == setup_level::deploy_system_contract ) return;
189 }
190
191 template<typename Lambda>
192 eosio_system_tester(Lambda setup) {
193 setup(*this);
194
195 basic_setup();
199 }
200
201
202 void create_accounts_with_resources( vector<account_name> accounts, account_name creator = config::system_account_name ) {
203 for( auto a : accounts ) {
204 create_account_with_resources( a, creator );
205 }
206 }
207
208 transaction_trace_ptr create_account_with_resources( account_name a, account_name creator, uint32_t ram_bytes = 8000 ) {
209 signed_transaction trx;
210 set_transaction_headers(trx);
211
212 authority owner_auth;
213 owner_auth = authority( get_public_key( a, "owner" ) );
214
215 trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
216 newaccount{
217 .creator = creator,
218 .name = a,
219 .owner = owner_auth,
220 .active = authority( get_public_key( a, "active" ) )
221 });
222
223 trx.actions.emplace_back( get_action( config::system_account_name, "buyrambytes"_n, vector<permission_level>{{creator,config::active_name}},
224 mvo()
225 ("payer", creator)
226 ("receiver", a)
227 ("bytes", ram_bytes) )
228 );
229 trx.actions.emplace_back( get_action( config::system_account_name, "delegatebw"_n, vector<permission_level>{{creator,config::active_name}},
230 mvo()
231 ("from", creator)
232 ("receiver", a)
233 ("stake_net_quantity", core_sym::from_string("10.0000") )
234 ("stake_cpu_quantity", core_sym::from_string("10.0000") )
235 ("transfer", 0 )
236 )
237 );
238
239 set_transaction_headers(trx);
240 trx.sign( get_private_key( creator, "active" ), control->get_chain_id() );
241 return push_transaction( trx );
242 }
243
244 transaction_trace_ptr create_account_with_resources( account_name a, account_name creator, asset ramfunds, bool multisig,
245 asset net = core_sym::from_string("10.0000"), asset cpu = core_sym::from_string("10.0000") ) {
246 signed_transaction trx;
247 set_transaction_headers(trx);
248
249 authority owner_auth;
250 if (multisig) {
251 // multisig between account's owner key and creators active permission
252 owner_auth = authority(2, {key_weight{get_public_key( a, "owner" ), 1}}, {permission_level_weight{{creator, config::active_name}, 1}});
253 } else {
254 owner_auth = authority( get_public_key( a, "owner" ) );
255 }
256
257 trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
258 newaccount{
259 .creator = creator,
260 .name = a,
261 .owner = owner_auth,
262 .active = authority( get_public_key( a, "active" ) )
263 });
264
265 trx.actions.emplace_back( get_action( config::system_account_name, "buyram"_n, vector<permission_level>{{creator,config::active_name}},
266 mvo()
267 ("payer", creator)
268 ("receiver", a)
269 ("quant", ramfunds) )
270 );
271
272 trx.actions.emplace_back( get_action( config::system_account_name, "delegatebw"_n, vector<permission_level>{{creator,config::active_name}},
273 mvo()
274 ("from", creator)
275 ("receiver", a)
276 ("stake_net_quantity", net )
277 ("stake_cpu_quantity", cpu )
278 ("transfer", 0 )
279 )
280 );
281
282 set_transaction_headers(trx);
283 trx.sign( get_private_key( creator, "active" ), control->get_chain_id() );
284 return push_transaction( trx );
285 }
286
287 transaction_trace_ptr setup_producer_accounts( const std::vector<account_name>& accounts,
288 asset ram = core_sym::from_string("1.0000"),
289 asset cpu = core_sym::from_string("80.0000"),
290 asset net = core_sym::from_string("80.0000")
291 )
292 {
293 account_name creator(config::system_account_name);
294 signed_transaction trx;
295 set_transaction_headers(trx);
296
297 for (const auto& a: accounts) {
298 authority owner_auth( get_public_key( a, "owner" ) );
299 trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
300 newaccount{
301 .creator = creator,
302 .name = a,
303 .owner = owner_auth,
304 .active = authority( get_public_key( a, "active" ) )
305 });
306
307 trx.actions.emplace_back( get_action( config::system_account_name, "buyram"_n, vector<permission_level>{ {creator, config::active_name} },
308 mvo()
309 ("payer", creator)
310 ("receiver", a)
311 ("quant", ram) )
312 );
313
314 trx.actions.emplace_back( get_action( config::system_account_name, "delegatebw"_n, vector<permission_level>{ {creator, config::active_name} },
315 mvo()
316 ("from", creator)
317 ("receiver", a)
318 ("stake_net_quantity", net)
319 ("stake_cpu_quantity", cpu )
320 ("transfer", 0 )
321 )
322 );
323 }
324
325 set_transaction_headers(trx);
326 trx.sign( get_private_key( creator, "active" ), control->get_chain_id() );
327 return push_transaction( trx );
328 }
329
330 action_result buyram( const account_name& payer, account_name receiver, const asset& eosin ) {
331 return push_action( payer, "buyram"_n, mvo()( "payer",payer)("receiver",receiver)("quant",eosin) );
332 }
333 action_result buyram( std::string_view payer, std::string_view receiver, const asset& eosin ) {
334 return buyram( account_name(payer), account_name(receiver), eosin );
335 }
336
337 action_result buyrambytes( const account_name& payer, account_name receiver, uint32_t numbytes ) {
338 return push_action( payer, "buyrambytes"_n, mvo()( "payer",payer)("receiver",receiver)("bytes",numbytes) );
339 }
340 action_result buyrambytes( std::string_view payer, std::string_view receiver, uint32_t numbytes ) {
341 return buyrambytes( account_name(payer), account_name(receiver), numbytes );
342 }
343
344 action_result sellram( const account_name& account, uint64_t numbytes ) {
345 return push_action( account, "sellram"_n, mvo()( "account", account)("bytes",numbytes) );
346 }
347 action_result sellram( std::string_view account, uint64_t numbytes ) {
348 return sellram( account_name(account), numbytes );
349 }
350
351 action_result push_action( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) {
352 string action_type_name = abi_ser.get_action_type(name);
353
354 action act;
355 act.account = config::system_account_name;
356 act.name = name;
357 act.data = abi_ser.variant_to_binary( action_type_name, data, abi_serializer::create_yield_function(abi_serializer_max_time) );
358
359 return base_tester::push_action( std::move(act), (auth ? signer : signer == "bob111111111"_n ? "alice1111111"_n : "bob111111111"_n).to_uint64_t() );
360 }
361
362 action_result stake( const account_name& from, const account_name& to, const asset& net, const asset& cpu ) {
363 return push_action( name(from), "delegatebw"_n, mvo()
364 ("from", from)
365 ("receiver", to)
366 ("stake_net_quantity", net)
367 ("stake_cpu_quantity", cpu)
368 ("transfer", 0 )
369 );
370 }
371 action_result stake( std::string_view from, std::string_view to, const asset& net, const asset& cpu ) {
372 return stake( account_name(from), account_name(to), net, cpu );
373 }
374
375 action_result stake( const account_name& acnt, const asset& net, const asset& cpu ) {
376 return stake( acnt, acnt, net, cpu );
377 }
378 action_result stake( std::string_view acnt, const asset& net, const asset& cpu ) {
379 return stake( account_name(acnt), net, cpu );
380 }
381
382 action_result stake_with_transfer( const account_name& from, const account_name& to, const asset& net, const asset& cpu ) {
383 return push_action( name(from), "delegatebw"_n, mvo()
384 ("from", from)
385 ("receiver", to)
386 ("stake_net_quantity", net)
387 ("stake_cpu_quantity", cpu)
388 ("transfer", true )
389 );
390 }
391 action_result stake_with_transfer( std::string_view from, std::string_view to, const asset& net, const asset& cpu ) {
392 return stake_with_transfer( account_name(from), account_name(to), net, cpu );
393 }
394
395 action_result stake_with_transfer( const account_name& acnt, const asset& net, const asset& cpu ) {
396 return stake_with_transfer( acnt, acnt, net, cpu );
397 }
398 action_result stake_with_transfer( std::string_view acnt, const asset& net, const asset& cpu ) {
399 return stake_with_transfer( account_name(acnt), net, cpu );
400 }
401
402 action_result unstake( const account_name& from, const account_name& to, const asset& net, const asset& cpu ) {
403 return push_action( name(from), "undelegatebw"_n, mvo()
404 ("from", from)
405 ("receiver", to)
406 ("unstake_net_quantity", net)
407 ("unstake_cpu_quantity", cpu)
408 );
409 }
410 action_result unstake( std::string_view from, std::string_view to, const asset& net, const asset& cpu ) {
411 return unstake( account_name(from), account_name(to), net, cpu );
412 }
413
414 action_result unstake( const account_name& acnt, const asset& net, const asset& cpu ) {
415 return unstake( acnt, acnt, net, cpu );
416 }
417 action_result unstake( std::string_view acnt, const asset& net, const asset& cpu ) {
418 return unstake( account_name(acnt), net, cpu );
419 }
420
421 int64_t bancor_convert( int64_t S, int64_t R, int64_t T ) { return double(R) * T / ( double(S) + T ); };
422
423 int64_t get_net_limit( account_name a ) {
424 int64_t ram_bytes = 0, net = 0, cpu = 0;
425 control->get_resource_limits_manager().get_account_limits( a, ram_bytes, net, cpu );
426 return net;
427 };
428
429 int64_t get_cpu_limit( account_name a ) {
430 int64_t ram_bytes = 0, net = 0, cpu = 0;
431 control->get_resource_limits_manager().get_account_limits( a, ram_bytes, net, cpu );
432 return cpu;
433 };
434
435 action_result deposit( const account_name& owner, const asset& amount ) {
436 return push_action( name(owner), "deposit"_n, mvo()
437 ("owner", owner)
438 ("amount", amount)
439 );
440 }
441
442 action_result withdraw( const account_name& owner, const asset& amount ) {
443 return push_action( name(owner), "withdraw"_n, mvo()
444 ("owner", owner)
445 ("amount", amount)
446 );
447 }
448
449 action_result buyrex( const account_name& from, const asset& amount ) {
450 return push_action( name(from), "buyrex"_n, mvo()
451 ("from", from)
452 ("amount", amount)
453 );
454 }
455
456 asset get_buyrex_result( const account_name& from, const asset& amount ) {
457 auto trace = base_tester::push_action( config::system_account_name, "buyrex"_n, from, mvo()("from", from)("amount", amount) );
458 asset rex_received;
459 for ( size_t i = 0; i < trace->action_traces.size(); ++i ) {
460 if ( trace->action_traces[i].act.name == "buyresult"_n ) {
461 fc::raw::unpack( trace->action_traces[i].act.data.data(),
462 trace->action_traces[i].act.data.size(),
463 rex_received );
464 return rex_received;
465 }
466 }
467 return rex_received;
468 }
469
470 action_result unstaketorex( const account_name& owner, const account_name& receiver, const asset& from_net, const asset& from_cpu ) {
471 return push_action( name(owner), "unstaketorex"_n, mvo()
472 ("owner", owner)
473 ("receiver", receiver)
474 ("from_net", from_net)
475 ("from_cpu", from_cpu)
476 );
477 }
478
479 asset get_unstaketorex_result( const account_name& owner, const account_name& receiver, const asset& from_net, const asset& from_cpu ) {
480 auto trace = base_tester::push_action( config::system_account_name, "unstaketorex"_n, owner, mvo()
481 ("owner", owner)
482 ("receiver", receiver)
483 ("from_net", from_net)
484 ("from_cpu", from_cpu)
485 );
486 asset rex_received;
487 for ( size_t i = 0; i < trace->action_traces.size(); ++i ) {
488 if ( trace->action_traces[i].act.name == "buyresult"_n ) {
489 fc::raw::unpack( trace->action_traces[i].act.data.data(),
490 trace->action_traces[i].act.data.size(),
491 rex_received );
492 return rex_received;
493 }
494 }
495 return rex_received;
496 }
497
498 action_result sellrex( const account_name& from, const asset& rex ) {
499 return push_action( name(from), "sellrex"_n, mvo()
500 ("from", from)
501 ("rex", rex)
502 );
503 }
504
505 asset get_sellrex_result( const account_name& from, const asset& rex ) {
506 auto trace = base_tester::push_action( config::system_account_name, "sellrex"_n, from, mvo()("from", from)("rex", rex) );
507 asset proceeds;
508 for ( size_t i = 0; i < trace->action_traces.size(); ++i ) {
509 if ( trace->action_traces[i].act.name == "sellresult"_n ) {
510 fc::raw::unpack( trace->action_traces[i].act.data.data(),
511 trace->action_traces[i].act.data.size(),
512 proceeds );
513 return proceeds;
514 }
515 }
516 return proceeds;
517 }
518
519 auto get_rexorder_result( const transaction_trace_ptr& trace ) {
520 std::vector<std::pair<account_name, asset>> output;
521 for ( size_t i = 0; i < trace->action_traces.size(); ++i ) {
522 if ( trace->action_traces[i].act.name == "orderresult"_n ) {
523 fc::datastream<const char*> ds( trace->action_traces[i].act.data.data(),
524 trace->action_traces[i].act.data.size() );
525 account_name owner; fc::raw::unpack( ds, owner );
526 asset proceeds; fc::raw::unpack( ds, proceeds );
527 output.emplace_back( owner, proceeds );
528 }
529 }
530 return output;
531 }
532
533 action_result cancelrexorder( const account_name& owner ) {
534 return push_action( name(owner), "cnclrexorder"_n, mvo()("owner", owner) );
535 }
536
537 action_result rentcpu( const account_name& from, const account_name& receiver, const asset& payment, const asset& fund = core_sym::from_string("0.0000") ) {
538 return push_action( name(from), "rentcpu"_n, mvo()
539 ("from", from)
540 ("receiver", receiver)
541 ("loan_payment", payment)
542 ("loan_fund", fund)
543 );
544 }
545
546 action_result rentnet( const account_name& from, const account_name& receiver, const asset& payment, const asset& fund = core_sym::from_string("0.0000") ) {
547 return push_action( name(from), "rentnet"_n, mvo()
548 ("from", from)
549 ("receiver", receiver)
550 ("loan_payment", payment)
551 ("loan_fund", fund)
552 );
553 }
554
555 asset _get_rentrex_result( const account_name& from, const account_name& receiver, const asset& payment, bool cpu ) {
556 const name act = cpu ? "rentcpu"_n : "rentnet"_n;
557 auto trace = base_tester::push_action( config::system_account_name, act, from, mvo()
558 ("from", from)
559 ("receiver", receiver)
560 ("loan_payment", payment)
561 ("loan_fund", core_sym::from_string("0.0000") )
562 );
563
564 asset rented_tokens = core_sym::from_string("0.0000");
565 for ( size_t i = 0; i < trace->action_traces.size(); ++i ) {
566 if ( trace->action_traces[i].act.name == "rentresult"_n ) {
567 fc::raw::unpack( trace->action_traces[i].act.data.data(),
568 trace->action_traces[i].act.data.size(),
569 rented_tokens );
570 return rented_tokens;
571 }
572 }
573 return rented_tokens;
574 }
575
576 asset get_rentcpu_result( const account_name& from, const account_name& receiver, const asset& payment ) {
577 return _get_rentrex_result( from, receiver, payment, true );
578 }
579
580 asset get_rentnet_result( const account_name& from, const account_name& receiver, const asset& payment ) {
581 return _get_rentrex_result( from, receiver, payment, false );
582 }
583
584 action_result fundcpuloan( const account_name& from, const uint64_t loan_num, const asset& payment ) {
585 return push_action( name(from), "fundcpuloan"_n, mvo()
586 ("from", from)
587 ("loan_num", loan_num)
588 ("payment", payment)
589 );
590 }
591
592 action_result fundnetloan( const account_name& from, const uint64_t loan_num, const asset& payment ) {
593 return push_action( name(from), "fundnetloan"_n, mvo()
594 ("from", from)
595 ("loan_num", loan_num)
596 ("payment", payment)
597 );
598 }
599
600
601 action_result defundcpuloan( const account_name& from, const uint64_t loan_num, const asset& amount ) {
602 return push_action( name(from), "defcpuloan"_n, mvo()
603 ("from", from)
604 ("loan_num", loan_num)
605 ("amount", amount)
606 );
607 }
608
609 action_result defundnetloan( const account_name& from, const uint64_t loan_num, const asset& amount ) {
610 return push_action( name(from), "defnetloan"_n, mvo()
611 ("from", from)
612 ("loan_num", loan_num)
613 ("amount", amount)
614 );
615 }
616
617 action_result updaterex( const account_name& owner ) {
618 return push_action( name(owner), "updaterex"_n, mvo()("owner", owner) );
619 }
620
621 action_result rexexec( const account_name& user, uint16_t max ) {
622 return push_action( name(user), "rexexec"_n, mvo()("user", user)("max", max) );
623 }
624
625 action_result consolidate( const account_name& owner ) {
626 return push_action( name(owner), "consolidate"_n, mvo()("owner", owner) );
627 }
628
629 action_result mvtosavings( const account_name& owner, const asset& rex ) {
630 return push_action( name(owner), "mvtosavings"_n, mvo()("owner", owner)("rex", rex) );
631 }
632
633 action_result mvfrsavings( const account_name& owner, const asset& rex ) {
634 return push_action( name(owner), "mvfrsavings"_n, mvo()("owner", owner)("rex", rex) );
635 }
636
637 action_result closerex( const account_name& owner ) {
638 return push_action( name(owner), "closerex"_n, mvo()("owner", owner) );
639 }
640
641 fc::variant get_last_loan(bool cpu) {
642 vector<char> data;
643 const auto& db = control->db();
644 namespace chain = eosio::chain;
645 auto table = cpu ? "cpuloan"_n : "netloan"_n;
646 const auto* t_id = db.find<eosio::chain::table_id_object, chain::by_code_scope_table>( boost::make_tuple( config::system_account_name, config::system_account_name, table ) );
647 if ( !t_id ) {
648 return fc::variant();
649 }
650
651 const auto& idx = db.get_index<chain::key_value_index, chain::by_scope_primary>();
652
653 auto itr = idx.upper_bound( boost::make_tuple( t_id->id, std::numeric_limits<uint64_t>::max() ));
654 if ( itr == idx.begin() ) {
655 return fc::variant();
656 }
657 --itr;
658 if ( itr->t_id != t_id->id ) {
659 return fc::variant();
660 }
661
662 data.resize( itr->value.size() );
663 memcpy( data.data(), itr->value.data(), data.size() );
664 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_loan", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
665 }
666
667 fc::variant get_last_cpu_loan() {
668 return get_last_loan( true );
669 }
670
671 fc::variant get_last_net_loan() {
672 return get_last_loan( false );
673 }
674
675 fc::variant get_loan_info( const uint64_t& loan_num, bool cpu ) const {
676 name table_name = cpu ? "cpuloan"_n : "netloan"_n;
677 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, table_name, account_name(loan_num) );
678 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_loan", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
679 }
680
681 fc::variant get_cpu_loan( const uint64_t loan_num ) const {
682 return get_loan_info( loan_num, true );
683 }
684
685 fc::variant get_net_loan( const uint64_t loan_num ) const {
686 return get_loan_info( loan_num, false );
687 }
688
689 fc::variant get_dbw_obj( const account_name& from, const account_name& receiver ) const {
690 vector<char> data = get_row_by_account( config::system_account_name, from, "delband"_n, receiver );
691 return data.empty() ? fc::variant() : abi_ser.binary_to_variant("delegated_bandwidth", data, abi_serializer::create_yield_function(abi_serializer_max_time));
692 }
693
694 asset get_rex_balance( const account_name& act ) const {
695 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexbal"_n, act );
696 return data.empty() ? asset(0, symbol(SY(4, REX))) : abi_ser.binary_to_variant("rex_balance", data, abi_serializer::create_yield_function(abi_serializer_max_time))["rex_balance"].as<asset>();
697 }
698
699 fc::variant get_rex_balance_obj( const account_name& act ) const {
700 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexbal"_n, act );
701 return data.empty() ? fc::variant() : abi_ser.binary_to_variant("rex_balance", data, abi_serializer::create_yield_function(abi_serializer_max_time));
702 }
703
704 asset get_rex_fund( const account_name& act ) const {
705 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexfund"_n, act );
706 return data.empty() ? asset(0, symbol{CORE_SYM}) : abi_ser.binary_to_variant("rex_fund", data, abi_serializer::create_yield_function(abi_serializer_max_time))["balance"].as<asset>();
707 }
708
709 fc::variant get_rex_fund_obj( const account_name& act ) const {
710 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexfund"_n, act );
711 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_fund", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
712 }
713
714 asset get_rex_vote_stake( const account_name& act ) const {
715 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexbal"_n, act );
716 return data.empty() ? core_sym::from_string("0.0000") : abi_ser.binary_to_variant("rex_balance", data, abi_serializer::create_yield_function(abi_serializer_max_time))["vote_stake"].as<asset>();
717 }
718
719 fc::variant get_rex_order( const account_name& act ) {
720 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexqueue"_n, act );
721 return abi_ser.binary_to_variant( "rex_order", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
722 }
723
724 fc::variant get_rex_order_obj( const account_name& act ) {
725 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "rexqueue"_n, act );
726 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_order", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
727 }
728
729 fc::variant get_rex_pool() const {
730 vector<char> data;
731 const auto& db = control->db();
732 namespace chain = eosio::chain;
733 const auto* t_id = db.find<eosio::chain::table_id_object, chain::by_code_scope_table>( boost::make_tuple( config::system_account_name, config::system_account_name, "rexpool"_n ) );
734 if ( !t_id ) {
735 return fc::variant();
736 }
737
738 const auto& idx = db.get_index<chain::key_value_index, chain::by_scope_primary>();
739
740 auto itr = idx.lower_bound( boost::make_tuple( t_id->id, 0 ) );
741 if ( itr == idx.end() || itr->t_id != t_id->id || 0 != itr->primary_key ) {
742 return fc::variant();
743 }
744
745 data.resize( itr->value.size() );
746 memcpy( data.data(), itr->value.data(), data.size() );
747 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_pool", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
748 }
749
750 fc::variant get_rex_return_pool() const {
751 vector<char> data;
752 const auto& db = control->db();
753 namespace chain = eosio::chain;
754 const auto* t_id = db.find<eosio::chain::table_id_object, chain::by_code_scope_table>( boost::make_tuple( config::system_account_name, config::system_account_name, "rexretpool"_n ) );
755 if ( !t_id ) {
756 return fc::variant();
757 }
758
759 const auto& idx = db.get_index<chain::key_value_index, chain::by_scope_primary>();
760
761 auto itr = idx.lower_bound( boost::make_tuple( t_id->id, 0 ) );
762 if ( itr == idx.end() || itr->t_id != t_id->id || 0 != itr->primary_key ) {
763 return fc::variant();
764 }
765
766 data.resize( itr->value.size() );
767 memcpy( data.data(), itr->value.data(), data.size() );
768 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_return_pool", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
769 }
770
771 fc::variant get_rex_return_buckets() const {
772 vector<char> data;
773 const auto& db = control->db();
774 namespace chain = eosio::chain;
775 const auto* t_id = db.find<eosio::chain::table_id_object, chain::by_code_scope_table>( boost::make_tuple( config::system_account_name, config::system_account_name, "retbuckets"_n ) );
776 if ( !t_id ) {
777 return fc::variant();
778 }
779
780 const auto& idx = db.get_index<chain::key_value_index, chain::by_scope_primary>();
781
782 auto itr = idx.lower_bound( boost::make_tuple( t_id->id, 0 ) );
783 if ( itr == idx.end() || itr->t_id != t_id->id || 0 != itr->primary_key ) {
784 return fc::variant();
785 }
786
787 data.resize( itr->value.size() );
788 memcpy( data.data(), itr->value.data(), data.size() );
789 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_return_buckets", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
790 }
791
792 void setup_rex_accounts( const std::vector<account_name>& accounts,
793 const asset& init_balance,
794 const asset& net = core_sym::from_string("80.0000"),
795 const asset& cpu = core_sym::from_string("80.0000"),
796 bool deposit_into_rex_fund = true ) {
797 const asset nstake = core_sym::from_string("10.0000");
798 const asset cstake = core_sym::from_string("10.0000");
799 create_account_with_resources( "proxyaccount"_n, config::system_account_name, core_sym::from_string("1.0000"), false, net, cpu );
800 BOOST_REQUIRE_EQUAL( success(), push_action( "proxyaccount"_n, "regproxy"_n, mvo()("proxy", "proxyaccount")("isproxy", true) ) );
801 for (const auto& a: accounts) {
802 create_account_with_resources( a, config::system_account_name, core_sym::from_string("1.0000"), false, net, cpu );
803 transfer( config::system_account_name, a, init_balance + nstake + cstake, config::system_account_name );
804 BOOST_REQUIRE_EQUAL( success(), stake( a, a, nstake, cstake) );
805 BOOST_REQUIRE_EQUAL( success(), vote( a, { }, "proxyaccount"_n ) );
806 BOOST_REQUIRE_EQUAL( init_balance, get_balance(a) );
807 BOOST_REQUIRE_EQUAL( asset::from_string("0.0000 REX"), get_rex_balance(a) );
808 if (deposit_into_rex_fund) {
809 BOOST_REQUIRE_EQUAL( success(), deposit( a, init_balance ) );
810 BOOST_REQUIRE_EQUAL( init_balance, get_rex_fund( a ) );
811 BOOST_REQUIRE_EQUAL( 0, get_balance( a ).get_amount() );
812 }
813 }
814 }
815
816 action_result bidname( const account_name& bidder, const account_name& newname, const asset& bid ) {
817 return push_action( name(bidder), "bidname"_n, mvo()
818 ("bidder", bidder)
819 ("newname", newname)
820 ("bid", bid)
821 );
822 }
823 action_result bidname( std::string_view bidder, std::string_view newname, const asset& bid ) {
824 return bidname( account_name(bidder), account_name(newname), bid );
825 }
826
827 static fc::variant_object producer_parameters_example( int n ) {
828 return mutable_variant_object()
829 ("max_block_net_usage", 10000000 + n )
830 ("target_block_net_usage_pct", 10 + n )
831 ("max_transaction_net_usage", 1000000 + n )
832 ("base_per_transaction_net_usage", 100 + n)
833 ("net_usage_leeway", 500 + n )
834 ("context_free_discount_net_usage_num", 1 + n )
835 ("context_free_discount_net_usage_den", 100 + n )
836 ("max_block_cpu_usage", 10000000 + n )
837 ("target_block_cpu_usage_pct", 10 + n )
838 ("max_transaction_cpu_usage", 1000000 + n )
839 ("min_transaction_cpu_usage", 100 + n )
840 ("max_transaction_lifetime", 3600 + n)
841 ("deferred_trx_expiration_window", 600 + n)
842 ("max_transaction_delay", 10*86400+n)
843 ("max_inline_action_size", 4096 + n)
844 ("max_inline_action_depth", 4 + n)
845 ("max_authority_depth", 6 + n)
846 ("max_ram_size", (n % 10 + 1) * 1024 * 1024)
847 ("ram_reserve_ratio", 100 + n);
848 }
849
850 action_result regproducer( const account_name& acnt, int params_fixture = 1 ) {
851 action_result r = push_action( acnt, "regproducer"_n, mvo()
852 ("producer", acnt )
853 ("producer_key", get_public_key( acnt, "active" ) )
854 ("url", "" )
855 ("location", 0 )
856 );
857 BOOST_REQUIRE_EQUAL( success(), r);
858 return r;
859 }
860
861 action_result vote( const account_name& voter, const std::vector<account_name>& producers, const account_name& proxy = name(0) ) {
862 return push_action(voter, "voteproducer"_n, mvo()
863 ("voter", voter)
864 ("proxy", proxy)
865 ("producers", producers));
866 }
867 action_result vote( const account_name& voter, const std::vector<account_name>& producers, std::string_view proxy ) {
868 return vote( voter, producers, account_name(proxy) );
869 }
870
871 uint32_t last_block_time() const {
872 return time_point_sec( control->head_block_time() ).sec_since_epoch();
873 }
874
875 asset get_balance( const account_name& act, symbol balance_symbol = symbol{CORE_SYM} ) {
876 vector<char> data = get_row_by_account( "eosio.token"_n, act, "accounts"_n, account_name(balance_symbol.to_symbol_code().value) );
877 return data.empty() ? asset(0, balance_symbol) : token_abi_ser.binary_to_variant("account", data, abi_serializer::create_yield_function(abi_serializer_max_time))["balance"].as<asset>();
878 }
879
880 asset get_balance( std::string_view act, symbol balance_symbol = symbol{CORE_SYM} ) {
881 return get_balance( account_name(act), balance_symbol );
882 }
883
884 fc::variant get_total_stake( const account_name& act ) {
885 vector<char> data = get_row_by_account( config::system_account_name, act, "userres"_n, act );
886 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "user_resources", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
887 }
888 fc::variant get_total_stake( std::string_view act ) {
889 return get_total_stake( account_name(act) );
890 }
891
892 fc::variant get_voter_info( const account_name& act ) {
893 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "voters"_n, act );
894 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "voter_info", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
895 }
896 fc::variant get_voter_info( std::string_view act ) {
897 return get_voter_info( account_name(act) );
898 }
899
900 fc::variant get_producer_info( const account_name& act ) {
901 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "producers"_n, act );
902 return abi_ser.binary_to_variant( "producer_info", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
903 }
904 fc::variant get_producer_info( std::string_view act ) {
905 return get_producer_info( account_name(act) );
906 }
907
908 fc::variant get_producer_info2( const account_name& act ) {
909 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "producers2"_n, act );
910 return abi_ser.binary_to_variant( "producer_info2", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
911 }
912 fc::variant get_producer_info2( std::string_view act ) {
913 return get_producer_info2( account_name(act) );
914 }
915
916 void create_currency( name contract, name manager, asset maxsupply ) {
917 auto act = mutable_variant_object()
918 ("issuer", manager )
919 ("maximum_supply", maxsupply );
920
922 }
923
924 void issue( const asset& amount, const name& manager = config::system_account_name ) {
925 base_tester::push_action( "eosio.token"_n, "issue"_n, manager, mutable_variant_object()
926 ("to", manager )
927 ("quantity", amount )
928 ("memo", "")
929 );
930 }
931
932 void transfer( const name& from, const name& to, const asset& amount, const name& manager = config::system_account_name ) {
933 base_tester::push_action( "eosio.token"_n, "transfer"_n, manager, mutable_variant_object()
934 ("from", from)
935 ("to", to )
936 ("quantity", amount)
937 ("memo", "")
938 );
939 }
940
941 void transfer( const name& from, std::string_view to, const asset& amount, const name& manager = config::system_account_name ) {
942 transfer( from, name(to), amount, manager );
943 }
944
945 void transfer( std::string_view from, std::string_view to, const asset& amount, std::string_view manager ) {
946 transfer( name(from), name(to), amount, name(manager) );
947 }
948
949 void transfer( std::string_view from, std::string_view to, const asset& amount ) {
950 transfer( name(from), name(to), amount );
951 }
952
953 void issue_and_transfer( const name& to, const asset& amount, const name& manager = config::system_account_name ) {
954 signed_transaction trx;
955 trx.actions.emplace_back( get_action( "eosio.token"_n, "issue"_n,
956 vector<permission_level>{{manager, config::active_name}},
957 mutable_variant_object()
958 ("to", manager )
959 ("quantity", amount )
960 ("memo", "")
961 )
962 );
963 if ( to != manager ) {
964 trx.actions.emplace_back( get_action( "eosio.token"_n, "transfer"_n,
965 vector<permission_level>{{manager, config::active_name}},
966 mutable_variant_object()
967 ("from", manager)
968 ("to", to )
969 ("quantity", amount )
970 ("memo", "")
971 )
972 );
973 }
974 set_transaction_headers( trx );
975 trx.sign( get_private_key( manager, "active" ), control->get_chain_id() );
976 push_transaction( trx );
977 }
978
979 void issue_and_transfer( std::string_view to, const asset& amount, std::string_view manager ) {
980 issue_and_transfer( name(to), amount, name(manager) );
981 }
982
983 void issue_and_transfer( std::string_view to, const asset& amount, const name& manager ) {
984 issue_and_transfer( name(to), amount, manager);
985 }
986
987 void issue_and_transfer( std::string_view to, const asset& amount ) {
988 issue_and_transfer( name(to), amount );
989 }
990
991 double stake2votes( asset stake ) {
992 auto now = control->pending_block_time().time_since_epoch().count() / 1000000;
993 return stake.get_amount() * pow(2, int64_t((now - (config::block_timestamp_epoch / 1000)) / (86400 * 7))/ double(52) ); // 52 week periods (i.e. ~years)
994 }
995
996 double stake2votes( const string& s ) {
998 }
999
1000 fc::variant get_stats( const string& symbolname ) {
1001 auto symb = eosio::chain::symbol::from_string(symbolname);
1002 auto symbol_code = symb.to_symbol_code().value;
1003 vector<char> data = get_row_by_account( "eosio.token"_n, name(symbol_code), "stat"_n, account_name(symbol_code) );
1004 return data.empty() ? fc::variant() : token_abi_ser.binary_to_variant( "currency_stats", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
1005 }
1006
1008 return get_stats("4," CORE_SYM_NAME)["supply"].as<asset>();
1009 }
1010
1011 uint64_t microseconds_since_epoch_of_iso_string( const fc::variant& v ) {
1012 return static_cast<uint64_t>( time_point::from_iso_string( v.as_string() ).time_since_epoch().count() );
1013 }
1014
1015 fc::variant get_emission_state() {
1016 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "emission"_n, "emission"_n );
1017 if (data.empty()) std::cout << "\nData is empty\n" << std::endl;
1018 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "emission_state", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
1019 }
1020
1021 fc::variant get_global_state() {
1022 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "global"_n, "global"_n );
1023 if (data.empty()) std::cout << "\nData is empty\n" << std::endl;
1024 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "eosio_global_state", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
1025 }
1026
1027 fc::variant get_global_state2() {
1028 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "global2"_n, "global2"_n );
1029 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "eosio_global_state2", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
1030 }
1031
1032 fc::variant get_global_state3() {
1033 vector<char> data = get_row_by_account( config::system_account_name, config::system_account_name, "global3"_n, "global3"_n );
1034 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "eosio_global_state3", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
1035 }
1036
1037 fc::variant get_refund_request( name account ) {
1038 vector<char> data = get_row_by_account( config::system_account_name, account, "refunds"_n, account );
1039 return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "refund_request", data, abi_serializer::create_yield_function(abi_serializer_max_time) );
1040 }
1041
1042 abi_serializer initialize_multisig() {
1043 abi_serializer msig_abi_ser;
1044 {
1045 create_account_with_resources( "eosio.msig"_n, config::system_account_name );
1046 BOOST_REQUIRE_EQUAL( success(), buyram( "eosio"_n, "eosio.msig"_n, core_sym::from_string("5000.0000") ) );
1047 produce_block();
1048
1049 auto trace = base_tester::push_action(config::system_account_name, "setpriv"_n,
1050 config::system_account_name, mutable_variant_object()
1051 ("account", "eosio.msig")
1052 ("is_priv", 1)
1053 );
1054
1055 set_code( "eosio.msig"_n, contracts::msig_wasm() );
1056 set_abi( "eosio.msig"_n, contracts::msig_abi().data() );
1057
1059 const auto& accnt = control->db().get<account_object,by_name>( "eosio.msig"_n );
1060 abi_def msig_abi;
1061 BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, msig_abi), true);
1062 msig_abi_ser.set_abi(msig_abi, abi_serializer::create_yield_function(abi_serializer_max_time));
1063 }
1064 return msig_abi_ser;
1065 }
1066
1068 //stake more than 15% of total EOS supply to activate chain
1069 transfer( "eosio"_n, "alice1111111"_n, core_sym::from_string("650000000.0000"), config::system_account_name );
1070 BOOST_REQUIRE_EQUAL( success(), stake( "alice1111111"_n, "alice1111111"_n, core_sym::from_string("300000000.0000"), core_sym::from_string("300000000.0000") ) );
1071
1072 // create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers
1073 std::vector<account_name> producer_names;
1074 {
1075 producer_names.reserve('z' - 'a' + 1);
1076 const std::string root("defproducer");
1077 for ( char c = 'a'; c < 'a'+21; ++c ) {
1078 producer_names.emplace_back(root + std::string(1, c));
1079 }
1080 setup_producer_accounts(producer_names);
1081 for (const auto& p: producer_names) {
1082
1083 BOOST_REQUIRE_EQUAL( success(), regproducer(p) );
1084 }
1085 }
1086 produce_blocks( 250);
1087
1088 auto trace_auth = TESTER::push_action(config::system_account_name, updateauth::get_name(), config::system_account_name, mvo()
1089 ("account", name(config::system_account_name).to_string())
1090 ("permission", name(config::active_name).to_string())
1091 ("parent", name(config::owner_name).to_string())
1092 ("auth", authority(1, {key_weight{get_public_key( config::system_account_name, "active" ), 1}}, {
1093 permission_level_weight{{config::system_account_name, config::eosio_code_name}, 1},
1094 permission_level_weight{{config::producers_account_name, config::active_name}, 1}
1095 }
1096 ))
1097 );
1098 BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace_auth->receipt->status);
1099
1100 //vote for producers
1101 {
1102 transfer( config::system_account_name, "alice1111111"_n, core_sym::from_string("100000000.0000"), config::system_account_name );
1103 BOOST_REQUIRE_EQUAL(success(), stake( "alice1111111"_n, core_sym::from_string("30000000.0000"), core_sym::from_string("30000000.0000") ) );
1104 BOOST_REQUIRE_EQUAL(success(), buyram( "alice1111111"_n, "alice1111111"_n, core_sym::from_string("30000000.0000") ) );
1105 BOOST_REQUIRE_EQUAL(success(), push_action("alice1111111"_n, "voteproducer"_n, mvo()
1106 ("voter", "alice1111111")
1107 ("proxy", name(0).to_string())
1108 ("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+21))
1109 )
1110 );
1111 }
1112 produce_blocks( 250 );
1113
1114 auto producer_keys = control->head_block_state()->active_schedule.producers;
1115 BOOST_REQUIRE_EQUAL( 21, producer_keys.size() );
1116 BOOST_REQUIRE_EQUAL( name("defproducera"), producer_keys[0].producer_name );
1117
1118 return producer_names;
1119 }
1120
1122 setup_producer_accounts({"producer1111"_n});
1123 regproducer("producer1111"_n);
1124 {
1125 signed_transaction trx;
1126 set_transaction_headers(trx);
1127
1128 trx.actions.emplace_back( get_action( config::system_account_name, "delegatebw"_n,
1129 vector<permission_level>{{config::system_account_name, config::active_name}},
1130 mvo()
1131 ("from", name{config::system_account_name})
1132 ("receiver", "producer1111")
1133 ("stake_net_quantity", core_sym::from_string("150000000.0000") )
1134 ("stake_cpu_quantity", core_sym::from_string("0.0000") )
1135 ("transfer", 1 )
1136 )
1137 );
1138 trx.actions.emplace_back( get_action( config::system_account_name, "voteproducer"_n,
1139 vector<permission_level>{{"producer1111"_n, config::active_name}},
1140 mvo()
1141 ("voter", "producer1111")
1142 ("proxy", name(0).to_string())
1143 ("producers", vector<account_name>(1, "producer1111"_n))
1144 )
1145 );
1146 trx.actions.emplace_back( get_action( config::system_account_name, "undelegatebw"_n,
1147 vector<permission_level>{{"producer1111"_n, config::active_name}},
1148 mvo()
1149 ("from", "producer1111")
1150 ("receiver", "producer1111")
1151 ("unstake_net_quantity", core_sym::from_string("150000000.0000") )
1152 ("unstake_cpu_quantity", core_sym::from_string("0.0000") )
1153 )
1154 );
1155
1156 set_transaction_headers(trx);
1157 trx.sign( get_private_key( config::system_account_name, "active" ), control->get_chain_id() );
1158 trx.sign( get_private_key( "producer1111"_n, "active" ), control->get_chain_id() );
1159 push_transaction( trx );
1160 produce_block();
1161 }
1162 }
1163
1164 action_result setinflation( int64_t annual_rate, int64_t inflation_pay_factor, int64_t votepay_factor ) {
1165 return push_action( "eosio"_n, "setinflation"_n, mvo()
1166 ("annual_rate", annual_rate)
1167 ("inflation_pay_factor", inflation_pay_factor)
1168 ("votepay_factor", votepay_factor)
1169 );
1170 }
1171
1172 abi_serializer abi_ser;
1173 abi_serializer token_abi_ser;
1174
1175 abi_serializer soviet_abi_ser;
1176 abi_serializer registrator_abi_ser;
1177 abi_serializer draft_abi_ser;
1178 abi_serializer fund_abi_ser;
1179 abi_serializer gateway_abi_ser;
1180 abi_serializer marketplace_abi_ser;
1181};
1182
1183inline fc::mutable_variant_object voter( account_name acct ) {
1184 return mutable_variant_object()
1185 ("owner", acct)
1186 ("proxy", name(0).to_string())
1187 ("producers", variants() )
1188 ("staked", int64_t(0))
1189 //("last_vote_weight", double(0))
1190 ("proxied_vote_weight", double(0))
1191 ("is_proxy", 0)
1192 ;
1193}
1194inline fc::mutable_variant_object voter( std::string_view acct ) {
1195 return voter( account_name(acct) );
1196}
1197
1198inline fc::mutable_variant_object voter( account_name acct, const asset& vote_stake ) {
1199 return voter( acct )( "staked", vote_stake.get_amount() );
1200}
1201inline fc::mutable_variant_object voter( std::string_view acct, const asset& vote_stake ) {
1202 return voter( account_name(acct), vote_stake );
1203}
1204
1205inline fc::mutable_variant_object voter( account_name acct, int64_t vote_stake ) {
1206 return voter( acct )( "staked", vote_stake );
1207}
1208inline fc::mutable_variant_object voter( std::string_view acct, int64_t vote_stake ) {
1209 return voter( account_name(acct), vote_stake );
1210}
1211
1212inline fc::mutable_variant_object proxy( account_name acct ) {
1213 return voter( acct )( "is_proxy", 1 );
1214}
1215
1216inline uint64_t M( const string& eos_str ) {
1217 return core_sym::from_string( eos_str ).get_amount();
1218}
1219
1220}
Definition: eosio.system_tester.hpp:45
fc::variant get_rex_fund_obj(const account_name &act) const
Definition: eosio.system_tester.hpp:709
action_result buyram(const account_name &payer, account_name receiver, const asset &eosin)
Definition: eosio.system_tester.hpp:330
fc::variant get_global_state3()
Definition: eosio.system_tester.hpp:1032
void create_accounts_with_resources(vector< account_name > accounts, account_name creator=config::system_account_name)
Definition: eosio.system_tester.hpp:202
action_result rentnet(const account_name &from, const account_name &receiver, const asset &payment, const asset &fund=core_sym::from_string("0.0000"))
Definition: eosio.system_tester.hpp:546
void create_core_token(symbol core_symbol=symbol{CORE_SYM})
Definition: eosio.system_tester.hpp:131
fc::variant get_global_state()
Definition: eosio.system_tester.hpp:1021
static fc::variant_object producer_parameters_example(int n)
Definition: eosio.system_tester.hpp:827
fc::variant get_last_loan(bool cpu)
Definition: eosio.system_tester.hpp:641
fc::variant get_loan_info(const uint64_t &loan_num, bool cpu) const
Definition: eosio.system_tester.hpp:675
action_result rentcpu(const account_name &from, const account_name &receiver, const asset &payment, const asset &fund=core_sym::from_string("0.0000"))
Definition: eosio.system_tester.hpp:537
action_result stake(const account_name &from, const account_name &to, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:362
fc::variant get_producer_info(std::string_view act)
Definition: eosio.system_tester.hpp:904
action_result consolidate(const account_name &owner)
Definition: eosio.system_tester.hpp:625
fc::variant get_rex_order(const account_name &act)
Definition: eosio.system_tester.hpp:719
void transfer(std::string_view from, std::string_view to, const asset &amount, std::string_view manager)
Definition: eosio.system_tester.hpp:945
asset get_balance(std::string_view act, symbol balance_symbol=symbol{CORE_SYM})
Definition: eosio.system_tester.hpp:880
void deploy_system_contract(bool call_init=true)
Definition: eosio.system_tester.hpp:138
fc::variant get_last_net_loan()
Definition: eosio.system_tester.hpp:671
action_result push_action(const account_name &signer, const action_name &name, const variant_object &data, bool auth=true)
Definition: eosio.system_tester.hpp:351
fc::variant get_rex_return_pool() const
Definition: eosio.system_tester.hpp:750
action_result buyrambytes(const account_name &payer, account_name receiver, uint32_t numbytes)
Definition: eosio.system_tester.hpp:337
int64_t get_net_limit(account_name a)
Definition: eosio.system_tester.hpp:423
eosio_system_tester(Lambda setup)
Definition: eosio.system_tester.hpp:192
fc::variant get_emission_state()
Definition: eosio.system_tester.hpp:1015
action_result stake_with_transfer(std::string_view acnt, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:398
action_result buyrex(const account_name &from, const asset &amount)
Definition: eosio.system_tester.hpp:449
action_result rexexec(const account_name &user, uint16_t max)
Definition: eosio.system_tester.hpp:621
action_result sellram(std::string_view account, uint64_t numbytes)
Definition: eosio.system_tester.hpp:347
action_result withdraw(const account_name &owner, const asset &amount)
Definition: eosio.system_tester.hpp:442
int64_t get_cpu_limit(account_name a)
Definition: eosio.system_tester.hpp:429
action_result unstake(std::string_view from, std::string_view to, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:410
eosio_system_tester(setup_level l=setup_level::full)
Definition: eosio.system_tester.hpp:179
abi_serializer draft_abi_ser
Definition: eosio.system_tester.hpp:1177
void issue_and_transfer(std::string_view to, const asset &amount, const name &manager)
Definition: eosio.system_tester.hpp:983
action_result setinflation(int64_t annual_rate, int64_t inflation_pay_factor, int64_t votepay_factor)
Definition: eosio.system_tester.hpp:1164
action_result defundnetloan(const account_name &from, const uint64_t loan_num, const asset &amount)
Definition: eosio.system_tester.hpp:609
action_result unstake(std::string_view acnt, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:417
asset get_sellrex_result(const account_name &from, const asset &rex)
Definition: eosio.system_tester.hpp:505
void basic_setup()
Definition: eosio.system_tester.hpp:48
action_result closerex(const account_name &owner)
Definition: eosio.system_tester.hpp:637
fc::variant get_producer_info2(std::string_view act)
Definition: eosio.system_tester.hpp:912
action_result defundcpuloan(const account_name &from, const uint64_t loan_num, const asset &amount)
Definition: eosio.system_tester.hpp:601
action_result regproducer(const account_name &acnt, int params_fixture=1)
Definition: eosio.system_tester.hpp:850
asset get_rentnet_result(const account_name &from, const account_name &receiver, const asset &payment)
Definition: eosio.system_tester.hpp:580
action_result fundcpuloan(const account_name &from, const uint64_t loan_num, const asset &payment)
Definition: eosio.system_tester.hpp:584
asset get_rex_vote_stake(const account_name &act) const
Definition: eosio.system_tester.hpp:714
void issue_and_transfer(std::string_view to, const asset &amount, std::string_view manager)
Definition: eosio.system_tester.hpp:979
fc::variant get_voter_info(const account_name &act)
Definition: eosio.system_tester.hpp:892
transaction_trace_ptr create_account_with_resources(account_name a, account_name creator, uint32_t ram_bytes=8000)
Definition: eosio.system_tester.hpp:208
asset get_unstaketorex_result(const account_name &owner, const account_name &receiver, const asset &from_net, const asset &from_cpu)
Definition: eosio.system_tester.hpp:479
abi_serializer abi_ser
Definition: eosio.system_tester.hpp:1172
fc::variant get_last_cpu_loan()
Definition: eosio.system_tester.hpp:667
asset _get_rentrex_result(const account_name &from, const account_name &receiver, const asset &payment, bool cpu)
Definition: eosio.system_tester.hpp:555
action_result deposit(const account_name &owner, const asset &amount)
Definition: eosio.system_tester.hpp:435
double stake2votes(asset stake)
Definition: eosio.system_tester.hpp:991
void transfer(const name &from, const name &to, const asset &amount, const name &manager=config::system_account_name)
Definition: eosio.system_tester.hpp:932
fc::variant get_dbw_obj(const account_name &from, const account_name &receiver) const
Definition: eosio.system_tester.hpp:689
action_result bidname(std::string_view bidder, std::string_view newname, const asset &bid)
Definition: eosio.system_tester.hpp:823
fc::variant get_voter_info(std::string_view act)
Definition: eosio.system_tester.hpp:896
fc::variant get_rex_balance_obj(const account_name &act) const
Definition: eosio.system_tester.hpp:699
vector< name > active_and_vote_producers()
Definition: eosio.system_tester.hpp:1067
action_result cancelrexorder(const account_name &owner)
Definition: eosio.system_tester.hpp:533
asset get_token_supply()
Definition: eosio.system_tester.hpp:1007
action_result sellram(const account_name &account, uint64_t numbytes)
Definition: eosio.system_tester.hpp:344
void create_currency(name contract, name manager, asset maxsupply)
Definition: eosio.system_tester.hpp:916
action_result unstake(const account_name &acnt, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:414
void issue(const asset &amount, const name &manager=config::system_account_name)
Definition: eosio.system_tester.hpp:924
uint64_t microseconds_since_epoch_of_iso_string(const fc::variant &v)
Definition: eosio.system_tester.hpp:1011
fc::variant get_total_stake(std::string_view act)
Definition: eosio.system_tester.hpp:888
action_result vote(const account_name &voter, const std::vector< account_name > &producers, const account_name &proxy=name(0))
Definition: eosio.system_tester.hpp:861
transaction_trace_ptr create_account_with_resources(account_name a, account_name creator, asset ramfunds, bool multisig, asset net=core_sym::from_string("10.0000"), asset cpu=core_sym::from_string("10.0000"))
Definition: eosio.system_tester.hpp:244
asset get_rentcpu_result(const account_name &from, const account_name &receiver, const asset &payment)
Definition: eosio.system_tester.hpp:576
fc::variant get_net_loan(const uint64_t loan_num) const
Definition: eosio.system_tester.hpp:685
fc::variant get_total_stake(const account_name &act)
Definition: eosio.system_tester.hpp:884
action_result sellrex(const account_name &from, const asset &rex)
Definition: eosio.system_tester.hpp:498
action_result mvtosavings(const account_name &owner, const asset &rex)
Definition: eosio.system_tester.hpp:629
asset get_rex_fund(const account_name &act) const
Definition: eosio.system_tester.hpp:704
action_result stake(std::string_view acnt, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:378
action_result stake_with_transfer(std::string_view from, std::string_view to, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:391
action_result unstake(const account_name &from, const account_name &to, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:402
fc::variant get_global_state2()
Definition: eosio.system_tester.hpp:1027
fc::variant get_cpu_loan(const uint64_t loan_num) const
Definition: eosio.system_tester.hpp:681
asset get_buyrex_result(const account_name &from, const asset &amount)
Definition: eosio.system_tester.hpp:456
void issue_and_transfer(const name &to, const asset &amount, const name &manager=config::system_account_name)
Definition: eosio.system_tester.hpp:953
action_result buyram(std::string_view payer, std::string_view receiver, const asset &eosin)
Definition: eosio.system_tester.hpp:333
abi_serializer gateway_abi_ser
Definition: eosio.system_tester.hpp:1179
fc::variant get_producer_info(const account_name &act)
Definition: eosio.system_tester.hpp:900
fc::variant get_producer_info2(const account_name &act)
Definition: eosio.system_tester.hpp:908
void cross_15_percent_threshold()
Definition: eosio.system_tester.hpp:1121
void transfer(std::string_view from, std::string_view to, const asset &amount)
Definition: eosio.system_tester.hpp:949
action_result vote(const account_name &voter, const std::vector< account_name > &producers, std::string_view proxy)
Definition: eosio.system_tester.hpp:867
asset get_rex_balance(const account_name &act) const
Definition: eosio.system_tester.hpp:694
abi_serializer fund_abi_ser
Definition: eosio.system_tester.hpp:1178
transaction_trace_ptr setup_producer_accounts(const std::vector< account_name > &accounts, asset ram=core_sym::from_string("1.0000"), asset cpu=core_sym::from_string("80.0000"), asset net=core_sym::from_string("80.0000"))
Definition: eosio.system_tester.hpp:287
action_result stake_with_transfer(const account_name &from, const account_name &to, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:382
int64_t bancor_convert(int64_t S, int64_t R, int64_t T)
Definition: eosio.system_tester.hpp:421
abi_serializer soviet_abi_ser
Definition: eosio.system_tester.hpp:1175
double stake2votes(const string &s)
Definition: eosio.system_tester.hpp:996
abi_serializer token_abi_ser
Definition: eosio.system_tester.hpp:1173
fc::variant get_stats(const string &symbolname)
Definition: eosio.system_tester.hpp:1000
action_result bidname(const account_name &bidder, const account_name &newname, const asset &bid)
Definition: eosio.system_tester.hpp:816
action_result stake(const account_name &acnt, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:375
void issue_and_transfer(std::string_view to, const asset &amount)
Definition: eosio.system_tester.hpp:987
action_result mvfrsavings(const account_name &owner, const asset &rex)
Definition: eosio.system_tester.hpp:633
action_result stake(std::string_view from, std::string_view to, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:371
fc::variant get_refund_request(name account)
Definition: eosio.system_tester.hpp:1037
void remaining_setup()
Definition: eosio.system_tester.hpp:160
fc::variant get_rex_pool() const
Definition: eosio.system_tester.hpp:729
void setup_rex_accounts(const std::vector< account_name > &accounts, const asset &init_balance, const asset &net=core_sym::from_string("80.0000"), const asset &cpu=core_sym::from_string("80.0000"), bool deposit_into_rex_fund=true)
Definition: eosio.system_tester.hpp:792
action_result fundnetloan(const account_name &from, const uint64_t loan_num, const asset &payment)
Definition: eosio.system_tester.hpp:592
asset get_balance(const account_name &act, symbol balance_symbol=symbol{CORE_SYM})
Definition: eosio.system_tester.hpp:875
fc::variant get_rex_order_obj(const account_name &act)
Definition: eosio.system_tester.hpp:724
action_result unstaketorex(const account_name &owner, const account_name &receiver, const asset &from_net, const asset &from_cpu)
Definition: eosio.system_tester.hpp:470
setup_level
Definition: eosio.system_tester.hpp:171
abi_serializer marketplace_abi_ser
Definition: eosio.system_tester.hpp:1180
abi_serializer registrator_abi_ser
Definition: eosio.system_tester.hpp:1176
action_result updaterex(const account_name &owner)
Definition: eosio.system_tester.hpp:617
uint32_t last_block_time() const
Definition: eosio.system_tester.hpp:871
abi_serializer initialize_multisig()
Definition: eosio.system_tester.hpp:1042
void transfer(const name &from, std::string_view to, const asset &amount, const name &manager=config::system_account_name)
Definition: eosio.system_tester.hpp:941
action_result buyrambytes(std::string_view payer, std::string_view receiver, uint32_t numbytes)
Definition: eosio.system_tester.hpp:340
auto get_rexorder_result(const transaction_trace_ptr &trace)
Definition: eosio.system_tester.hpp:519
fc::variant get_rex_return_buckets() const
Definition: eosio.system_tester.hpp:771
action_result stake_with_transfer(const account_name &acnt, const asset &net, const asset &cpu)
Definition: eosio.system_tester.hpp:395
Константы контракта управления фондами
Definition: fund.hpp:54
const auto owner
Definition: eosio.limitauth_tests.cpp:16
transaction_trace_ptr trace
Definition: eosio.msig_tests.cpp:305
contract
Definition: eosio.msig_tests.cpp:977
push_action("alice"_n, "propose"_n, mvo()("proposer", "alice")("proposal_name", "first")("trx", trx)("requested", vector< permission_level >{{ "alice"_n, config::active_name }}))
create_accounts({ "eosio.token"_n, "eosio.rex"_n })
transaction trx
Definition: eosio.msig_tests.cpp:367
action act
Definition: eosio.msig_tests.cpp:974
set_abi("eosio.token"_n, contracts::token_abi().data())
fc::mutable_variant_object mvo
Definition: eosio.msig_tests.cpp:17
BOOST_REQUIRE_EQUAL(core_sym::from_string("1000000000.0000"), get_balance(config::system_account_name)+get_balance("eosio.ramfee"_n)+get_balance("eosio.stake"_n)+get_balance("eosio.ram"_n))
produce_blocks()
set_code("eosio.token"_n, contracts::token_wasm())
static constexpr eosio::chain::name _soviet
Definition: eosio.system_tester.hpp:34
static constexpr eosio::chain::name _registrator
Definition: eosio.system_tester.hpp:35
static constexpr eosio::chain::name _power_account
Definition: eosio.system_tester.hpp:38
static constexpr eosio::chain::name _fund
Definition: eosio.system_tester.hpp:37
static constexpr eosio::chain::name _system
Definition: eosio.system_tester.hpp:36
static constexpr eosio::chain::name _provider
Definition: eosio.system_tester.hpp:27
static constexpr eosio::chain::name _marketplace
Definition: eosio.system_tester.hpp:33
static constexpr eosio::chain::name _draft
Definition: eosio.system_tester.hpp:32
fc::mutable_variant_object mvo
Definition: eosio.system_tester.hpp:16
#define TESTER
Definition: eosio.system_tester.hpp:22
static constexpr eosio::chain::name _gateway
Definition: eosio.system_tester.hpp:31
static constexpr eosio::chain::name _ano
Definition: eosio.system_tester.hpp:30
static constexpr eosio::chain::name _provider_chairman
Definition: eosio.system_tester.hpp:28
static constexpr eosio::chain::name _saving_account
Definition: eosio.system_tester.hpp:39
asset max(10, symbol(SY(0, NKT)))
share_type amount
Definition: eosio.token_tests.cpp:174
produce_block()
Definition: eosio.system_tester.hpp:42
fc::mutable_variant_object voter(account_name acct)
Definition: eosio.system_tester.hpp:1183
fc::mutable_variant_object proxy(account_name acct)
Definition: eosio.system_tester.hpp:1212
uint64_t M(const string &eos_str)
Definition: eosio.system_tester.hpp:1216
action(permission_level{ _gateway, "active"_n}, _gateway, "adduser"_n, std::make_tuple(coopname, deposit->username, to_spread, to_circulation, eosio::current_time_point(), true)).send()
Структура, представляющая учетные записи аккаунтов.
Definition: accounts.hpp:60
Definition: permissions.hpp:25
static eosio::chain::asset from_string(const std::string &s)
Definition: test_symbol.hpp:13
Definition: permissions.hpp:9
Definition: permissions.hpp:1
#define CORE_SYM_STR
Definition: test_symbol.hpp:9
#define CORE_SYM_NAME
Definition: test_symbol.hpp:3
#define CORE_SYM
Definition: test_symbol.hpp:10