采用整数参数的公共方法模拟测试失败,错误码"WasmUnknownError"



使用命令"接近vm";执行assemblyscript智能合约方法的模拟测试,该方法接受i32、u32、i64、u64等类型号的输入。返回以下错误";FunctionCallError":"WasmUnknownError";。

如何复制:

  1. git克隆https://github.com/Learn-NEAR/starter--near-sdk-as
  2. 生成(yarn(和运行测试(yarn test(。一切都应该运转良好
  3. 现在添加一个简单的公共方法来添加到src/simple/assembly/index.ts中的数字
export function add(a: i32, b: i32): i32 {
return a + b;
}
  1. 可选地,您还可以添加相应的单元测试src/simple/__tests__/index.unit.spec.ts,它将成功通过
it("should return the sum of two integers", () => {
const sum = add(1, 2);
expect(sum).toBe(3);
})
  1. 现在使用near-vm运行模拟测试时出现问题
yarn near-vm --wasm-file build/debug/simple.wasm --method-name add --input '{"a": 1, "b": :2}

然后你得到";FunctionCallError":"WasmUnknowError";

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

请注意,当方法参数为字符串时,不会出现此问题。

那里的模拟测试已经过时,需要更新

看看这种模拟NEAR合同的新方法

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

最新更新