open-dust/cairo-foundry

Read the JSON file of compiled cairo contracts and the find return signatures of test functions that will be mocked

Eikix opened this issue · 2 comments

Eikix commented

Tim: Lire le compiled.json pour trouver la struct et size de chacune des Cairo types.

Eikix commented

end goal:
mock_call(name_of_my_func, [42, “shortstring”, ids.myVarName, Uint256 {high: 42, low: 0x0}])

Return payload in compiled JSON file is available with the following command:

$ cat balance.json | jq '.program.identifiers | to_entries | .[] | select(.key|test(".*Return"))'

which will output the following:

{
  "key": "__main__.get_balance.Return",
  "value": {
    "cairo_type": "(balance: felt)",
    "type": "type_definition"
  }
}
{
  "key": "__main__.increase_balance.Return",
  "value": {
    "cairo_type": "()",
    "type": "type_definition"
  }
}
{
  "key": "__main__.multiple_outputs.Return",
  "value": {
    "cairo_type": "(account: __main__.MyAccount, total: starkware.cairo.common.uint256.Uint256, ref: felt)",
    "type": "type_definition"
  }
}
{
  "key": "__main__.multiple_outputs_with_array.Return",
  "value": {
    "cairo_type": "(id: felt, b_len: felt, b: felt*, answer: felt)",
    "type": "type_definition"
  }
}
{
  "key": "__main__.sum.Return",
  "value": {
    "cairo_type": "(sum: felt)",
    "type": "type_definition"
  }
}