Search code examples
nearprotocolassemblyscript

Simulation test of public method taking integers arguments fails with errorcode "WasmUnknownError"


The problem occurs when using the command "near-vm" to execute a simulation test of an assemblyscript smart contract method that takes inputs of type numbers like i32, u32, i64, u64. The following error is returned "FunctionCallError":"WasmUnknownError".

How to reproduce:

  1. git clone the https://github.com/Learn-NEAR/starter--near-sdk-as
  2. Build (yarn) and Run test (yarn test). Everything should works well
  3. Now add simple public method to add to numbers in src/simple/assembly/index.ts
export function add(a: i32, b: i32): i32 {
  return a + b;
}
  1. Optionally you can also add a corresponding unit test src/simple/__tests__/index.unit.spec.ts and it will pass successfully
it("should return the sum of two integers", () => {
    const sum = add(1, 2);

    expect(sum).toBe(3);
 })
  1. Now the problem occurs when running simulation test using near-vm
yarn near-vm --wasm-file build/debug/simple.wasm --method-name add --input '{"a": 1, "b": :2}

Then you get "FunctionCallError":"WasmUnknownError"

{"outcome"{"balance":"10000000000000000000000000",
"storage_usage":100,"return_data":"None","burnt_gas":39848843793,"used_gas":39848843793,"logs":[]},
"err":{"FunctionCallError":"WasmUnknownError"},"receipts":[],"state":{}}

Note that this problem doesn't occur when the method parameters are strings.


Solution

  • the simulation tests there are outdated and need to be updated

    Check out this new way of simulating NEAR contracts

    https://github.com/near/workspaces-js