Skip to content

Commit d0248fb

Browse files
authored
Merge pull request #250 from AlexKushnir1/typescript-updating
feat: Update typescript and ECMAScript target
2 parents 683ec26 + 7220b30 commit d0248fb

File tree

120 files changed

+2460
-5685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2460
-5685
lines changed

.github/workflows/lint.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ jobs:
2121
cache: 'pnpm'
2222

2323
- run: pnpm install
24+
- run: pnpm build
2425
- run: pnpm lint

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ near-vm-*.tar.gz
22
node_modules/
33
.near-credentials/
44
coverage
5-
**/dist/tsconfig.tsbuildinfo
65
.idea
76
package-lock.json
7+
**/dist/

.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
pnpm lint && pnpm build && git add packages/*/dist
4+
pnpm lint && pnpm build

.xo-config.json

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"space": true,
3+
"rules": {
4+
"import/extensions": 0,
5+
"n/file-extension-in-import": 0,
6+
"unicorn/prefer-node-protocol": 0,
7+
"unicorn/prefer-module": 0,
8+
"unicorn/no-array-callback-reference": 0,
9+
"unicorn/prevent-abbreviations": [
10+
"error",
11+
{
12+
"allowList": {
13+
"args": true,
14+
"Args": true,
15+
"refFinance": true,
16+
"createRef": true,
17+
"getNetworkFromEnv": true,
18+
"refContract": true
19+
}
20+
}
21+
],
22+
"n/prefer-global/url": 0,
23+
"ava/no-ignored-test-files": 0,
24+
"@typescript-eslint/no-unsafe-return": 0,
25+
"@typescript-eslint/consistent-type-definitions": 0,
26+
"@typescript-eslint/naming-convention": [
27+
"error",
28+
{
29+
"selector": "variable",
30+
"modifiers": ["const"],
31+
"format": ["camelCase", "UPPER_CASE"],
32+
"leadingUnderscore": "allow",
33+
"trailingUnderscore": "allow"
34+
}
35+
],
36+
"@typescript-eslint/ban-types": [
37+
"error",
38+
{
39+
"types": {
40+
"null": false,
41+
"Buffer": false
42+
}
43+
}
44+
]
45+
},
46+
"ignores": ["examples/**/*.js", "*.cjs"],
47+
"overrides": [
48+
{
49+
"files": ["**/__tests__/**/*.spec.ts", "**/__tests__/**/*.ava.ts"],
50+
"rules": {
51+
"@typescript-eslint/naming-convention": 0,
52+
"@typescript-eslint/no-unsafe-assignment": 0,
53+
"unicorn/prefer-module": 0,
54+
"@typescript-eslint/no-unsafe-call": 0,
55+
"@typescript-eslint/no-empty-function": 0,
56+
"import/no-extraneous-dependencies": 0,
57+
"import/extensions": 0
58+
}
59+
}
60+
]
61+
}

__tests__/01.basic-transactions.ava.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* on testnet by using the `test:sandbox` and `test:testnet` scripts in
88
* package.json.
99
*/
10-
import anyTest, {TestFn} from 'ava';
11-
import {Worker, NEAR, NearAccount} from '../packages/js';
10+
import anyTest, {type TestFn} from 'ava';
11+
import {Worker, NEAR, type NearAccount} from 'near-workspaces';
1212

1313
const test = anyTest as TestFn<{
1414
worker: Worker;
@@ -34,7 +34,7 @@ test.beforeEach(async t => {
3434

3535
test.afterEach.always(async t => {
3636
// Stop Sandbox server
37-
await t.context.worker.tearDown().catch(error => {
37+
await t.context.worker.tearDown().catch((error: unknown) => {
3838
console.log('Failed to tear down the worker:', error);
3939
});
4040
});

__tests__/03.single-use-access-keys-with-linkdrop.ava.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
*
1212
* You can see this functionality in action below using `signWithKey`.
1313
*/
14-
import anyTest, {TestFn} from 'ava';
15-
import {Worker, createKeyPair, NEAR, NearAccount} from '../packages/js';
14+
import anyTest, {type TestFn} from 'ava';
15+
import {
16+
Worker, createKeyPair, NEAR, type NearAccount,
17+
} from 'near-workspaces';
1618

1719
/* Contract API for reference
1820
impl Linkdrop {
@@ -44,7 +46,7 @@ test.beforeEach(async t => {
4446
});
4547

4648
test.afterEach.always(async t => {
47-
await t.context.worker.tearDown().catch(error => {
49+
await t.context.worker.tearDown().catch((error: unknown) => {
4850
console.log('Failed to tear down the worker:', error);
4951
});
5052
});

__tests__/04.cross-contract-calls-with-fungible-token.ava.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
* tests below initiate chains of transactions using near-workspaces's transaction
1414
* builder. Search for `batch` below.
1515
*/
16-
import anyTest, {TestFn} from 'ava';
17-
import {Worker, NearAccount, captureError, BN, NEAR} from '../packages/js';
16+
import anyTest, {type TestFn} from 'ava';
17+
import {
18+
Worker, type NearAccount, captureError, BN, NEAR,
19+
} from 'near-workspaces';
1820

1921
const STORAGE_BYTE_COST = '1.5 mN';
2022

@@ -70,11 +72,13 @@ test.beforeEach(async t => {
7072
const ali = await root.createSubAccount('ali', {initialBalance: NEAR.parse('1 N').toJSON()});
7173

7274
t.context.worker = worker;
73-
t.context.accounts = {root, ft, defi, ali};
75+
t.context.accounts = {
76+
root, ft, defi, ali,
77+
};
7478
});
7579

7680
test.afterEach.always(async t => {
77-
await t.context.worker.tearDown().catch(error => {
81+
await t.context.worker.tearDown().catch((error: unknown) => {
7882
console.log('Failed to tear down the worker:', error);
7983
});
8084
});

__tests__/05.spoon-contract-to-sandbox.ava.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
* contracts can give you a huge confidence boost that your contracts will work
1919
* as expected once actually deployed.
2020
*/
21-
import anyTest, {TestFn} from 'ava';
22-
import {Gas, NEAR, NearAccount, Worker, captureError} from '../packages/js';
21+
import anyTest, {type TestFn} from 'ava';
22+
import {
23+
Gas,
24+
NEAR,
25+
type NearAccount,
26+
Worker,
27+
captureError,
28+
} from 'near-workspaces';
2329

2430
const REF_FINANCE_ACCOUNT = 'v2.ref-finance.near';
2531

@@ -37,7 +43,7 @@ test.beforeEach(async t => {
3743
});
3844

3945
test.afterEach.always(async t => {
40-
await t.context.worker.tearDown().catch(error => {
46+
await t.context.worker.tearDown().catch((error: unknown) => {
4147
console.log('Failed to tear down the worker:', error);
4248
});
4349
});
@@ -130,13 +136,15 @@ test('integrate own FT with Ref.Finance', async t => {
130136
token_out: wNEAR,
131137
});
132138
t.is(expectedOut, '1662497915624478906119726');
133-
const amountOut: string = await root.call(refFinance, 'swap', {actions: [{
134-
pool_id,
135-
token_in: ft,
136-
amount_in: NEAR.parse('1 N'),
137-
token_out: wNEAR,
138-
min_amount_out: '1',
139-
}]}, {
139+
const amountOut: string = await root.call(refFinance, 'swap', {
140+
actions: [{
141+
pool_id,
142+
token_in: ft,
143+
amount_in: NEAR.parse('1 N'),
144+
token_out: wNEAR,
145+
min_amount_out: '1',
146+
}],
147+
}, {
140148
attachedDeposit: '1',
141149
});
142150
t.is(amountOut, expectedOut);

__tests__/06.init-config.ava.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import anyTest, {TestFn} from 'ava';
2-
import {getNetworkFromEnv, NearAccount, Worker} from '../packages/js';
1+
import anyTest, {type TestFn} from 'ava';
2+
import {getNetworkFromEnv, type NearAccount, Worker} from 'near-workspaces';
33

44
if (getNetworkFromEnv() === 'testnet') {
55
const test = anyTest as TestFn<{
@@ -15,7 +15,7 @@ if (getNetworkFromEnv() === 'testnet') {
1515
});
1616

1717
test.afterEach.always(async t => {
18-
await t.context.worker.tearDown().catch(error => {
18+
await t.context.worker.tearDown().catch((error: unknown) => {
1919
console.log('Failed to tear down the worker:', error);
2020
});
2121
});

__tests__/07.resue-worker.ava.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* Keep in mind that tests are executed in parallel.
66
* It means that they should not depend on each other.
77
*/
8-
import anyTest, {TestFn} from 'ava';
9-
import {Worker, NEAR, NearAccount} from '../packages/js';
8+
import anyTest, {type TestFn} from 'ava';
9+
import {Worker, NEAR, type NearAccount} from 'near-workspaces';
1010

1111
const test = anyTest as TestFn<{
1212
worker: Worker;
@@ -28,7 +28,7 @@ test.before(async t => {
2828
});
2929

3030
test.after.always(async t => {
31-
await t.context.worker.tearDown().catch(error => {
31+
await t.context.worker.tearDown().catch((error: unknown) => {
3232
console.log('Failed to tear down the worker:', error);
3333
});
3434
});

__tests__/08.custom-network.ava.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'process';
2-
import anyTest, {TestFn} from 'ava';
3-
import {Worker, getNetworkFromEnv} from '../packages/js';
2+
import anyTest, {type TestFn} from 'ava';
3+
import {Worker, getNetworkFromEnv} from 'near-workspaces';
44

55
// To run this test, you need to set the NEAR_RPC_API_KEY environment variable tied the Pagoda testnet network.
66
// And the NEAR_WORKSPACES_NETWORK environment variable to 'custom'.
@@ -21,7 +21,7 @@ if (getNetworkFromEnv() === 'custom' && process.env.NEAR_RPC_API_KEY !== '') {
2121
});
2222

2323
test.after.always(async t => {
24-
await t.context.worker.tearDown().catch(error => {
24+
await t.context.worker.tearDown().catch((error: unknown) => {
2525
console.log('Failed to tear down the worker:', error);
2626
});
2727
});

__tests__/09.fast-forward.ava.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import anyTest, {TestFn} from 'ava';
2-
import {NearAccount, Worker, getNetworkFromEnv} from '../packages/js';
1+
import anyTest, {type TestFn} from 'ava';
2+
import {type NearAccount, Worker, getNetworkFromEnv} from 'near-workspaces';
33

44
// The contract provided contains only one view call, returning the
55
// block_timestamp and epoch_height of the current block as a tuple.
66
// Source is here <https://github.com/near/near-workspaces-rs/blob/main/examples/simple-contract/src/lib.rs>
77
const contract_wasm = '__tests__/build/debug/simple_contract.wasm';
88

99
// Represents the timestamp and epoch_height result from the view call.
10-
type EnvData = [number, number];
10+
type EnvironmentData = [number, number];
1111

1212
if (getNetworkFromEnv() === 'sandbox') {
1313
const test = anyTest as TestFn<{
@@ -25,15 +25,15 @@ if (getNetworkFromEnv() === 'sandbox') {
2525
});
2626

2727
test.afterEach.always(async t => {
28-
await t.context.worker.tearDown().catch(error => {
28+
await t.context.worker.tearDown().catch((error: unknown) => {
2929
console.log('Failed to tear down the worker:', error);
3030
});
3131
});
3232

3333
test('Fast Forward', async t => {
3434
const before = await t.context.contract.view('current_env_data');
35-
const env_before = before as EnvData;
36-
console.log(`Before: timestamp = ${env_before[0]}, epoch_height = ${env_before[1]}`);
35+
const environmentBefore = before as EnvironmentData;
36+
console.log(`Before: timestamp = ${environmentBefore[0]}, epoch_height = ${environmentBefore[1]}`);
3737

3838
const forward_height = 10_000;
3939

@@ -42,8 +42,8 @@ if (getNetworkFromEnv() === 'sandbox') {
4242
await t.context.worker.provider.fastForward(forward_height);
4343

4444
const after = await t.context.contract.view('current_env_data');
45-
const env_after = after as EnvData;
46-
console.log(`After: timestamp = ${env_after[0]}, epoch_height = ${env_after[1]}`);
45+
const environmentAfter = after as EnvironmentData;
46+
console.log(`After: timestamp = ${environmentAfter[0]}, epoch_height = ${environmentAfter[1]}`);
4747

4848
const block = await t.context.worker.provider.block({finality: 'final'});
4949

__tests__/ci-ignore-02.patch-state.ava.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
* testnet. That's why they're wrapped with `if (getNetworkFromEnv() === 'sandbox')`.
1212
*/
1313

14-
/* eslint-disable @typescript-eslint/no-extraneous-class, @typescript-eslint/no-unsafe-member-access */
15-
import anyTest, {TestFn} from 'ava';
14+
/* eslint-disable @typescript-eslint/no-extraneous-class, @typescript-eslint/no-unsafe-argument */
15+
import anyTest, {type TestFn} from 'ava';
1616
import * as borsh from '../packages/js/node_modules/borsh';
17-
import {Worker, getNetworkFromEnv, NearAccount} from '../packages/js';
17+
import {Worker, getNetworkFromEnv, type NearAccount} from '../packages/js';
1818
import {NEAR} from '../packages/js/node_modules/near-units';
1919

2020
if (getNetworkFromEnv() === 'sandbox') {
@@ -34,7 +34,7 @@ if (getNetworkFromEnv() === 'sandbox') {
3434
});
3535

3636
test.afterEach.always(async t => {
37-
await t.context.worker.tearDown().catch(error => {
37+
await t.context.worker.tearDown().catch((error: unknown) => {
3838
console.log('Failed to tear down the worker:', error);
3939
});
4040
});

package.json

+6-34
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,23 @@
2222
"docs:generate": "typedoc"
2323
},
2424
"devDependencies": {
25-
"@ava/typescript": "^2.0.0",
25+
"@ava/typescript": "^5.0.0",
2626
"@types/bn.js": "^5.1.0",
2727
"@types/fs-extra": "^9.0.12",
2828
"@types/node": "20.0.0",
2929
"@types/rimraf": "^3.0.1",
30-
"ava": "^4.0.1",
30+
"borsh": "^0.5.0",
31+
"ava": "^6.2.0",
3132
"husky": "^7.0.1",
3233
"ts-node": "^10.9.1",
3334
"typedoc": "^0.24",
34-
"typescript": "^4.7.4",
35-
"xo": "^0.44.0"
35+
"typescript": "5.4.5",
36+
"xo": "^0.60.0",
37+
"near-workspaces": "workspace:*"
3638
},
3739
"engines": {
3840
"node": ">=20.15.0",
3941
"pnpm": ">= 9.15"
4042
},
41-
"xo": {
42-
"space": true,
43-
"rules": {
44-
"unicorn/prefer-node-protocol": 0,
45-
"unicorn/prefer-module": 0,
46-
"unicorn/no-array-callback-reference": 0,
47-
"node/prefer-global/url": 0,
48-
"ava/no-ignored-test-files": 0,
49-
"@typescript-eslint/no-unsafe-return": 0
50-
},
51-
"ignores": [
52-
"examples/**/*.js"
53-
],
54-
"overrides": [
55-
{
56-
"files": [
57-
"**/__tests__/**/*.spec.ts",
58-
"**/__tests__/**/*.ava.ts"
59-
],
60-
"rules": {
61-
"@typescript-eslint/no-unsafe-assignment": 0,
62-
"unicorn/prefer-module": 0,
63-
"@typescript-eslint/no-unsafe-call": 0,
64-
"@typescript-eslint/no-empty-function": 0,
65-
"import/no-extraneous-dependencies": 0,
66-
"import/extensions": 0
67-
}
68-
}
69-
]
70-
},
7143
"private": true
7244
}

packages/js/__tests__/account-manager.ava.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import anyTest, {TestFn} from 'ava';
1+
import anyTest, {type TestFn} from 'ava';
22
import {
33
AccountManager,
44
TestnetWorker,
5-
Worker,
6-
TestnetManager,
5+
type Worker,
6+
type TestnetManager,
77
getNetworkFromEnv,
88
} from '..';
99

0 commit comments

Comments
 (0)