Hey guys, I'm trying to test a recv_internal function:
() recv_internal (int balance, int msg_value, cell in_msg_full, slice in_msg_body) {
(slice sender_address, _) = parse_sender_address(in_msg_full);
slice owner_address = load_data();
var msg = begin_cell()
.store_uint(0x10, 6)
.store_slice(owner_address)
.store_grams(0)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_slice(sender_address)
.store_ref(begin_cell().store_slice(in_msg_body).end_cell())
.end_cell();
send_raw_message(msg, 64);
}
With the following test case:
int __test_fwd_message() {
slice owner_addr = get_owner_addr();
slice sender_addr = get_owner_addr();
set_owner_addr(owner_addr);
cell in_msg_body = begin_cell()
.store_uint(10, 4) ;; 1010
.end_cell();
cell in_msg_full = begin_cell()
.store_uint(0x6, 4) ;; 0110
.store_slice(sender_addr)
.end_cell();
var (int gas_used, _) = invoke_method(
recv_internal,
[12345, 10, in_msg_full, in_msg_body.begin_parse()]
);
slice actions = get_actions();
actions~load_ref();
int prefix = actions~load_uint(32);
throw_unless(100, prefix == 0x0ec3c86d);
int flag = actions~load_uint(8);
throw_unless(101, flag == 64);
cell msg = actions~load_ref();
slice cs = msg.begin_parse();
cs~skip_bits(6);
slice dest_addr = cs~load_msg_addr();
throw_unless(102, equal_slices(dest_addr, owner_addr));
int grams = cs~load_grams();
~dump(grams);
;;throw_unless(103, grams > 0); FAILS
cs~skip_bits(1 + 4 + 4 + 64 + 32 + 1 + 1);
slice sender_addr = cs~load_msg_addr();
throw_unless(104, equal_slices(sender_addr, sender_addr));
slice fwd_msg_body = (cs~load_ref()).begin_parse();
int fwd_msg_value = fwd_msg_body~load_uint(4);
throw_unless(105, fwd_msg_value == 10);
return gas_used;
}
When I check if the amount of grams is greater than 10 (the amount I provided to int msg_value), it doesn't pass the test. Anyone know the problem?
Jan 1, 2023, 10:16 AM
I was wondering, maybe the forwarding of remaining grams after paying for fees (mode 64) substitution in the internal msg occurs afterwards?
Jan 1, 2023, 10:17 AM
Test environment doesn't rewrite outgoing messages' value, source, etc. Rewriting is done in action phase.
Jan 1, 2023, 1:34 PM