diff --git a/contract-ts/package.json b/contract-ts/package.json index 4387d44..a4b723c 100644 --- a/contract-ts/package.json +++ b/contract-ts/package.json @@ -8,16 +8,16 @@ "test": "$npm_execpath build && ava -- ./build/contract.wasm" }, "dependencies": { - "near-cli": "^4.0.8", + "near-cli": "^4.0.10", "near-sdk-js": "1.0.0" }, "devDependencies": { "@ava/typescript": "^4.1.0", "ava": "^6.1.2", "near-workspaces": "^3.5.0", - "ts-morph": "^21.0.1", + "ts-morph": "^22.0.0", "ts-node": "^10.9.2", "tsimp": "^2.0.11", - "typescript": "^5.3.3" + "typescript": "^5.4.2" } } \ No newline at end of file diff --git a/contract-ts/sandbox-ts/main.ava.ts b/contract-ts/sandbox-ts/main.ava.ts index 83b2e65..10cd3c7 100644 --- a/contract-ts/sandbox-ts/main.ava.ts +++ b/contract-ts/sandbox-ts/main.ava.ts @@ -3,14 +3,11 @@ import anyTest, { TestFn } from 'ava'; import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node >v17 // Global context -let worker: Worker; -let accounts: Record; +const test = anyTest as TestFn<{ worker: Worker, accounts: Record }>; -const test = anyTest as TestFn<{}>; - -test.before(async (t) => { - // Init the worker and start a Sandbox server - worker = await Worker.init(); +test.beforeEach(async (t) => { + // Create sandbox, accounts, deploy contracts, etc. + const worker = t.context.worker = await Worker.init(); // deploy contract const root = worker.rootAccount; @@ -27,18 +24,18 @@ test.before(async (t) => { await contract.deploy(process.argv[2]); // Save state for test runs, it is unique for each test - accounts = { root, contract, alice }; + t.context.accounts = { root, contract, alice }; }); -test.after.always(async (t) => { +test.afterEach.always(async (t) => { // Stop Sandbox server - await worker.tearDown().catch((error) => { - console.log("Failed to stop the Sandbox:", error); + await t.context.worker.tearDown().catch((error) => { + console.log('Failed to stop the Sandbox:', error); }); }); test("send one message and retrieve it", async (t) => { - const { root, contract } = accounts; + const { root, contract } = t.context.accounts; await root.call(contract, "add_message", { text: "aloha" }); const msgs = await contract.view("get_messages"); const expectedMessagesResult = [ @@ -48,7 +45,7 @@ test("send one message and retrieve it", async (t) => { }); test("send two messages and expect two total", async (t) => { - const { root, contract, alice } = accounts; + const { root, contract, alice } = t.context.accounts; await root.call(contract, "add_message", { text: "aloha" }); await alice.call(contract, "add_message", { text: "hola" }, { attachedDeposit: NEAR.parse('1') });