forked from XPRNetwork/eosio.evm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eosio.evm_tests.cpp
729 lines (626 loc) · 59.7 KB
/
eosio.evm_tests.cpp
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#include <boost/test/unit_test.hpp>
#include <boost/algorithm/string.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/abi_serializer.hpp>
#include "eosio.system_tester.hpp"
#include <eosio/chain/exceptions.hpp>
#include "Runtime/Runtime.h"
#include "external/div.cpp"
#include "external/rlp.hpp"
#include <fc/variant_object.hpp>
#include <iostream>
#include <filesystem>
#include <iostream>
#include <array>
#include <vector>
namespace fs = std::filesystem;
using namespace eosio::testing;
using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
using namespace fc;
using namespace std;
using mvo = fc::mutable_variant_object;
constexpr auto FORK = "Istanbul";
const bool base_enabled = false;
const bool erc20_enabled = false;
const bool erc721_enabled = false;
const bool transaction_tests_enabled = false;
const bool state_tests_enabled = true;
const bool debugging_enabled = false;
class eosio_evm_tester : public tester {
public:
eosio_evm_tester() {
produce_blocks( 2 );
create_accounts( {
N(evm), N(eosio.evm), N(eosio.token), N(1234test1111), N(erc20), N(erc721), N(vestvestvest)
} );
produce_blocks( 2 );
// Deploy evm
set_code( N(eosio.evm), contracts::evm_wasm() );
set_abi( N(eosio.evm), contracts::evm_abi().data() );
produce_blocks();
const auto& wasm_accnt = control->db().get<account_object, by_name>( N(eosio.evm) );
abi_def wasm_abi;
BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(wasm_accnt.abi, wasm_abi), true);
abi_ser.set_abi(wasm_abi, abi_serializer_max_time);
// Deploy token
set_code( N(eosio.token), contracts::token_wasm() );
set_abi( N(eosio.token), contracts::token_abi().data() );
create_currency( N(eosio.token), N(vestvestvest), asset(100000000000000, symbol{CORE_SYM}) );
issue( asset(10000000000000, symbol{CORE_SYM}), N(vestvestvest) );
produce_blocks();
const auto& token_acct = control->db().get<account_object, by_name>( N(eosio.evm) );
abi_def token_abi;
BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(token_acct.abi, token_abi), true);
abi_ser.set_abi(token_abi, abi_serializer_max_time);
}
fc::variant get_account( account_name acc )
{
vector<char> data = get_row_by_account( N(eosio.evm), N(eosio.evm), N(account), acc );
return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "Account", data, abi_serializer_max_time );
}
transaction_trace_ptr create( const name& signer, const name& account, const std::string& data )
{
return base_tester::push_action( N(eosio.evm), N(create), signer, mvo()
( "account", account)
( "data", data)
);
}
transaction_trace_ptr testtx( const std::string& tx )
{
return base_tester::push_action( N(eosio.evm), N(testtx), N(eosio.evm), mvo()
( "tx", tx)
);
}
void create_currency( name contract, name manager, asset maxsupply ) {
auto act = mutable_variant_object()
("issuer", manager )
("maximum_supply", maxsupply );
base_tester::push_action(contract, N(create), contract, act );
}
void issue( const asset& amount, const name& manager = config::system_account_name ) {
base_tester::push_action( N(eosio.token), N(issue), manager, mutable_variant_object()
("to", manager )
("quantity", amount )
("memo", "")
);
}
void transfer( const name& from, const name& to, const asset& amount ) {
base_tester::push_action( N(eosio.token), N(transfer), from, mutable_variant_object()
("from", from)
("to", to )
("quantity", amount)
("memo", "")
);
}
transaction_trace_ptr push_transaction2( signed_transaction& trx,
fc::time_point deadline,
uint32_t billed_cpu_time_us,
bool no_throw
)
{
if( !control->is_building_block() )
_start_block(control->head_block_time() + fc::microseconds(config::block_interval_us));
auto c = packed_transaction::compression_type::none;
if( fc::raw::pack_size(trx) > 1000 ) {
c = packed_transaction::compression_type::zlib;
}
auto time_limit = deadline == fc::time_point::maximum() ?
fc::microseconds::maximum() :
fc::microseconds( deadline - fc::time_point::now() );
auto ptrx = std::make_shared<packed_transaction>( trx, c );
auto fut = transaction_metadata::start_recover_keys( ptrx, control->get_thread_pool(), control->get_chain_id(), time_limit );
auto r = control->push_transaction( fut.get(), deadline, billed_cpu_time_us );
if (no_throw) return r;
if( r->except_ptr ) std::rethrow_exception( r->except_ptr );
if( r->except) throw *r->except;
return r;
}
transaction_trace_ptr push_action2( const account_name& code,
const action_name& acttype,
const account_name& actor,
const variant_object& data,
uint32_t expiration = 30,
uint32_t delay_sec = 0
)
{
vector<permission_level> auths;
auths.push_back( permission_level{actor, config::active_name} );
return push_action2( code, acttype, auths, data, expiration, delay_sec );
}
transaction_trace_ptr push_action2( const account_name& code,
const action_name& acttype,
const vector<account_name>& actors,
const variant_object& data,
uint32_t expiration,
uint32_t delay_sec
)
{
vector<permission_level> auths;
for (const auto& actor : actors) {
auths.push_back( permission_level{actor, config::active_name} );
}
return push_action2( code, acttype, auths, data, expiration, delay_sec );
}
transaction_trace_ptr push_action2( const account_name& code,
const action_name& acttype,
const vector<permission_level>& auths,
const variant_object& data,
uint32_t expiration,
uint32_t delay_sec
)
{
signed_transaction trx;
trx.actions.emplace_back( get_action( code, acttype, auths, data ) );
set_transaction_headers( trx, expiration, delay_sec );
for (const auto& auth : auths) {
trx.sign( get_private_key( auth.actor, auth.permission.to_string() ), control->get_chain_id() );
}
return push_transaction2( trx, fc::time_point::maximum(), 5000, true );
}
abi_serializer abi_ser;
};
std::vector<uint8_t> to_bin(std::string binstr)
{
std::vector<uint8_t> out;
for (auto i = 0; i < binstr.size(); i++) {
out.push_back((uint8_t) binstr[i]);
}
return out;
}
std::vector<uint8_t> hex2bin(std::string hexstr)
{
size_t len = hexstr.size();
if(len % 2 != 0) return {}; // ERROR
size_t final_len = len / 2;
std::vector<uint8_t> chrs (final_len);
for (size_t i=0, j=0; j<final_len; i+=2, j++) {
chrs[j] = (std::toupper(hexstr[i]) % 32 + 9) % 25 * 16 + (std::toupper(hexstr[i+1]) % 32 + 9) % 25;
}
return chrs;
}
std::string bin2hex(const std::vector<uint8_t>& bin)
{
std::string res;
const char hex[] = "0123456789abcdef";
for(auto byte : bin) {
res += hex[byte >> 4];
res += hex[byte & 0xf];
}
return res;
}
BOOST_AUTO_TEST_SUITE(eosio_evm_base, * boost::unit_test::enable_if<base_enabled>())
BOOST_FIXTURE_TEST_CASE( test_create, eosio_evm_tester ) try {
// Create first time
create( N(1234test1111), N(1234test1111), std::string("hi") );
auto stats = get_account( N(0) );
REQUIRE_MATCHING_OBJECT( stats, mvo()
("index", 0)
("address", "bc5c5b389d1bd6b0e356bfcb2b3d748a98304a0c")
("account", "1234test1111")
("balance", "0000000000000000000000000000000000000000000000000000000000000000")
("nonce", 1)
("code", vector<uint8_t>{})
);
produce_blocks(2);
// Create same time (same arbitrary string)
BOOST_CHECK_EXCEPTION(
create( N(1234test1111), N(1234test1111), std::string("hi") ),
eosio_assert_message_exception,
[](const eosio_assert_message_exception& e) {
return expect_assert_message(e, "an EVM account is already linked to this EOS account");
}
);
produce_blocks(2);
// Create same time (different arbitrary string)
BOOST_CHECK_EXCEPTION(
create( N(1234test1111), N(1234test1111), std::string("him") ),
eosio_assert_message_exception,
[](const eosio_assert_message_exception& e) {
return expect_assert_message(e, "an EVM account is already linked to this EOS account");
}
);
produce_blocks(1);
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( test_create_wrong_auth, eosio_evm_tester ) try {
BOOST_CHECK_EXCEPTION(
create( N(evm), N(1234test1111), std::string("hi") ),
missing_auth_exception,
[](const missing_auth_exception& e) {
return expect_assert_message(e, "missing authority of");
}
);
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_evm_erc20, * boost::unit_test::enable_if<erc20_enabled>())
BOOST_FIXTURE_TEST_CASE( erc_20, eosio_evm_tester ) try {
// Create new address
base_tester::push_action( N(eosio.evm), N(create), N(vestvestvest), mvo()
( "account", N(vestvestvest))
( "data", "test")
);
// Transfer token to contract to deposit
transfer(N(vestvestvest), N(eosio.evm), asset::from_string("200.0000 EOS"));
// Transfer token from linked address to unlinked new address
base_tester::push_action( N(eosio.evm), N(raw), N(vestvestvest), mvo()
( "tx", "e00101831e848094f79b834a37f3143f4a73fc3934edac67fd3a01cd0180808080")
( "sender", "10d10ef03ef3316b750d2544bae8c96309aa4360")
);
// Deploy erc20 SYED
push_action2( N(eosio.evm), N(raw), N(vestvestvest), mvo()
( "tx", "f917858001831e84808080b9173760806040523480156200001157600080fd5b506040516200165738038062001657833981810160405260608110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b838201915060208201858111156200006f57600080fd5b82518660018202830111640100000000821117156200008d57600080fd5b8083526020830192505050908051906020019080838360005b83811015620000c3578082015181840152602081019050620000a6565b50505050905090810190601f168015620000f15780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200011557600080fd5b838201915060208201858111156200012c57600080fd5b82518660018202830111640100000000821117156200014a57600080fd5b8083526020830192505050908051906020019080838360005b838110156200018057808201518184015260208101905062000163565b50505050905090810190601f168015620001ae5780820380516001836020036101000a031916815260200191505b50604052602001805190602001909291905050508282828260039080519060200190620001dd929190620004a7565b508160049080519060200190620001f6929190620004a7565b5080600560006101000a81548160ff021916908360ff16021790555050505062000232338260ff16600a0a620f4240026200023b60201b60201c565b50505062000556565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415620002df576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b620002f3600083836200041960201b60201c565b6200030f816002546200041e60201b62000f2d1790919060201c565b6002819055506200036d816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546200041e60201b62000f2d1790919060201c565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b505050565b6000808284019050838110156200049d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620004ea57805160ff19168380011785556200051b565b828001600101855582156200051b579182015b828111156200051a578251825591602001919060010190620004fd565b5b5090506200052a91906200052e565b5090565b6200055391905b808211156200054f57600081600090555060010162000535565b5090565b90565b6110f180620005666000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461025f57806370a08231146102c557806395d89b411461031d578063a457c2d7146103a0578063a9059cbb14610406578063dd62ed3e1461046c576100a9565b806306fdde03146100ae578063095ea7b31461013157806318160ddd1461019757806323b872dd146101b5578063313ce5671461023b575b600080fd5b6100b66104e4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f65780820151818401526020810190506100db565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61017d6004803603604081101561014757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610586565b604051808215151515815260200191505060405180910390f35b61019f6105a4565b6040518082815260200191505060405180910390f35b610221600480360360608110156101cb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105ae565b604051808215151515815260200191505060405180910390f35b610243610687565b604051808260ff1660ff16815260200191505060405180910390f35b6102ab6004803603604081101561027557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061069e565b604051808215151515815260200191505060405180910390f35b610307600480360360208110156102db57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610751565b6040518082815260200191505060405180910390f35b610325610799565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036557808201518184015260208101905061034a565b50505050905090810190601f1680156103925780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103ec600480360360408110156103b657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061083b565b604051808215151515815260200191505060405180910390f35b6104526004803603604081101561041c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610908565b604051808215151515815260200191505060405180910390f35b6104ce6004803603604081101561048257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610926565b6040518082815260200191505060405180910390f35b606060038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561057c5780601f106105515761010080835404028352916020019161057c565b820191906000526020600020905b81548152906001019060200180831161055f57829003601f168201915b5050505050905090565b600061059a6105936109ad565b84846109b5565b6001905092915050565b6000600254905090565b60006105bb848484610bac565b61067c846105c76109ad565b6106778560405180606001604052806028815260200161102660289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061062d6109ad565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610e6d9092919063ffffffff16565b6109b5565b600190509392505050565b6000600560009054906101000a900460ff16905090565b60006107476106ab6109ad565b8461074285600160006106bc6109ad565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f2d90919063ffffffff16565b6109b5565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108315780601f1061080657610100808354040283529160200191610831565b820191906000526020600020905b81548152906001019060200180831161081457829003601f168201915b5050505050905090565b60006108fe6108486109ad565b846108f98560405180606001604052806025815260200161109760259139600160006108726109ad565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610e6d9092919063ffffffff16565b6109b5565b6001905092915050565b600061091c6109156109ad565b8484610bac565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610a3b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806110736024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610ac1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180610fde6022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610c32576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602581526020018061104e6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610cb8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180610fbb6023913960400191505060405180910390fd5b610cc3838383610fb5565b610d2e81604051806060016040528060268152602001611000602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610e6d9092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610dc1816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610f2d90919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290610f1a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610edf578082015181840152602081019050610ec4565b50505050905090810190601f168015610f0c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015610fab576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220d2db32fd070f5d5c2299e3157a25d9184a233cd35690d15eab1cf135b8bdfb3364736f6c63430006010033000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000453796564000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004535945440000000000000000000000000000000000000000000000000000000025a033f0ab1e47ce324cb8108b521015cda2bb8fb467385005d13d241aaba229bf9ca00a42d52dfee23996be64616c56f95d4db6dfd5080a9710b4c330651c81b289fb")
( "sender", "424a26f6de36eb738762cead721bac23c62a724e")
);
// Transfer SYED tokens
auto transfer_res = push_action2( N(eosio.evm), N(raw), N(vestvestvest), mvo()
( "tx", "f88d0101831e84808080b84000000000000000000000000010d10ef03ef3316b750d2544bae8c96309aa436000000000000000000000000000000000000000000000000000000000000003e825a020e1cb44a38ac9d6d78eb86e6dd736ff22d559c58bb5c7dce8ada0c4df7eb6a8a06515f6f24d1086b6f7e65595559bc2d7ea8b8af817e17b89e5d63e4d99707a3c")
( "sender", "")
);
std::cout << transfer_res->action_traces[0].console << std::endl;
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_evm_erc721, * boost::unit_test::enable_if<erc721_enabled>())
BOOST_FIXTURE_TEST_CASE( erc_721, eosio_evm_tester ) try {
base_tester::push_action( N(eosio.evm), N(devnewacct), N(eosio.evm), mvo()
( "address", "f79b834a37f3143f4a73fc3934edac67fd3a01cd")
( "balance", 0)
( "code", std::vector<uint8_t>{})
( "nonce", 0)
( "account", "")
);
base_tester::push_action( N(eosio.evm), N(raw), N(erc721), mvo()
( "tx", "f920bd8001831e84808080b9206f60806040523480156200001157600080fd5b5060405162001faf38038062001faf833981810160405260408110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b9083019060208201858111156200006e57600080fd5b82516401000000008111828201881017156200008957600080fd5b82525081516020918201929091019080838360005b83811015620000b85781810151838201526020016200009e565b50505050905090810190601f168015620000e65780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200010a57600080fd5b9083019060208201858111156200012057600080fd5b82516401000000008111828201881017156200013b57600080fd5b82525081516020918201929091019080838360005b838110156200016a57818101518382015260200162000150565b50505050905090810190601f168015620001985780820380516001836020036101000a031916815260200191505b50604052508391508290508181620001c06301ffc9a760e01b6001600160e01b036200024916565b620001db6380ac58cd60e01b6001600160e01b036200024916565b620001f663780e9d6360e01b6001600160e01b036200024916565b81516200020b906009906020850190620002ce565b5080516200022190600a906020840190620002ce565b506200023d635b5e139f60e01b6001600160e01b036200024916565b50505050505062000373565b6001600160e01b03198082161415620002a9576040805162461bcd60e51b815260206004820152601c60248201527f4552433136353a20696e76616c696420696e7465726661636520696400000000604482015290519081900360640190fd5b6001600160e01b0319166000908152602081905260409020805460ff19166001179055565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200031157805160ff191683800117855562000341565b8280016001018555821562000341579182015b828111156200034157825182559160200191906001019062000324565b506200034f92915062000353565b5090565b6200037091905b808211156200034f57600081556001016200035a565b90565b611c2c80620003836000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c80636352211e116100a2578063a22cb46511610071578063a22cb4651461035c578063b88d4fde1461038a578063c87b56dd14610450578063cf3783431461046d578063e985e9c51461052357610116565b80636352211e146103095780636c0360eb1461032657806370a082311461032e57806395d89b411461035457610116565b806318160ddd116100e957806318160ddd1461023a57806323b872dd146102545780632f745c591461028a57806342842e0e146102b65780634f6ccce7146102ec57610116565b806301ffc9a71461011b57806306fdde0314610156578063081812fc146101d3578063095ea7b31461020c575b600080fd5b6101426004803603602081101561013157600080fd5b50356001600160e01b031916610551565b604080519115158252519081900360200190f35b61015e610574565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610198578181015183820152602001610180565b50505050905090810190601f1680156101c55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101f0600480360360208110156101e957600080fd5b503561060b565b604080516001600160a01b039092168252519081900360200190f35b6102386004803603604081101561022257600080fd5b506001600160a01b03813516906020013561066d565b005b610242610748565b60408051918252519081900360200190f35b6102386004803603606081101561026a57600080fd5b506001600160a01b0381358116916020810135909116906040013561074e565b610242600480360360408110156102a057600080fd5b506001600160a01b0381351690602001356107a5565b610238600480360360608110156102cc57600080fd5b506001600160a01b03813581169160208101359091169060400135610824565b6102426004803603602081101561030257600080fd5b503561083f565b6101f06004803603602081101561031f57600080fd5b50356108a5565b61015e6108ff565b6102426004803603602081101561034457600080fd5b50356001600160a01b0316610960565b61015e6109c8565b6102386004803603604081101561037257600080fd5b506001600160a01b0381351690602001351515610a29565b610238600480360360808110156103a057600080fd5b6001600160a01b038235811692602081013590911691604082013591908101906080810160608201356401000000008111156103db57600080fd5b8201836020820111156103ed57600080fd5b8035906020019184600183028401116401000000008311171561040f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610b2e945050505050565b61015e6004803603602081101561046657600080fd5b5035610b8c565b6102426004803603604081101561048357600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156104ae57600080fd5b8201836020820111156104c057600080fd5b803590602001918460018302840111640100000000831117156104e257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610d58945050505050565b6101426004803603604081101561053957600080fd5b506001600160a01b0381358116916020013516610d8d565b6001600160e01b0319811660009081526020819052604090205460ff165b919050565b60098054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106005780601f106105d557610100808354040283529160200191610600565b820191906000526020600020905b8154815290600101906020018083116105e357829003601f168201915b505050505090505b90565b600061061682610dbb565b6106515760405162461bcd60e51b815260040180806020018281038252602c815260200180611ac9602c913960400191505060405180910390fd5b506000908152600260205260409020546001600160a01b031690565b6000610678826108a5565b9050806001600160a01b0316836001600160a01b031614156106cb5760405162461bcd60e51b8152600401808060200182810382526021815260200180611b796021913960400191505060405180910390fd5b806001600160a01b03166106dd610dd8565b6001600160a01b031614806106fe57506106fe816106f9610dd8565b610d8d565b6107395760405162461bcd60e51b8152600401808060200182810382526038815260200180611a3e6038913960400191505060405180910390fd5b6107438383610ddc565b505050565b60075490565b61075f610759610dd8565b82610e4a565b61079a5760405162461bcd60e51b8152600401808060200182810382526031815260200180611b9a6031913960400191505060405180910390fd5b610743838383610eee565b60006107b083610960565b82106107ed5760405162461bcd60e51b815260040180806020018281038252602b815260200180611991602b913960400191505060405180910390fd5b6001600160a01b038316600090815260056020526040902080548390811061081157fe5b9060005260206000200154905092915050565b61074383838360405180602001604052806000815250610b2e565b6000610849610748565b82106108865760405162461bcd60e51b815260040180806020018281038252602c815260200180611bcb602c913960400191505060405180910390fd5b6007828154811061089357fe5b90600052602060002001549050919050565b6000818152600160205260408120546001600160a01b0316806108f95760405162461bcd60e51b8152600401808060200182810382526029815260200180611aa06029913960400191505060405180910390fd5b92915050565b600b8054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106005780601f106105d557610100808354040283529160200191610600565b60006001600160a01b0382166109a75760405162461bcd60e51b815260040180806020018281038252602a815260200180611a76602a913960400191505060405180910390fd5b6001600160a01b03821660009081526003602052604090206108f99061103f565b600a8054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106005780601f106105d557610100808354040283529160200191610600565b610a31610dd8565b6001600160a01b0316826001600160a01b03161415610a97576040805162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015290519081900360640190fd5b8060046000610aa4610dd8565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155610ae8610dd8565b60408051841515815290516001600160a01b0392909216917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c319181900360200190a35050565b610b3f610b39610dd8565b83610e4a565b610b7a5760405162461bcd60e51b8152600401808060200182810382526031815260200180611b9a6031913960400191505060405180910390fd5b610b8684848484611043565b50505050565b6060610b9782610dbb565b610bd25760405162461bcd60e51b815260040180806020018281038252602f815260200180611b4a602f913960400191505060405180910390fd5b6000828152600c602090815260409182902080548351601f6002600019610100600186161502019093169290920491820184900484028101840190945280845260609392830182828015610c675780601f10610c3c57610100808354040283529160200191610c67565b820191906000526020600020905b815481529060010190602001808311610c4a57829003601f168201915b50505050509050805160001415610c8e57505060408051602081019091526000815261056f565b600b816040516020018083805460018160011615610100020316600290048015610cef5780601f10610ccd576101008083540402835291820191610cef565b820191906000526020600020905b815481529060010190602001808311610cdb575b5050825160208401908083835b60208310610d1b5780518252601f199092019160209182019101610cfc565b6001836020036101000a0380198251168184511680821785525050505050509050019250505060405160208183030381529060405291505061056f565b6000610d64600d611095565b6000610d70600d61103f565b9050610d7c848261109e565b610d8681846111db565b9392505050565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205460ff1690565b6000908152600160205260409020546001600160a01b0316151590565b3390565b600081815260026020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610e11826108a5565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610e5582610dbb565b610e905760405162461bcd60e51b815260040180806020018281038252602c815260200180611a12602c913960400191505060405180910390fd5b6000610e9b836108a5565b9050806001600160a01b0316846001600160a01b03161480610ed65750836001600160a01b0316610ecb8461060b565b6001600160a01b0316145b80610ee65750610ee68185610d8d565b949350505050565b826001600160a01b0316610f01826108a5565b6001600160a01b031614610f465760405162461bcd60e51b8152600401808060200182810382526029815260200180611b216029913960400191505060405180910390fd5b6001600160a01b038216610f8b5760405162461bcd60e51b81526004018080602001828103825260248152602001806119ee6024913960400191505060405180910390fd5b610f9683838361123e565b610fa1600082610ddc565b6001600160a01b0383166000908152600360205260409020610fc290611249565b6001600160a01b0382166000908152600360205260409020610fe390611095565b60008181526001602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b5490565b61104e848484610eee565b61105a84848484611260565b610b865760405162461bcd60e51b81526004018080602001828103825260328152602001806119bc6032913960400191505060405180910390fd5b80546001019055565b6001600160a01b0382166110f9576040805162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015290519081900360640190fd5b61110281610dbb565b15611154576040805162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015290519081900360640190fd5b6111606000838361123e565b600081815260016020908152604080832080546001600160a01b0319166001600160a01b03871690811790915583526003909152902061119f90611095565b60405181906001600160a01b038416906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6111e482610dbb565b61121f5760405162461bcd60e51b815260040180806020018281038252602c815260200180611af5602c913960400191505060405180910390fd5b6000828152600c602090815260409091208251610743928401906118b1565b61074383838361149b565b805461125c90600163ffffffff6114f216565b9055565b6000611274846001600160a01b0316611534565b61128057506001610ee6565b600060606001600160a01b038616630a85bd0160e11b61129e610dd8565b89888860405160240180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156113175781810151838201526020016112ff565b50505050905090810190601f1680156113445780820380516001836020036101000a031916815260200191505b5060408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909a16999099178952518151919890975087965094509250829150849050835b602083106113ac5780518252601f19909201916020918201910161138d565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461140e576040519150601f19603f3d011682016040523d82523d6000602084013e611413565b606091505b5091509150816114645780511561142d5780518082602001fd5b60405162461bcd60e51b81526004018080602001828103825260328152602001806119bc6032913960400191505060405180910390fd5b600081806020019051602081101561147b57600080fd5b50516001600160e01b031916630a85bd0160e11b149350610ee692505050565b6114a683838361156d565b6001600160a01b038216610743576000818152600c60205260409020546002600019610100600184161502019091160415610743576000818152600c602052604081206107439161192f565b6000610d8683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506115e2565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590610ee6575050151592915050565b611578838383610743565b6001600160a01b03831661159e576115908282611679565b611599816116b7565b610743565b6001600160a01b0382166115ce576115b683826116fb565b600081815260066020526040812055611599816117fd565b6115d883826116fb565b6107438282611679565b600081848411156116715760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561163657818101518382015260200161161e565b50505050905090810190601f1680156116635780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6001600160a01b0390911660009081526005602081815260408084208054868652600684529185208290559282526001810183559183529091200155565b600780546000838152600860205260408120829055600182018355919091527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c6880155565b6001600160a01b03821660009081526005602052604081205461172590600163ffffffff6114f216565b6000838152600660205260409020549091508082146117c0576001600160a01b038416600090815260056020526040812080548490811061176257fe5b906000526020600020015490508060056000876001600160a01b03166001600160a01b0316815260200190815260200160002083815481106117a057fe5b600091825260208083209091019290925591825260069052604090208190555b6001600160a01b03841660009081526005602052604090208054806117e157fe5b6001900381819060005260206000200160009055905550505050565b60075460009061181490600163ffffffff6114f216565b6000838152600860205260408120546007805493945090928490811061183657fe5b90600052602060002001549050806007838154811061185157fe5b6000918252602080832090910192909255828152600890915260409020829055600780548061187c57fe5b600190038181906000526020600020016000905590556000600860008681526020019081526020016000208190555050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106118f257805160ff191683800117855561191f565b8280016001018555821561191f579182015b8281111561191f578251825591602001919060010190611904565b5061192b929150611976565b5090565b50805460018160011615610100020316600290046000825580601f106119555750611973565b601f0160209004906000526020600020908101906119739190611976565b50565b61060891905b8082111561192b576000815560010161197c56fe455243373231456e756d657261626c653a206f776e657220696e646578206f7574206f6620626f756e64734552433732313a207472616e7366657220746f206e6f6e20455243373231526563656976657220696d706c656d656e7465724552433732313a207472616e7366657220746f20746865207a65726f20616464726573734552433732313a206f70657261746f7220717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732313a20617070726f76652063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f76656420666f7220616c6c4552433732313a2062616c616e636520717565727920666f7220746865207a65726f20616464726573734552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732313a20617070726f76656420717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732314d657461646174613a2055524920736574206f66206e6f6e6578697374656e7420746f6b656e4552433732313a207472616e73666572206f6620746f6b656e2074686174206973206e6f74206f776e4552433732314d657461646174613a2055524920717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732313a20617070726f76616c20746f2063757272656e74206f776e65724552433732313a207472616e736665722063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f766564455243373231456e756d657261626c653a20676c6f62616c20696e646578206f7574206f6620626f756e6473a26469706673582212205eddf980a11e8c2b2c0e992d2a57080274322af41c7b6604b20c5c83378200f464736f6c6343000603003300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000d43727970746f6b6974746965730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074b4954544945530000000000000000000000000000000000000000000000000025a0a0ec15067cb6ab011bb75cb01a80f5d5c9cc78df4be3b6267dccbf03d71101eea0368d85cec55579eb01d1e15ac19568e32cb9a43dbec9983336532919bc007611")
( "sender", "424a26f6de36eb738762cead721bac23c62a724e")
);
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_evm_tt, * boost::unit_test::enable_if<transaction_tests_enabled>())
BOOST_FIXTURE_TEST_CASE( transaction_tests, eosio_evm_tester ) try {
auto testDirectory = "jsontests/TransactionTests";
// For each folder in Transact=][pnTests
for (const auto & entry : fs::directory_iterator(testDirectory)) {
std::string subFolderPath = entry.path();
vector<string> subFolderPathSplit;
boost::split(subFolderPathSplit, subFolderPath, boost::is_any_of("/"));
std::string category = subFolderPathSplit[2];
// For each test in ttAddress
for (const auto& testPathItr : fs::directory_iterator(subFolderPath)) {
std::string testPath = testPathItr.path();
// Get test name
vector<string> testPathSplit;
boost::split(testPathSplit, testPath, boost::is_any_of("/"));
std::string testName = testPathSplit[3];
// Remove .json extension
size_t extIdx = testName.find_last_of(".");
testName = testName.substr(0, extIdx);
// Get the json
auto json = fc::json::from_file(testPath, fc::json::relaxed_parser);
// Find out if it is valid
auto fork_res = json.get_object()[testName][FORK].get_object();
auto is_valid = fork_res.find("hash") != fork_res.end();
// Get rlp and erase 0x
std::string rlp = json.get_object()[testName]["rlp"].get_string();
rlp.erase(0, 2);
// Skip
// String10MbData: EOSIO doesnt support data of 10 MB
// dataTx_bcValidBlockTestFrontier: For frontier
if (testName == "String10MbData" || testName == "dataTx_bcValidBlockTestFrontier") {
// NO OP
}
// If valid
else if (is_valid)
{
auto res = testtx(rlp);
auto console = fc::json::from_string(res->action_traces[0].console);
auto hash = *(console.get_object().find("hash"));
auto sender = *(console.get_object().find("sender"));
auto expected_hash = *(fork_res.find("hash"));
auto expected_sender = *(fork_res.find("sender"));
if (hash != expected_hash || sender != expected_sender) {
std::cout << "\033[1;32m" << category << " - " << testName << " (Expected to pass!) \"\033[0m" << std::endl;
BOOST_REQUIRE_EQUAL( hash, expected_hash );
BOOST_REQUIRE_EQUAL( sender, expected_sender );
}
}
// If not valid
else
{
try {
testtx(rlp);
std::cout << "\033[1;32m" << category << " - " << testName << " (Expected to fail!) \033[0m" << std::endl;
} catch(const fc::exception& e) {
auto matches = expect_assert_message(e, "Invalid Transaction") || expect_assert_message(e, "secp256k1_ecdsa_recover_compact") || expect_assert_message(e, "Invalid hex character");
if (matches) {
// std::cout << "\033[1;32m" << e.top_message() << "\033[0m" << std::endl;
} else {
std::cout << "\033[1;31m" << category << " - " << testName << " (Expected to fail!)\033[0m" << std::endl;
std::cout << "\033[1;31m" << e.to_string() << "\033[0m" << std::endl;
}
}
}
produce_blocks(1);
}
}
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_evm_debug, * boost::unit_test::enable_if<debugging_enabled>())
BOOST_FIXTURE_TEST_CASE( debugging, eosio_evm_tester ) try {
try {
base_tester::push_action( N(eosio.evm), N(devnewacct), N(eosio.evm), mvo()
( "address", "a94f5374fce5edbc8e2a8697c15331677e6ebf0b")
( "balance", "1000000000000000000")
( "code", std::vector<uint8_t>{})
( "nonce", 0)
( "account", "")
);
base_tester::push_action( N(eosio.evm), N(devnewacct), N(eosio.evm), mvo()
( "address", "095e7baea6a6c7c4c2dfeb977efac326af552d87")
( "balance", 0)
( "code", eosio_system::HexToBytes("73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d8731f060005500"))
( "nonce", 0)
( "account", "")
);
base_tester::push_action( N(eosio.evm), N(raw), N(eosio.evm), mvo()
( "tx", "f85f800183061a8094095e7baea6a6c7c4c2dfeb977efac326af552d870180259ffc52968a0cfe417d4f0d046e3d4763d78e5e53932ea3b3b7aa987e5a631cf7a021e496f759eafe0c921834b2397439e518ac04e6a6654e714d8000cd12e44a55")
( "sender", "424a26f6de36eb738762cead721bac23c62a724e")
);
} catch(const fc::exception& e) {
std::cout << "\033[1;31m" << e.to_string() << "\033[0m" << std::endl;
}
produce_blocks(1);
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(eosio_evm_st, * boost::unit_test::enable_if<state_tests_enabled>())
BOOST_FIXTURE_TEST_CASE( general_state_tests, eosio_evm_tester ) try {
std::cout << "\033[93m***********************************************************************************************************" << std::endl;
std::cout << "***********************************************************************************************************" << std::endl << std::endl;
std::cout << "ENSURE (TESTING, CHARGE_SENDER_FOR_GAS) IS ENABLED AND (OPTRACE, PRINT_LOGS) IS DISABLED FOR ETH TESTS!" << std::endl << std::endl;
std::cout << "***********************************************************************************************************" << std::endl;
std::cout << "***********************************************************************************************************\033[0m" << std::endl << std::endl;
auto testDirectory = "jsontests/BlockchainTests/GeneralStateTests";
// For each folder in GeneralStateTestsEOS
auto totalTests = 0;
for (const auto & entry : fs::directory_iterator(testDirectory)) {
std::string subFolderPath = entry.path();
vector<string> subFolderPathSplit;
boost::split(subFolderPathSplit, subFolderPath, boost::is_any_of("/"));
std::string category = subFolderPathSplit[2];
// For each test in each folder
for (const auto& testPathItr : fs::directory_iterator(subFolderPath)) {
std::string testPath = testPathItr.path();
// Get test name
vector<string> testPathSplit;
boost::split(testPathSplit, testPath, boost::is_any_of("/"));
std::string testName = testPathSplit[4];
std::string testCategory = testPathSplit[3];
// Remove .json extension
size_t extIdx = testName.find_last_of(".");
testName = testName.substr(0, extIdx);
// Print name of test
std::cout << testPath << " " << testName << std::endl;
// // Execute Only this folder
// if (testCategory != "stPreCompiledContracts2") {
// continue;
// }
// // Execute only this file
// if (testName != "sloadGasCost" ) {
// continue;
// }
// SKIP file
if (
// Time consuming (all passing, comment out to run them)
testName == "sstore_combinations_initial00" ||
testName == "sstore_combinations_initial01" ||
testName == "sstore_combinations_initial10" ||
testName == "sstore_combinations_initial11" ||
testName == "sstore_combinations_initial20" ||
testName == "sstore_combinations_initial21" ||
testName == "CALLBlake2f_MaxRounds" || // Takes an hour to complete
// Out of memory due to 1000s of calls (No way in EOSIO to reclaim memory once allocated)
testName == "randomStatetest36" ||
testName == "randomStatetest177" ||
testName == "QuadraticComplexitySolidity_CallDataCopy" ||
testName == "static_LoopCallsThenRevert" ||
testName == "JUMPDEST_AttackwithJump" ||
testName == "JUMPDEST_Attack" ||
testName == "static_Call50000_sha256"
) {
continue;
}
// Get the json
auto json = fc::json::from_file(testPath, fc::json::relaxed_parser);
// For every test in the file
for (const auto& singleTest: json.get_object()) {
std::cout << singleTest.key() << std::endl;
// // Execute only this test
// if (singleTest.key() != "randomStatetest36_d0g0v0_Istanbul") {
// continue;
// }
// Skip these specific tests
if (
// Only hash provided in test, cannot verify (no state merkle tree for EOSIO)
singleTest.key() == "recursiveCreateReturnValue_d0g0v0_Istanbul" ||
singleTest.key() == "Create2Recursive_d0g0v0_Istanbul" ||
singleTest.key() == "Create2Recursive_d0g1v0_Istanbul" ||
// Not Istanbul (old eth forks)
singleTest.key() == "sloadGasCost_d0g0v0_Byzantium" ||
singleTest.key() == "sloadGasCost_d0g0v0_Constantinople" ||
singleTest.key() == "sloadGasCost_d0g0v0_ConstantinopleFix" ||
singleTest.key() == "sloadGasCost_d0g0v0_EIP150" ||
singleTest.key() == "sloadGasCost_d0g0v0_EIP158" ||
singleTest.key() == "sloadGasCost_d0g0v0_Frontier" ||
singleTest.key() == "sloadGasCost_d0g0v0_Homestead" ||
// Long running Quadratic Complexity tests, all go out of memory in EOSIO 32MB limit
singleTest.key() == "Call1024PreCalls_d0g0v0_Istanbul" ||
singleTest.key() == "Call1024PreCalls_d0g1v0_Istanbul" ||
singleTest.key() == "Call20KbytesContract50_2_d0g1v0_Istanbul" ||
singleTest.key() == "Call20KbytesContract50_3_d0g1v0_Istanbul" ||
singleTest.key() == "Callcode50000_d0g1v0_Istanbul" ||
singleTest.key() == "Call1MB1024Calldepth_d0g1v0_Istanbul" ||
singleTest.key() == "Return50000_2_d0g1v0_Istanbul" ||
singleTest.key() == "Return50000_d0g1v0_Istanbul" ||
singleTest.key() == "Create1000_d0g1v0_Istanbul" ||
singleTest.key() == "Create1000Byzantium_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_ecrec_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_sha256_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_identity2_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_identity_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_rip160_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_d0g1v0_Istanbul" ||
singleTest.key() == "Call50000_d0g1v0_Istanbul" ||
singleTest.key() == "static_Call1MB1024Calldepth_d1g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_rip160_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_rip160_d1g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_ecrec_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_ecrec_d1g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_d1g0v0_Istanbul" ||
singleTest.key() == "static_Return50000_2_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_identity_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_identity_d1g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_identity2_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000_identity2_d1g0v0_Istanbul" ||
singleTest.key() == "static_Call50000bytesContract50_2_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000bytesContract50_2_d1g0v0_Istanbul" ||
singleTest.key() == "static_Call50000bytesContract50_3_d0g0v0_Istanbul" ||
singleTest.key() == "static_Call50000bytesContract50_3_d1g0v0_Istanbul" ||
singleTest.key() == "ContractCreationSpam_d0g0v0_Istanbul"
) {
continue;
}
auto testObject = singleTest.value().get_object();
// For every pre object
for (const auto& singlePre: testObject["pre"].get_object()) {
auto singlePreObject = singlePre.value().get_object();
std::string address = singlePre.key();
std::string code = singlePreObject["code"].get_string();
std::string balance = singlePreObject["balance"].get_string();
unsigned long long nonce = std::stoull(singlePreObject["nonce"].get_string(), 0, 16);
// Create pre account
base_tester::push_action( N(eosio.evm), N(devnewacct), N(eosio.evm), mvo()
( "address", address.substr(2) )
( "balance", balance )
( "code", eosio_system::HexToBytes(code.substr(2)) )
( "nonce", nonce )
( "account", "" )
);
// Create pre storage
for (const auto& singlePreStorage: singlePreObject["storage"].get_object()) {
auto key = std::string(singlePreStorage.key());
auto value = singlePreStorage.value().get_string();
base_tester::push_action( N(eosio.evm), N(devnewstore), N(eosio.evm), mvo()
( "address", address.substr(2))
( "key", key )
( "value", value )
);
}
produce_blocks(1);
}
vector<std::string> miners = {};
// For Every block
for (const auto& singleBlock: testObject["blocks"].get_array()) {
auto blockObject = singleBlock.get_object();
auto blockEnv = blockObject["blockHeader"].get_object();
miners.emplace_back(blockEnv["coinbase"].get_string());
// Encode RLP for each TX
auto transactions = blockObject["transactions"].get_array();
for (auto i = 0; i < transactions.size(); i++) {
// Encode TX
auto t = transactions[i];
auto to_i = t["to"].get_string();
auto data_i = t["data"].get_string();
to_i.erase(0, 2);
data_i.erase(0, 2);
auto encoded_rlp = rlp::encode(
intx::from_string<intx::uint256>(t["nonce"].get_string()),
intx::from_string<intx::uint256>(t["gasPrice"].get_string()),
intx::from_string<intx::uint256>(t["gasLimit"].get_string()),
hex2bin(to_i),
intx::from_string<intx::uint256>(t["value"].get_string()),
hex2bin(data_i),
static_cast<uint8_t>(intx::from_string<intx::uint256>(t["v"].get_string())),
intx::from_string<intx::uint256>(t["r"].get_string()),
intx::from_string<intx::uint256>(t["s"].get_string())
);
// Execute TX
base_tester::push_action( N(eosio.evm), N(teststatetx), N(eosio.evm), mvo()
( "tx", bin2hex(to_bin(encoded_rlp)))
( "env", mvo()
("currentCoinbase", blockEnv["coinbase"].get_string())
("currentDifficulty", blockEnv["difficulty"].get_string())
("currentGasLimit", blockEnv["gasLimit"].get_string())
("currentNumber", blockEnv["number"].get_string())
("currentTimestamp", blockEnv["timestamp"].get_string())
("previousHash", blockEnv["parentHash"].get_string())
)
);
produce_blocks(1);
}
}
// For each result
for (const auto& singlePost: testObject["postState"].get_object()) {
auto singlePostObject = singlePost.value().get_object();
std::string address = singlePost.key();
std::string code = singlePostObject["code"].get_string();
std::string nonce = singlePostObject["nonce"].get_string();
std::string balance = singlePostObject["balance"].get_string();
// Skip miners
if (std::find(miners.begin(), miners.end(), address) != miners.end()) {
continue;
}
// Print info
std::cout << singleTest.key() << " " << address << std::endl;
// Get account
auto accountResponse = base_tester::push_action( N(eosio.evm), N(printaccount), N(eosio.evm), mvo()
( "address", address.substr(2) )
);
produce_blocks(1);
// Check nonce, balance and code
auto account = fc::json::from_string(accountResponse->action_traces[0].console).get_object();
auto actual_code = account["code"].get_string();
auto actual_nonce = account["nonce"].get_string();
auto actual_balance = account["balance"].get_string();
BOOST_REQUIRE_EQUAL( code, actual_code );
BOOST_REQUIRE_EQUAL( nonce, actual_nonce );
BOOST_REQUIRE_EQUAL( balance, actual_balance );
// Get state
auto res = base_tester::push_action( N(eosio.evm), N(printstate), N(eosio.evm), mvo()
( "address", address.substr(2) )
);
produce_blocks(1);
// Check console against storage
for (auto& singleExpectedStorage: singlePostObject["storage"].get_object()) {
auto expected_storage_key = singleExpectedStorage.key();
auto expected_storage_value = singleExpectedStorage.value().get_string();
// Check if key exists
bool valid = false;
try {
auto singleActualStorage = fc::json::from_string(res->action_traces[0].console).get_object();
auto actual_storage_value = singleActualStorage[expected_storage_key].get_string();
if (expected_storage_value == actual_storage_value) {
std::cout << "\033[1;32mExpected: " << expected_storage_value << " Actual: " << actual_storage_value << "\033[0m\n";
valid = true;
}
} catch (...) {}
if (!valid) {
std::cout << std::endl << "Failed Test: " << singleTest.key() << std::endl;
std::cout << "Actual: " << res->action_traces[0].console << std::endl;
std::cout << "Expected: " << fc::json::to_string(singlePostObject["storage"], fc::time_point::maximum()) << std::endl;
BOOST_REQUIRE_EQUAL( true, false );
}
}
}
// Reset chain
base_tester::push_action( N(eosio.evm), N(clearall), N(eosio.evm), mvo());
produce_blocks(1);
}
next_test:
// Reset chain
base_tester::push_action( N(eosio.evm), N(clearall), N(eosio.evm), mvo());
produce_blocks(1);
totalTests++;
}
}
} FC_LOG_AND_RETHROW()
BOOST_AUTO_TEST_SUITE_END()