Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Calling Balance_of (or get_balance) from CameLIGO test #99

@egarson

Description

@egarson

Hello,
I want to call the Balance_of entrypoint for a standard FA2 contract in a CameLIGO unit test (or it's "implementation" get_balance).
I am trying to formulate the correct balance_of_request.callback parameter, but the continuation-passing style is giving me trouble - I cannot conjure up the correct incantation.
Below is the test in development. Notice that I typed all the parameters, and broke everything down completely, to isolate completely the error.
The problem I have is only with the callback parameter ("Cannot unify ..."). I have tried a number of things, but I cannot get the right incantation.
My last effort has been trying to pass a fun to the callback, because I thought it might require a fun going from balance_of_response list to contract. It is a unique signature amongst all the other ones with which I have successfully worked.

let test_call_get_balance =
    let addr,_,_ = Test.originate main {initial_storage with admin = admin} 0tez in
    let contract = (Test.to_contract addr) in
    let balance_request: balance_of_request = {owner = alice; token_id = 0n} in
    let requests: balance_of_request list = [balance_request] in
    // OR: let requests: balance_of_request list = [{owner = alice; token_id = 0n}] in
    // !!Trying to formulate balance_of_request.callback parameter here!!
    // This is "just" another attempt, I am not sure how to reconcile this with CPS
    let callback = fun(l: balance_of_response list): contract ->
        let _printList = Test.log("Got list: ", l) in
        contract
    in
    let balance_param: balance_of_param = ({ requests = requests; callback = callback}) in
    // And finally call get_balance (alternatively the Balance_of entrypoint)
    let balance_of_response: balance_of_response = get_balance(requests) in
    Test.log("Alice's balance is:", balance_of_response.balance)

What is the correct incantation such that I can get the above to pass? You can see what I'm trying to do, I hope?
I will also take this opportunity to thank you very much for the significant value I have derived from this repository.
Cheers!
Edward Garson
Developer Evangelist @ ECAD Labs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions