thirdweb 5.80.1-nightly-a7b6cb3211e8b5232e77965cb8dd8ff96b369424-20241228000338 → 5.80.1-nightly-03bf859809de255d20f4ed8285a3bb75cef17252-20241230000334
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/cjs/chains/utils.js +4 -0
- package/dist/cjs/chains/utils.js.map +1 -1
- package/dist/cjs/exports/utils.js +2 -2
- package/dist/cjs/exports/utils.js.map +1 -1
- package/dist/cjs/utils/bytecode/{extractMnimalProxyImplementationAddress.js → extractMinimalProxyImplementationAddress.js} +1 -1
- package/dist/cjs/utils/bytecode/extractMinimalProxyImplementationAddress.js.map +1 -0
- package/dist/cjs/utils/bytecode/resolveImplementation.js +2 -2
- package/dist/cjs/utils/bytecode/resolveImplementation.js.map +1 -1
- package/dist/cjs/utils/promise/p-limit.js +5 -0
- package/dist/cjs/utils/promise/p-limit.js.map +1 -1
- package/dist/cjs/utils/semver.js +1 -0
- package/dist/cjs/utils/semver.js.map +1 -1
- package/dist/cjs/utils/url.js +3 -0
- package/dist/cjs/utils/url.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/chains/utils.js +4 -1
- package/dist/esm/chains/utils.js.map +1 -1
- package/dist/esm/exports/utils.js +1 -1
- package/dist/esm/exports/utils.js.map +1 -1
- package/dist/esm/utils/bytecode/{extractMnimalProxyImplementationAddress.js → extractMinimalProxyImplementationAddress.js} +1 -1
- package/dist/esm/utils/bytecode/extractMinimalProxyImplementationAddress.js.map +1 -0
- package/dist/esm/utils/bytecode/resolveImplementation.js +1 -1
- package/dist/esm/utils/bytecode/resolveImplementation.js.map +1 -1
- package/dist/esm/utils/promise/p-limit.js +4 -1
- package/dist/esm/utils/promise/p-limit.js.map +1 -1
- package/dist/esm/utils/semver.js +1 -1
- package/dist/esm/utils/semver.js.map +1 -1
- package/dist/esm/utils/url.js +3 -3
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/chains/utils.d.ts +4 -0
- package/dist/types/chains/utils.d.ts.map +1 -1
- package/dist/types/exports/utils.d.ts +1 -1
- package/dist/types/exports/utils.d.ts.map +1 -1
- package/dist/types/utils/bytecode/{extractMnimalProxyImplementationAddress.d.ts → extractMinimalProxyImplementationAddress.d.ts} +1 -1
- package/dist/types/utils/bytecode/extractMinimalProxyImplementationAddress.d.ts.map +1 -0
- package/dist/types/utils/promise/p-limit.d.ts +13 -0
- package/dist/types/utils/promise/p-limit.d.ts.map +1 -1
- package/dist/types/utils/semver.d.ts +15 -0
- package/dist/types/utils/semver.d.ts.map +1 -1
- package/dist/types/utils/url.d.ts +12 -0
- package/dist/types/utils/url.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/auth/verify-hash.test.ts +3 -3
- package/src/chains/utils.test.ts +70 -1
- package/src/chains/utils.ts +4 -1
- package/src/contract/contract.test.ts +42 -0
- package/src/exports/utils.ts +1 -1
- package/src/extensions/thirdweb/write/publish.test.ts +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.test.tsx +52 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.test.ts +174 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/formatSeconds.test.ts +30 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/utils.test.ts +20 -0
- package/src/react/web/wallets/injected/locale/getInjectedWalletLocale.test.ts +39 -0
- package/src/react/web/wallets/smartWallet/locale/getSmartWalletLocale.test.ts +39 -0
- package/src/utils/abi/normalizeFunctionParams.test.ts +108 -0
- package/src/utils/bigint.test.ts +91 -1
- package/src/utils/bytecode/extractMinimalProxyImplementationAddress.test.ts +60 -0
- package/src/utils/bytecode/resolveImplementation.ts +1 -1
- package/src/utils/domain.test.ts +78 -0
- package/src/utils/encoding/hex.test.ts +163 -1
- package/src/utils/ens/encodeLabelToLabelhash.test.ts +28 -0
- package/src/utils/ens/encodeLabelhash.test.ts +18 -0
- package/src/utils/ens/namehash.test.ts +17 -0
- package/src/utils/nft/{parse-nft.test.ts → parseNft.test.ts} +39 -0
- package/src/utils/promise/p-limit.test.ts +105 -0
- package/src/utils/promise/p-limit.ts +4 -1
- package/src/utils/promise/withCache.test.ts +73 -0
- package/src/utils/semver.test.ts +72 -0
- package/src/utils/semver.ts +1 -1
- package/src/utils/url.test.ts +90 -1
- package/src/utils/url.ts +6 -3
- package/src/version.ts +1 -1
- package/src/wallets/eip5792/get-calls-status.test.ts +4 -4
- package/src/wallets/eip5792/send-calls.test.ts +7 -7
- package/src/wallets/eip5792/show-calls-status.test.ts +2 -2
- package/dist/cjs/utils/bytecode/extractMnimalProxyImplementationAddress.js.map +0 -1
- package/dist/esm/utils/bytecode/extractMnimalProxyImplementationAddress.js.map +0 -1
- package/dist/types/utils/bytecode/extractMnimalProxyImplementationAddress.d.ts.map +0 -1
- /package/src/utils/bytecode/{extractMnimalProxyImplementationAddress.ts → extractMinimalProxyImplementationAddress.ts} +0 -0
package/src/utils/bigint.test.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
2
|
-
import { max, min, toBigInt } from "./bigint.js";
|
2
|
+
import { max, min, replaceBigInts, toBigInt } from "./bigint.js";
|
3
3
|
|
4
4
|
describe("min", () => {
|
5
5
|
it("should return the smaller value when a is smaller than b", () => {
|
@@ -79,4 +79,94 @@ describe("toBigInt", () => {
|
|
79
79
|
`Expected value to be an integer to convert to a bigint, got ${value} of type number`,
|
80
80
|
);
|
81
81
|
});
|
82
|
+
|
83
|
+
it("should convert a Uint8Array to a BigInt", () => {
|
84
|
+
const uint8Array = new Uint8Array([1, 2, 3, 4]);
|
85
|
+
const result = toBigInt(uint8Array);
|
86
|
+
expect(result).toBe(BigInt("0x01020304"));
|
87
|
+
});
|
88
|
+
|
89
|
+
it("should handle a Uint8Array with leading zeros", () => {
|
90
|
+
const uint8Array = new Uint8Array([0, 0, 1, 2]);
|
91
|
+
const result = toBigInt(uint8Array);
|
92
|
+
expect(result).toBe(BigInt("0x00000102"));
|
93
|
+
});
|
94
|
+
|
95
|
+
it("should handle a large Uint8Array", () => {
|
96
|
+
const uint8Array = new Uint8Array([255, 255, 255, 255]);
|
97
|
+
const result = toBigInt(uint8Array);
|
98
|
+
expect(result).toBe(BigInt("0xffffffff"));
|
99
|
+
});
|
100
|
+
|
101
|
+
describe("replaceBigInts", () => {
|
102
|
+
it("should replace a single bigint value", () => {
|
103
|
+
const input = BigInt(123);
|
104
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
105
|
+
expect(result).toBe("123");
|
106
|
+
});
|
107
|
+
|
108
|
+
it("should handle arrays containing bigints", () => {
|
109
|
+
const input = [BigInt(1), BigInt(2), BigInt(3)];
|
110
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
111
|
+
expect(result).toEqual(["1", "2", "3"]);
|
112
|
+
});
|
113
|
+
|
114
|
+
it("should handle nested arrays with bigints", () => {
|
115
|
+
const input = [BigInt(1), [BigInt(2), BigInt(3)]];
|
116
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
117
|
+
expect(result).toEqual(["1", ["2", "3"]]);
|
118
|
+
});
|
119
|
+
|
120
|
+
it("should handle objects containing bigints", () => {
|
121
|
+
const input = { a: BigInt(1), b: BigInt(2) };
|
122
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
123
|
+
expect(result).toEqual({ a: "1", b: "2" });
|
124
|
+
});
|
125
|
+
|
126
|
+
it("should handle nested objects with bigints", () => {
|
127
|
+
const input = { a: BigInt(1), b: { c: BigInt(2), d: BigInt(3) } };
|
128
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
129
|
+
expect(result).toEqual({ a: "1", b: { c: "2", d: "3" } });
|
130
|
+
});
|
131
|
+
|
132
|
+
it("should handle mixed arrays and objects", () => {
|
133
|
+
const input = {
|
134
|
+
a: [BigInt(1), { b: BigInt(2), c: [BigInt(3)] }],
|
135
|
+
};
|
136
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
137
|
+
expect(result).toEqual({ a: ["1", { b: "2", c: ["3"] }] });
|
138
|
+
});
|
139
|
+
|
140
|
+
it("should handle empty arrays and objects", () => {
|
141
|
+
expect(replaceBigInts([], (x) => x.toString())).toEqual([]);
|
142
|
+
expect(replaceBigInts({}, (x) => x.toString())).toEqual({});
|
143
|
+
});
|
144
|
+
|
145
|
+
it("should leave other types untouched", () => {
|
146
|
+
const input = {
|
147
|
+
a: "string",
|
148
|
+
b: 42,
|
149
|
+
c: null,
|
150
|
+
d: undefined,
|
151
|
+
e: true,
|
152
|
+
f: [1, "test"],
|
153
|
+
};
|
154
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
155
|
+
expect(result).toEqual(input);
|
156
|
+
});
|
157
|
+
|
158
|
+
it("should handle complex deeply nested structures", () => {
|
159
|
+
const input = {
|
160
|
+
a: BigInt(1),
|
161
|
+
b: [BigInt(2), { c: [BigInt(3), { d: BigInt(4) }] }],
|
162
|
+
e: { f: { g: BigInt(5) } },
|
163
|
+
};
|
164
|
+
const result = replaceBigInts(input, (x) => x.toString());
|
165
|
+
expect(result).toEqual({
|
166
|
+
a: "1",
|
167
|
+
b: ["2", { c: ["3", { d: "4" }] }],
|
168
|
+
e: { f: { g: "5" } },
|
169
|
+
});
|
170
|
+
});
|
171
|
+
});
|
82
172
|
});
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
2
|
+
import { extractMinimalProxyImplementationAddress } from "./extractMinimalProxyImplementationAddress.js";
|
3
|
+
|
4
|
+
describe("extractMinimalProxyImplementationAddress", () => {
|
5
|
+
it("should handle bytecode without 0x prefix", () => {
|
6
|
+
const bytecode =
|
7
|
+
"363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3";
|
8
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
9
|
+
expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe");
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should extract address from EIP-1167 clone minimal proxy", () => {
|
13
|
+
const bytecode =
|
14
|
+
"0x363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3";
|
15
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
16
|
+
expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe");
|
17
|
+
});
|
18
|
+
|
19
|
+
it("should extract address from 0xSplits minimal proxy", () => {
|
20
|
+
const bytecode =
|
21
|
+
"0x36603057343d52307f830d2d700a97af574b186c80d40429385d24241565b08a7c559ba283a964d9b1583103d5942010000000000000000000000001234567890123456789012345678901234567890";
|
22
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
23
|
+
expect(result).toBe("0x234567890123456789012345678901234567890");
|
24
|
+
});
|
25
|
+
|
26
|
+
it("should extract address from 0age's minimal proxy", () => {
|
27
|
+
const bytecode =
|
28
|
+
"0x3d3d3d3d363d3d37363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3";
|
29
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
30
|
+
expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe");
|
31
|
+
});
|
32
|
+
|
33
|
+
it("should extract address from Vyper's minimal proxy (Uniswap v1)", () => {
|
34
|
+
const bytecode =
|
35
|
+
"0x366000600037611000600036600073bebebebebebebebebebebebebebebebebebebebe5af41558576110006000f3";
|
36
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
37
|
+
expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe");
|
38
|
+
});
|
39
|
+
|
40
|
+
it("should extract address from alternative Vyper minimal proxy", () => {
|
41
|
+
const bytecode =
|
42
|
+
"0x36600080376020600036600073bebebebebebebebebebebebebebebebebebebebe5af41558576020600060006000f3";
|
43
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
44
|
+
expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe");
|
45
|
+
});
|
46
|
+
|
47
|
+
it("should extract address from EIP-7511 minimal proxy with PUSH0 opcode", () => {
|
48
|
+
const bytecode =
|
49
|
+
"0x365f5f375f5f365f73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3";
|
50
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
51
|
+
expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe");
|
52
|
+
});
|
53
|
+
|
54
|
+
it("should return undefined for non-matching bytecode", () => {
|
55
|
+
const bytecode =
|
56
|
+
"0x60806040526000805534801561001457600080fd5b50610150806100246000396000f3fe";
|
57
|
+
const result = extractMinimalProxyImplementationAddress(bytecode);
|
58
|
+
expect(result).toBeUndefined();
|
59
|
+
});
|
60
|
+
});
|
@@ -5,7 +5,7 @@ import { getRpcClient } from "../../rpc/rpc.js";
|
|
5
5
|
import { readContract } from "../../transaction/read-contract.js";
|
6
6
|
import { isAddress } from "../address.js";
|
7
7
|
import type { Hex } from "../encoding/hex.js";
|
8
|
-
import { extractMinimalProxyImplementationAddress } from "./
|
8
|
+
import { extractMinimalProxyImplementationAddress } from "./extractMinimalProxyImplementationAddress.js";
|
9
9
|
|
10
10
|
// TODO: move to const exports
|
11
11
|
const AddressZero = "0x0000000000000000000000000000000000000000";
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
2
|
+
import {
|
3
|
+
DEFAULT_RPC_URL,
|
4
|
+
getThirdwebBaseUrl,
|
5
|
+
getThirdwebDomains,
|
6
|
+
setThirdwebDomains,
|
7
|
+
} from "./domains.js";
|
8
|
+
|
9
|
+
describe("Thirdweb Domains", () => {
|
10
|
+
const defaultDomains = {
|
11
|
+
rpc: "rpc.thirdweb.com",
|
12
|
+
social: "social.thirdweb.com",
|
13
|
+
inAppWallet: "embedded-wallet.thirdweb.com",
|
14
|
+
pay: "pay.thirdweb.com",
|
15
|
+
storage: "storage.thirdweb.com",
|
16
|
+
bundler: "bundler.thirdweb.com",
|
17
|
+
analytics: "c.thirdweb.com",
|
18
|
+
};
|
19
|
+
|
20
|
+
beforeEach(() => {
|
21
|
+
// Reset to default domains before each test
|
22
|
+
setThirdwebDomains({});
|
23
|
+
});
|
24
|
+
|
25
|
+
describe("getThirdwebDomains", () => {
|
26
|
+
it("should return the default domains if no overrides are set", () => {
|
27
|
+
expect(getThirdwebDomains()).toEqual(defaultDomains);
|
28
|
+
});
|
29
|
+
});
|
30
|
+
|
31
|
+
describe("setThirdwebDomains", () => {
|
32
|
+
it("should override specific domains while keeping others as default", () => {
|
33
|
+
setThirdwebDomains({
|
34
|
+
rpc: "custom.rpc.com",
|
35
|
+
analytics: "custom.analytics.com",
|
36
|
+
});
|
37
|
+
|
38
|
+
expect(getThirdwebDomains()).toEqual({
|
39
|
+
...defaultDomains,
|
40
|
+
rpc: "custom.rpc.com",
|
41
|
+
analytics: "custom.analytics.com",
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
it("should not modify domains that are not overridden", () => {
|
46
|
+
setThirdwebDomains({ pay: "custom.pay.com" });
|
47
|
+
|
48
|
+
const domains = getThirdwebDomains();
|
49
|
+
expect(domains.pay).toBe("custom.pay.com");
|
50
|
+
expect(domains.rpc).toBe(defaultDomains.rpc);
|
51
|
+
expect(domains.analytics).toBe(defaultDomains.analytics);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
55
|
+
describe("getThirdwebBaseUrl", () => {
|
56
|
+
it("should return an HTTPS URL for non-localhost domains", () => {
|
57
|
+
const baseUrl = getThirdwebBaseUrl("rpc");
|
58
|
+
expect(baseUrl).toBe(`https://${DEFAULT_RPC_URL}`);
|
59
|
+
});
|
60
|
+
|
61
|
+
it("should return an HTTP URL for localhost domains", () => {
|
62
|
+
setThirdwebDomains({ rpc: "localhost:8545" });
|
63
|
+
const baseUrl = getThirdwebBaseUrl("rpc");
|
64
|
+
expect(baseUrl).toBe("http://localhost:8545");
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should reflect the updated domain overrides", () => {
|
68
|
+
setThirdwebDomains({ storage: "custom.storage.com" });
|
69
|
+
const baseUrl = getThirdwebBaseUrl("storage");
|
70
|
+
expect(baseUrl).toBe("https://custom.storage.com");
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should throw an error if an invalid service is requested", () => {
|
74
|
+
// biome-ignore lint/suspicious/noExplicitAny: for test
|
75
|
+
expect(() => getThirdwebBaseUrl("invalid" as any)).toThrow();
|
76
|
+
});
|
77
|
+
});
|
78
|
+
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
2
|
-
import { numberToHex } from "./hex.js";
|
2
|
+
import { fromHex, numberToHex, padHex, toHex } from "./hex.js";
|
3
3
|
|
4
4
|
describe("hex.ts", () => {
|
5
5
|
it("should convert number with no padding", () => {
|
@@ -54,3 +54,165 @@ describe("hex.ts", () => {
|
|
54
54
|
);
|
55
55
|
});
|
56
56
|
});
|
57
|
+
|
58
|
+
describe("toHex without parameters", () => {
|
59
|
+
it("should convert number to hex", () => {
|
60
|
+
expect(toHex(1)).toBe("0x1");
|
61
|
+
});
|
62
|
+
|
63
|
+
it("should convert bigint to hex", () => {
|
64
|
+
expect(toHex(1n)).toBe("0x1");
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should convert string to hex", () => {
|
68
|
+
expect(toHex("1")).toBe("0x31");
|
69
|
+
});
|
70
|
+
|
71
|
+
it("should convert boolean to hex", () => {
|
72
|
+
expect(toHex(true)).toBe("0x1");
|
73
|
+
expect(toHex(false)).toBe("0x0");
|
74
|
+
});
|
75
|
+
|
76
|
+
it("should convert uint8 array to hex", () => {
|
77
|
+
expect(toHex(new Uint8Array([42, 255, 0, 128, 64]))).toBe("0x2aff008040");
|
78
|
+
});
|
79
|
+
});
|
80
|
+
|
81
|
+
describe("toHex WITH parameters", () => {
|
82
|
+
it("should convert number to hex", () => {
|
83
|
+
expect(toHex(1, { size: 32 })).toBe(
|
84
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
85
|
+
);
|
86
|
+
});
|
87
|
+
|
88
|
+
it("should convert bigint to hex", () => {
|
89
|
+
expect(toHex(1n, { size: 32 })).toBe(
|
90
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
91
|
+
);
|
92
|
+
});
|
93
|
+
|
94
|
+
it("should convert string to hex", () => {
|
95
|
+
expect(toHex("1", { size: 32 })).toBe(
|
96
|
+
"0x3100000000000000000000000000000000000000000000000000000000000000",
|
97
|
+
);
|
98
|
+
});
|
99
|
+
|
100
|
+
it("should convert boolean to hex", () => {
|
101
|
+
expect(toHex(true, { size: 32 })).toBe(
|
102
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
103
|
+
);
|
104
|
+
expect(toHex(false, { size: 32 })).toBe(
|
105
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
106
|
+
);
|
107
|
+
});
|
108
|
+
|
109
|
+
it("should convert uint8 array to hex", () => {
|
110
|
+
expect(toHex(new Uint8Array([42, 255, 0, 128, 64]), { size: 32 })).toBe(
|
111
|
+
"0x2aff008040000000000000000000000000000000000000000000000000000000",
|
112
|
+
);
|
113
|
+
});
|
114
|
+
});
|
115
|
+
|
116
|
+
describe("fromHex without parameter", () => {
|
117
|
+
it("should convert hex to number", () => {
|
118
|
+
expect(fromHex("0x1", { to: "number" })).toBe(1);
|
119
|
+
});
|
120
|
+
|
121
|
+
it("should convert hex to bigint", () => {
|
122
|
+
expect(fromHex("0x1", { to: "bigint" })).toBe(1n);
|
123
|
+
});
|
124
|
+
|
125
|
+
it("should convert hex to string", () => {
|
126
|
+
expect(fromHex("0x31", "string")).toBe("1");
|
127
|
+
});
|
128
|
+
|
129
|
+
it("should convert hex to boolean:true", () => {
|
130
|
+
expect(fromHex("0x1", "boolean")).toBe(true);
|
131
|
+
});
|
132
|
+
|
133
|
+
it("should convert hex to boolean:false", () => {
|
134
|
+
expect(fromHex("0x0", "boolean")).toBe(false);
|
135
|
+
});
|
136
|
+
|
137
|
+
it("should convert hex to uint8 array", () => {
|
138
|
+
expect(fromHex("0x2aff008040", "bytes")).toStrictEqual(
|
139
|
+
new Uint8Array([42, 255, 0, 128, 64]),
|
140
|
+
);
|
141
|
+
});
|
142
|
+
});
|
143
|
+
|
144
|
+
describe("fromHex WITH parameter", () => {
|
145
|
+
it("should convert hex to number", () => {
|
146
|
+
expect(
|
147
|
+
fromHex(
|
148
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
149
|
+
{ to: "number", size: 32 },
|
150
|
+
),
|
151
|
+
).toBe(1);
|
152
|
+
});
|
153
|
+
|
154
|
+
it("should convert hex to bigint", () => {
|
155
|
+
expect(
|
156
|
+
fromHex(
|
157
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
158
|
+
{ to: "bigint", size: 32 },
|
159
|
+
),
|
160
|
+
).toBe(1n);
|
161
|
+
});
|
162
|
+
|
163
|
+
it("should convert hex to string", () => {
|
164
|
+
expect(
|
165
|
+
fromHex(
|
166
|
+
"0x3100000000000000000000000000000000000000000000000000000000000000",
|
167
|
+
{ to: "string", size: 32 },
|
168
|
+
),
|
169
|
+
).toBe("1");
|
170
|
+
});
|
171
|
+
|
172
|
+
it("should convert hex to boolean:true", () => {
|
173
|
+
expect(
|
174
|
+
fromHex(
|
175
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
176
|
+
{ to: "boolean", size: 32 },
|
177
|
+
),
|
178
|
+
).toBe(true);
|
179
|
+
});
|
180
|
+
|
181
|
+
it("should convert hex to boolean:false", () => {
|
182
|
+
expect(
|
183
|
+
fromHex(
|
184
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
185
|
+
{ to: "boolean", size: 32 },
|
186
|
+
),
|
187
|
+
).toBe(false);
|
188
|
+
});
|
189
|
+
|
190
|
+
it("should convert hex to uint8 array", () => {
|
191
|
+
expect(
|
192
|
+
fromHex(
|
193
|
+
"0x2aff008040000000000000000000000000000000000000000000000000000000",
|
194
|
+
{ to: "bytes", size: 32 },
|
195
|
+
).toString(),
|
196
|
+
).toStrictEqual(
|
197
|
+
"42,255,0,128,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
|
198
|
+
);
|
199
|
+
});
|
200
|
+
});
|
201
|
+
|
202
|
+
describe("padHex", () => {
|
203
|
+
it("should return the original value if size is undefined", () => {
|
204
|
+
expect(padHex("0x0", { size: null })).toBe("0x0");
|
205
|
+
});
|
206
|
+
|
207
|
+
it("should produce correct result if padding direction is right", () => {
|
208
|
+
expect(padHex("0x1", { size: 10, dir: "right" })).toBe(
|
209
|
+
"0x10000000000000000000",
|
210
|
+
);
|
211
|
+
});
|
212
|
+
|
213
|
+
it("should produce correct result if padding direction is Left", () => {
|
214
|
+
expect(padHex("0x1", { size: 10, dir: "left" })).toBe(
|
215
|
+
"0x00000000000000000001",
|
216
|
+
);
|
217
|
+
});
|
218
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
2
|
+
import { encodedLabelToLabelhash } from "./encodeLabelToLabelhash.js";
|
3
|
+
|
4
|
+
describe("encodedLabelToLabelhash", () => {
|
5
|
+
it("should return null if the label length is not 66", () => {
|
6
|
+
expect(encodedLabelToLabelhash("")).toBeNull();
|
7
|
+
expect(encodedLabelToLabelhash("[123456]")).toBeNull();
|
8
|
+
expect(encodedLabelToLabelhash("[1234567890]".padEnd(67, "0"))).toBeNull();
|
9
|
+
});
|
10
|
+
|
11
|
+
it("should return null if the label does not start with '['", () => {
|
12
|
+
const input = "1234567890".padStart(66, "0");
|
13
|
+
expect(encodedLabelToLabelhash(input)).toBeNull();
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should return null if the label does not end with ']' at position 65", () => {
|
17
|
+
const input = "[1234567890".padEnd(66, "0");
|
18
|
+
expect(encodedLabelToLabelhash(input)).toBeNull();
|
19
|
+
});
|
20
|
+
|
21
|
+
it("should return the hash if the label is valid", () => {
|
22
|
+
const validHash = "a".repeat(64);
|
23
|
+
const input = `[${validHash}]`;
|
24
|
+
|
25
|
+
const result = encodedLabelToLabelhash(input);
|
26
|
+
expect(result).toBe(`0x${validHash}`);
|
27
|
+
});
|
28
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
2
|
+
import type { Hex } from "../encoding/hex.js";
|
3
|
+
import { encodeLabelhash } from "./encodeLabelhash.js";
|
4
|
+
|
5
|
+
describe("encodeLabelhash", () => {
|
6
|
+
it("should encode a valid hex hash correctly", () => {
|
7
|
+
const input = "0x1234567890abcdef";
|
8
|
+
const expectedOutput = "[1234567890abcdef]";
|
9
|
+
expect(encodeLabelhash(input)).toBe(expectedOutput);
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should handle hashes of varying valid lengths", () => {
|
13
|
+
const shortHash = "0x1";
|
14
|
+
const longHash = `0x${"a".repeat(64)}`;
|
15
|
+
expect(encodeLabelhash(shortHash)).toBe("[1]");
|
16
|
+
expect(encodeLabelhash(longHash as Hex)).toBe(`[${"a".repeat(64)}]`);
|
17
|
+
});
|
18
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { bytesToHex, concat } from "viem/utils";
|
2
|
+
import { describe, expect, it } from "vitest";
|
3
|
+
import { namehash } from "./namehash.js";
|
4
|
+
|
5
|
+
describe("namehash", () => {
|
6
|
+
it("should return a zero-filled hash for an empty name", () => {
|
7
|
+
const result = namehash("");
|
8
|
+
expect(result).toBe(bytesToHex(new Uint8Array(32).fill(0)));
|
9
|
+
});
|
10
|
+
|
11
|
+
it("should correctly concatenate intermediate hashes", () => {
|
12
|
+
const labelBytes1 = new Uint8Array([1, 2, 3]);
|
13
|
+
const labelBytes2 = new Uint8Array([4, 5, 6]);
|
14
|
+
const concatenated = concat([labelBytes1, labelBytes2]);
|
15
|
+
expect(concat([labelBytes1, labelBytes2])).toEqual(concatenated);
|
16
|
+
});
|
17
|
+
});
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
2
|
+
import { TEST_CLIENT } from "~test/test-clients.js";
|
2
3
|
import {
|
3
4
|
type NFT,
|
4
5
|
type NFTMetadata,
|
5
6
|
type ParseNFTOptions,
|
6
7
|
parseNFT,
|
8
|
+
parseNftUri,
|
7
9
|
} from "./parseNft.js";
|
8
10
|
|
9
11
|
const base: NFTMetadata = {
|
@@ -11,6 +13,8 @@ const base: NFTMetadata = {
|
|
11
13
|
uri: "ipfs://",
|
12
14
|
};
|
13
15
|
|
16
|
+
const client = TEST_CLIENT;
|
17
|
+
|
14
18
|
describe("parseNft", () => {
|
15
19
|
it("should parse ERC721 token", () => {
|
16
20
|
const option: ParseNFTOptions = {
|
@@ -57,4 +61,39 @@ describe("parseNft", () => {
|
|
57
61
|
// @ts-ignore For testing purpose
|
58
62
|
expect(() => parseNFT(base, option)).toThrowError(/Invalid NFT type/);
|
59
63
|
});
|
64
|
+
|
65
|
+
it("should throw an error for an invalid EIP namespace", async () => {
|
66
|
+
const uri = "invalid:1/erc721:0x1234567890abcdef1234567890abcdef12345678/1";
|
67
|
+
await expect(parseNftUri({ client, uri })).rejects.toThrow(
|
68
|
+
'Invalid EIP namespace, expected EIP155, got: "invalid"',
|
69
|
+
);
|
70
|
+
});
|
71
|
+
|
72
|
+
it("should throw an error for a missing chain ID", async () => {
|
73
|
+
const uri = "eip155:/erc721:0x1234567890abcdef1234567890abcdef12345678/1";
|
74
|
+
await expect(parseNftUri({ client, uri })).rejects.toThrow(
|
75
|
+
"Chain ID not found",
|
76
|
+
);
|
77
|
+
});
|
78
|
+
|
79
|
+
it("should throw an error for an invalid contract address", async () => {
|
80
|
+
const uri = "eip155:1/erc721:invalid-address/1";
|
81
|
+
await expect(parseNftUri({ client, uri })).rejects.toThrow(
|
82
|
+
"Contract address not found",
|
83
|
+
);
|
84
|
+
});
|
85
|
+
|
86
|
+
it("should throw an error for a missing token ID", async () => {
|
87
|
+
const uri = "eip155:1/erc721:0x1234567890abcdef1234567890abcdef12345678/";
|
88
|
+
await expect(parseNftUri({ client, uri })).rejects.toThrow(
|
89
|
+
"Token ID not found",
|
90
|
+
);
|
91
|
+
});
|
92
|
+
|
93
|
+
it("should throw an error for an invalid ERC namespace", async () => {
|
94
|
+
const uri = "eip155:1/invalid:0x1234567890abcdef1234567890abcdef12345678/1";
|
95
|
+
await expect(parseNftUri({ client, uri })).rejects.toThrow(
|
96
|
+
'Invalid ERC namespace, expected ERC721 or ERC1155, got: "invalid"',
|
97
|
+
);
|
98
|
+
});
|
60
99
|
});
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
2
|
+
import { Queue, pLimit } from "./p-limit.js";
|
3
|
+
|
4
|
+
describe("p-limit queue", () => {
|
5
|
+
it("should enqueue and dequeue items in the correct order", () => {
|
6
|
+
const queue = new Queue<number>();
|
7
|
+
queue.enqueue(1);
|
8
|
+
queue.enqueue(2);
|
9
|
+
queue.enqueue(3);
|
10
|
+
|
11
|
+
expect(queue.size).toBe(3);
|
12
|
+
expect(queue.dequeue()).toBe(1);
|
13
|
+
expect(queue.dequeue()).toBe(2);
|
14
|
+
expect(queue.dequeue()).toBe(3);
|
15
|
+
expect(queue.dequeue()).toBeUndefined();
|
16
|
+
});
|
17
|
+
|
18
|
+
it("should correctly report size", () => {
|
19
|
+
const queue = new Queue<number>();
|
20
|
+
expect(queue.size).toBe(0);
|
21
|
+
|
22
|
+
queue.enqueue(1);
|
23
|
+
expect(queue.size).toBe(1);
|
24
|
+
|
25
|
+
queue.dequeue();
|
26
|
+
expect(queue.size).toBe(0);
|
27
|
+
});
|
28
|
+
|
29
|
+
it("should clear the queue", () => {
|
30
|
+
const queue = new Queue<number>();
|
31
|
+
queue.enqueue(1);
|
32
|
+
queue.enqueue(2);
|
33
|
+
queue.clear();
|
34
|
+
|
35
|
+
expect(queue.size).toBe(0);
|
36
|
+
expect(queue.dequeue()).toBeUndefined();
|
37
|
+
});
|
38
|
+
|
39
|
+
it("should support iteration", () => {
|
40
|
+
const queue = new Queue<number>();
|
41
|
+
queue.enqueue(1);
|
42
|
+
queue.enqueue(2);
|
43
|
+
queue.enqueue(3);
|
44
|
+
|
45
|
+
const values = [...queue];
|
46
|
+
expect(values).toEqual([1, 2, 3]);
|
47
|
+
});
|
48
|
+
});
|
49
|
+
|
50
|
+
describe("pLimit", () => {
|
51
|
+
it("should limit the number of concurrent executions", async () => {
|
52
|
+
const limit = pLimit(2);
|
53
|
+
const executionOrder: number[] = [];
|
54
|
+
const delayedTask = (id: number) =>
|
55
|
+
limit(async () => {
|
56
|
+
executionOrder.push(id);
|
57
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
58
|
+
});
|
59
|
+
|
60
|
+
await Promise.all([
|
61
|
+
delayedTask(1),
|
62
|
+
delayedTask(2),
|
63
|
+
delayedTask(3),
|
64
|
+
delayedTask(4),
|
65
|
+
]);
|
66
|
+
|
67
|
+
// Ensure tasks were executed in the correct order with concurrency of 2
|
68
|
+
expect(executionOrder).toEqual([1, 2, 3, 4]);
|
69
|
+
});
|
70
|
+
|
71
|
+
it("should handle rejected promises gracefully", async () => {
|
72
|
+
const limit = pLimit(1);
|
73
|
+
|
74
|
+
await expect(
|
75
|
+
limit(async () => {
|
76
|
+
throw new Error("Test error");
|
77
|
+
}),
|
78
|
+
).rejects.toThrow("Test error");
|
79
|
+
|
80
|
+
expect(limit.activeCount).toBe(0);
|
81
|
+
expect(limit.pendingCount).toBe(0);
|
82
|
+
});
|
83
|
+
|
84
|
+
it("should handle mixed resolutions and rejections", async () => {
|
85
|
+
const limit = pLimit(2);
|
86
|
+
|
87
|
+
const task1 = limit(async () => {
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
89
|
+
return 1;
|
90
|
+
});
|
91
|
+
|
92
|
+
const task2 = limit(async () => {
|
93
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
94
|
+
return 2;
|
95
|
+
});
|
96
|
+
|
97
|
+
const task3 = limit(async () => {
|
98
|
+
throw new Error("Task failed");
|
99
|
+
}).catch(() => "Task failed");
|
100
|
+
|
101
|
+
const results = await Promise.all([task1, task2, task3]);
|
102
|
+
|
103
|
+
expect(results).toStrictEqual([1, 2, "Task failed"]);
|
104
|
+
});
|
105
|
+
});
|