@ar.io/sdk 3.12.0-alpha.1 → 3.12.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.12.0-alpha.1",
3
+ "version": "3.12.0",
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
- });
@@ -1,111 +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 ant_js_1 = require("./ant.js");
6
- (0, node_test_1.describe)('sortANTRecordsByPriority', () => {
7
- (0, node_test_1.it)('should sort records by priority and then lexicographically', () => {
8
- const records = {
9
- undername01: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, // same priority, lexicographic sorting applied to the name
10
- undername1: { priority: 1, transactionId: 'test', ttlSeconds: 1 },
11
- undername11: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, // same priority, lexicographic sorting applied to the name
12
- undername2: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
13
- undername3: { priority: 3, transactionId: 'test', ttlSeconds: 1 }, // colliding priorities default to lexicographic sorting
14
- undername4: { priority: 3, transactionId: 'test', ttlSeconds: 1 },
15
- undername5: { priority: 100, transactionId: 'test', ttlSeconds: 1 }, // priority does not represent the index or position of the record, just the order of resolution relative to other records
16
- noPriority: { transactionId: 'test', ttlSeconds: 1 },
17
- noPriority01: { transactionId: 'test', ttlSeconds: 1 },
18
- noPriority1: { transactionId: 'test', ttlSeconds: 1 },
19
- noPriority11: { transactionId: 'test', ttlSeconds: 1 },
20
- '@': { transactionId: 'test', ttlSeconds: 1 }, // always first, even if no priority
21
- };
22
- const sorted = (0, ant_js_1.sortANTRecords)(records);
23
- node_assert_1.strict.deepStrictEqual(sorted, {
24
- '@': { transactionId: 'test', ttlSeconds: 1, index: 0 }, // always first, even if no priority
25
- undername01: {
26
- priority: 1,
27
- transactionId: 'test',
28
- ttlSeconds: 1,
29
- index: 1,
30
- },
31
- undername1: {
32
- priority: 1,
33
- transactionId: 'test',
34
- ttlSeconds: 1,
35
- index: 2,
36
- },
37
- undername11: {
38
- priority: 1,
39
- transactionId: 'test',
40
- ttlSeconds: 1,
41
- index: 3,
42
- },
43
- undername2: {
44
- priority: 2,
45
- transactionId: 'test',
46
- ttlSeconds: 1,
47
- index: 4,
48
- },
49
- undername3: {
50
- priority: 3,
51
- transactionId: 'test',
52
- ttlSeconds: 1,
53
- index: 5,
54
- },
55
- undername4: {
56
- priority: 3,
57
- transactionId: 'test',
58
- ttlSeconds: 1,
59
- index: 6,
60
- },
61
- undername5: {
62
- priority: 100,
63
- transactionId: 'test',
64
- ttlSeconds: 1,
65
- index: 7,
66
- },
67
- noPriority: { transactionId: 'test', ttlSeconds: 1, index: 8 },
68
- noPriority01: { transactionId: 'test', ttlSeconds: 1, index: 9 },
69
- noPriority1: { transactionId: 'test', ttlSeconds: 1, index: 10 },
70
- noPriority11: { transactionId: 'test', ttlSeconds: 1, index: 11 },
71
- });
72
- });
73
- (0, node_test_1.it)('should always return @ as the first, regardless of priority', () => {
74
- const scenarios = [
75
- {
76
- records: {
77
- '@': { priority: 5, transactionId: 'test', ttlSeconds: 1 }, // priorities set on '@' are ignored, they are always first
78
- undername1: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
79
- },
80
- expected: {
81
- '@': { priority: 5, transactionId: 'test', ttlSeconds: 1, index: 0 },
82
- undername1: {
83
- priority: 2,
84
- transactionId: 'test',
85
- ttlSeconds: 1,
86
- index: 1,
87
- },
88
- },
89
- },
90
- {
91
- records: {
92
- '@': { transactionId: 'test', ttlSeconds: 1 }, // priority 0 is missing, but '@' is always first
93
- undername1: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
94
- },
95
- expected: {
96
- '@': { transactionId: 'test', ttlSeconds: 1, index: 0 },
97
- undername1: {
98
- priority: 2,
99
- transactionId: 'test',
100
- ttlSeconds: 1,
101
- index: 1,
102
- },
103
- },
104
- },
105
- ];
106
- for (const scenario of scenarios) {
107
- const sorted = (0, ant_js_1.sortANTRecords)(scenario.records);
108
- node_assert_1.strict.deepStrictEqual(sorted, scenario.expected);
109
- }
110
- });
111
- });
@@ -1,72 +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 base64_js_1 = require("./base64.js");
6
- (0, node_test_1.describe)('b64utils', () => {
7
- (0, node_test_1.it)('should convert various strings to base64url and back', () => {
8
- const testStrings = [
9
- 'Hello, World!',
10
- 'Test123!@#',
11
- 'Base64URLEncoding',
12
- 'Special_Chars+/',
13
- '',
14
- 'A',
15
- '1234567890',
16
- ];
17
- for (const str of testStrings) {
18
- const encoded = (0, base64_js_1.toB64Url)(Buffer.from(str));
19
- const decoded = (0, base64_js_1.fromB64Url)(encoded);
20
- node_assert_1.strict.deepStrictEqual(decoded, Buffer.from(str), `Failed for string: ${str}`);
21
- }
22
- });
23
- (0, node_test_1.it)('should convert various buffers to base64url and back', () => {
24
- const testBuffers = [
25
- Buffer.from('Hello, World!'),
26
- Buffer.from([0, 1, 2, 3, 4, 5]),
27
- Buffer.from('Test123!@#'),
28
- Buffer.from('Base64URLEncoding'),
29
- Buffer.from('Special_Chars+/'),
30
- Buffer.alloc(0),
31
- Buffer.from('A'),
32
- Buffer.from('1234567890'),
33
- ];
34
- for (const buf of testBuffers) {
35
- const encoded = (0, base64_js_1.toB64Url)(buf);
36
- const decoded = (0, base64_js_1.fromB64Url)(encoded);
37
- node_assert_1.strict.deepStrictEqual(decoded, buf, `Failed for buffer: ${buf.toString()}`);
38
- }
39
- });
40
- (0, node_test_1.it)('should handle edge cases for base64url conversion', () => {
41
- const edgeCases = [
42
- '',
43
- 'A',
44
- 'AA',
45
- 'AAA',
46
- '====',
47
- '===',
48
- '==',
49
- '=',
50
- 'A===',
51
- 'AA==',
52
- 'AAA=',
53
- ];
54
- for (const testCase of edgeCases) {
55
- const encoded = (0, base64_js_1.toB64Url)(Buffer.from(testCase));
56
- const decoded = Buffer.from((0, base64_js_1.fromB64Url)(encoded)).toString();
57
- node_assert_1.strict.strictEqual(decoded, testCase, `Failed for edge case: ${testCase}`);
58
- }
59
- });
60
- (0, node_test_1.it)('should generate random text', () => {
61
- const randomText = (0, base64_js_1.getRandomText)();
62
- const randomText2 = (0, base64_js_1.getRandomText)();
63
- node_assert_1.strict.strictEqual(randomText.length, 32);
64
- node_assert_1.strict.strictEqual(randomText2.length, 32);
65
- node_assert_1.strict.notStrictEqual(randomText, randomText2);
66
- const smallRandomText = (0, base64_js_1.getRandomText)(16);
67
- const smallRandomText2 = (0, base64_js_1.getRandomText)(16);
68
- node_assert_1.strict.strictEqual(smallRandomText.length, 16);
69
- node_assert_1.strict.strictEqual(smallRandomText2.length, 16);
70
- node_assert_1.strict.notStrictEqual(smallRandomText, smallRandomText2);
71
- });
72
- });
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_test_1 = require("node:test");
8
- const url_js_1 = require("./url.js");
9
- (0, node_test_1.test)('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
10
- const result = (0, url_js_1.urlWithSearchParams)({
11
- baseUrl: 'https://example.com',
12
- params: {
13
- number: 1,
14
- string: 'string',
15
- boolean: true,
16
- empty: '',
17
- zero: 0,
18
- false: false,
19
- null: null,
20
- undef: undefined,
21
- },
22
- });
23
- node_assert_1.default.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
24
- });
@@ -1,194 +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 ao_js_1 = require("./ao.js");
6
- const arweave_js_1 = require("./arweave.js");
7
- (0, node_test_1.describe)('pruneTags', () => {
8
- (0, node_test_1.it)('should remove tags with undefined values', () => {
9
- const tags = [
10
- { name: 'Tag1', value: 'value1' },
11
- { name: 'Tag2', value: undefined },
12
- { name: 'Tag3', value: 'value3' },
13
- { name: 'Tag4', value: undefined },
14
- ];
15
- const prunedTags = (0, arweave_js_1.pruneTags)(tags);
16
- node_assert_1.strict.deepEqual(prunedTags, [
17
- { name: 'Tag1', value: 'value1' },
18
- { name: 'Tag3', value: 'value3' },
19
- ]);
20
- });
21
- (0, node_test_1.it)('should return empty array when all tags have undefined values', () => {
22
- const tags = [
23
- { name: 'Tag1', value: undefined },
24
- { name: 'Tag2', value: undefined },
25
- ];
26
- const prunedTags = (0, arweave_js_1.pruneTags)(tags);
27
- node_assert_1.strict.deepEqual(prunedTags, []);
28
- });
29
- (0, node_test_1.it)('should return same array when no tags have undefined values', () => {
30
- const tags = [
31
- { name: 'Tag1', value: 'value1' },
32
- { name: 'Tag2', value: 'value2' },
33
- ];
34
- const prunedTags = (0, arweave_js_1.pruneTags)(tags);
35
- node_assert_1.strict.deepEqual(prunedTags, tags);
36
- });
37
- (0, node_test_1.it)('should return empty array with no tags', () => {
38
- const tags = [];
39
- const prunedTags = (0, arweave_js_1.pruneTags)(tags);
40
- node_assert_1.strict.deepEqual(prunedTags, []);
41
- });
42
- });
43
- (0, node_test_1.describe)('errorMessageFromOutput', () => {
44
- (0, node_test_1.it)('should return error message from Error field', () => {
45
- const output = {
46
- Error: 'Error message',
47
- };
48
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
49
- node_assert_1.strict.equal(errorMessage, 'Error message');
50
- });
51
- (0, node_test_1.it)('should return error message from Error tag', () => {
52
- const output = {
53
- Messages: [
54
- {
55
- Tags: [{ name: 'Error', value: 'Error message' }],
56
- },
57
- ],
58
- };
59
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
60
- node_assert_1.strict.equal(errorMessage, 'Error message');
61
- });
62
- (0, node_test_1.it)('should return error message from Error tag if Error field is undefined', () => {
63
- const output = {
64
- Messages: [
65
- {
66
- Tags: [{ name: 'Error', value: 'Error message' }],
67
- },
68
- ],
69
- };
70
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
71
- node_assert_1.strict.equal(errorMessage, 'Error message');
72
- });
73
- (0, node_test_1.it)('should return undefined if no error message is present', () => {
74
- const output = {
75
- Messages: [
76
- {
77
- Tags: [{ name: 'Tag1', value: 'value1' }],
78
- },
79
- ],
80
- };
81
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
82
- node_assert_1.strict.equal(errorMessage, undefined);
83
- });
84
- (0, node_test_1.it)('should return error message with line number', () => {
85
- const output = {
86
- Error: '[string "aos"]:123: Error message',
87
- };
88
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
89
- node_assert_1.strict.equal(errorMessage, 'Error message (line 123)');
90
- });
91
- (0, node_test_1.it)('should return error message with line number and remove unicode', () => {
92
- const output = {
93
- Error: '[string "aos"]:123: Error message\u001b[0m',
94
- };
95
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
96
- node_assert_1.strict.equal(errorMessage, 'Error message (line 123)');
97
- });
98
- const knownErrorMessages = '\u001b[31mError\u001b[90m handling message with Action = Register\u001b[0m\n\u001b[32m[string ".handlers"]:723: [string "aos"]:128: Already registered\u001b[0m\n\n\u001b[90mstack traceback:\n\t[string ".process"]:871: in function \'.process.handle\'\u001b[0m\n\n\u001b[31merror:\n\u001b[0m[string ".handlers"]:723: [string "aos"]:128: Already registered';
99
- (0, node_test_1.it)('should display a clean error for a known error message', () => {
100
- const output = {
101
- Error: knownErrorMessages,
102
- };
103
- const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
104
- node_assert_1.strict.equal(errorMessage, 'Already registered (line 128)');
105
- });
106
- });
107
- (0, node_test_1.describe)('sortAndPaginateEpochDataIntoEligibleDistributions', () => {
108
- const mockEpochData = {
109
- distributions: {
110
- distributedTimestamp: 1234567890,
111
- rewards: {
112
- eligible: {
113
- gateway1: {
114
- operatorReward: 50,
115
- delegateRewards: {
116
- delegate1: 20,
117
- delegate2: 30,
118
- },
119
- },
120
- gateway2: {
121
- operatorReward: 70,
122
- delegateRewards: {
123
- delegate3: 40,
124
- },
125
- },
126
- },
127
- },
128
- },
129
- };
130
- (0, node_test_1.it)('sorts rewards in descending order by eligibleReward', () => {
131
- const result = (0, arweave_js_1.sortAndPaginateEpochDataIntoEligibleDistributions)(mockEpochData);
132
- node_assert_1.strict.deepEqual(result.items, [
133
- {
134
- type: 'operatorReward',
135
- recipient: 'gateway2',
136
- eligibleReward: 70,
137
- cursorId: 'gateway2_gateway2',
138
- gatewayAddress: 'gateway2',
139
- },
140
- {
141
- type: 'operatorReward',
142
- recipient: 'gateway1',
143
- eligibleReward: 50,
144
- cursorId: 'gateway1_gateway1',
145
- gatewayAddress: 'gateway1',
146
- },
147
- {
148
- type: 'delegateReward',
149
- recipient: 'delegate3',
150
- eligibleReward: 40,
151
- cursorId: 'gateway2_delegate3',
152
- gatewayAddress: 'gateway2',
153
- },
154
- {
155
- type: 'delegateReward',
156
- recipient: 'delegate2',
157
- eligibleReward: 30,
158
- cursorId: 'gateway1_delegate2',
159
- gatewayAddress: 'gateway1',
160
- },
161
- {
162
- type: 'delegateReward',
163
- recipient: 'delegate1',
164
- eligibleReward: 20,
165
- cursorId: 'gateway1_delegate1',
166
- gatewayAddress: 'gateway1',
167
- },
168
- ]);
169
- });
170
- (0, node_test_1.it)('supports sorting in ascending order', () => {
171
- const result = (0, arweave_js_1.sortAndPaginateEpochDataIntoEligibleDistributions)(mockEpochData, {
172
- sortOrder: 'asc',
173
- });
174
- node_assert_1.strict.equal(result.items[0].eligibleReward, 20);
175
- node_assert_1.strict.equal(result.items[result.items.length - 1].eligibleReward, 70);
176
- });
177
- (0, node_test_1.it)('paginates results correctly', () => {
178
- const result = (0, arweave_js_1.sortAndPaginateEpochDataIntoEligibleDistributions)(mockEpochData, {
179
- limit: 2,
180
- });
181
- node_assert_1.strict.equal(result.items.length, 2);
182
- node_assert_1.strict.equal(result.hasMore, true);
183
- node_assert_1.strict.equal(result.nextCursor, 'gateway2_delegate3');
184
- });
185
- (0, node_test_1.it)('resumes pagination from cursor', () => {
186
- const firstPage = (0, arweave_js_1.sortAndPaginateEpochDataIntoEligibleDistributions)(mockEpochData, { limit: 2 });
187
- const secondPage = (0, arweave_js_1.sortAndPaginateEpochDataIntoEligibleDistributions)(mockEpochData, {
188
- limit: 2,
189
- cursor: firstPage.nextCursor,
190
- });
191
- node_assert_1.strict.equal(secondPage.items.length, 2);
192
- node_assert_1.strict.equal(secondPage.items[0].cursorId, 'gateway1_delegate2');
193
- });
194
- });