> ava
✖ Add a hash to the notes of alice Rejected promise returned by test
─
Add a hash to the notes of alice
__tests__/index.ava.js:40
39:
40: const notesAlice = await alice.call(contract, "getAllNotes");
41:
Rejected promise returned by test. Reason:
TypeError {
message: 'Cannot read properties of undefined (reading \'byteLength\')',
}
› stringifyJsonOrBytes (node_modules/near-api-js/lib/transaction.js:67:31)
› functionCall (node_modules/near-api-js/lib/transaction.js:83:76)
› ManagedTransaction.functionCall (node_modules/near-workspaces/src/transaction.ts:88:19)
› Account.callRaw (node_modules/near-workspaces/src/account/account.ts:227:8)
› Account.call (node_modules/near-workspaces/src/account/account.ts:245:33)
› file://__tests__/index.ava.js:40:34
─
1 test failed
Created
August 4, 2022 14:13
-
-
Save sandoche/b1785994315ecc04719644deb85c5537 to your computer and use it in GitHub Desktop.
Issue with NEAR-SDK-JS - Cannot read properties of undefined (reading \'byteLength\')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { contract, alice } = t.context.accounts; | |
await alice.call(contract, "addNote", { | |
ipfsHash: "Qmbx3aPb36KZwrPH1KPT94EsGkyHKVMxf9CaufwQYAkkvX", | |
}); | |
const notesAlice = await alice.call(contract, "getAllNotes"); | |
t.deepEqual(notesAlice, ["Qmbx3aPb36KZwrPH1KPT94EsGkyHKVMxf9CaufwQYAkkvX"]); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: { [key: string]: string[] }; | |
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() { | |
const accountId = near.signerAccountId(); | |
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