From 21f476ba48a71243cd0f03773a96dfed83e015a7 Mon Sep 17 00:00:00 2001 From: Serhii Volovyk Date: Sun, 4 Dec 2022 15:33:56 +0200 Subject: [PATCH 1/3] extended contract added (now working), counter tests improved --- examples/__tests__/test-counter.ava.js | 30 ++++++++++++++++++++------ examples/package.json | 8 ++++--- examples/src/counter-extended.ts | 10 +++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 examples/src/counter-extended.ts diff --git a/examples/__tests__/test-counter.ava.js b/examples/__tests__/test-counter.ava.js index b8a94a0f..a8972a6a 100644 --- a/examples/__tests__/test-counter.ava.js +++ b/examples/__tests__/test-counter.ava.js @@ -8,14 +8,30 @@ test.beforeEach(async (t) => { // Prepare sandbox for tests, create accounts, deploy contracts, etc. const root = worker.rootAccount; + let counterContract; + + switch (process.env.COUNTER_CONTRACT_TYPE) { + case "COUNTER_LOW_LEVEL": { + counterContract = "./build/counter-lowlevel.wasm"; + break; + } + case "COUNTER_TS": { + counterContract = "./build/counter-ts.wasm"; + break; + } + case "COUNTER_JS":{ + counterContract = "./build/counter.wasm"; + break; + } + case "COUNTER_EXTENDED": { + counterContract = "./build/counter-extended.wasm"; + break; + } + default: throw Error("Unknown COUNTER_CONTRACT_TYPE"); + } + // Deploy the counter contract. - const counter = await root.devDeploy( - process.env["COUNTER_LOWLEVEL"] - ? "./build/counter-lowlevel.wasm" - : process.env["COUNTER_TS"] - ? "./build/counter-ts.wasm" - : "./build/counter.wasm" - ); + const counter = await root.devDeploy(counterContract); // Test users const ali = await root.createSubAccount("ali"); diff --git a/examples/package.json b/examples/package.json index b884bcfa..9e13f7eb 100644 --- a/examples/package.json +++ b/examples/package.json @@ -12,6 +12,7 @@ "build:counter": "near-sdk-js build src/counter.js build/counter.wasm", "build:counter-lowlevel": "near-sdk-js build src/counter-lowlevel.js build/counter-lowlevel.wasm", "build:counter-ts": "near-sdk-js build src/counter.ts build/counter-ts.wasm", + "build:counter-extended": "near-sdk-js build src/counter-extended.ts build/counter-extended.wasm", "build:cross-contract-call": "near-sdk-js build src/status-message.js build/status-message.wasm && near-sdk-js build src/cross-contract-call.js build/cross-contract-call.wasm", "build:cross-contract-call-loop": "near-sdk-js build src/counter.js build/counter.wasm && near-sdk-js build src/cross-contract-call-loop.js build/cross-contract-call-loop.wasm", "build:fungible-token-lockable": "near-sdk-js build src/fungible-token-lockable.js build/fungible-token-lockable.wasm", @@ -29,9 +30,10 @@ "test:nft": "ava __tests__/standard-nft/*", "test:status-message": "ava __tests__/test-status-message.ava.js", "test:clean-state": "ava __tests__/test-clean-state.ava.js", - "test:counter": "ava __tests__/test-counter.ava.js", - "test:counter-lowlevel": "COUNTER_LOWLEVEL=1 ava __tests__/test-counter.ava.js", - "test:counter-ts": "COUNTER_TS=1 ava __tests__/test-counter.ava.js", + "test:counter": "COUNTER_CONTRACT_TYPE=COUNTER_JS ava __tests__/test-counter.ava.js", + "test:counter-lowlevel": "COUNTER_CONTRACT_TYPE=COUNTER_LOW_LEVEL ava __tests__/test-counter.ava.js", + "test:counter-ts": "COUNTER_CONTRACT_TYPE=COUNTER_TS ava __tests__/test-counter.ava.js", + "test:counter-extended": "COUNTER_CONTRACT_TYPE=COUNTER_EXTENDED ava __tests__/test-counter.ava.js", "test:cross-contract-call": "ava __tests__/test-cross-contract-call.ava.js", "test:cross-contract-call-loop": "ava __tests__/test-cross-contract-call-loop.ava.js", "test:fungible-token-lockable": "ava __tests__/test-fungible-token-lockable.ava.js", diff --git a/examples/src/counter-extended.ts b/examples/src/counter-extended.ts new file mode 100644 index 00000000..00a4f6e1 --- /dev/null +++ b/examples/src/counter-extended.ts @@ -0,0 +1,10 @@ +import { near, call } from "near-sdk-js"; +import { Counter } from "./counter"; + +export class CounterWithReset extends Counter { + @call({}) + reset() { + this.count = 0; + near.log(`Counter is set to 0`); + } +} \ No newline at end of file From b26d0fcdf95b7e4d5c8b4dd48230e4a806f65422 Mon Sep 17 00:00:00 2001 From: Serhii Volovyk Date: Sun, 4 Dec 2022 15:45:16 +0200 Subject: [PATCH 2/3] NearBindgen added --- examples/src/counter-extended.ts | 3 ++- examples/yarn.lock | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/src/counter-extended.ts b/examples/src/counter-extended.ts index 00a4f6e1..c2096823 100644 --- a/examples/src/counter-extended.ts +++ b/examples/src/counter-extended.ts @@ -1,6 +1,7 @@ -import { near, call } from "near-sdk-js"; +import { near, NearBindgen, call } from "near-sdk-js"; import { Counter } from "./counter"; +@NearBindgen({}) export class CounterWithReset extends Counter { @call({}) reset() { diff --git a/examples/yarn.lock b/examples/yarn.lock index 55d691bc..cb0357eb 100644 --- a/examples/yarn.lock +++ b/examples/yarn.lock @@ -1986,7 +1986,7 @@ near-api-js@^0.44.1: version "1.0.0" dependencies: lodash-es "^4.17.21" - near-sdk-js "file:../../../../.cache/yarn/v6/npm-near-contract-standards-1.0.0-44ba4407-9321-422d-9b66-26dc109d51f6-1669093810887/node_modules" + near-sdk-js "file:../../../../Library/Caches/Yarn/v6/npm-near-contract-standards-1.0.0-2ae17a81-d14a-4d52-9193-4a013dd46b97-1670160866905/node_modules" near-sandbox@^0.0.13: version "0.0.13" @@ -2008,17 +2008,17 @@ near-sandbox@^0.0.13: "@scure/base" "^1.1.1" commander "^9.4.1" near-abi "^0.1.0" - near-typescript-json-schema "0.54.1" + near-typescript-json-schema "0.55.0" rollup "^2.61.1" rollup-plugin-sourcemaps "^0.6.3" signale "^1.4.0" ts-morph "^16.0.0" typescript "~4.7.2" -near-typescript-json-schema@0.54.1: - version "0.54.1" - resolved "https://registry.yarnpkg.com/near-typescript-json-schema/-/near-typescript-json-schema-0.54.1.tgz#0ece6bf683539f6521255c383b5c5cfa81d283e1" - integrity sha512-rFhVb4s0LRVLRBiORAG78tWvd6nvj609mrl0um8Lwdfzm4DEkHK0ey3CMeXGT4EHIPDROQSLGm8VJbvOUTIgLg== +near-typescript-json-schema@0.55.0: + version "0.55.0" + resolved "https://registry.yarnpkg.com/near-typescript-json-schema/-/near-typescript-json-schema-0.55.0.tgz#386cd6c7e37214fdeed4dfc05d5d5f00a18905dc" + integrity sha512-3AFYm89FHB3Bn3+Usow5iP7avF9QIkxh6PP5qCgr66/IT9SIQSG0PGPBtNDcj+WLZCL4yHzLmW7TkdK7nDzy1A== dependencies: "@types/json-schema" "^7.0.9" "@types/node" "^16.9.2" From 540bcc13fa05263ea5feb4a3ca6853edc5030ac8 Mon Sep 17 00:00:00 2001 From: Serhii Volovyk Date: Mon, 5 Dec 2022 11:31:50 +0200 Subject: [PATCH 3/3] lint fix --- examples/__tests__/test-counter.ava.js | 5 +++-- examples/src/counter-extended.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/__tests__/test-counter.ava.js b/examples/__tests__/test-counter.ava.js index a8972a6a..bf2cf03c 100644 --- a/examples/__tests__/test-counter.ava.js +++ b/examples/__tests__/test-counter.ava.js @@ -19,7 +19,7 @@ test.beforeEach(async (t) => { counterContract = "./build/counter-ts.wasm"; break; } - case "COUNTER_JS":{ + case "COUNTER_JS": { counterContract = "./build/counter.wasm"; break; } @@ -27,7 +27,8 @@ test.beforeEach(async (t) => { counterContract = "./build/counter-extended.wasm"; break; } - default: throw Error("Unknown COUNTER_CONTRACT_TYPE"); + default: + throw Error("Unknown COUNTER_CONTRACT_TYPE"); } // Deploy the counter contract. diff --git a/examples/src/counter-extended.ts b/examples/src/counter-extended.ts index c2096823..de1f23b9 100644 --- a/examples/src/counter-extended.ts +++ b/examples/src/counter-extended.ts @@ -3,9 +3,9 @@ import { Counter } from "./counter"; @NearBindgen({}) export class CounterWithReset extends Counter { - @call({}) - reset() { - this.count = 0; - near.log(`Counter is set to 0`); - } -} \ No newline at end of file + @call({}) + reset() { + this.count = 0; + near.log(`Counter is set to 0`); + } +}