Skip to content

Commit

Permalink
Merge pull request #5 from garikbesson/fix-js-tests
Browse files Browse the repository at this point in the history
Fix JS tests
  • Loading branch information
gagdiez authored Mar 18, 2024
2 parents 0183515 + b419167 commit 5567524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions contract-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
23 changes: 10 additions & 13 deletions contract-ts/sandbox-ts/main.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, NearAccount>;
const test = anyTest as TestFn<{ worker: Worker, accounts: Record<string, NearAccount> }>;

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;
Expand All @@ -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 = [
Expand All @@ -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') });

Expand Down

0 comments on commit 5567524

Please sign in to comment.