I can't make toncli tests work. When I run "toncli run_tests", first it prints error: ( function invoke_method undefined ). Then it says build successful. Then there is several lines of weird logs, ending with error: Error interpreting file C:\Users\andyr\AppData\Local\Temp\tmpkuarq9x3.fif: contract_tests.fif:27: }END>c:main procedure not defined
Then I looked into the "contract_tests.fif", and I found out that:
1. "AsmTests.fif" is not included in it.
2. "__test_gcd" (my test function) body (inside the {}) is empty.
I installed toncli following the instructions. Can anyone help me make tests work, please?
Aug 6, 2022, 10:52 AM
just as a guess, check thee method_id of all test functions, they must be unique.
also check the following post on Ton Contest Chat (https://t.me/toncontests_chat) 👇
also check the following post on Ton Contest Chat (https://t.me/toncontests_chat) 👇
Almost yes. Check this one. (this is one of my tests for the first task, I hope I will not be banned from the contest for this 😅)
Here is a small difference between testing getters or get-functions (like in this contest) and recv_internal or recv_external
Please, note that you need to specify unique function_selector
By default, for recv_internal it is 0 (and recv_external is -1). But for getters it is unique.
To get the function selector for your getter, you should run toncli build and then open ./build/contract.fif file and find there something like this 93344 DECLMETHOD gcd
93344 will be what are you looking for
Here is a small difference between testing getters or get-functions (like in this contest) and recv_internal or recv_external
Please, note that you need to specify unique function_selector
By default, for recv_internal it is 0 (and recv_external is -1). But for getters it is unique.
To get the function selector for your getter, you should run toncli build and then open ./build/contract.fif file and find there something like this 93344 DECLMETHOD gcd
93344 will be what are you looking for
Aug 6, 2022, 11:38 AM
I didn't have method_id(0) I already use function selector to reference the function. Now there is a new error, which indicates that there is no code of the function. Error: Error interpreting file C:\Users\andyr\AppData\Local\Temp\tmpdft_qdou.fif: contract_tests.fif:27: }END>c:invoke_method: procedure declared but left undefined
Here's the code of the test file:
() __test_gcd() method_id(0) {
var (int gas_used, tuple results) = invoke_method(93344, [10, 15]);
}
Here's the code of the test file:
() __test_gcd() method_id(0) {
var (int gas_used, tuple results) = invoke_method(93344, [10, 15]);
}
I added some code to see what will happen in the generated fift code:
int __test_gcd() method_id(0) {
int e = 100;
e~dump();
var (int gas_used, tuple results) = invoke_method(93344, [10, 15]);
return e;
}
In the fift code:
__test_gcd PROC:<{
//
100 PUSHINT // e=100
s0 DUMP // e
}>
The error: contract_tests.fif:29: }END>c:invoke_method: procedure declared but left undefined
So, I think that toncli somehow doesn't include the method. And I think this is somehow related to the fact that AsmTests.fif is not included in that file. Any ideas on how to fix this?
int __test_gcd() method_id(0) {
int e = 100;
e~dump();
var (int gas_used, tuple results) = invoke_method(93344, [10, 15]);
return e;
}
In the fift code:
__test_gcd PROC:<{
//
100 PUSHINT // e=100
s0 DUMP // e
}>
The error: contract_tests.fif:29: }END>c:invoke_method: procedure declared but left undefined
So, I think that toncli somehow doesn't include the method. And I think this is somehow related to the fact that AsmTests.fif is not included in that file. Any ideas on how to fix this?
Aug 6, 2022, 1:49 PM
Try return (e, gas_used): looks like invoke_method is optimised out because result is not used
Aug 6, 2022, 1:51 PM
I saw that func has special flag for warnings, think it's needed to pass output of func to toncli run. Guess it will help a lot for devs
Aug 6, 2022, 1:53 PM
Same error, fift code changed though.
__test_gcd PROC:<{
//
100 PUSHINT // e=100
s0 DUMP // e
93344 PUSHINT // e _6=93344
10 PUSHINT // e _6=93344 _8=10
15 PUSHINT // e _6=93344 _8=10 _9=15
PAIR // e _6=93344 _7
invoke_method CALLDICT // e _11 _12
DROP // e gas_used
}>
__test_gcd PROC:<{
//
100 PUSHINT // e=100
s0 DUMP // e
93344 PUSHINT // e _6=93344
10 PUSHINT // e _6=93344 _8=10
15 PUSHINT // e _6=93344 _8=10 _9=15
PAIR // e _6=93344 _7
invoke_method CALLDICT // e _11 _12
DROP // e gas_used
}>
Aug 6, 2022, 1:54 PM