diff --git a/cli/cli.js b/cli/cli.js index f604e611b..d74c6804b 100755 --- a/cli/cli.js +++ b/cli/cli.js @@ -80,7 +80,7 @@ async function build(argv) { async function checkTsBuildWithTsc(sourceFileWithPath) { console.log(`check TypeScript build of ${sourceFileWithPath} with tsc`) - await executeCommand(`${TSC} --noEmit --experimentalDecorators --target es5 ${sourceFileWithPath}`); + await executeCommand(`${TSC} --noEmit --experimentalDecorators --target es2020 --moduleResolution node ${sourceFileWithPath}`); } // Common build function diff --git a/examples/tsconfig.json b/examples/tsconfig.json index ad8999a80..34d7bd188 100644 --- a/examples/tsconfig.json +++ b/examples/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "experimentalDecorators": true, - "target": "es5", + "target": "es2020", "noEmit": true }, "exclude": [ diff --git a/tests/__tests__/typescript.ava.js b/tests/__tests__/typescript.ava.js new file mode 100644 index 000000000..46b23eddc --- /dev/null +++ b/tests/__tests__/typescript.ava.js @@ -0,0 +1,37 @@ +import { Worker } from 'near-workspaces'; +import test from 'ava'; + + +test.before(async t => { + // Init the worker and start a Sandbox server + const worker = await Worker.init(); + + // Prepare sandbox for tests, create accounts, deploy contracts, etx. + const root = worker.rootAccount; + + // Deploy the test contract. + const typescriptContract = await root.devDeploy( + 'build/typescript.wasm', + ); + await typescriptContract.call(typescriptContract, 'init', {}) + + // Test users + const ali = await root.createSubAccount('ali'); + + // Save state for test runs + t.context.worker = worker; + t.context.accounts = { root, typescriptContract, ali }; +}); + +test.after(async t => { + await t.context.worker.tearDown().catch(error => { + console.log('Failed to tear down the worker:', error); + }); +}); + + +test('bigint', async t => { + const { typescriptContract } = t.context.accounts; + let r = await typescriptContract.view('bigint', ''); + t.is(r, "3"); +}); diff --git a/tests/package.json b/tests/package.json index b8ae04d2e..0d1bc5b0c 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "postinstall": "cd .. && yarn link && cd tests && yarn link near-sdk-js", - "build": "yarn build:context-api && yarn build:math-api && yarn build:storage-api && yarn build:log-panic-api && yarn build:promise-api && yarn build:promise-batch-api && yarn build:function-params && yarn build:lookup-map && yarn build:lookup-set && yarn build:unordered-map && yarn build:unordered-set && yarn build:vector && yarn build:bytes", + "build": "yarn build:context-api && yarn build:math-api && yarn build:storage-api && yarn build:log-panic-api && yarn build:promise-api && yarn build:promise-batch-api && yarn build:function-params && yarn build:lookup-map && yarn build:lookup-set && yarn build:unordered-map && yarn build:unordered-set && yarn build:vector && yarn build:bytes && yarn build:typescript", "build:context-api": "near-sdk-js build src/context_api.js build/context_api.wasm", "build:math-api": "near-sdk-js build src/math_api.js build/math_api.wasm", "build:storage-api": "near-sdk-js build src/storage_api.js build/storage_api.wasm", @@ -20,6 +20,7 @@ "build:unordered-set": "near-sdk-js build src/unordered-set.js build/unordered-set.wasm", "build:vector": "near-sdk-js build src/vector.js build/vector.wasm", "build:bytes": "near-sdk-js build src/bytes.js build/bytes.wasm", + "build:typescript": "near-sdk-js build src/typescript.ts build/typescript.wasm", "test": "ava", "test:context-api": "ava __tests__/test_context_api.ava.js", "test:math-api": "ava __tests__/test_math_api.ava.js", @@ -32,12 +33,14 @@ "test:unordered-set": "ava __tests__/unordered-set.ava.js", "test:unordered-map": "ava __tests__/unordered-map.ava.js", "test:vector": "ava __tests__/vector.ava.js", - "test:bytes": "ava __tests__/bytes.ava.js" + "test:bytes": "ava __tests__/bytes.ava.js", + "test:typescript": "ava __tests__/typescript.ava.js" }, "author": "Near Inc ", "license": "Apache-2.0", "devDependencies": { "ava": "^4.2.0", - "near-workspaces": "3.1.0" + "near-workspaces": "3.1.0", + "typescript": "^4.7.4" } } diff --git a/tests/src/typescript.ts b/tests/src/typescript.ts new file mode 100644 index 000000000..c53e7a0a1 --- /dev/null +++ b/tests/src/typescript.ts @@ -0,0 +1,18 @@ +import { + NearContract, + NearBindgen, + view, +} from 'near-sdk-js' + +@NearBindgen +class TypeScriptTestContract extends NearContract { + @view + bigint() { + // JSON.stringify cannot seriaize a BigInt, need manually toString + return (1n + 2n).toString() + } + + default() { + return new TypeScriptTestContract() + } +} \ No newline at end of file diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 000000000..34d7bd188 --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "target": "es2020", + "noEmit": true + }, + "exclude": [ + "node_modules" + ], +} \ No newline at end of file diff --git a/tests/yarn.lock b/tests/yarn.lock index 7d4bcfb60..196ce3c5a 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -1463,6 +1463,11 @@ type-fest@^0.13.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.13.1.tgz#0172cb5bce80b0bd542ea348db50c7e21834d934" integrity sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg== +typescript@^4.7.4: + version "4.7.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" + integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== + u3@^0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/u3/-/u3-0.1.1.tgz#5f52044f42ee76cd8de33148829e14528494b73b"