Skip to content

Instantly share code, notes, and snippets.

@sandoche
Created August 4, 2022 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandoche/9e7decca99b5f590ca9c87d7a225ed08 to your computer and use it in GitHub Desktop.
Save sandoche/9e7decca99b5f590ca9c87d7a225ed08 to your computer and use it in GitHub Desktop.
NEAR Workspace error
Excecuting wasi-stub...
node_modules/near-sdk-js/cli/deps/binaryen/wasi-stub/run.sh build/contract.wasm >/dev/null


> nearwrite-smartcontracts@0.1.0 test
> ava


  ✖ Add a hash to the notes of alice Rejected promise returned by test
  ─

  Add a hash to the notes of alice

  Rejected promise returned by test. Reason:

  Error (TypedError) {
    context: undefined,
    type: 'CodeDoesNotExist',
    message: `Querying [object Object] failed: wasm execution failed with error: FunctionCallError(CompilationError(CodeDoesNotExist { account_id: AccountId("alice.test.near") })).␊
    {␊
      "block_hash": "BPQAeGmidJzaRDL7BYsSLCSx8QczB9xNV3TkAqExFCEG",␊
      "block_height": 19,␊
      "error": "wasm execution failed with error: FunctionCallError(CompilationError(CodeDoesNotExist { account_id: AccountId(\\"alice.test.near\\") }))",␊
      "logs": []␊
    }`,
  }

  › }
  › JsonRpcProvider.query (node_modules/near-api-js/lib/providers/json-rpc-provider.js:123:19)
  › Account.view (node_modules/near-workspaces/src/account/account.ts:262:20)
  › async file://__tests__/index.ava.js:39:17



  1 test failed
import { Worker } from "near-workspaces";
import test from "ava";
test.beforeEach(async (t) => {
// Init the worker and start a Sandbox server
const worker = await Worker.init();
// Prepare sandbox for tests, create accounts, deploy contracts, etc.
const root = worker.rootAccount;
// Deploy the counter contract.
const contract = await root.devDeploy("./build/contract.wasm");
// Init the contract
await contract.call(contract, "init", {});
// Test users
const alice = await root.createSubAccount("alice");
const bob = await root.createSubAccount("bob");
// Save state for test runs
t.context.worker = worker;
t.context.accounts = { root, contract, alice, bob };
});
// If the environment is reused, use test.after to replace test.afterEach
test.afterEach(async (t) => {
await t.context.worker.tearDown().catch((error) => {
console.log("Failed to tear down the worker:", error);
});
});
test("Add a hash to the notes of alice", async (t) => {
const { accounts } = t.context;
const { contract, alice } = accounts;
await alice.call(contract, "addNote", {
ipfsHash: "Qmbx3aPb36KZwrPH1KPT94EsGkyHKVMxf9CaufwQYAkkvX",
});
const notes = await alice.view(contract, "getAllNotes", {
accountId: alice.accountId,
});
t.deepEqual(notes, ["Qmbx3aPb36KZwrPH1KPT94EsGkyHKVMxf9CaufwQYAkkvX"]);
});
import { NearContract, NearBindgen, call, view, near } from "near-sdk-js";
const assert = (condition, message) => {
if (!condition) {
throw new Error(message);
}
};
@NearBindgen
class UserNotes extends NearContract {
notes: any;
constructor() {
super();
this.notes = {};
}
@call
addNote({ ipfsHash }) {
assert(ipfsHash.length === 46, "Invalid ipfsHash");
const accountId = near.signerAccountId();
near.log(`Adding the ipfsHash ${ipfsHash} to ${accountId}`);
const notes = this.notes[accountId] || [];
this.notes[accountId] = [ipfsHash, ...notes];
}
@view
getAllNotes({ accountId }) {
near.log(`Getting all the notes from ${accountId}`);
return this.notes[accountId] || [];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment