@@ -400,3 +400,58 @@ TEST(Emulator, tvm_emulator) {
400
400
CHECK (stack_res->depth () == 1 );
401
401
CHECK (stack_res.write ().pop_int ()->to_long () == init_data.seqno );
402
402
}
403
+
404
+ TEST (Emulator, tvm_emulator_extra_currencies) {
405
+ void *tvm_emulator = tvm_emulator_create (" te6cckEBBAEAHgABFP8A9KQT9LzyyAsBAgFiAgMABtBfBAAJofpP8E8XmGlj" , " te6cckEBAQEAAgAAAEysuc0=" , 1 );
406
+ std::string addr = " 0:" + std::string (64 , ' F' );
407
+ tvm_emulator_set_c7 (tvm_emulator, addr.c_str (), 1337 , 1000 , std::string (64 , ' F' ).c_str (), nullptr );
408
+ CHECK (tvm_emulator_set_extra_currencies (tvm_emulator, " 100=20000 200=1" ));
409
+ unsigned method_crc = td::crc16 (" get_balance" );
410
+ unsigned method_id = (method_crc & 0xffff ) | 0x10000 ;
411
+
412
+ auto stack = td::make_ref<vm::Stack>();
413
+ vm::CellBuilder stack_cb;
414
+ CHECK (stack->serialize (stack_cb));
415
+ auto stack_cell = stack_cb.finalize ();
416
+ auto stack_boc = td::base64_encode (std_boc_serialize (stack_cell).move_as_ok ());
417
+
418
+ std::string tvm_res = tvm_emulator_run_get_method (tvm_emulator, method_id, stack_boc.c_str ());
419
+
420
+ auto result_json = td::json_decode (td::MutableSlice (tvm_res));
421
+ auto result = result_json.move_as_ok ();
422
+ auto & result_obj = result.get_object ();
423
+
424
+ auto success_field = td::get_json_object_field (result_obj, " success" , td::JsonValue::Type::Boolean , false );
425
+ auto success = success_field.move_as_ok ().get_boolean ();
426
+ CHECK (success);
427
+
428
+ auto stack_field = td::get_json_object_field (result_obj, " stack" , td::JsonValue::Type::String, false );
429
+ auto stack_val = stack_field.move_as_ok ();
430
+ auto & stack_obj = stack_val.get_string ();
431
+ auto stack_res_boc = td::base64_decode (stack_obj);
432
+ auto stack_res_cell = vm::std_boc_deserialize (stack_res_boc.move_as_ok ());
433
+ td::Ref<vm::Stack> stack_res;
434
+ auto stack_res_cs = vm::load_cell_slice (stack_res_cell.move_as_ok ());
435
+ CHECK (vm::Stack::deserialize_to (stack_res_cs, stack_res));
436
+ CHECK (stack_res->depth () == 1 );
437
+ auto tuple = stack_res.write ().pop_tuple ();
438
+ CHECK (tuple->size () == 2 );
439
+
440
+ auto ton_balance = tuple->at (0 ).as_int ();
441
+ CHECK (ton_balance == 1000 );
442
+
443
+ auto cell = tuple->at (1 ).as_cell ();
444
+ auto dict = vm::Dictionary{cell, 32 };
445
+ auto it = dict.begin ();
446
+ std::map<uint32_t , td::RefInt256> ec_balance;
447
+ while (!it.eof ()) {
448
+ auto id = td::BitArray<32 >(it.cur_pos ()).to_ulong ();
449
+ auto value_cs = it.cur_value ();
450
+ auto value = block::tlb::t_VarUInteger_32.as_integer (value_cs);
451
+ ec_balance[id] = value;
452
+ ++it;
453
+ }
454
+ CHECK (ec_balance.size () == 2 );
455
+ CHECK (ec_balance[100 ] == 20000 );
456
+ CHECK (ec_balance[200 ] == 1 );
457
+ }
0 commit comments