@ar.io/sdk 3.11.1-alpha.1 → 3.12.0-alpha.2
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/bundles/web.bundle.min.js +2 -2
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -0
- package/lib/cjs/cli/options.js +6 -0
- package/lib/cjs/cli/utils.js +11 -2
- package/lib/cjs/common/io.js +1 -0
- package/lib/cjs/common/turbo.js +2 -1
- package/lib/cjs/utils/json.js +0 -1
- package/lib/cjs/utils/url.js +10 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +6 -1
- package/lib/esm/cli/options.js +6 -0
- package/lib/esm/cli/utils.js +10 -2
- package/lib/esm/common/io.js +1 -0
- package/lib/esm/common/turbo.js +2 -1
- package/lib/esm/utils/json.js +0 -1
- package/lib/esm/utils/url.js +10 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/options.d.ts +5 -0
- package/lib/types/cli/utils.d.ts +1 -0
- package/lib/types/common/turbo.d.ts +6 -6
- package/lib/types/types/io.d.ts +1 -0
- package/lib/types/utils/json.d.ts +1 -1
- package/lib/types/utils/url.d.ts +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +3 -2
- package/lib/cjs/types/ant.test.js +0 -150
- package/lib/cjs/types/token.test.js +0 -83
- package/lib/cjs/utils/ant.test.js +0 -111
- package/lib/cjs/utils/b64.test.js +0 -72
- package/lib/cjs/utils/url.test.js +0 -24
- package/lib/cjs/utils/utils.test.js +0 -194
- package/lib/esm/types/ant.test.js +0 -148
- package/lib/esm/types/token.test.js +0 -81
- package/lib/esm/utils/ant.test.js +0 -109
- package/lib/esm/utils/b64.test.js +0 -70
- package/lib/esm/utils/url.test.js +0 -19
- package/lib/esm/utils/utils.test.js +0 -192
- package/lib/types/types/ant.test.d.ts +0 -1
- package/lib/types/types/token.test.d.ts +0 -1
- package/lib/types/utils/ant.test.d.ts +0 -1
- package/lib/types/utils/b64.test.d.ts +0 -1
- package/lib/types/utils/url.test.d.ts +0 -1
- package/lib/types/utils/utils.test.d.ts +0 -1
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -39,6 +39,7 @@ exports.readANTFromOptions = readANTFromOptions;
|
|
|
39
39
|
exports.writeANTFromOptions = writeANTFromOptions;
|
|
40
40
|
exports.booleanFromOptions = booleanFromOptions;
|
|
41
41
|
exports.requiredStringFromOptions = requiredStringFromOptions;
|
|
42
|
+
exports.stringArrayFromOptions = stringArrayFromOptions;
|
|
42
43
|
exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
|
|
43
44
|
exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
|
|
44
45
|
exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
|
|
@@ -352,6 +353,7 @@ function requiredMARIOFromOptions(options, key) {
|
|
|
352
353
|
}
|
|
353
354
|
async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
354
355
|
if (costDetailsParams.fundFrom === 'turbo') {
|
|
356
|
+
// TODO: Get turbo balance and assert it is enough -- retain paid-by from balance result and pass to CLI logic
|
|
355
357
|
return;
|
|
356
358
|
}
|
|
357
359
|
const costDetails = await ario.getCostDetails(costDetailsParams);
|
|
@@ -428,16 +430,23 @@ function requiredStringFromOptions(options, key) {
|
|
|
428
430
|
}
|
|
429
431
|
return value;
|
|
430
432
|
}
|
|
431
|
-
function
|
|
433
|
+
function stringArrayFromOptions(options, key) {
|
|
432
434
|
const value = options[key];
|
|
433
435
|
if (value === undefined) {
|
|
434
|
-
|
|
436
|
+
return undefined;
|
|
435
437
|
}
|
|
436
438
|
if (!Array.isArray(value)) {
|
|
437
439
|
throw new Error(`--${key} must be an array`);
|
|
438
440
|
}
|
|
439
441
|
return value;
|
|
440
442
|
}
|
|
443
|
+
function requiredStringArrayFromOptions(options, key) {
|
|
444
|
+
const value = stringArrayFromOptions(options, key);
|
|
445
|
+
if (value === undefined) {
|
|
446
|
+
throw new Error(`--${key} is required`);
|
|
447
|
+
}
|
|
448
|
+
return value;
|
|
449
|
+
}
|
|
441
450
|
function positiveIntegerFromOptions(options, key) {
|
|
442
451
|
const value = options[key];
|
|
443
452
|
if (value === undefined) {
|
package/lib/cjs/common/io.js
CHANGED
package/lib/cjs/common/turbo.js
CHANGED
|
@@ -155,7 +155,7 @@ class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnau
|
|
|
155
155
|
}
|
|
156
156
|
this.signer = signer;
|
|
157
157
|
}
|
|
158
|
-
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
158
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, paidBy = [], }) {
|
|
159
159
|
// Signer check is implicitly handled by requiring it in the constructor
|
|
160
160
|
const url = (0, url_js_1.urlWithSearchParams)({
|
|
161
161
|
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
@@ -164,6 +164,7 @@ class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnau
|
|
|
164
164
|
processId,
|
|
165
165
|
type,
|
|
166
166
|
years,
|
|
167
|
+
paidBy,
|
|
167
168
|
},
|
|
168
169
|
});
|
|
169
170
|
const headers = await signedRequestHeadersFromSigner({
|
package/lib/cjs/utils/json.js
CHANGED
package/lib/cjs/utils/url.js
CHANGED
|
@@ -21,7 +21,16 @@ const urlWithSearchParams = ({ baseUrl, params, }) => {
|
|
|
21
21
|
Object.entries(params).forEach(([key, value]) => {
|
|
22
22
|
if (value === undefined || value === null)
|
|
23
23
|
return;
|
|
24
|
-
|
|
24
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
25
|
+
for (const v of value) {
|
|
26
|
+
if (v === undefined || v === null)
|
|
27
|
+
continue;
|
|
28
|
+
urlObj.searchParams.append(key, v.toString());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
urlObj.searchParams.set(key, value.toString());
|
|
33
|
+
}
|
|
25
34
|
});
|
|
26
35
|
return urlObj.toString();
|
|
27
36
|
};
|
package/lib/cjs/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertConfirmationPrompt, assertEnoughBalanceForArNSPurchase, customTagsFromOptions, fundFromFromOptions, positiveIntegerFromOptions, recordTypeFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, writeARIOFromOptions, } from '../utils.js';
|
|
1
|
+
import { assertConfirmationPrompt, assertEnoughBalanceForArNSPurchase, customTagsFromOptions, fundFromFromOptions, positiveIntegerFromOptions, recordTypeFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, stringArrayFromOptions, writeARIOFromOptions, } from '../utils.js';
|
|
2
2
|
export async function buyRecordCLICommand(o) {
|
|
3
3
|
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
4
4
|
const name = requiredStringFromOptions(o, 'name');
|
|
@@ -37,6 +37,7 @@ export async function buyRecordCLICommand(o) {
|
|
|
37
37
|
type,
|
|
38
38
|
years,
|
|
39
39
|
fundFrom: fundFromFromOptions(o),
|
|
40
|
+
paidBy: stringArrayFromOptions(o, 'paidBy'),
|
|
40
41
|
}, customTagsFromOptions(o));
|
|
41
42
|
}
|
|
42
43
|
export async function upgradeRecordCLICommand(o) {
|
|
@@ -68,6 +69,7 @@ export async function upgradeRecordCLICommand(o) {
|
|
|
68
69
|
return ario.upgradeRecord({
|
|
69
70
|
name,
|
|
70
71
|
fundFrom,
|
|
72
|
+
paidBy: stringArrayFromOptions(o, 'paidBy'),
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
75
|
export async function extendLeaseCLICommand(o) {
|
|
@@ -101,6 +103,7 @@ export async function extendLeaseCLICommand(o) {
|
|
|
101
103
|
return ario.extendLease({
|
|
102
104
|
name,
|
|
103
105
|
years,
|
|
106
|
+
paidBy: stringArrayFromOptions(o, 'paidBy'),
|
|
104
107
|
}, customTagsFromOptions(o));
|
|
105
108
|
}
|
|
106
109
|
export async function increaseUndernameLimitCLICommand(o) {
|
|
@@ -131,6 +134,7 @@ export async function increaseUndernameLimitCLICommand(o) {
|
|
|
131
134
|
return ario.increaseUndernameLimit({
|
|
132
135
|
name,
|
|
133
136
|
increaseCount,
|
|
137
|
+
paidBy: stringArrayFromOptions(o, 'paidBy'),
|
|
134
138
|
}, customTagsFromOptions(o));
|
|
135
139
|
}
|
|
136
140
|
export async function requestPrimaryNameCLICommand(o) {
|
|
@@ -155,5 +159,6 @@ export async function requestPrimaryNameCLICommand(o) {
|
|
|
155
159
|
return ario.requestPrimaryName({
|
|
156
160
|
name,
|
|
157
161
|
fundFrom,
|
|
162
|
+
paidBy: stringArrayFromOptions(o, 'paidBy'),
|
|
158
163
|
}, customTagsFromOptions(o));
|
|
159
164
|
}
|
package/lib/esm/cli/options.js
CHANGED
|
@@ -278,6 +278,11 @@ export const optionMap = {
|
|
|
278
278
|
description: 'Crypto token type for wallet or action',
|
|
279
279
|
default: 'arweave',
|
|
280
280
|
},
|
|
281
|
+
paidBy: {
|
|
282
|
+
alias: '--paid-by <paidBy...>',
|
|
283
|
+
description: 'Addresses to pay for the interaction',
|
|
284
|
+
type: 'array',
|
|
285
|
+
},
|
|
281
286
|
};
|
|
282
287
|
export const walletOptions = [
|
|
283
288
|
optionMap.walletFile,
|
|
@@ -299,6 +304,7 @@ export const arnsPurchaseOptions = [
|
|
|
299
304
|
...writeActionOptions,
|
|
300
305
|
optionMap.name,
|
|
301
306
|
optionMap.fundFrom,
|
|
307
|
+
optionMap.paidBy,
|
|
302
308
|
optionMap.paymentUrl,
|
|
303
309
|
];
|
|
304
310
|
export const epochOptions = [optionMap.epochIndex, optionMap.timestamp];
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -304,6 +304,7 @@ export function requiredMARIOFromOptions(options, key) {
|
|
|
304
304
|
}
|
|
305
305
|
export async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
306
306
|
if (costDetailsParams.fundFrom === 'turbo') {
|
|
307
|
+
// TODO: Get turbo balance and assert it is enough -- retain paid-by from balance result and pass to CLI logic
|
|
307
308
|
return;
|
|
308
309
|
}
|
|
309
310
|
const costDetails = await ario.getCostDetails(costDetailsParams);
|
|
@@ -380,16 +381,23 @@ export function requiredStringFromOptions(options, key) {
|
|
|
380
381
|
}
|
|
381
382
|
return value;
|
|
382
383
|
}
|
|
383
|
-
export function
|
|
384
|
+
export function stringArrayFromOptions(options, key) {
|
|
384
385
|
const value = options[key];
|
|
385
386
|
if (value === undefined) {
|
|
386
|
-
|
|
387
|
+
return undefined;
|
|
387
388
|
}
|
|
388
389
|
if (!Array.isArray(value)) {
|
|
389
390
|
throw new Error(`--${key} must be an array`);
|
|
390
391
|
}
|
|
391
392
|
return value;
|
|
392
393
|
}
|
|
394
|
+
export function requiredStringArrayFromOptions(options, key) {
|
|
395
|
+
const value = stringArrayFromOptions(options, key);
|
|
396
|
+
if (value === undefined) {
|
|
397
|
+
throw new Error(`--${key} is required`);
|
|
398
|
+
}
|
|
399
|
+
return value;
|
|
400
|
+
}
|
|
393
401
|
export function positiveIntegerFromOptions(options, key) {
|
|
394
402
|
const value = options[key];
|
|
395
403
|
if (value === undefined) {
|
package/lib/esm/common/io.js
CHANGED
package/lib/esm/common/turbo.js
CHANGED
|
@@ -148,7 +148,7 @@ export class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProvi
|
|
|
148
148
|
}
|
|
149
149
|
this.signer = signer;
|
|
150
150
|
}
|
|
151
|
-
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
|
|
151
|
+
async initiateArNSPurchase({ intent, name, quantity, type, processId, years, paidBy = [], }) {
|
|
152
152
|
// Signer check is implicitly handled by requiring it in the constructor
|
|
153
153
|
const url = urlWithSearchParams({
|
|
154
154
|
baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
|
|
@@ -157,6 +157,7 @@ export class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProvi
|
|
|
157
157
|
processId,
|
|
158
158
|
type,
|
|
159
159
|
years,
|
|
160
|
+
paidBy,
|
|
160
161
|
},
|
|
161
162
|
});
|
|
162
163
|
const headers = await signedRequestHeadersFromSigner({
|
package/lib/esm/utils/json.js
CHANGED
package/lib/esm/utils/url.js
CHANGED
|
@@ -18,7 +18,16 @@ export const urlWithSearchParams = ({ baseUrl, params, }) => {
|
|
|
18
18
|
Object.entries(params).forEach(([key, value]) => {
|
|
19
19
|
if (value === undefined || value === null)
|
|
20
20
|
return;
|
|
21
|
-
|
|
21
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
22
|
+
for (const v of value) {
|
|
23
|
+
if (v === undefined || v === null)
|
|
24
|
+
continue;
|
|
25
|
+
urlObj.searchParams.append(key, v.toString());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
urlObj.searchParams.set(key, value.toString());
|
|
30
|
+
}
|
|
22
31
|
});
|
|
23
32
|
return urlObj.toString();
|
|
24
33
|
};
|
package/lib/esm/version.js
CHANGED
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare function readANTFromOptions(options: ProcessIdCLIOptions): AoANTR
|
|
|
75
75
|
export declare function writeANTFromOptions(options: ProcessIdCLIOptions, signer?: ContractSigner): AoANTWrite;
|
|
76
76
|
export declare function booleanFromOptions<O extends GlobalCLIOptions>(options: O, key: string): boolean;
|
|
77
77
|
export declare function requiredStringFromOptions<O extends GlobalCLIOptions>(options: O, key: string): string;
|
|
78
|
+
export declare function stringArrayFromOptions<O extends GlobalCLIOptions>(options: O, key: string): string[] | undefined;
|
|
78
79
|
export declare function requiredStringArrayFromOptions<O extends GlobalCLIOptions>(options: O, key: string): string[];
|
|
79
80
|
export declare function positiveIntegerFromOptions<O extends GlobalCLIOptions>(options: O, key: string): number | undefined;
|
|
80
81
|
export declare function requiredPositiveIntegerFromOptions<O extends GlobalCLIOptions>(options: O, key: string): number;
|
|
@@ -29,10 +29,12 @@ export interface ArNSPaymentProvider {
|
|
|
29
29
|
mARIO: mARIOToken;
|
|
30
30
|
}>;
|
|
31
31
|
}
|
|
32
|
+
export interface TurboInitiateArNSPurchaseParams extends AoTokenCostParams {
|
|
33
|
+
processId?: TransactionId;
|
|
34
|
+
paidBy?: string | string[];
|
|
35
|
+
}
|
|
32
36
|
export interface ArNSAuthenticatedPaymentProvider extends ArNSPaymentProvider {
|
|
33
|
-
initiateArNSPurchase(params:
|
|
34
|
-
processId?: TransactionId;
|
|
35
|
-
}): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
37
|
+
initiateArNSPurchase(params: TurboInitiateArNSPurchaseParams): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
36
38
|
}
|
|
37
39
|
export declare class TurboArNSPaymentFactory {
|
|
38
40
|
static init(): TurboArNSPaymentProviderUnauthenticated;
|
|
@@ -55,8 +57,6 @@ export declare class TurboArNSPaymentProviderUnauthenticated implements ArNSPaym
|
|
|
55
57
|
export declare class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated implements ArNSAuthenticatedPaymentProvider {
|
|
56
58
|
private readonly signer;
|
|
57
59
|
constructor({ signer, ...restConfig }: TurboAuthenticatedConfig);
|
|
58
|
-
initiateArNSPurchase({ intent, name, quantity, type, processId, years, }:
|
|
59
|
-
processId?: TransactionId;
|
|
60
|
-
}): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
60
|
+
initiateArNSPurchase({ intent, name, quantity, type, processId, years, paidBy, }: TurboInitiateArNSPurchaseParams): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
|
|
61
61
|
}
|
|
62
62
|
export declare function isTurboArNSSigner(signer: unknown): signer is TurboArNSSigner;
|
package/lib/types/types/io.d.ts
CHANGED
|
@@ -346,6 +346,7 @@ export type AoGetVaultParams = {
|
|
|
346
346
|
};
|
|
347
347
|
export type AoArNSPurchaseParams = AoArNSNameParams & {
|
|
348
348
|
fundFrom?: FundFrom;
|
|
349
|
+
paidBy?: WalletAddress | WalletAddress[];
|
|
349
350
|
};
|
|
350
351
|
export type AoBuyRecordParams = AoArNSPurchaseParams & {
|
|
351
352
|
years?: number;
|
package/lib/types/utils/url.d.ts
CHANGED
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const urlWithSearchParams: ({ baseUrl, params, }: {
|
|
17
17
|
baseUrl: string;
|
|
18
|
-
params: Record<string, string | number | boolean | null | undefined>;
|
|
18
|
+
params: Record<string, string | number | boolean | string[] | null | undefined>;
|
|
19
19
|
}) => string;
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0-alpha.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"test:cjs": "yarn build:cjs && yarn link && cd ./tests/e2e/cjs && yarn && yarn test",
|
|
73
73
|
"test:esm": "yarn build:esm && yarn link && cd ./tests/e2e/esm && yarn && yarn test",
|
|
74
74
|
"test:web": "yarn build:esm && yarn link && cd ./tests/e2e/web && yarn && yarn test",
|
|
75
|
-
"test:unit": "node --import=./register.mjs --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
|
|
75
|
+
"test:unit": "c8 node --import=./register.mjs --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
|
|
76
76
|
"test:link": "yarn build && yarn link",
|
|
77
77
|
"test:e2e": "yarn test:cjs && yarn test:esm && yarn test:web",
|
|
78
78
|
"test:integration": "yarn build:esm && yarn link && cd ./tests/integration && yarn && yarn test",
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
100
100
|
"@typescript-eslint/parser": "^6.4.0",
|
|
101
101
|
"arconnect": "^1.0.3",
|
|
102
|
+
"c8": "^10.1.3",
|
|
102
103
|
"dotenv": "^16.4.5",
|
|
103
104
|
"dotenv-cli": "^7.4.2",
|
|
104
105
|
"esbuild": "^0.25.2",
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_assert_1 = require("node:assert");
|
|
4
|
-
const node_test_1 = require("node:test");
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const ant_js_1 = require("./ant.js");
|
|
7
|
-
const stub_arweave_address = 'valid-address'.padEnd(43, '1');
|
|
8
|
-
const stub_eth_address = '0x8B5f221c8837d862b818799e6b19cc23CE23B0E5';
|
|
9
|
-
(0, node_test_1.describe)('ANT Schemas', () => {
|
|
10
|
-
(0, node_test_1.it)('should validate AntStateSchema', () => {
|
|
11
|
-
const validState = {
|
|
12
|
-
Name: 'TestToken',
|
|
13
|
-
Ticker: 'TST',
|
|
14
|
-
Description: 'Test description',
|
|
15
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
16
|
-
Denomination: 0,
|
|
17
|
-
Owner: stub_arweave_address,
|
|
18
|
-
Controllers: [stub_arweave_address],
|
|
19
|
-
Records: {
|
|
20
|
-
record1: {
|
|
21
|
-
transactionId: stub_arweave_address,
|
|
22
|
-
ttlSeconds: 3600,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
Balances: {
|
|
26
|
-
[stub_arweave_address]: 1,
|
|
27
|
-
},
|
|
28
|
-
Logo: stub_arweave_address,
|
|
29
|
-
TotalSupply: 1,
|
|
30
|
-
Initialized: true,
|
|
31
|
-
};
|
|
32
|
-
const invalidState = {
|
|
33
|
-
Name: 'TestToken',
|
|
34
|
-
Ticker: 'TST',
|
|
35
|
-
Description: 'Test description',
|
|
36
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
37
|
-
Denomination: 0,
|
|
38
|
-
Owner: stub_arweave_address,
|
|
39
|
-
Controllers: [stub_arweave_address],
|
|
40
|
-
Records: {
|
|
41
|
-
record1: {
|
|
42
|
-
transactionId: 'invalid-id',
|
|
43
|
-
ttlSeconds: '3600',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
Balances: {
|
|
47
|
-
[stub_arweave_address]: 1,
|
|
48
|
-
},
|
|
49
|
-
Logo: stub_arweave_address,
|
|
50
|
-
TotalSupply: -1,
|
|
51
|
-
Initialized: true,
|
|
52
|
-
};
|
|
53
|
-
node_assert_1.strict.doesNotThrow(() => ant_js_1.AntStateSchema.parse(validState));
|
|
54
|
-
node_assert_1.strict.throws(() => ant_js_1.AntStateSchema.parse(invalidState), zod_1.z.ZodError);
|
|
55
|
-
});
|
|
56
|
-
(0, node_test_1.it)('should validate AntStateSchema with ETH address', () => {
|
|
57
|
-
const validState = {
|
|
58
|
-
Name: 'TestToken',
|
|
59
|
-
Ticker: 'TST',
|
|
60
|
-
Description: 'Test description',
|
|
61
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
62
|
-
Denomination: 0,
|
|
63
|
-
Owner: stub_eth_address,
|
|
64
|
-
Controllers: [stub_eth_address],
|
|
65
|
-
Records: {
|
|
66
|
-
record1: {
|
|
67
|
-
transactionId: stub_arweave_address,
|
|
68
|
-
ttlSeconds: 3600,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
Balances: {
|
|
72
|
-
[stub_eth_address]: 1,
|
|
73
|
-
},
|
|
74
|
-
Logo: stub_arweave_address,
|
|
75
|
-
TotalSupply: 1,
|
|
76
|
-
Initialized: true,
|
|
77
|
-
};
|
|
78
|
-
node_assert_1.strict.doesNotThrow(() => ant_js_1.AntStateSchema.parse(validState));
|
|
79
|
-
});
|
|
80
|
-
(0, node_test_1.it)('should validate AntInfoSchema', () => {
|
|
81
|
-
const validInfo = {
|
|
82
|
-
Name: 'TestToken',
|
|
83
|
-
Owner: stub_arweave_address,
|
|
84
|
-
Ticker: 'TST',
|
|
85
|
-
Description: 'Test description',
|
|
86
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
87
|
-
['Total-Supply']: '1',
|
|
88
|
-
Logo: stub_arweave_address,
|
|
89
|
-
Denomination: '0',
|
|
90
|
-
Handlers: ant_js_1.AntHandlerNames,
|
|
91
|
-
};
|
|
92
|
-
const invalidInfo = {
|
|
93
|
-
Name: 'TestToken',
|
|
94
|
-
Owner: stub_arweave_address,
|
|
95
|
-
Ticker: 'TST',
|
|
96
|
-
['Total-Supply']: 1000,
|
|
97
|
-
Logo: stub_arweave_address,
|
|
98
|
-
Denomination: '1',
|
|
99
|
-
Handlers: ant_js_1.AntHandlerNames,
|
|
100
|
-
};
|
|
101
|
-
node_assert_1.strict.doesNotThrow(() => ant_js_1.AntInfoSchema.parse(validInfo));
|
|
102
|
-
node_assert_1.strict.throws(() => ant_js_1.AntInfoSchema.parse(invalidInfo), zod_1.z.ZodError);
|
|
103
|
-
});
|
|
104
|
-
(0, node_test_1.it)('should validate isAoANTState', () => {
|
|
105
|
-
const validState = {
|
|
106
|
-
Name: 'TestToken',
|
|
107
|
-
Ticker: 'TST',
|
|
108
|
-
Description: 'Test description',
|
|
109
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
110
|
-
Denomination: 0,
|
|
111
|
-
Owner: stub_arweave_address,
|
|
112
|
-
Controllers: [stub_arweave_address],
|
|
113
|
-
Records: {
|
|
114
|
-
record1: {
|
|
115
|
-
transactionId: stub_arweave_address,
|
|
116
|
-
ttlSeconds: 3600,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
Balances: {
|
|
120
|
-
[stub_arweave_address]: 1,
|
|
121
|
-
},
|
|
122
|
-
Logo: stub_arweave_address,
|
|
123
|
-
TotalSupply: 0,
|
|
124
|
-
Initialized: true,
|
|
125
|
-
};
|
|
126
|
-
const invalidState = {
|
|
127
|
-
Name: 'TestToken',
|
|
128
|
-
Ticker: 'TST',
|
|
129
|
-
Description: 'Test description',
|
|
130
|
-
Keywords: ['keyword1', 'keyword2', 'keyword3'],
|
|
131
|
-
Denomination: 0,
|
|
132
|
-
Owner: stub_arweave_address,
|
|
133
|
-
Controllers: [stub_arweave_address],
|
|
134
|
-
Records: {
|
|
135
|
-
record1: {
|
|
136
|
-
transactionId: 'invalid-id',
|
|
137
|
-
ttlSeconds: '3600',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
Balances: {
|
|
141
|
-
[stub_arweave_address]: 1,
|
|
142
|
-
},
|
|
143
|
-
Logo: stub_arweave_address,
|
|
144
|
-
TotalSupply: -1,
|
|
145
|
-
Initialized: true,
|
|
146
|
-
};
|
|
147
|
-
node_assert_1.strict.strictEqual((0, ant_js_1.isAoANTState)(validState), true);
|
|
148
|
-
node_assert_1.strict.strictEqual((0, ant_js_1.isAoANTState)(invalidState), false);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_assert_1 = require("node:assert");
|
|
4
|
-
const node_test_1 = require("node:test");
|
|
5
|
-
const token_js_1 = require("./token.js");
|
|
6
|
-
(0, node_test_1.describe)('ARIOToken', () => {
|
|
7
|
-
(0, node_test_1.it)('should throw an error on invalid input', () => {
|
|
8
|
-
node_assert_1.strict.throws(() => new token_js_1.ARIOToken(-1));
|
|
9
|
-
});
|
|
10
|
-
(0, node_test_1.it)('should round at 6 decimal places', () => {
|
|
11
|
-
const token = new token_js_1.ARIOToken(1.123456789);
|
|
12
|
-
node_assert_1.strict.strictEqual(token.valueOf(), 1.123457);
|
|
13
|
-
});
|
|
14
|
-
(0, node_test_1.it)('should convert to mARIOToken', () => {
|
|
15
|
-
const token = new token_js_1.ARIOToken(1);
|
|
16
|
-
const mToken = token.toMARIO();
|
|
17
|
-
node_assert_1.strict.strictEqual(mToken.valueOf(), 1000000);
|
|
18
|
-
});
|
|
19
|
-
(0, node_test_1.it)('should print as a string', () => {
|
|
20
|
-
const token = new token_js_1.ARIOToken(1);
|
|
21
|
-
node_assert_1.strict.strictEqual(`${token}`, '1');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
(0, node_test_1.describe)('mARIOToken', () => {
|
|
25
|
-
(0, node_test_1.it)('should multiply by a number', () => {
|
|
26
|
-
const token = new token_js_1.mARIOToken(1);
|
|
27
|
-
const result = token.multiply(2);
|
|
28
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 2);
|
|
29
|
-
});
|
|
30
|
-
(0, node_test_1.it)('should multiply by another mARIOToken', () => {
|
|
31
|
-
const token = new token_js_1.mARIOToken(1);
|
|
32
|
-
const result = token.multiply(new token_js_1.mARIOToken(2));
|
|
33
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 2);
|
|
34
|
-
});
|
|
35
|
-
(0, node_test_1.it)('should divide by a number', () => {
|
|
36
|
-
const token = new token_js_1.mARIOToken(2);
|
|
37
|
-
const result = token.divide(2);
|
|
38
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
39
|
-
});
|
|
40
|
-
(0, node_test_1.it)('should divide by another mARIOToken', () => {
|
|
41
|
-
const token = new token_js_1.mARIOToken(2);
|
|
42
|
-
const result = token.divide(new token_js_1.mARIOToken(2));
|
|
43
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
44
|
-
});
|
|
45
|
-
(0, node_test_1.it)('should throw an error on division by zero', () => {
|
|
46
|
-
const token = new token_js_1.mARIOToken(2);
|
|
47
|
-
node_assert_1.strict.throws(() => token.divide(0));
|
|
48
|
-
});
|
|
49
|
-
(0, node_test_1.it)('should round down on multiplication of a number', () => {
|
|
50
|
-
const token = new token_js_1.mARIOToken(1);
|
|
51
|
-
const result = token.multiply(1.5);
|
|
52
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
53
|
-
});
|
|
54
|
-
(0, node_test_1.it)('should round down on division with a number', () => {
|
|
55
|
-
const token = new token_js_1.mARIOToken(2);
|
|
56
|
-
const result = token.divide(3);
|
|
57
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 0);
|
|
58
|
-
});
|
|
59
|
-
(0, node_test_1.it)('should round down on division with another mARIOToken', () => {
|
|
60
|
-
const token = new token_js_1.mARIOToken(2);
|
|
61
|
-
const result = token.divide(new token_js_1.mARIOToken(3));
|
|
62
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 0);
|
|
63
|
-
});
|
|
64
|
-
(0, node_test_1.it)('should add', () => {
|
|
65
|
-
const token = new token_js_1.mARIOToken(1);
|
|
66
|
-
const result = token.plus(new token_js_1.mARIOToken(1));
|
|
67
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 2);
|
|
68
|
-
});
|
|
69
|
-
(0, node_test_1.it)('should subtract', () => {
|
|
70
|
-
const token = new token_js_1.mARIOToken(2);
|
|
71
|
-
const result = token.minus(new token_js_1.mARIOToken(1));
|
|
72
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
73
|
-
});
|
|
74
|
-
(0, node_test_1.it)('should convert to ARIO', () => {
|
|
75
|
-
const token = new token_js_1.mARIOToken(1000000);
|
|
76
|
-
const result = token.toARIO();
|
|
77
|
-
node_assert_1.strict.strictEqual(result.valueOf(), 1);
|
|
78
|
-
});
|
|
79
|
-
(0, node_test_1.it)('should print as a string', () => {
|
|
80
|
-
const token = new token_js_1.mARIOToken(1);
|
|
81
|
-
node_assert_1.strict.strictEqual(`${token}`, '1');
|
|
82
|
-
});
|
|
83
|
-
});
|