@swapkit/helpers 1.0.0-rc.70 → 1.0.0-rc.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -19
- package/dist/index.es.js +400 -363
- package/dist/index.es.js.map +1 -1
- package/package.json +12 -16
- package/src/helpers/__tests__/asset.test.ts +64 -62
- package/src/helpers/__tests__/memo.test.ts +42 -40
- package/src/helpers/__tests__/others.test.ts +31 -31
- package/src/helpers/asset.ts +53 -52
- package/src/helpers/liquidity.ts +9 -9
- package/src/helpers/memo.ts +17 -18
- package/src/helpers/others.ts +3 -3
- package/src/helpers/validators.ts +5 -5
- package/src/index.ts +9 -9
- package/src/modules/__tests__/assetValue.test.ts +245 -144
- package/src/modules/__tests__/bigIntArithmetics.test.ts +8 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +232 -232
- package/src/modules/assetValue.ts +78 -40
- package/src/modules/bigIntArithmetics.ts +86 -86
- package/src/modules/swapKitError.ts +17 -2
- package/src/modules/swapKitNumber.ts +1 -1
- package/src/types.ts +13 -13
package/package.json
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "swapkit-oss
|
|
2
|
+
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit Lib swapkit-helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@swapkit/api": "1.0.0-rc.
|
|
5
|
+
"@swapkit/api": "1.0.0-rc.39"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"@vitest/coverage-istanbul": "1.
|
|
9
|
-
"vite": "5.
|
|
10
|
-
"vitest": "1.
|
|
11
|
-
"@
|
|
12
|
-
"@swapkit/
|
|
13
|
-
"@swapkit/types": "1.0.0-rc.37"
|
|
14
|
-
},
|
|
15
|
-
"eslintConfig": {
|
|
16
|
-
"extends": "../../../internal/eslint-config"
|
|
8
|
+
"@vitest/coverage-istanbul": "1.3.1",
|
|
9
|
+
"vite": "5.1.3",
|
|
10
|
+
"vitest": "1.3.1",
|
|
11
|
+
"@swapkit/tokens": "1.0.0-rc.35",
|
|
12
|
+
"@swapkit/types": "1.0.0-rc.38"
|
|
17
13
|
},
|
|
18
14
|
"peerDependencies": {
|
|
19
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
20
|
-
"@swapkit/types": "1.0.0-rc.
|
|
15
|
+
"@swapkit/tokens": "1.0.0-rc.35",
|
|
16
|
+
"@swapkit/types": "1.0.0-rc.38"
|
|
21
17
|
},
|
|
22
18
|
"exports": {
|
|
23
19
|
".": {
|
|
@@ -42,11 +38,11 @@
|
|
|
42
38
|
},
|
|
43
39
|
"type": "module",
|
|
44
40
|
"types": "./dist/index.d.ts",
|
|
45
|
-
"version": "1.0.0-rc.
|
|
41
|
+
"version": "1.0.0-rc.72",
|
|
46
42
|
"scripts": {
|
|
47
43
|
"build": "vite build",
|
|
48
|
-
"clean": "rm -rf dist vite.config.ts.*
|
|
49
|
-
"lint": "
|
|
44
|
+
"clean": "rm -rf dist vite.config.ts.* node_modules",
|
|
45
|
+
"lint": "biome check --apply ./src",
|
|
50
46
|
"test": "vitest --run",
|
|
51
47
|
"test:coverage": "vitest run --coverage"
|
|
52
48
|
}
|
|
@@ -1,155 +1,157 @@
|
|
|
1
|
-
import { BaseDecimal, Chain } from
|
|
2
|
-
import { describe, expect,
|
|
1
|
+
import { BaseDecimal, Chain } from "@swapkit/types";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { getAssetType, getDecimal } from
|
|
4
|
+
import { getAssetType, getDecimal } from "../asset.ts";
|
|
5
5
|
|
|
6
6
|
const tickerMap: Record<string, string> = {
|
|
7
|
-
[Chain.THORChain]:
|
|
8
|
-
[Chain.Cosmos]:
|
|
9
|
-
[Chain.BinanceSmartChain]:
|
|
7
|
+
[Chain.THORChain]: "RUNE",
|
|
8
|
+
[Chain.Cosmos]: "ATOM",
|
|
9
|
+
[Chain.BinanceSmartChain]: "BNB",
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
describe(
|
|
13
|
-
describe(
|
|
14
|
-
|
|
15
|
-
const result = getAssetType({ chain: Chain.Bitcoin, symbol:
|
|
16
|
-
expect(result).toBe(
|
|
12
|
+
describe("getAssetType", () => {
|
|
13
|
+
describe("when isSynth is true", () => {
|
|
14
|
+
test('should return "Synth"', () => {
|
|
15
|
+
const result = getAssetType({ chain: Chain.Bitcoin, symbol: "BTC/BTC" });
|
|
16
|
+
expect(result).toBe("Synth");
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
describe(
|
|
21
|
-
describe(
|
|
22
|
-
Object.values(Chain)
|
|
23
|
-
|
|
20
|
+
describe("when isSynth is false", () => {
|
|
21
|
+
describe("for native chains and their assets", () => {
|
|
22
|
+
for (const chain of Object.values(Chain)) {
|
|
23
|
+
test(`should return "Native" for chain ${chain} asset`, () => {
|
|
24
24
|
const ticker = tickerMap[chain] || chain;
|
|
25
25
|
const result = getAssetType({ chain: chain as Chain, symbol: ticker });
|
|
26
26
|
|
|
27
|
-
expect(result).toBe(
|
|
27
|
+
expect(result).toBe("Native");
|
|
28
28
|
});
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
describe(
|
|
33
|
-
|
|
34
|
-
const result = getAssetType({ chain: Chain.Cosmos, symbol:
|
|
35
|
-
expect(result).toBe(
|
|
32
|
+
describe("for Cosmos chain", () => {
|
|
33
|
+
test('should return "GAIA" for non-ATOM tickers', () => {
|
|
34
|
+
const result = getAssetType({ chain: Chain.Cosmos, symbol: "NOT_ATOM" });
|
|
35
|
+
expect(result).toBe("GAIA");
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
describe(
|
|
40
|
-
|
|
41
|
-
const result = getAssetType({ chain: Chain.Binance, symbol:
|
|
42
|
-
expect(result).toBe(
|
|
39
|
+
describe("for Binance chain", () => {
|
|
40
|
+
test('should return "BEP2" for non-BNB tickers', () => {
|
|
41
|
+
const result = getAssetType({ chain: Chain.Binance, symbol: "NOT_BNB" });
|
|
42
|
+
expect(result).toBe("BEP2");
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
describe(
|
|
47
|
-
|
|
48
|
-
const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol:
|
|
49
|
-
expect(result).toBe(
|
|
46
|
+
describe("for Binance Smart Chain", () => {
|
|
47
|
+
test('should return "BEP20" for non-BNB tickers', () => {
|
|
48
|
+
const result = getAssetType({ chain: Chain.BinanceSmartChain, symbol: "NOT_BNB" });
|
|
49
|
+
expect(result).toBe("BEP20");
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
describe(
|
|
54
|
-
|
|
55
|
-
const result = getAssetType({ chain: Chain.Ethereum, symbol:
|
|
56
|
-
expect(result).toBe(
|
|
53
|
+
describe("for Ethereum chain", () => {
|
|
54
|
+
test('should return "ERC20" for non-ETH tickers', () => {
|
|
55
|
+
const result = getAssetType({ chain: Chain.Ethereum, symbol: "NOT_ETH" });
|
|
56
|
+
expect(result).toBe("ERC20");
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
describe(
|
|
61
|
-
|
|
62
|
-
const result = getAssetType({ chain: Chain.Avalanche, symbol:
|
|
63
|
-
expect(result).toBe(
|
|
60
|
+
describe("for Avalanche chain", () => {
|
|
61
|
+
test('should return "AVAX" for non-AVAX tickers', () => {
|
|
62
|
+
const result = getAssetType({ chain: Chain.Avalanche, symbol: "NOT_AVAX" });
|
|
63
|
+
expect(result).toBe("AVAX");
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
describe(
|
|
69
|
+
describe("getDecimal", () => {
|
|
70
70
|
/**
|
|
71
71
|
* Test out native
|
|
72
72
|
*/
|
|
73
|
-
Object.values(Chain)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
73
|
+
const filteredChains = Object.values(Chain).filter(
|
|
74
|
+
(c) => ![Chain.Ethereum, Chain.Avalanche].includes(c),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
for (const chain of filteredChains) {
|
|
78
|
+
describe(chain, () => {
|
|
79
|
+
test(`returns proper decimal for native ${chain} asset`, async () => {
|
|
80
|
+
const decimal = await getDecimal({ chain, symbol: chain });
|
|
81
|
+
expect(decimal).toBe(BaseDecimal[chain]);
|
|
81
82
|
});
|
|
82
83
|
});
|
|
84
|
+
}
|
|
83
85
|
|
|
84
|
-
describe(
|
|
85
|
-
|
|
86
|
-
const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol:
|
|
86
|
+
describe("ETH", () => {
|
|
87
|
+
test("returns proper decimal for eth and it's assets", async () => {
|
|
88
|
+
const ethDecimal = await getDecimal({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
87
89
|
expect(ethDecimal).toBe(BaseDecimal.ETH);
|
|
88
90
|
|
|
89
91
|
const usdcDecimal = await getDecimal({
|
|
90
92
|
chain: Chain.Ethereum,
|
|
91
|
-
symbol:
|
|
93
|
+
symbol: "USDC-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
92
94
|
});
|
|
93
95
|
expect(usdcDecimal).toBe(6);
|
|
94
96
|
|
|
95
97
|
const wbtcDecimal = await getDecimal({
|
|
96
98
|
chain: Chain.Ethereum,
|
|
97
|
-
symbol:
|
|
99
|
+
symbol: "WBTC-0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
98
100
|
});
|
|
99
101
|
expect(wbtcDecimal).toBe(8);
|
|
100
102
|
|
|
101
103
|
const decDecimal = await getDecimal({
|
|
102
104
|
chain: Chain.Ethereum,
|
|
103
|
-
symbol:
|
|
105
|
+
symbol: "ZIL-0x05f4a42e251f2d52b8ed15e9fedaacfcef1fad27",
|
|
104
106
|
});
|
|
105
107
|
expect(decDecimal).toBe(12);
|
|
106
108
|
|
|
107
109
|
const kindDecimal = await getDecimal({
|
|
108
110
|
chain: Chain.Ethereum,
|
|
109
|
-
symbol:
|
|
111
|
+
symbol: "KIND-0x4618519de4c304f3444ffa7f812dddc2971cc688",
|
|
110
112
|
});
|
|
111
113
|
expect(kindDecimal).toBe(8);
|
|
112
114
|
|
|
113
115
|
const shitcoinDecimal = await getDecimal({
|
|
114
116
|
chain: Chain.Ethereum,
|
|
115
|
-
symbol:
|
|
117
|
+
symbol: "HOMI-0xCa208BfD69ae6D2667f1FCbE681BAe12767c0078",
|
|
116
118
|
});
|
|
117
119
|
expect(shitcoinDecimal).toBe(0);
|
|
118
120
|
});
|
|
119
121
|
});
|
|
120
122
|
|
|
121
|
-
describe(
|
|
122
|
-
|
|
123
|
-
const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol:
|
|
123
|
+
describe("AVAX", () => {
|
|
124
|
+
test.skip("returns proper decimal for avax and it's assets", async () => {
|
|
125
|
+
const avaxDecimal = await getDecimal({ chain: Chain.Avalanche, symbol: "AVAX" });
|
|
124
126
|
expect(avaxDecimal).toBe(BaseDecimal.AVAX);
|
|
125
127
|
|
|
126
128
|
const wbtceDecimal = await getDecimal({
|
|
127
129
|
chain: Chain.Avalanche,
|
|
128
|
-
symbol:
|
|
130
|
+
symbol: "WBTC.e-0x50b7545627a5162f82a992c33b87adc75187b218",
|
|
129
131
|
});
|
|
130
132
|
expect(wbtceDecimal).toBe(8);
|
|
131
133
|
|
|
132
134
|
const btcbDecimal = await getDecimal({
|
|
133
135
|
chain: Chain.Avalanche,
|
|
134
|
-
symbol:
|
|
136
|
+
symbol: "BTC.b-0x152b9d0FdC40C096757F570A51E494bd4b943E50",
|
|
135
137
|
});
|
|
136
138
|
expect(btcbDecimal).toBe(8);
|
|
137
139
|
|
|
138
140
|
const timeDecimal = await getDecimal({
|
|
139
141
|
chain: Chain.Avalanche,
|
|
140
|
-
symbol:
|
|
142
|
+
symbol: "TIME-0xb54f16fB19478766A268F172C9480f8da1a7c9C3",
|
|
141
143
|
});
|
|
142
144
|
expect(timeDecimal).toBe(9);
|
|
143
145
|
|
|
144
146
|
const usdtDecimal = await getDecimal({
|
|
145
147
|
chain: Chain.Avalanche,
|
|
146
|
-
symbol:
|
|
148
|
+
symbol: "USDT-0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
|
147
149
|
});
|
|
148
150
|
expect(usdtDecimal).toBe(6);
|
|
149
151
|
|
|
150
152
|
const usdcDecimal = await getDecimal({
|
|
151
153
|
chain: Chain.Avalanche,
|
|
152
|
-
symbol:
|
|
154
|
+
symbol: "USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
153
155
|
});
|
|
154
156
|
expect(usdcDecimal).toBe(6);
|
|
155
157
|
});
|
|
@@ -1,79 +1,81 @@
|
|
|
1
|
-
import { Chain, MemoType } from
|
|
2
|
-
import { describe, expect,
|
|
1
|
+
import { Chain, MemoType } from "@swapkit/types";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { getMemoFor } from
|
|
4
|
+
import { getMemoFor } from "../memo.ts";
|
|
5
5
|
|
|
6
|
-
describe(
|
|
7
|
-
describe(
|
|
8
|
-
[
|
|
9
|
-
[MemoType.LEAVE,
|
|
10
|
-
[MemoType.BOND,
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
describe("getMemoFor", () => {
|
|
7
|
+
describe("for Leave, Upgrade, and Bond", () => {
|
|
8
|
+
const nodeMemos = [
|
|
9
|
+
[MemoType.LEAVE, "LEAVE:ABC123"],
|
|
10
|
+
[MemoType.BOND, "BOND:ABC123"],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
for (const [memoType, expected] of nodeMemos) {
|
|
14
|
+
test(`returns correct memo for ${memoType}`, () => {
|
|
15
|
+
const result = getMemoFor(memoType as MemoType, { address: "ABC123" });
|
|
14
16
|
expect(result).toBe(expected);
|
|
15
17
|
});
|
|
16
|
-
}
|
|
18
|
+
}
|
|
17
19
|
});
|
|
18
20
|
|
|
19
|
-
describe(
|
|
20
|
-
|
|
21
|
-
const result = getMemoFor(MemoType.UNBOND, { address:
|
|
22
|
-
expect(result).toBe(
|
|
21
|
+
describe("for Unbond and Thorname Register", () => {
|
|
22
|
+
test("returns correct memo for Unbond", () => {
|
|
23
|
+
const result = getMemoFor(MemoType.UNBOND, { address: "ABC123", unbondAmount: 1000000000 });
|
|
24
|
+
expect(result).toBe("UNBOND:ABC123:1000000000");
|
|
23
25
|
});
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
test("returns correct memo for Thorname Register", () => {
|
|
26
28
|
const result = getMemoFor(MemoType.THORNAME_REGISTER, {
|
|
27
|
-
name:
|
|
28
|
-
chain:
|
|
29
|
-
address:
|
|
30
|
-
owner:
|
|
29
|
+
name: "thorname",
|
|
30
|
+
chain: "BNB",
|
|
31
|
+
address: "0xABC123",
|
|
32
|
+
owner: "0xDEF456",
|
|
31
33
|
});
|
|
32
|
-
expect(result).toBe(
|
|
34
|
+
expect(result).toBe("~:thorname:BNB:0xABC123:0xDEF456");
|
|
33
35
|
});
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
describe(
|
|
37
|
-
|
|
38
|
+
describe("for Deposit", () => {
|
|
39
|
+
test("returns correct memo for Deposit (single side)", () => {
|
|
38
40
|
const result = getMemoFor(MemoType.DEPOSIT, {
|
|
39
41
|
chain: Chain.Ethereum,
|
|
40
|
-
symbol:
|
|
42
|
+
symbol: "ETH",
|
|
41
43
|
singleSide: true,
|
|
42
44
|
});
|
|
43
|
-
expect(result).toBe(
|
|
45
|
+
expect(result).toBe("+:ETH/ETH");
|
|
44
46
|
});
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
test("returns correct memo for Deposit (dual side)", () => {
|
|
47
49
|
const result = getMemoFor(MemoType.DEPOSIT, {
|
|
48
50
|
chain: Chain.Avalanche,
|
|
49
|
-
symbol:
|
|
50
|
-
address:
|
|
51
|
+
symbol: "AVAX",
|
|
52
|
+
address: "0xABC123",
|
|
51
53
|
});
|
|
52
|
-
expect(result).toBe(
|
|
54
|
+
expect(result).toBe("+:AVAX.AVAX:0xABC123");
|
|
53
55
|
});
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
describe(
|
|
57
|
-
|
|
58
|
+
describe("for Withdraw", () => {
|
|
59
|
+
test("returns correct memo for Withdraw (single side)", () => {
|
|
58
60
|
const result = getMemoFor(MemoType.WITHDRAW, {
|
|
59
61
|
chain: Chain.Bitcoin,
|
|
60
|
-
ticker:
|
|
61
|
-
symbol:
|
|
62
|
+
ticker: "BTC",
|
|
63
|
+
symbol: "BTC",
|
|
62
64
|
basisPoints: 10000,
|
|
63
65
|
singleSide: true,
|
|
64
66
|
});
|
|
65
|
-
expect(result).toBe(
|
|
67
|
+
expect(result).toBe("-:BTC/BTC:10000");
|
|
66
68
|
});
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
test("returns correct memo for Withdraw (dual side)", () => {
|
|
69
71
|
const result = getMemoFor(MemoType.WITHDRAW, {
|
|
70
72
|
chain: Chain.Ethereum,
|
|
71
|
-
ticker:
|
|
72
|
-
symbol:
|
|
73
|
+
ticker: "ETH",
|
|
74
|
+
symbol: "ETH",
|
|
73
75
|
basisPoints: 100,
|
|
74
|
-
targetAssetString:
|
|
76
|
+
targetAssetString: "ETH.ETH",
|
|
75
77
|
});
|
|
76
|
-
expect(result).toBe(
|
|
78
|
+
expect(result).toBe("-:ETH.ETH:100:ETH.ETH");
|
|
77
79
|
});
|
|
78
80
|
});
|
|
79
81
|
});
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { describe, expect,
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { derivationPathToString, getTHORNameCost, validateTHORName } from
|
|
3
|
+
import { derivationPathToString, getTHORNameCost, validateTHORName } from "../others.ts";
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
|
|
5
|
+
describe("derivationPathToString", () => {
|
|
6
|
+
test("should return the correct string for a full path", () => {
|
|
7
7
|
const path = [1, 2, 3, 4, 5];
|
|
8
|
-
|
|
9
|
-
expect(result).toEqual("1'/2'/3'/4/5");
|
|
8
|
+
expect(derivationPathToString(path)).toEqual("1'/2'/3'/4/5");
|
|
10
9
|
});
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
test("should return the correct string for a short path", () => {
|
|
13
12
|
const path = [1, 2, 3, 4];
|
|
14
|
-
|
|
15
|
-
expect(result).toEqual("1'/2'/3'/4");
|
|
13
|
+
expect(derivationPathToString(path)).toEqual("1'/2'/3'/4");
|
|
16
14
|
});
|
|
17
15
|
});
|
|
18
16
|
|
|
19
|
-
describe(
|
|
20
|
-
describe(
|
|
21
|
-
[
|
|
17
|
+
describe("getTHORNameCost", () => {
|
|
18
|
+
describe("for correct values", () => {
|
|
19
|
+
const costCases = [
|
|
22
20
|
[1, 11],
|
|
23
21
|
[2, 12],
|
|
24
22
|
[3, 13],
|
|
25
23
|
[10, 20],
|
|
26
|
-
]
|
|
27
|
-
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for (const [years, expected] of costCases) {
|
|
27
|
+
test(`returns correct ${expected} cost for ${years} years`, () => {
|
|
28
28
|
const result = getTHORNameCost(years);
|
|
29
29
|
expect(result).toBe(expected);
|
|
30
30
|
});
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
expect(() => getTHORNameCost(-1)).toThrowError(
|
|
34
|
+
test("throws an error for negative years", () => {
|
|
35
|
+
expect(() => getTHORNameCost(-1)).toThrowError("Invalid number of year");
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
describe(
|
|
39
|
+
describe("validateTHORName", () => {
|
|
40
40
|
const casesWithExpectation: [string, boolean][] = [
|
|
41
|
-
[
|
|
42
|
-
[
|
|
43
|
-
[
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
41
|
+
["validname", true],
|
|
42
|
+
["valid-name", true],
|
|
43
|
+
["valid_name", true],
|
|
44
|
+
["valid+name", true],
|
|
45
|
+
["name_with_numbers123", true],
|
|
46
|
+
["UPPER_CASE", true],
|
|
47
|
+
["toolongname123456789012345678901", false],
|
|
48
|
+
["invalid@name", false],
|
|
49
|
+
["invalid!name", false],
|
|
50
|
+
["invalid#name", false],
|
|
51
51
|
];
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
for (const [name, expected] of casesWithExpectation) {
|
|
54
|
+
test(`returns ${expected} for THORName "${name}"`, () => {
|
|
55
55
|
const result = validateTHORName(name);
|
|
56
56
|
expect(result).toBe(expected);
|
|
57
57
|
});
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
59
|
});
|