bitbadgesjs-sdk 0.31.0 → 0.31.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/dist/cjs/api-indexer/BitBadgesCollection.d.ts +1 -0
- package/dist/cjs/api-indexer/BitBadgesCollection.d.ts.map +1 -1
- package/dist/cjs/api-indexer/BitBadgesCollection.js +4 -1
- package/dist/cjs/api-indexer/BitBadgesCollection.js.map +1 -1
- package/dist/cjs/core/approval-utils.spec.d.ts +2 -0
- package/dist/cjs/core/approval-utils.spec.d.ts.map +1 -0
- package/dist/cjs/core/approval-utils.spec.js +240 -0
- package/dist/cjs/core/approval-utils.spec.js.map +1 -0
- package/dist/cjs/core/approvals.spec.js +96 -0
- package/dist/cjs/core/approvals.spec.js.map +1 -1
- package/dist/cjs/core/bids.spec.d.ts +2 -0
- package/dist/cjs/core/bids.spec.d.ts.map +1 -0
- package/dist/cjs/core/bids.spec.js +201 -0
- package/dist/cjs/core/bids.spec.js.map +1 -0
- package/dist/cjs/core/blockin.spec.d.ts +2 -0
- package/dist/cjs/core/blockin.spec.d.ts.map +1 -0
- package/dist/cjs/core/blockin.spec.js +163 -0
- package/dist/cjs/core/blockin.spec.js.map +1 -0
- package/dist/cjs/core/coin.spec.d.ts +2 -0
- package/dist/cjs/core/coin.spec.d.ts.map +1 -0
- package/dist/cjs/core/coin.spec.js +80 -0
- package/dist/cjs/core/coin.spec.js.map +1 -0
- package/dist/cjs/core/cosmos-wrappers.spec.d.ts +2 -0
- package/dist/cjs/core/cosmos-wrappers.spec.d.ts.map +1 -0
- package/dist/cjs/core/cosmos-wrappers.spec.js +623 -0
- package/dist/cjs/core/cosmos-wrappers.spec.js.map +1 -0
- package/dist/cjs/core/managersplitter.spec.d.ts +2 -0
- package/dist/cjs/core/managersplitter.spec.d.ts.map +1 -0
- package/dist/cjs/core/managersplitter.spec.js +170 -0
- package/dist/cjs/core/managersplitter.spec.js.map +1 -0
- package/dist/cjs/core/overlaps.spec.js +201 -0
- package/dist/cjs/core/overlaps.spec.js.map +1 -1
- package/dist/cjs/core/permission-utils.spec.d.ts +2 -0
- package/dist/cjs/core/permission-utils.spec.d.ts.map +1 -0
- package/dist/cjs/core/permission-utils.spec.js +192 -0
- package/dist/cjs/core/permission-utils.spec.js.map +1 -0
- package/dist/cjs/core/permissions.js +4 -4
- package/dist/cjs/core/permissions.js.map +1 -1
- package/dist/cjs/core/permissions.spec.d.ts +2 -0
- package/dist/cjs/core/permissions.spec.d.ts.map +1 -0
- package/dist/cjs/core/permissions.spec.js +2051 -0
- package/dist/cjs/core/permissions.spec.js.map +1 -0
- package/dist/cjs/core/transfers.d.ts.map +1 -1
- package/dist/cjs/core/transfers.js +11 -7
- package/dist/cjs/core/transfers.js.map +1 -1
- package/dist/cjs/core/transfers.spec.js +647 -0
- package/dist/cjs/core/transfers.spec.js.map +1 -1
- package/dist/cjs/core/userBalances.spec.d.ts +2 -0
- package/dist/cjs/core/userBalances.spec.d.ts.map +1 -0
- package/dist/cjs/core/userBalances.spec.js +184 -0
- package/dist/cjs/core/userBalances.spec.js.map +1 -0
- package/dist/cjs/core/validate-utils.spec.d.ts +2 -0
- package/dist/cjs/core/validate-utils.spec.d.ts.map +1 -0
- package/dist/cjs/core/validate-utils.spec.js +202 -0
- package/dist/cjs/core/validate-utils.spec.js.map +1 -0
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/api-indexer/BitBadgesCollection.d.ts +1 -0
- package/dist/esm/api-indexer/BitBadgesCollection.d.ts.map +1 -1
- package/dist/esm/api-indexer/BitBadgesCollection.js +4 -1
- package/dist/esm/api-indexer/BitBadgesCollection.js.map +1 -1
- package/dist/esm/core/approval-utils.spec.d.ts +2 -0
- package/dist/esm/core/approval-utils.spec.d.ts.map +1 -0
- package/dist/esm/core/approval-utils.spec.js +238 -0
- package/dist/esm/core/approval-utils.spec.js.map +1 -0
- package/dist/esm/core/approvals.spec.js +97 -1
- package/dist/esm/core/approvals.spec.js.map +1 -1
- package/dist/esm/core/bids.spec.d.ts +2 -0
- package/dist/esm/core/bids.spec.d.ts.map +1 -0
- package/dist/esm/core/bids.spec.js +199 -0
- package/dist/esm/core/bids.spec.js.map +1 -0
- package/dist/esm/core/blockin.spec.d.ts +2 -0
- package/dist/esm/core/blockin.spec.d.ts.map +1 -0
- package/dist/esm/core/blockin.spec.js +161 -0
- package/dist/esm/core/blockin.spec.js.map +1 -0
- package/dist/esm/core/coin.spec.d.ts +2 -0
- package/dist/esm/core/coin.spec.d.ts.map +1 -0
- package/dist/esm/core/coin.spec.js +78 -0
- package/dist/esm/core/coin.spec.js.map +1 -0
- package/dist/esm/core/cosmos-wrappers.spec.d.ts +2 -0
- package/dist/esm/core/cosmos-wrappers.spec.d.ts.map +1 -0
- package/dist/esm/core/cosmos-wrappers.spec.js +621 -0
- package/dist/esm/core/cosmos-wrappers.spec.js.map +1 -0
- package/dist/esm/core/managersplitter.spec.d.ts +2 -0
- package/dist/esm/core/managersplitter.spec.d.ts.map +1 -0
- package/dist/esm/core/managersplitter.spec.js +168 -0
- package/dist/esm/core/managersplitter.spec.js.map +1 -0
- package/dist/esm/core/overlaps.spec.js +202 -1
- package/dist/esm/core/overlaps.spec.js.map +1 -1
- package/dist/esm/core/permission-utils.spec.d.ts +2 -0
- package/dist/esm/core/permission-utils.spec.d.ts.map +1 -0
- package/dist/esm/core/permission-utils.spec.js +190 -0
- package/dist/esm/core/permission-utils.spec.js.map +1 -0
- package/dist/esm/core/permissions.js +4 -4
- package/dist/esm/core/permissions.js.map +1 -1
- package/dist/esm/core/permissions.spec.d.ts +2 -0
- package/dist/esm/core/permissions.spec.d.ts.map +1 -0
- package/dist/esm/core/permissions.spec.js +2049 -0
- package/dist/esm/core/permissions.spec.js.map +1 -0
- package/dist/esm/core/transfers.d.ts.map +1 -1
- package/dist/esm/core/transfers.js +11 -7
- package/dist/esm/core/transfers.js.map +1 -1
- package/dist/esm/core/transfers.spec.js +648 -1
- package/dist/esm/core/transfers.spec.js.map +1 -1
- package/dist/esm/core/userBalances.spec.d.ts +2 -0
- package/dist/esm/core/userBalances.spec.d.ts.map +1 -0
- package/dist/esm/core/userBalances.spec.js +182 -0
- package/dist/esm/core/userBalances.spec.js.map +1 -0
- package/dist/esm/core/validate-utils.spec.d.ts +2 -0
- package/dist/esm/core/validate-utils.spec.d.ts.map +1 -0
- package/dist/esm/core/validate-utils.spec.js +200 -0
- package/dist/esm/core/validate-utils.spec.js.map +1 -0
- package/dist/esm/tsconfig-esm.build.tsbuildinfo +1 -1
- package/package.json +4 -5
|
@@ -0,0 +1,2051 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const addressLists_spec_js_1 = require("./addressLists.spec.js");
|
|
4
|
+
const addressLists_js_1 = require("./addressLists.js");
|
|
5
|
+
const permissions_js_1 = require("./permissions.js");
|
|
6
|
+
const uintRanges_js_1 = require("./uintRanges.js");
|
|
7
|
+
const string_numbers_js_1 = require("../common/string-numbers.js");
|
|
8
|
+
BigInt.prototype.toJSON = function () {
|
|
9
|
+
return this.toString();
|
|
10
|
+
};
|
|
11
|
+
const fullRange = () => uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 18446744073709551615n }]);
|
|
12
|
+
const allAddresses = () => new addressLists_js_1.AddressList({
|
|
13
|
+
listId: 'All',
|
|
14
|
+
addresses: [],
|
|
15
|
+
whitelist: false,
|
|
16
|
+
uri: '',
|
|
17
|
+
customData: '',
|
|
18
|
+
createdBy: ''
|
|
19
|
+
});
|
|
20
|
+
const whitelistOf = (addresses) => new addressLists_js_1.AddressList({
|
|
21
|
+
listId: 'custom',
|
|
22
|
+
addresses,
|
|
23
|
+
whitelist: true,
|
|
24
|
+
uri: '',
|
|
25
|
+
customData: '',
|
|
26
|
+
createdBy: ''
|
|
27
|
+
});
|
|
28
|
+
describe('ActionPermission', () => {
|
|
29
|
+
describe('construction', () => {
|
|
30
|
+
it('should create an instance with empty times', () => {
|
|
31
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
32
|
+
permanentlyPermittedTimes: [],
|
|
33
|
+
permanentlyForbiddenTimes: []
|
|
34
|
+
});
|
|
35
|
+
expect(perm).toBeTruthy();
|
|
36
|
+
expect(perm.permanentlyPermittedTimes.length).toBe(0);
|
|
37
|
+
expect(perm.permanentlyForbiddenTimes.length).toBe(0);
|
|
38
|
+
});
|
|
39
|
+
it('should create an instance with permitted times', () => {
|
|
40
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
41
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
42
|
+
permanentlyForbiddenTimes: []
|
|
43
|
+
});
|
|
44
|
+
expect(perm.permanentlyPermittedTimes.length).toBe(1);
|
|
45
|
+
expect(perm.permanentlyPermittedTimes[0].start).toBe(1n);
|
|
46
|
+
expect(perm.permanentlyPermittedTimes[0].end).toBe(100n);
|
|
47
|
+
});
|
|
48
|
+
it('should create an instance with forbidden times', () => {
|
|
49
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
50
|
+
permanentlyPermittedTimes: [],
|
|
51
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
52
|
+
});
|
|
53
|
+
expect(perm.permanentlyForbiddenTimes.length).toBe(1);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('castToUniversalPermission', () => {
|
|
57
|
+
it('should cast to universal permission with all uses flags false', () => {
|
|
58
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
59
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
60
|
+
permanentlyForbiddenTimes: []
|
|
61
|
+
});
|
|
62
|
+
const universal = perm.castToUniversalPermission();
|
|
63
|
+
expect(universal.usesTokenIds).toBe(false);
|
|
64
|
+
expect(universal.usesTimelineTimes).toBe(false);
|
|
65
|
+
expect(universal.usesTransferTimes).toBe(false);
|
|
66
|
+
expect(universal.usesToList).toBe(false);
|
|
67
|
+
expect(universal.usesFromList).toBe(false);
|
|
68
|
+
expect(universal.usesInitiatedByList).toBe(false);
|
|
69
|
+
expect(universal.usesOwnershipTimes).toBe(false);
|
|
70
|
+
expect(universal.usesApprovalIdList).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
it('should preserve permitted/forbidden times in cast', () => {
|
|
73
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
74
|
+
permanentlyPermittedTimes: [{ start: 10n, end: 20n }],
|
|
75
|
+
permanentlyForbiddenTimes: [{ start: 30n, end: 40n }]
|
|
76
|
+
});
|
|
77
|
+
const universal = perm.castToUniversalPermission();
|
|
78
|
+
expect(universal.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
79
|
+
expect(universal.permanentlyPermittedTimes[0].end).toBe(20n);
|
|
80
|
+
expect(universal.permanentlyForbiddenTimes[0].start).toBe(30n);
|
|
81
|
+
expect(universal.permanentlyForbiddenTimes[0].end).toBe(40n);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('validateUpdate', () => {
|
|
85
|
+
it('should allow identical permissions (no change)', () => {
|
|
86
|
+
const perms = [
|
|
87
|
+
new permissions_js_1.ActionPermission({
|
|
88
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
89
|
+
permanentlyForbiddenTimes: []
|
|
90
|
+
})
|
|
91
|
+
];
|
|
92
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(perms, perms);
|
|
93
|
+
expect(err).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
it('should allow adding new permissions that were not previously defined', () => {
|
|
96
|
+
const oldPerms = [];
|
|
97
|
+
const newPerms = [
|
|
98
|
+
new permissions_js_1.ActionPermission({
|
|
99
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
100
|
+
permanentlyForbiddenTimes: []
|
|
101
|
+
})
|
|
102
|
+
];
|
|
103
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
104
|
+
expect(err).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
it('should reject removing previously defined permissions', () => {
|
|
107
|
+
const oldPerms = [
|
|
108
|
+
new permissions_js_1.ActionPermission({
|
|
109
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
110
|
+
permanentlyForbiddenTimes: []
|
|
111
|
+
})
|
|
112
|
+
];
|
|
113
|
+
const newPerms = [];
|
|
114
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
115
|
+
expect(err).not.toBeNull();
|
|
116
|
+
});
|
|
117
|
+
it('should reject changing permanently permitted times to forbidden', () => {
|
|
118
|
+
const oldPerms = [
|
|
119
|
+
new permissions_js_1.ActionPermission({
|
|
120
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
121
|
+
permanentlyForbiddenTimes: []
|
|
122
|
+
})
|
|
123
|
+
];
|
|
124
|
+
const newPerms = [
|
|
125
|
+
new permissions_js_1.ActionPermission({
|
|
126
|
+
permanentlyPermittedTimes: [],
|
|
127
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
128
|
+
})
|
|
129
|
+
];
|
|
130
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
131
|
+
expect(err).not.toBeNull();
|
|
132
|
+
});
|
|
133
|
+
it('should reject changing permanently forbidden times to permitted', () => {
|
|
134
|
+
const oldPerms = [
|
|
135
|
+
new permissions_js_1.ActionPermission({
|
|
136
|
+
permanentlyPermittedTimes: [],
|
|
137
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
138
|
+
})
|
|
139
|
+
];
|
|
140
|
+
const newPerms = [
|
|
141
|
+
new permissions_js_1.ActionPermission({
|
|
142
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
143
|
+
permanentlyForbiddenTimes: []
|
|
144
|
+
})
|
|
145
|
+
];
|
|
146
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
147
|
+
expect(err).not.toBeNull();
|
|
148
|
+
});
|
|
149
|
+
it('should allow extending permitted times (adding more times)', () => {
|
|
150
|
+
const oldPerms = [
|
|
151
|
+
new permissions_js_1.ActionPermission({
|
|
152
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
153
|
+
permanentlyForbiddenTimes: []
|
|
154
|
+
})
|
|
155
|
+
];
|
|
156
|
+
const newPerms = [
|
|
157
|
+
new permissions_js_1.ActionPermission({
|
|
158
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
159
|
+
permanentlyForbiddenTimes: []
|
|
160
|
+
})
|
|
161
|
+
];
|
|
162
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
163
|
+
expect(err).toBeNull();
|
|
164
|
+
});
|
|
165
|
+
it('should allow extending forbidden times (adding more times)', () => {
|
|
166
|
+
const oldPerms = [
|
|
167
|
+
new permissions_js_1.ActionPermission({
|
|
168
|
+
permanentlyPermittedTimes: [],
|
|
169
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
170
|
+
})
|
|
171
|
+
];
|
|
172
|
+
const newPerms = [
|
|
173
|
+
new permissions_js_1.ActionPermission({
|
|
174
|
+
permanentlyPermittedTimes: [],
|
|
175
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
176
|
+
})
|
|
177
|
+
];
|
|
178
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
179
|
+
expect(err).toBeNull();
|
|
180
|
+
});
|
|
181
|
+
it('should reject shrinking permitted times', () => {
|
|
182
|
+
const oldPerms = [
|
|
183
|
+
new permissions_js_1.ActionPermission({
|
|
184
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
185
|
+
permanentlyForbiddenTimes: []
|
|
186
|
+
})
|
|
187
|
+
];
|
|
188
|
+
const newPerms = [
|
|
189
|
+
new permissions_js_1.ActionPermission({
|
|
190
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
191
|
+
permanentlyForbiddenTimes: []
|
|
192
|
+
})
|
|
193
|
+
];
|
|
194
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
195
|
+
expect(err).not.toBeNull();
|
|
196
|
+
});
|
|
197
|
+
it('should reject shrinking forbidden times', () => {
|
|
198
|
+
const oldPerms = [
|
|
199
|
+
new permissions_js_1.ActionPermission({
|
|
200
|
+
permanentlyPermittedTimes: [],
|
|
201
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
202
|
+
})
|
|
203
|
+
];
|
|
204
|
+
const newPerms = [
|
|
205
|
+
new permissions_js_1.ActionPermission({
|
|
206
|
+
permanentlyPermittedTimes: [],
|
|
207
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
208
|
+
})
|
|
209
|
+
];
|
|
210
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(oldPerms, newPerms);
|
|
211
|
+
expect(err).not.toBeNull();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
describe('check', () => {
|
|
215
|
+
it('should return null when no permissions are defined (neutral)', () => {
|
|
216
|
+
const err = permissions_js_1.ActionPermission.check([]);
|
|
217
|
+
expect(err).toBeNull();
|
|
218
|
+
});
|
|
219
|
+
it('should return null when action is permanently permitted at current time', () => {
|
|
220
|
+
const now = BigInt(Date.now());
|
|
221
|
+
const perms = [
|
|
222
|
+
new permissions_js_1.ActionPermission({
|
|
223
|
+
permanentlyPermittedTimes: [{ start: 1n, end: now + 1000000n }],
|
|
224
|
+
permanentlyForbiddenTimes: []
|
|
225
|
+
})
|
|
226
|
+
];
|
|
227
|
+
const err = permissions_js_1.ActionPermission.check(perms, now);
|
|
228
|
+
expect(err).toBeNull();
|
|
229
|
+
});
|
|
230
|
+
it('should return error when action is permanently forbidden at given time', () => {
|
|
231
|
+
const checkTime = 50n;
|
|
232
|
+
const perms = [
|
|
233
|
+
new permissions_js_1.ActionPermission({
|
|
234
|
+
permanentlyPermittedTimes: [],
|
|
235
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
236
|
+
})
|
|
237
|
+
];
|
|
238
|
+
const err = permissions_js_1.ActionPermission.check(perms, checkTime);
|
|
239
|
+
expect(err).not.toBeNull();
|
|
240
|
+
expect(err.message).toContain('forbidden');
|
|
241
|
+
});
|
|
242
|
+
it('should return null when action is forbidden at a different time', () => {
|
|
243
|
+
const checkTime = 200n;
|
|
244
|
+
const perms = [
|
|
245
|
+
new permissions_js_1.ActionPermission({
|
|
246
|
+
permanentlyPermittedTimes: [],
|
|
247
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
248
|
+
})
|
|
249
|
+
];
|
|
250
|
+
const err = permissions_js_1.ActionPermission.check(perms, checkTime);
|
|
251
|
+
expect(err).toBeNull();
|
|
252
|
+
});
|
|
253
|
+
it('should return error when forbidden covers all time', () => {
|
|
254
|
+
const perms = [
|
|
255
|
+
new permissions_js_1.ActionPermission({
|
|
256
|
+
permanentlyPermittedTimes: [],
|
|
257
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
258
|
+
})
|
|
259
|
+
];
|
|
260
|
+
const err = permissions_js_1.ActionPermission.check(perms, 500n);
|
|
261
|
+
expect(err).not.toBeNull();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
describe('TokenIdsActionPermission', () => {
|
|
266
|
+
describe('construction', () => {
|
|
267
|
+
it('should create an instance with token IDs and times', () => {
|
|
268
|
+
const perm = new permissions_js_1.TokenIdsActionPermission({
|
|
269
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
270
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
271
|
+
permanentlyForbiddenTimes: []
|
|
272
|
+
});
|
|
273
|
+
expect(perm).toBeTruthy();
|
|
274
|
+
expect(perm.tokenIds.length).toBe(1);
|
|
275
|
+
expect(perm.tokenIds[0].start).toBe(1n);
|
|
276
|
+
expect(perm.tokenIds[0].end).toBe(10n);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
describe('castToUniversalPermission', () => {
|
|
280
|
+
it('should set usesTokenIds to true', () => {
|
|
281
|
+
const perm = new permissions_js_1.TokenIdsActionPermission({
|
|
282
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
283
|
+
permanentlyPermittedTimes: [],
|
|
284
|
+
permanentlyForbiddenTimes: []
|
|
285
|
+
});
|
|
286
|
+
const universal = perm.castToUniversalPermission();
|
|
287
|
+
expect(universal.usesTokenIds).toBe(true);
|
|
288
|
+
expect(universal.usesTimelineTimes).toBe(false);
|
|
289
|
+
expect(universal.usesTransferTimes).toBe(false);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
describe('validateUpdate', () => {
|
|
293
|
+
it('should allow identical permissions', () => {
|
|
294
|
+
const perms = [
|
|
295
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
296
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
297
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
298
|
+
permanentlyForbiddenTimes: []
|
|
299
|
+
})
|
|
300
|
+
];
|
|
301
|
+
const err = permissions_js_1.TokenIdsActionPermission.validateUpdate(perms, perms);
|
|
302
|
+
expect(err).toBeNull();
|
|
303
|
+
});
|
|
304
|
+
it('should reject removing a permission with tokenIds', () => {
|
|
305
|
+
const oldPerms = [
|
|
306
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
307
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
308
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
309
|
+
permanentlyForbiddenTimes: []
|
|
310
|
+
})
|
|
311
|
+
];
|
|
312
|
+
const newPerms = [];
|
|
313
|
+
const err = permissions_js_1.TokenIdsActionPermission.validateUpdate(oldPerms, newPerms);
|
|
314
|
+
expect(err).not.toBeNull();
|
|
315
|
+
});
|
|
316
|
+
it('should reject changing permitted to forbidden for same token IDs', () => {
|
|
317
|
+
const oldPerms = [
|
|
318
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
319
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
320
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
321
|
+
permanentlyForbiddenTimes: []
|
|
322
|
+
})
|
|
323
|
+
];
|
|
324
|
+
const newPerms = [
|
|
325
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
326
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
327
|
+
permanentlyPermittedTimes: [],
|
|
328
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
329
|
+
})
|
|
330
|
+
];
|
|
331
|
+
const err = permissions_js_1.TokenIdsActionPermission.validateUpdate(oldPerms, newPerms);
|
|
332
|
+
expect(err).not.toBeNull();
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
describe('check', () => {
|
|
336
|
+
it('should return null when no permissions forbid the action', () => {
|
|
337
|
+
const perms = [
|
|
338
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
339
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
340
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
341
|
+
permanentlyForbiddenTimes: []
|
|
342
|
+
})
|
|
343
|
+
];
|
|
344
|
+
const err = permissions_js_1.TokenIdsActionPermission.check([{ tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 5n }]) }], perms, 50n);
|
|
345
|
+
expect(err).toBeNull();
|
|
346
|
+
});
|
|
347
|
+
it('should return error when forbidden for the requested token IDs', () => {
|
|
348
|
+
const perms = [
|
|
349
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
350
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
351
|
+
permanentlyPermittedTimes: [],
|
|
352
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
353
|
+
})
|
|
354
|
+
];
|
|
355
|
+
const err = permissions_js_1.TokenIdsActionPermission.check([{ tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 5n, end: 5n }]) }], perms, 50n);
|
|
356
|
+
expect(err).not.toBeNull();
|
|
357
|
+
expect(err.message).toContain('forbidden');
|
|
358
|
+
});
|
|
359
|
+
it('should return null when checking token IDs not covered by forbidden permission', () => {
|
|
360
|
+
const perms = [
|
|
361
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
362
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
363
|
+
permanentlyPermittedTimes: [],
|
|
364
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
365
|
+
})
|
|
366
|
+
];
|
|
367
|
+
const err = permissions_js_1.TokenIdsActionPermission.check([{ tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 20n, end: 20n }]) }], perms, 50n);
|
|
368
|
+
expect(err).toBeNull();
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
describe('CollectionApprovalPermissionWithDetails', () => {
|
|
373
|
+
const makeApprovalPerm = (opts) => {
|
|
374
|
+
return new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
375
|
+
fromListId: 'All',
|
|
376
|
+
toListId: 'All',
|
|
377
|
+
initiatedByListId: 'All',
|
|
378
|
+
approvalId: 'All',
|
|
379
|
+
tokenIds: (opts.tokenIds || [[1n, 18446744073709551615n]]).map(([s, e]) => ({ start: s, end: e })),
|
|
380
|
+
transferTimes: (opts.transferTimes || [[1n, 18446744073709551615n]]).map(([s, e]) => ({ start: s, end: e })),
|
|
381
|
+
ownershipTimes: (opts.ownershipTimes || [[1n, 18446744073709551615n]]).map(([s, e]) => ({ start: s, end: e })),
|
|
382
|
+
permanentlyPermittedTimes: (opts.permitted || []).map(([s, e]) => ({ start: s, end: e })),
|
|
383
|
+
permanentlyForbiddenTimes: (opts.forbidden || []).map(([s, e]) => ({ start: s, end: e })),
|
|
384
|
+
fromList: allAddresses(),
|
|
385
|
+
toList: allAddresses(),
|
|
386
|
+
initiatedByList: allAddresses()
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
describe('construction', () => {
|
|
390
|
+
it('should create an instance with all fields', () => {
|
|
391
|
+
const perm = makeApprovalPerm({ permitted: [[1n, 100n]] });
|
|
392
|
+
expect(perm).toBeTruthy();
|
|
393
|
+
expect(perm.fromList).toBeTruthy();
|
|
394
|
+
expect(perm.toList).toBeTruthy();
|
|
395
|
+
expect(perm.initiatedByList).toBeTruthy();
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
describe('castToUniversalPermission', () => {
|
|
399
|
+
it('should set all uses flags to true', () => {
|
|
400
|
+
const perm = makeApprovalPerm({});
|
|
401
|
+
const universal = perm.castToUniversalPermission();
|
|
402
|
+
expect(universal.usesTokenIds).toBe(true);
|
|
403
|
+
expect(universal.usesTransferTimes).toBe(true);
|
|
404
|
+
expect(universal.usesOwnershipTimes).toBe(true);
|
|
405
|
+
expect(universal.usesToList).toBe(true);
|
|
406
|
+
expect(universal.usesFromList).toBe(true);
|
|
407
|
+
expect(universal.usesInitiatedByList).toBe(true);
|
|
408
|
+
expect(universal.usesApprovalIdList).toBe(true);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
describe('validateUpdate', () => {
|
|
412
|
+
it('should allow identical approval permissions', () => {
|
|
413
|
+
const perms = [makeApprovalPerm({ permitted: [[1n, 100n]] })];
|
|
414
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(perms, perms);
|
|
415
|
+
expect(err).toBeNull();
|
|
416
|
+
});
|
|
417
|
+
it('should reject removing approval permissions', () => {
|
|
418
|
+
const oldPerms = [makeApprovalPerm({ permitted: [[1n, 100n]] })];
|
|
419
|
+
const newPerms = [];
|
|
420
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
421
|
+
expect(err).not.toBeNull();
|
|
422
|
+
});
|
|
423
|
+
it('should reject changing permitted to forbidden for approvals', () => {
|
|
424
|
+
const oldPerms = [makeApprovalPerm({ permitted: [[1n, 100n]] })];
|
|
425
|
+
const newPerms = [makeApprovalPerm({ forbidden: [[1n, 100n]] })];
|
|
426
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
427
|
+
expect(err).not.toBeNull();
|
|
428
|
+
});
|
|
429
|
+
it('should allow extending permitted times for approvals', () => {
|
|
430
|
+
const oldPerms = [makeApprovalPerm({ permitted: [[1n, 50n]] })];
|
|
431
|
+
const newPerms = [makeApprovalPerm({ permitted: [[1n, 100n]] })];
|
|
432
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
433
|
+
expect(err).toBeNull();
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
describe('check', () => {
|
|
437
|
+
it('should return null when approvals are permitted', () => {
|
|
438
|
+
const perms = [makeApprovalPerm({ permitted: [[1n, 18446744073709551615n]] })];
|
|
439
|
+
const err = permissions_js_1.CollectionApprovalPermission.check([
|
|
440
|
+
{
|
|
441
|
+
tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 10n }]),
|
|
442
|
+
ownershipTimes: fullRange(),
|
|
443
|
+
transferTimes: fullRange(),
|
|
444
|
+
toList: allAddresses(),
|
|
445
|
+
fromList: allAddresses(),
|
|
446
|
+
initiatedByList: allAddresses(),
|
|
447
|
+
approvalIdList: allAddresses()
|
|
448
|
+
}
|
|
449
|
+
], perms, 50n);
|
|
450
|
+
expect(err).toBeNull();
|
|
451
|
+
});
|
|
452
|
+
it('should return error when approvals are forbidden', () => {
|
|
453
|
+
const perms = [makeApprovalPerm({ forbidden: [[1n, 18446744073709551615n]] })];
|
|
454
|
+
const err = permissions_js_1.CollectionApprovalPermission.check([
|
|
455
|
+
{
|
|
456
|
+
tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 10n }]),
|
|
457
|
+
ownershipTimes: fullRange(),
|
|
458
|
+
transferTimes: fullRange(),
|
|
459
|
+
toList: allAddresses(),
|
|
460
|
+
fromList: allAddresses(),
|
|
461
|
+
initiatedByList: allAddresses(),
|
|
462
|
+
approvalIdList: allAddresses()
|
|
463
|
+
}
|
|
464
|
+
], perms, 50n);
|
|
465
|
+
expect(err).not.toBeNull();
|
|
466
|
+
expect(err.message).toContain('forbidden');
|
|
467
|
+
});
|
|
468
|
+
it('should return null when checking at a time outside forbidden range', () => {
|
|
469
|
+
const perms = [makeApprovalPerm({ forbidden: [[1n, 100n]] })];
|
|
470
|
+
const err = permissions_js_1.CollectionApprovalPermission.check([
|
|
471
|
+
{
|
|
472
|
+
tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 10n }]),
|
|
473
|
+
ownershipTimes: fullRange(),
|
|
474
|
+
transferTimes: fullRange(),
|
|
475
|
+
toList: allAddresses(),
|
|
476
|
+
fromList: allAddresses(),
|
|
477
|
+
initiatedByList: allAddresses(),
|
|
478
|
+
approvalIdList: allAddresses()
|
|
479
|
+
}
|
|
480
|
+
], perms, 200n);
|
|
481
|
+
expect(err).toBeNull();
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
describe('UserPermissions', () => {
|
|
486
|
+
describe('construction', () => {
|
|
487
|
+
it('should create an instance with empty arrays', () => {
|
|
488
|
+
const perms = permissions_js_1.UserPermissions.InitEmpty();
|
|
489
|
+
expect(perms).toBeTruthy();
|
|
490
|
+
expect(perms.canUpdateOutgoingApprovals.length).toBe(0);
|
|
491
|
+
expect(perms.canUpdateIncomingApprovals.length).toBe(0);
|
|
492
|
+
expect(perms.canUpdateAutoApproveSelfInitiatedOutgoingTransfers.length).toBe(0);
|
|
493
|
+
expect(perms.canUpdateAutoApproveSelfInitiatedIncomingTransfers.length).toBe(0);
|
|
494
|
+
expect(perms.canUpdateAutoApproveAllIncomingTransfers.length).toBe(0);
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
describe('validateUpdate', () => {
|
|
498
|
+
it('should allow empty to empty update', () => {
|
|
499
|
+
const makeEmpty = () => new permissions_js_1.UserPermissionsWithDetails({
|
|
500
|
+
canUpdateOutgoingApprovals: [],
|
|
501
|
+
canUpdateIncomingApprovals: [],
|
|
502
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [],
|
|
503
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [],
|
|
504
|
+
canUpdateAutoApproveAllIncomingTransfers: []
|
|
505
|
+
});
|
|
506
|
+
const err = permissions_js_1.UserPermissions.validateUpdate(makeEmpty(), makeEmpty());
|
|
507
|
+
expect(err).toBeNull();
|
|
508
|
+
});
|
|
509
|
+
it('should reject removing auto-approve permission', () => {
|
|
510
|
+
const oldPerms = new permissions_js_1.UserPermissionsWithDetails({
|
|
511
|
+
canUpdateOutgoingApprovals: [],
|
|
512
|
+
canUpdateIncomingApprovals: [],
|
|
513
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [
|
|
514
|
+
new permissions_js_1.ActionPermission({
|
|
515
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
516
|
+
permanentlyForbiddenTimes: []
|
|
517
|
+
})
|
|
518
|
+
],
|
|
519
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [],
|
|
520
|
+
canUpdateAutoApproveAllIncomingTransfers: []
|
|
521
|
+
});
|
|
522
|
+
const newPerms = new permissions_js_1.UserPermissionsWithDetails({
|
|
523
|
+
canUpdateOutgoingApprovals: [],
|
|
524
|
+
canUpdateIncomingApprovals: [],
|
|
525
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [],
|
|
526
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [],
|
|
527
|
+
canUpdateAutoApproveAllIncomingTransfers: []
|
|
528
|
+
});
|
|
529
|
+
const err = permissions_js_1.UserPermissions.validateUpdate(oldPerms, newPerms);
|
|
530
|
+
expect(err).not.toBeNull();
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
describe('CollectionPermissions', () => {
|
|
535
|
+
describe('construction', () => {
|
|
536
|
+
it('should create via InitEmpty', () => {
|
|
537
|
+
const perms = permissions_js_1.CollectionPermissions.InitEmpty();
|
|
538
|
+
expect(perms).toBeTruthy();
|
|
539
|
+
expect(perms.canDeleteCollection.length).toBe(0);
|
|
540
|
+
expect(perms.canArchiveCollection.length).toBe(0);
|
|
541
|
+
expect(perms.canUpdateStandards.length).toBe(0);
|
|
542
|
+
expect(perms.canUpdateCustomData.length).toBe(0);
|
|
543
|
+
expect(perms.canUpdateManager.length).toBe(0);
|
|
544
|
+
expect(perms.canUpdateCollectionMetadata.length).toBe(0);
|
|
545
|
+
expect(perms.canUpdateValidTokenIds.length).toBe(0);
|
|
546
|
+
expect(perms.canUpdateTokenMetadata.length).toBe(0);
|
|
547
|
+
expect(perms.canUpdateCollectionApprovals.length).toBe(0);
|
|
548
|
+
expect(perms.canAddMoreAliasPaths.length).toBe(0);
|
|
549
|
+
expect(perms.canAddMoreCosmosCoinWrapperPaths.length).toBe(0);
|
|
550
|
+
});
|
|
551
|
+
it('should construct with permissions', () => {
|
|
552
|
+
const perms = new permissions_js_1.CollectionPermissions({
|
|
553
|
+
canDeleteCollection: [
|
|
554
|
+
new permissions_js_1.ActionPermission({
|
|
555
|
+
permanentlyPermittedTimes: [],
|
|
556
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
557
|
+
})
|
|
558
|
+
],
|
|
559
|
+
canArchiveCollection: [],
|
|
560
|
+
canUpdateStandards: [],
|
|
561
|
+
canUpdateCustomData: [],
|
|
562
|
+
canUpdateManager: [],
|
|
563
|
+
canUpdateCollectionMetadata: [],
|
|
564
|
+
canUpdateValidTokenIds: [],
|
|
565
|
+
canUpdateTokenMetadata: [],
|
|
566
|
+
canUpdateCollectionApprovals: [],
|
|
567
|
+
canAddMoreAliasPaths: [],
|
|
568
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
569
|
+
});
|
|
570
|
+
expect(perms.canDeleteCollection.length).toBe(1);
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
describe('validateUpdate', () => {
|
|
574
|
+
it('should allow identical collection permissions', () => {
|
|
575
|
+
const makePerms = () => new permissions_js_1.CollectionPermissionsWithDetails({
|
|
576
|
+
canDeleteCollection: [
|
|
577
|
+
new permissions_js_1.ActionPermission({
|
|
578
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
579
|
+
permanentlyForbiddenTimes: []
|
|
580
|
+
})
|
|
581
|
+
],
|
|
582
|
+
canArchiveCollection: [],
|
|
583
|
+
canUpdateStandards: [],
|
|
584
|
+
canUpdateCustomData: [],
|
|
585
|
+
canUpdateManager: [],
|
|
586
|
+
canUpdateCollectionMetadata: [],
|
|
587
|
+
canUpdateValidTokenIds: [],
|
|
588
|
+
canUpdateTokenMetadata: [],
|
|
589
|
+
canUpdateCollectionApprovals: [],
|
|
590
|
+
canAddMoreAliasPaths: [],
|
|
591
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
592
|
+
});
|
|
593
|
+
const err = permissions_js_1.CollectionPermissionsWithDetails.validateUpdate(makePerms(), makePerms());
|
|
594
|
+
expect(err).toBeNull();
|
|
595
|
+
});
|
|
596
|
+
it('should reject removing canDeleteCollection permission', () => {
|
|
597
|
+
const oldPerms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
598
|
+
canDeleteCollection: [
|
|
599
|
+
new permissions_js_1.ActionPermission({
|
|
600
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
601
|
+
permanentlyForbiddenTimes: []
|
|
602
|
+
})
|
|
603
|
+
],
|
|
604
|
+
canArchiveCollection: [],
|
|
605
|
+
canUpdateStandards: [],
|
|
606
|
+
canUpdateCustomData: [],
|
|
607
|
+
canUpdateManager: [],
|
|
608
|
+
canUpdateCollectionMetadata: [],
|
|
609
|
+
canUpdateValidTokenIds: [],
|
|
610
|
+
canUpdateTokenMetadata: [],
|
|
611
|
+
canUpdateCollectionApprovals: [],
|
|
612
|
+
canAddMoreAliasPaths: [],
|
|
613
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
614
|
+
});
|
|
615
|
+
const newPerms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
616
|
+
canDeleteCollection: [],
|
|
617
|
+
canArchiveCollection: [],
|
|
618
|
+
canUpdateStandards: [],
|
|
619
|
+
canUpdateCustomData: [],
|
|
620
|
+
canUpdateManager: [],
|
|
621
|
+
canUpdateCollectionMetadata: [],
|
|
622
|
+
canUpdateValidTokenIds: [],
|
|
623
|
+
canUpdateTokenMetadata: [],
|
|
624
|
+
canUpdateCollectionApprovals: [],
|
|
625
|
+
canAddMoreAliasPaths: [],
|
|
626
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
627
|
+
});
|
|
628
|
+
const err = permissions_js_1.CollectionPermissionsWithDetails.validateUpdate(oldPerms, newPerms);
|
|
629
|
+
expect(err).not.toBeNull();
|
|
630
|
+
});
|
|
631
|
+
it('should reject changing canUpdateManager from permitted to forbidden', () => {
|
|
632
|
+
const oldPerms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
633
|
+
canDeleteCollection: [],
|
|
634
|
+
canArchiveCollection: [],
|
|
635
|
+
canUpdateStandards: [],
|
|
636
|
+
canUpdateCustomData: [],
|
|
637
|
+
canUpdateManager: [
|
|
638
|
+
new permissions_js_1.ActionPermission({
|
|
639
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
640
|
+
permanentlyForbiddenTimes: []
|
|
641
|
+
})
|
|
642
|
+
],
|
|
643
|
+
canUpdateCollectionMetadata: [],
|
|
644
|
+
canUpdateValidTokenIds: [],
|
|
645
|
+
canUpdateTokenMetadata: [],
|
|
646
|
+
canUpdateCollectionApprovals: [],
|
|
647
|
+
canAddMoreAliasPaths: [],
|
|
648
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
649
|
+
});
|
|
650
|
+
const newPerms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
651
|
+
canDeleteCollection: [],
|
|
652
|
+
canArchiveCollection: [],
|
|
653
|
+
canUpdateStandards: [],
|
|
654
|
+
canUpdateCustomData: [],
|
|
655
|
+
canUpdateManager: [
|
|
656
|
+
new permissions_js_1.ActionPermission({
|
|
657
|
+
permanentlyPermittedTimes: [],
|
|
658
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
659
|
+
})
|
|
660
|
+
],
|
|
661
|
+
canUpdateCollectionMetadata: [],
|
|
662
|
+
canUpdateValidTokenIds: [],
|
|
663
|
+
canUpdateTokenMetadata: [],
|
|
664
|
+
canUpdateCollectionApprovals: [],
|
|
665
|
+
canAddMoreAliasPaths: [],
|
|
666
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
667
|
+
});
|
|
668
|
+
const err = permissions_js_1.CollectionPermissionsWithDetails.validateUpdate(oldPerms, newPerms);
|
|
669
|
+
expect(err).not.toBeNull();
|
|
670
|
+
});
|
|
671
|
+
it('should allow all-empty to all-empty', () => {
|
|
672
|
+
const makeEmpty = () => new permissions_js_1.CollectionPermissionsWithDetails({
|
|
673
|
+
canDeleteCollection: [],
|
|
674
|
+
canArchiveCollection: [],
|
|
675
|
+
canUpdateStandards: [],
|
|
676
|
+
canUpdateCustomData: [],
|
|
677
|
+
canUpdateManager: [],
|
|
678
|
+
canUpdateCollectionMetadata: [],
|
|
679
|
+
canUpdateValidTokenIds: [],
|
|
680
|
+
canUpdateTokenMetadata: [],
|
|
681
|
+
canUpdateCollectionApprovals: [],
|
|
682
|
+
canAddMoreAliasPaths: [],
|
|
683
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
684
|
+
});
|
|
685
|
+
const err = permissions_js_1.CollectionPermissionsWithDetails.validateUpdate(makeEmpty(), makeEmpty());
|
|
686
|
+
expect(err).toBeNull();
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
describe('UserOutgoingApprovalPermission', () => {
|
|
691
|
+
const makeOutgoing = (permitted = [], forbidden = []) => new permissions_js_1.UserOutgoingApprovalPermission({
|
|
692
|
+
toListId: 'All',
|
|
693
|
+
initiatedByListId: 'All',
|
|
694
|
+
approvalId: 'All',
|
|
695
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
696
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
697
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
698
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
699
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
700
|
+
});
|
|
701
|
+
describe('construction', () => {
|
|
702
|
+
it('should create with all required fields', () => {
|
|
703
|
+
const perm = makeOutgoing([[1n, 100n]]);
|
|
704
|
+
expect(perm).toBeTruthy();
|
|
705
|
+
expect(perm.toListId).toBe('All');
|
|
706
|
+
expect(perm.initiatedByListId).toBe('All');
|
|
707
|
+
expect(perm.approvalId).toBe('All');
|
|
708
|
+
expect(perm.transferTimes.length).toBe(1);
|
|
709
|
+
expect(perm.tokenIds.length).toBe(1);
|
|
710
|
+
expect(perm.ownershipTimes.length).toBe(1);
|
|
711
|
+
expect(perm.permanentlyPermittedTimes.length).toBe(1);
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
describe('convert', () => {
|
|
715
|
+
it('should convert number type to string', () => {
|
|
716
|
+
const perm = makeOutgoing([[1n, 50n]]);
|
|
717
|
+
const stringified = perm.convert(string_numbers_js_1.Stringify);
|
|
718
|
+
expect(stringified.tokenIds[0].start).toBe('1');
|
|
719
|
+
expect(stringified.tokenIds[0].end).toBe('18446744073709551615');
|
|
720
|
+
expect(stringified.permanentlyPermittedTimes[0].start).toBe('1');
|
|
721
|
+
expect(stringified.permanentlyPermittedTimes[0].end).toBe('50');
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
describe('toProto / fromProto', () => {
|
|
725
|
+
it('should round-trip through proto', () => {
|
|
726
|
+
const perm = makeOutgoing([[10n, 200n]]);
|
|
727
|
+
const proto = perm.toProto();
|
|
728
|
+
expect(proto).toBeTruthy();
|
|
729
|
+
const restored = permissions_js_1.UserOutgoingApprovalPermission.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
730
|
+
expect(restored.toListId).toBe('All');
|
|
731
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
732
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(200n);
|
|
733
|
+
});
|
|
734
|
+
});
|
|
735
|
+
describe('fromJson / fromJsonString', () => {
|
|
736
|
+
it('should round-trip through JSON', () => {
|
|
737
|
+
const perm = makeOutgoing([[5n, 50n]]);
|
|
738
|
+
const jsonVal = perm.toProto().toJson();
|
|
739
|
+
const restored = permissions_js_1.UserOutgoingApprovalPermission.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
740
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
741
|
+
});
|
|
742
|
+
it('should round-trip through JSON string', () => {
|
|
743
|
+
const perm = makeOutgoing([], [[1n, 100n]]);
|
|
744
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
745
|
+
const restored = permissions_js_1.UserOutgoingApprovalPermission.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
746
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
747
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(100n);
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
describe('castToCollectionApprovalPermission', () => {
|
|
751
|
+
it('should cast to CollectionApprovalPermission with given fromListId', () => {
|
|
752
|
+
const perm = makeOutgoing([[1n, 100n]]);
|
|
753
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
754
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
755
|
+
expect(casted.fromListId).toBe(addr);
|
|
756
|
+
});
|
|
757
|
+
});
|
|
758
|
+
describe('toBech32Addresses', () => {
|
|
759
|
+
it('should convert listIds to bech32', () => {
|
|
760
|
+
const perm = makeOutgoing();
|
|
761
|
+
expect(() => perm.toBech32Addresses('bb')).not.toThrow();
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
describe('validateUpdate', () => {
|
|
765
|
+
it('should allow identical outgoing permissions', () => {
|
|
766
|
+
const makeWithDetails = (permitted) => new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
767
|
+
toListId: 'All',
|
|
768
|
+
initiatedByListId: 'All',
|
|
769
|
+
approvalId: 'All',
|
|
770
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
771
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
772
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
773
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
774
|
+
permanentlyForbiddenTimes: [],
|
|
775
|
+
toList: allAddresses(),
|
|
776
|
+
initiatedByList: allAddresses()
|
|
777
|
+
});
|
|
778
|
+
const perms = [makeWithDetails([[1n, 100n]])];
|
|
779
|
+
const err = permissions_js_1.UserOutgoingApprovalPermission.validateUpdate(perms, perms);
|
|
780
|
+
expect(err).toBeNull();
|
|
781
|
+
});
|
|
782
|
+
it('should reject removing outgoing permission', () => {
|
|
783
|
+
const makeWithDetails = () => new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
784
|
+
toListId: 'All',
|
|
785
|
+
initiatedByListId: 'All',
|
|
786
|
+
approvalId: 'All',
|
|
787
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
788
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
789
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
790
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
791
|
+
permanentlyForbiddenTimes: [],
|
|
792
|
+
toList: allAddresses(),
|
|
793
|
+
initiatedByList: allAddresses()
|
|
794
|
+
});
|
|
795
|
+
const err = permissions_js_1.UserOutgoingApprovalPermission.validateUpdate([makeWithDetails()], []);
|
|
796
|
+
expect(err).not.toBeNull();
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
describe('check', () => {
|
|
800
|
+
it('should return null when outgoing approval is permitted', () => {
|
|
801
|
+
const perm = new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
802
|
+
toListId: 'All',
|
|
803
|
+
initiatedByListId: 'All',
|
|
804
|
+
approvalId: 'All',
|
|
805
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
806
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
807
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
808
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
809
|
+
permanentlyForbiddenTimes: [],
|
|
810
|
+
toList: allAddresses(),
|
|
811
|
+
initiatedByList: allAddresses()
|
|
812
|
+
});
|
|
813
|
+
const err = permissions_js_1.UserOutgoingApprovalPermission.check([
|
|
814
|
+
{
|
|
815
|
+
tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 5n }]),
|
|
816
|
+
ownershipTimes: fullRange(),
|
|
817
|
+
transferTimes: fullRange(),
|
|
818
|
+
toList: allAddresses(),
|
|
819
|
+
fromList: allAddresses(),
|
|
820
|
+
initiatedByList: allAddresses(),
|
|
821
|
+
approvalIdList: allAddresses(),
|
|
822
|
+
amountTrackerIdList: allAddresses(),
|
|
823
|
+
challengeTrackerIdList: allAddresses()
|
|
824
|
+
}
|
|
825
|
+
], [perm], 50n);
|
|
826
|
+
expect(err).toBeNull();
|
|
827
|
+
});
|
|
828
|
+
it('should return error when outgoing approval is forbidden', () => {
|
|
829
|
+
const perm = new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
830
|
+
toListId: 'All',
|
|
831
|
+
initiatedByListId: 'All',
|
|
832
|
+
approvalId: 'All',
|
|
833
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
834
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
835
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
836
|
+
permanentlyPermittedTimes: [],
|
|
837
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
838
|
+
toList: allAddresses(),
|
|
839
|
+
initiatedByList: allAddresses()
|
|
840
|
+
});
|
|
841
|
+
const err = permissions_js_1.UserOutgoingApprovalPermission.check([
|
|
842
|
+
{
|
|
843
|
+
tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 5n }]),
|
|
844
|
+
ownershipTimes: fullRange(),
|
|
845
|
+
transferTimes: fullRange(),
|
|
846
|
+
toList: allAddresses(),
|
|
847
|
+
fromList: allAddresses(),
|
|
848
|
+
initiatedByList: allAddresses(),
|
|
849
|
+
approvalIdList: allAddresses(),
|
|
850
|
+
amountTrackerIdList: allAddresses(),
|
|
851
|
+
challengeTrackerIdList: allAddresses()
|
|
852
|
+
}
|
|
853
|
+
], [perm], 50n);
|
|
854
|
+
expect(err).not.toBeNull();
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
describe('UserIncomingApprovalPermission', () => {
|
|
859
|
+
const makeIncoming = (permitted = [], forbidden = []) => new permissions_js_1.UserIncomingApprovalPermission({
|
|
860
|
+
fromListId: 'All',
|
|
861
|
+
initiatedByListId: 'All',
|
|
862
|
+
approvalId: 'All',
|
|
863
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
864
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
865
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
866
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
867
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
868
|
+
});
|
|
869
|
+
describe('construction', () => {
|
|
870
|
+
it('should create with all required fields', () => {
|
|
871
|
+
const perm = makeIncoming([[1n, 100n]]);
|
|
872
|
+
expect(perm).toBeTruthy();
|
|
873
|
+
expect(perm.fromListId).toBe('All');
|
|
874
|
+
expect(perm.initiatedByListId).toBe('All');
|
|
875
|
+
expect(perm.approvalId).toBe('All');
|
|
876
|
+
expect(perm.permanentlyPermittedTimes.length).toBe(1);
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
describe('convert', () => {
|
|
880
|
+
it('should convert to string type', () => {
|
|
881
|
+
const perm = makeIncoming([[1n, 50n]]);
|
|
882
|
+
const stringified = perm.convert(string_numbers_js_1.Stringify);
|
|
883
|
+
expect(stringified.tokenIds[0].start).toBe('1');
|
|
884
|
+
expect(stringified.permanentlyPermittedTimes[0].end).toBe('50');
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
describe('toProto / fromProto', () => {
|
|
888
|
+
it('should round-trip through proto', () => {
|
|
889
|
+
const perm = makeIncoming([[10n, 200n]]);
|
|
890
|
+
const proto = perm.toProto();
|
|
891
|
+
const restored = permissions_js_1.UserIncomingApprovalPermission.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
892
|
+
expect(restored.fromListId).toBe('All');
|
|
893
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
describe('fromJson / fromJsonString', () => {
|
|
897
|
+
it('should round-trip through JSON', () => {
|
|
898
|
+
const perm = makeIncoming([[5n, 50n]]);
|
|
899
|
+
const jsonVal = perm.toProto().toJson();
|
|
900
|
+
const restored = permissions_js_1.UserIncomingApprovalPermission.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
901
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
902
|
+
});
|
|
903
|
+
it('should round-trip through JSON string', () => {
|
|
904
|
+
const perm = makeIncoming([], [[1n, 100n]]);
|
|
905
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
906
|
+
const restored = permissions_js_1.UserIncomingApprovalPermission.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
907
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
908
|
+
});
|
|
909
|
+
});
|
|
910
|
+
describe('castToCollectionApprovalPermission', () => {
|
|
911
|
+
it('should cast to CollectionApprovalPermission with given toListId', () => {
|
|
912
|
+
const perm = makeIncoming([[1n, 100n]]);
|
|
913
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
914
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
915
|
+
expect(casted.toListId).toBe(addr);
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
describe('toBech32Addresses', () => {
|
|
919
|
+
it('should not throw when converting reserved list IDs', () => {
|
|
920
|
+
const perm = makeIncoming();
|
|
921
|
+
expect(() => perm.toBech32Addresses('bb')).not.toThrow();
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
describe('validateUpdate', () => {
|
|
925
|
+
it('should allow identical incoming permissions', () => {
|
|
926
|
+
const makeWithDetails = () => new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
927
|
+
fromListId: 'All',
|
|
928
|
+
initiatedByListId: 'All',
|
|
929
|
+
approvalId: 'All',
|
|
930
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
931
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
932
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
933
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
934
|
+
permanentlyForbiddenTimes: [],
|
|
935
|
+
fromList: allAddresses(),
|
|
936
|
+
initiatedByList: allAddresses()
|
|
937
|
+
});
|
|
938
|
+
const perms = [makeWithDetails()];
|
|
939
|
+
const err = permissions_js_1.UserIncomingApprovalPermission.validateUpdate(perms, perms);
|
|
940
|
+
expect(err).toBeNull();
|
|
941
|
+
});
|
|
942
|
+
it('should reject removing incoming permission', () => {
|
|
943
|
+
const makeWithDetails = () => new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
944
|
+
fromListId: 'All',
|
|
945
|
+
initiatedByListId: 'All',
|
|
946
|
+
approvalId: 'All',
|
|
947
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
948
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
949
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
950
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
951
|
+
permanentlyForbiddenTimes: [],
|
|
952
|
+
fromList: allAddresses(),
|
|
953
|
+
initiatedByList: allAddresses()
|
|
954
|
+
});
|
|
955
|
+
const err = permissions_js_1.UserIncomingApprovalPermission.validateUpdate([makeWithDetails()], []);
|
|
956
|
+
expect(err).not.toBeNull();
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
describe('check', () => {
|
|
960
|
+
it('should return null when incoming approval is permitted', () => {
|
|
961
|
+
const perm = new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
962
|
+
fromListId: 'All',
|
|
963
|
+
initiatedByListId: 'All',
|
|
964
|
+
approvalId: 'All',
|
|
965
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
966
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
967
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
968
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
969
|
+
permanentlyForbiddenTimes: [],
|
|
970
|
+
fromList: allAddresses(),
|
|
971
|
+
initiatedByList: allAddresses()
|
|
972
|
+
});
|
|
973
|
+
const err = permissions_js_1.UserIncomingApprovalPermission.check([
|
|
974
|
+
{
|
|
975
|
+
tokenIds: fullRange(),
|
|
976
|
+
ownershipTimes: fullRange(),
|
|
977
|
+
transferTimes: fullRange(),
|
|
978
|
+
toList: allAddresses(),
|
|
979
|
+
fromList: allAddresses(),
|
|
980
|
+
initiatedByList: allAddresses(),
|
|
981
|
+
approvalIdList: allAddresses(),
|
|
982
|
+
amountTrackerIdList: allAddresses(),
|
|
983
|
+
challengeTrackerIdList: allAddresses()
|
|
984
|
+
}
|
|
985
|
+
], [perm], 50n);
|
|
986
|
+
expect(err).toBeNull();
|
|
987
|
+
});
|
|
988
|
+
it('should return error when incoming approval is forbidden', () => {
|
|
989
|
+
const perm = new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
990
|
+
fromListId: 'All',
|
|
991
|
+
initiatedByListId: 'All',
|
|
992
|
+
approvalId: 'All',
|
|
993
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
994
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
995
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
996
|
+
permanentlyPermittedTimes: [],
|
|
997
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
998
|
+
fromList: allAddresses(),
|
|
999
|
+
initiatedByList: allAddresses()
|
|
1000
|
+
});
|
|
1001
|
+
const err = permissions_js_1.UserIncomingApprovalPermission.check([
|
|
1002
|
+
{
|
|
1003
|
+
tokenIds: fullRange(),
|
|
1004
|
+
ownershipTimes: fullRange(),
|
|
1005
|
+
transferTimes: fullRange(),
|
|
1006
|
+
toList: allAddresses(),
|
|
1007
|
+
fromList: allAddresses(),
|
|
1008
|
+
initiatedByList: allAddresses(),
|
|
1009
|
+
approvalIdList: allAddresses(),
|
|
1010
|
+
amountTrackerIdList: allAddresses(),
|
|
1011
|
+
challengeTrackerIdList: allAddresses()
|
|
1012
|
+
}
|
|
1013
|
+
], [perm], 50n);
|
|
1014
|
+
expect(err).not.toBeNull();
|
|
1015
|
+
});
|
|
1016
|
+
});
|
|
1017
|
+
});
|
|
1018
|
+
describe('CollectionPermissions - serialization', () => {
|
|
1019
|
+
const makeEmpty = () => permissions_js_1.CollectionPermissions.InitEmpty();
|
|
1020
|
+
describe('convert', () => {
|
|
1021
|
+
it('should convert all fields when they contain data (covers map bodies in convert)', () => {
|
|
1022
|
+
const perms = new permissions_js_1.CollectionPermissions({
|
|
1023
|
+
canDeleteCollection: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 1n, end: 50n }], permanentlyForbiddenTimes: [] })],
|
|
1024
|
+
canArchiveCollection: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 2n, end: 3n }], permanentlyForbiddenTimes: [] })],
|
|
1025
|
+
canUpdateStandards: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 4n, end: 5n }], permanentlyForbiddenTimes: [] })],
|
|
1026
|
+
canUpdateCustomData: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 6n, end: 7n }], permanentlyForbiddenTimes: [] })],
|
|
1027
|
+
canUpdateManager: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 8n, end: 9n }], permanentlyForbiddenTimes: [] })],
|
|
1028
|
+
canUpdateCollectionMetadata: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 10n, end: 11n }], permanentlyForbiddenTimes: [] })],
|
|
1029
|
+
canUpdateValidTokenIds: [new permissions_js_1.TokenIdsActionPermission({ tokenIds: [{ start: 1n, end: 5n }], permanentlyPermittedTimes: [{ start: 1n, end: 10n }], permanentlyForbiddenTimes: [] })],
|
|
1030
|
+
canUpdateTokenMetadata: [new permissions_js_1.TokenIdsActionPermission({ tokenIds: [{ start: 6n, end: 10n }], permanentlyPermittedTimes: [], permanentlyForbiddenTimes: [{ start: 1n, end: 100n }] })],
|
|
1031
|
+
canUpdateCollectionApprovals: [],
|
|
1032
|
+
canAddMoreAliasPaths: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 20n, end: 30n }], permanentlyForbiddenTimes: [] })],
|
|
1033
|
+
canAddMoreCosmosCoinWrapperPaths: [new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 40n, end: 50n }], permanentlyForbiddenTimes: [] })]
|
|
1034
|
+
});
|
|
1035
|
+
const converted = perms.convert(string_numbers_js_1.Stringify);
|
|
1036
|
+
expect(converted.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe('1');
|
|
1037
|
+
expect(converted.canArchiveCollection[0].permanentlyPermittedTimes[0].start).toBe('2');
|
|
1038
|
+
expect(converted.canUpdateStandards[0].permanentlyPermittedTimes[0].start).toBe('4');
|
|
1039
|
+
expect(converted.canUpdateCustomData[0].permanentlyPermittedTimes[0].start).toBe('6');
|
|
1040
|
+
expect(converted.canUpdateManager[0].permanentlyPermittedTimes[0].start).toBe('8');
|
|
1041
|
+
expect(converted.canUpdateCollectionMetadata[0].permanentlyPermittedTimes[0].start).toBe('10');
|
|
1042
|
+
expect(converted.canUpdateValidTokenIds[0].tokenIds[0].start).toBe('1');
|
|
1043
|
+
expect(converted.canUpdateTokenMetadata[0].permanentlyForbiddenTimes[0].start).toBe('1');
|
|
1044
|
+
expect(converted.canAddMoreAliasPaths[0].permanentlyPermittedTimes[0].start).toBe('20');
|
|
1045
|
+
expect(converted.canAddMoreCosmosCoinWrapperPaths[0].permanentlyPermittedTimes[0].start).toBe('40');
|
|
1046
|
+
});
|
|
1047
|
+
});
|
|
1048
|
+
describe('toProto / fromProto', () => {
|
|
1049
|
+
it('should round-trip empty permissions through proto', () => {
|
|
1050
|
+
const perms = makeEmpty();
|
|
1051
|
+
const proto = perms.toProto();
|
|
1052
|
+
const restored = permissions_js_1.CollectionPermissions.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1053
|
+
expect(restored).toBeTruthy();
|
|
1054
|
+
expect(restored.canDeleteCollection.length).toBe(0);
|
|
1055
|
+
expect(restored.canUpdateManager.length).toBe(0);
|
|
1056
|
+
});
|
|
1057
|
+
it('should round-trip permissions with data through proto', () => {
|
|
1058
|
+
const perms = new permissions_js_1.CollectionPermissions({
|
|
1059
|
+
canDeleteCollection: [
|
|
1060
|
+
new permissions_js_1.ActionPermission({
|
|
1061
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1062
|
+
permanentlyForbiddenTimes: []
|
|
1063
|
+
})
|
|
1064
|
+
],
|
|
1065
|
+
canArchiveCollection: [],
|
|
1066
|
+
canUpdateStandards: [],
|
|
1067
|
+
canUpdateCustomData: [],
|
|
1068
|
+
canUpdateManager: [
|
|
1069
|
+
new permissions_js_1.ActionPermission({
|
|
1070
|
+
permanentlyPermittedTimes: [],
|
|
1071
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
1072
|
+
})
|
|
1073
|
+
],
|
|
1074
|
+
canUpdateCollectionMetadata: [],
|
|
1075
|
+
canUpdateValidTokenIds: [
|
|
1076
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
1077
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1078
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1079
|
+
permanentlyForbiddenTimes: []
|
|
1080
|
+
})
|
|
1081
|
+
],
|
|
1082
|
+
canUpdateTokenMetadata: [],
|
|
1083
|
+
canUpdateCollectionApprovals: [],
|
|
1084
|
+
canAddMoreAliasPaths: [],
|
|
1085
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1086
|
+
});
|
|
1087
|
+
const proto = perms.toProto();
|
|
1088
|
+
const restored = permissions_js_1.CollectionPermissions.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1089
|
+
expect(restored.canDeleteCollection.length).toBe(1);
|
|
1090
|
+
expect(restored.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1091
|
+
expect(restored.canDeleteCollection[0].permanentlyPermittedTimes[0].end).toBe(100n);
|
|
1092
|
+
expect(restored.canUpdateManager.length).toBe(1);
|
|
1093
|
+
expect(restored.canUpdateManager[0].permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
1094
|
+
expect(restored.canUpdateValidTokenIds.length).toBe(1);
|
|
1095
|
+
expect(restored.canUpdateValidTokenIds[0].tokenIds[0].start).toBe(1n);
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
describe('fromJson / fromJsonString', () => {
|
|
1099
|
+
it('should round-trip through JSON', () => {
|
|
1100
|
+
const perms = new permissions_js_1.CollectionPermissions({
|
|
1101
|
+
canDeleteCollection: [
|
|
1102
|
+
new permissions_js_1.ActionPermission({
|
|
1103
|
+
permanentlyPermittedTimes: [{ start: 10n, end: 20n }],
|
|
1104
|
+
permanentlyForbiddenTimes: []
|
|
1105
|
+
})
|
|
1106
|
+
],
|
|
1107
|
+
canArchiveCollection: [],
|
|
1108
|
+
canUpdateStandards: [],
|
|
1109
|
+
canUpdateCustomData: [],
|
|
1110
|
+
canUpdateManager: [],
|
|
1111
|
+
canUpdateCollectionMetadata: [],
|
|
1112
|
+
canUpdateValidTokenIds: [],
|
|
1113
|
+
canUpdateTokenMetadata: [],
|
|
1114
|
+
canUpdateCollectionApprovals: [],
|
|
1115
|
+
canAddMoreAliasPaths: [],
|
|
1116
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1117
|
+
});
|
|
1118
|
+
const jsonVal = perms.toProto().toJson();
|
|
1119
|
+
const restored = permissions_js_1.CollectionPermissions.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
1120
|
+
expect(restored.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe(10n);
|
|
1121
|
+
});
|
|
1122
|
+
it('should round-trip through JSON string', () => {
|
|
1123
|
+
const perms = makeEmpty();
|
|
1124
|
+
const jsonStr = perms.toProto().toJsonString();
|
|
1125
|
+
const restored = permissions_js_1.CollectionPermissions.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
1126
|
+
expect(restored.canDeleteCollection.length).toBe(0);
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
describe('toBech32Addresses', () => {
|
|
1130
|
+
it('should run without throwing for empty permissions', () => {
|
|
1131
|
+
const perms = makeEmpty();
|
|
1132
|
+
expect(() => perms.toBech32Addresses('bb')).not.toThrow();
|
|
1133
|
+
});
|
|
1134
|
+
it('should convert collection approval permission addresses', () => {
|
|
1135
|
+
const perms = new permissions_js_1.CollectionPermissions({
|
|
1136
|
+
canDeleteCollection: [],
|
|
1137
|
+
canArchiveCollection: [],
|
|
1138
|
+
canUpdateStandards: [],
|
|
1139
|
+
canUpdateCustomData: [],
|
|
1140
|
+
canUpdateManager: [],
|
|
1141
|
+
canUpdateCollectionMetadata: [],
|
|
1142
|
+
canUpdateValidTokenIds: [],
|
|
1143
|
+
canUpdateTokenMetadata: [],
|
|
1144
|
+
canUpdateCollectionApprovals: [
|
|
1145
|
+
new permissions_js_1.CollectionApprovalPermission({
|
|
1146
|
+
fromListId: 'All',
|
|
1147
|
+
toListId: 'All',
|
|
1148
|
+
initiatedByListId: 'All',
|
|
1149
|
+
approvalId: 'All',
|
|
1150
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1151
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1152
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1153
|
+
permanentlyPermittedTimes: [],
|
|
1154
|
+
permanentlyForbiddenTimes: []
|
|
1155
|
+
})
|
|
1156
|
+
],
|
|
1157
|
+
canAddMoreAliasPaths: [],
|
|
1158
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1159
|
+
});
|
|
1160
|
+
expect(() => perms.toBech32Addresses('bb')).not.toThrow();
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
describe('validateUpdate - more permission types', () => {
|
|
1164
|
+
const makePerms = (opts) => new permissions_js_1.CollectionPermissionsWithDetails({
|
|
1165
|
+
canDeleteCollection: [],
|
|
1166
|
+
canArchiveCollection: [],
|
|
1167
|
+
canUpdateStandards: [],
|
|
1168
|
+
canUpdateCustomData: [],
|
|
1169
|
+
canUpdateManager: [],
|
|
1170
|
+
canUpdateCollectionMetadata: [],
|
|
1171
|
+
canUpdateValidTokenIds: opts.canUpdateValidTokenIds || [],
|
|
1172
|
+
canUpdateTokenMetadata: [],
|
|
1173
|
+
canUpdateCollectionApprovals: opts.canUpdateCollectionApprovals || [],
|
|
1174
|
+
canAddMoreAliasPaths: [],
|
|
1175
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1176
|
+
});
|
|
1177
|
+
it('should reject removing canUpdateValidTokenIds permission', () => {
|
|
1178
|
+
const oldPerms = makePerms({
|
|
1179
|
+
canUpdateValidTokenIds: [
|
|
1180
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
1181
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1182
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1183
|
+
permanentlyForbiddenTimes: []
|
|
1184
|
+
})
|
|
1185
|
+
]
|
|
1186
|
+
});
|
|
1187
|
+
const newPerms = makePerms({});
|
|
1188
|
+
const err = permissions_js_1.CollectionPermissionsWithDetails.validateUpdate(oldPerms, newPerms);
|
|
1189
|
+
expect(err).not.toBeNull();
|
|
1190
|
+
});
|
|
1191
|
+
it('should allow adding canUpdateValidTokenIds when previously empty', () => {
|
|
1192
|
+
const oldPerms = makePerms({});
|
|
1193
|
+
const newPerms = makePerms({
|
|
1194
|
+
canUpdateValidTokenIds: [
|
|
1195
|
+
new permissions_js_1.TokenIdsActionPermission({
|
|
1196
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1197
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1198
|
+
permanentlyForbiddenTimes: []
|
|
1199
|
+
})
|
|
1200
|
+
]
|
|
1201
|
+
});
|
|
1202
|
+
const err = permissions_js_1.CollectionPermissionsWithDetails.validateUpdate(oldPerms, newPerms);
|
|
1203
|
+
expect(err).toBeNull();
|
|
1204
|
+
});
|
|
1205
|
+
});
|
|
1206
|
+
});
|
|
1207
|
+
describe('CollectionApprovalPermission - serialization', () => {
|
|
1208
|
+
const makeApprovalBase = (permitted = [], forbidden = []) => new permissions_js_1.CollectionApprovalPermission({
|
|
1209
|
+
fromListId: 'All',
|
|
1210
|
+
toListId: 'All',
|
|
1211
|
+
initiatedByListId: 'All',
|
|
1212
|
+
approvalId: 'All',
|
|
1213
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1214
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1215
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1216
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
1217
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
1218
|
+
});
|
|
1219
|
+
it('should round-trip through proto', () => {
|
|
1220
|
+
const perm = makeApprovalBase([[10n, 50n]]);
|
|
1221
|
+
const proto = perm.toProto();
|
|
1222
|
+
const restored = permissions_js_1.CollectionApprovalPermission.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1223
|
+
expect(restored.fromListId).toBe('All');
|
|
1224
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
1225
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(50n);
|
|
1226
|
+
});
|
|
1227
|
+
it('should round-trip through JSON', () => {
|
|
1228
|
+
const perm = makeApprovalBase([[5n, 100n]]);
|
|
1229
|
+
const jsonVal = perm.toProto().toJson();
|
|
1230
|
+
const restored = permissions_js_1.CollectionApprovalPermission.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
1231
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
1232
|
+
});
|
|
1233
|
+
it('should round-trip through JSON string', () => {
|
|
1234
|
+
const perm = makeApprovalBase([], [[1n, 200n]]);
|
|
1235
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
1236
|
+
const restored = permissions_js_1.CollectionApprovalPermission.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
1237
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
1238
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(200n);
|
|
1239
|
+
});
|
|
1240
|
+
it('should toBech32Addresses without throwing', () => {
|
|
1241
|
+
const perm = makeApprovalBase();
|
|
1242
|
+
expect(() => perm.toBech32Addresses('bb')).not.toThrow();
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
describe('TokenIdsActionPermission - serialization', () => {
|
|
1246
|
+
const makePerm = (permitted = [], forbidden = []) => new permissions_js_1.TokenIdsActionPermission({
|
|
1247
|
+
tokenIds: [{ start: 1n, end: 100n }],
|
|
1248
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
1249
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
1250
|
+
});
|
|
1251
|
+
it('should round-trip through proto', () => {
|
|
1252
|
+
const perm = makePerm([[1n, 50n]]);
|
|
1253
|
+
const proto = perm.toProto();
|
|
1254
|
+
const restored = permissions_js_1.TokenIdsActionPermission.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1255
|
+
expect(restored.tokenIds[0].start).toBe(1n);
|
|
1256
|
+
expect(restored.tokenIds[0].end).toBe(100n);
|
|
1257
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1258
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(50n);
|
|
1259
|
+
});
|
|
1260
|
+
it('should round-trip through JSON', () => {
|
|
1261
|
+
const perm = makePerm([[5n, 80n]]);
|
|
1262
|
+
const jsonVal = perm.toProto().toJson();
|
|
1263
|
+
const restored = permissions_js_1.TokenIdsActionPermission.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
1264
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(80n);
|
|
1265
|
+
});
|
|
1266
|
+
it('should round-trip through JSON string', () => {
|
|
1267
|
+
const perm = makePerm([], [[10n, 20n]]);
|
|
1268
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
1269
|
+
const restored = permissions_js_1.TokenIdsActionPermission.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
1270
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(10n);
|
|
1271
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(20n);
|
|
1272
|
+
});
|
|
1273
|
+
});
|
|
1274
|
+
describe('ActionPermission - serialization', () => {
|
|
1275
|
+
it('should round-trip through proto', () => {
|
|
1276
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
1277
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1278
|
+
permanentlyForbiddenTimes: [{ start: 200n, end: 300n }]
|
|
1279
|
+
});
|
|
1280
|
+
const proto = perm.toProto();
|
|
1281
|
+
const restored = permissions_js_1.ActionPermission.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1282
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1283
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(100n);
|
|
1284
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(200n);
|
|
1285
|
+
});
|
|
1286
|
+
it('should round-trip through JSON', () => {
|
|
1287
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
1288
|
+
permanentlyPermittedTimes: [{ start: 5n, end: 50n }],
|
|
1289
|
+
permanentlyForbiddenTimes: []
|
|
1290
|
+
});
|
|
1291
|
+
const jsonVal = perm.toProto().toJson();
|
|
1292
|
+
const restored = permissions_js_1.ActionPermission.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
1293
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
1294
|
+
});
|
|
1295
|
+
it('should round-trip through JSON string', () => {
|
|
1296
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
1297
|
+
permanentlyPermittedTimes: [],
|
|
1298
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 10n }]
|
|
1299
|
+
});
|
|
1300
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
1301
|
+
const restored = permissions_js_1.ActionPermission.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
1302
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(10n);
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
describe('UserPermissions - serialization', () => {
|
|
1306
|
+
it('should round-trip empty permissions through proto', () => {
|
|
1307
|
+
const perms = permissions_js_1.UserPermissions.InitEmpty();
|
|
1308
|
+
const proto = perms.toProto();
|
|
1309
|
+
const restored = permissions_js_1.UserPermissions.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1310
|
+
expect(restored.canUpdateOutgoingApprovals.length).toBe(0);
|
|
1311
|
+
expect(restored.canUpdateIncomingApprovals.length).toBe(0);
|
|
1312
|
+
});
|
|
1313
|
+
it('should round-trip full UserPermissions with actual data through proto (covers fromProto map bodies)', () => {
|
|
1314
|
+
const perms = new permissions_js_1.UserPermissions({
|
|
1315
|
+
canUpdateOutgoingApprovals: [
|
|
1316
|
+
new permissions_js_1.UserOutgoingApprovalPermission({
|
|
1317
|
+
toListId: 'All',
|
|
1318
|
+
initiatedByListId: 'All',
|
|
1319
|
+
approvalId: 'All',
|
|
1320
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1321
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1322
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1323
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1324
|
+
permanentlyForbiddenTimes: []
|
|
1325
|
+
})
|
|
1326
|
+
],
|
|
1327
|
+
canUpdateIncomingApprovals: [
|
|
1328
|
+
new permissions_js_1.UserIncomingApprovalPermission({
|
|
1329
|
+
fromListId: 'All',
|
|
1330
|
+
initiatedByListId: 'All',
|
|
1331
|
+
approvalId: 'All',
|
|
1332
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1333
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1334
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1335
|
+
permanentlyPermittedTimes: [],
|
|
1336
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
1337
|
+
})
|
|
1338
|
+
],
|
|
1339
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [
|
|
1340
|
+
new permissions_js_1.ActionPermission({
|
|
1341
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1342
|
+
permanentlyForbiddenTimes: []
|
|
1343
|
+
})
|
|
1344
|
+
],
|
|
1345
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [
|
|
1346
|
+
new permissions_js_1.ActionPermission({
|
|
1347
|
+
permanentlyPermittedTimes: [],
|
|
1348
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 10n }]
|
|
1349
|
+
})
|
|
1350
|
+
],
|
|
1351
|
+
canUpdateAutoApproveAllIncomingTransfers: [
|
|
1352
|
+
new permissions_js_1.ActionPermission({
|
|
1353
|
+
permanentlyPermittedTimes: [{ start: 10n, end: 20n }],
|
|
1354
|
+
permanentlyForbiddenTimes: []
|
|
1355
|
+
})
|
|
1356
|
+
]
|
|
1357
|
+
});
|
|
1358
|
+
const proto = perms.toProto();
|
|
1359
|
+
const restored = permissions_js_1.UserPermissions.fromProto(proto, string_numbers_js_1.BigIntify);
|
|
1360
|
+
expect(restored.canUpdateOutgoingApprovals.length).toBe(1);
|
|
1361
|
+
expect(restored.canUpdateOutgoingApprovals[0].permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1362
|
+
expect(restored.canUpdateIncomingApprovals.length).toBe(1);
|
|
1363
|
+
expect(restored.canUpdateIncomingApprovals[0].permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
1364
|
+
expect(restored.canUpdateAutoApproveSelfInitiatedOutgoingTransfers.length).toBe(1);
|
|
1365
|
+
expect(restored.canUpdateAutoApproveSelfInitiatedOutgoingTransfers[0].permanentlyPermittedTimes[0].end).toBe(100n);
|
|
1366
|
+
expect(restored.canUpdateAutoApproveSelfInitiatedIncomingTransfers.length).toBe(1);
|
|
1367
|
+
expect(restored.canUpdateAutoApproveAllIncomingTransfers.length).toBe(1);
|
|
1368
|
+
expect(restored.canUpdateAutoApproveAllIncomingTransfers[0].permanentlyPermittedTimes[0].start).toBe(10n);
|
|
1369
|
+
});
|
|
1370
|
+
it('should round-trip through JSON', () => {
|
|
1371
|
+
const perms = permissions_js_1.UserPermissions.InitEmpty();
|
|
1372
|
+
const jsonVal = perms.toProto().toJson();
|
|
1373
|
+
const restored = permissions_js_1.UserPermissions.fromJson(jsonVal, string_numbers_js_1.BigIntify);
|
|
1374
|
+
expect(restored).toBeTruthy();
|
|
1375
|
+
});
|
|
1376
|
+
it('should round-trip through JSON string', () => {
|
|
1377
|
+
const perms = permissions_js_1.UserPermissions.InitEmpty();
|
|
1378
|
+
const jsonStr = perms.toProto().toJsonString();
|
|
1379
|
+
const restored = permissions_js_1.UserPermissions.fromJsonString(jsonStr, string_numbers_js_1.BigIntify);
|
|
1380
|
+
expect(restored).toBeTruthy();
|
|
1381
|
+
});
|
|
1382
|
+
it('should toBech32Addresses without throwing on empty permissions', () => {
|
|
1383
|
+
const perms = permissions_js_1.UserPermissions.InitEmpty();
|
|
1384
|
+
expect(() => perms.toBech32Addresses('bb')).not.toThrow();
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
describe('UserPermissionsWithDetails - constructor with data', () => {
|
|
1388
|
+
it('should map all arrays when constructed with non-empty data (covers constructor map bodies)', () => {
|
|
1389
|
+
const makeOutgoingWithDetails = () => new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
1390
|
+
toListId: 'All',
|
|
1391
|
+
initiatedByListId: 'All',
|
|
1392
|
+
approvalId: 'All',
|
|
1393
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1394
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1395
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1396
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1397
|
+
permanentlyForbiddenTimes: [],
|
|
1398
|
+
toList: allAddresses(),
|
|
1399
|
+
initiatedByList: allAddresses()
|
|
1400
|
+
});
|
|
1401
|
+
const makeIncomingWithDetails = () => new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
1402
|
+
fromListId: 'All',
|
|
1403
|
+
initiatedByListId: 'All',
|
|
1404
|
+
approvalId: 'All',
|
|
1405
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1406
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1407
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1408
|
+
permanentlyPermittedTimes: [],
|
|
1409
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }],
|
|
1410
|
+
fromList: allAddresses(),
|
|
1411
|
+
initiatedByList: allAddresses()
|
|
1412
|
+
});
|
|
1413
|
+
const perms = new permissions_js_1.UserPermissionsWithDetails({
|
|
1414
|
+
canUpdateOutgoingApprovals: [makeOutgoingWithDetails()],
|
|
1415
|
+
canUpdateIncomingApprovals: [makeIncomingWithDetails()],
|
|
1416
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [
|
|
1417
|
+
new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 1n, end: 100n }], permanentlyForbiddenTimes: [] })
|
|
1418
|
+
],
|
|
1419
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [
|
|
1420
|
+
new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [], permanentlyForbiddenTimes: [{ start: 1n, end: 10n }] })
|
|
1421
|
+
],
|
|
1422
|
+
canUpdateAutoApproveAllIncomingTransfers: [
|
|
1423
|
+
new permissions_js_1.ActionPermission({ permanentlyPermittedTimes: [{ start: 10n, end: 20n }], permanentlyForbiddenTimes: [] })
|
|
1424
|
+
]
|
|
1425
|
+
});
|
|
1426
|
+
expect(perms.canUpdateOutgoingApprovals.length).toBe(1);
|
|
1427
|
+
expect(perms.canUpdateOutgoingApprovals[0].toList).toBeDefined();
|
|
1428
|
+
expect(perms.canUpdateIncomingApprovals.length).toBe(1);
|
|
1429
|
+
expect(perms.canUpdateIncomingApprovals[0].fromList).toBeDefined();
|
|
1430
|
+
expect(perms.canUpdateAutoApproveSelfInitiatedOutgoingTransfers.length).toBe(1);
|
|
1431
|
+
expect(perms.canUpdateAutoApproveSelfInitiatedIncomingTransfers.length).toBe(1);
|
|
1432
|
+
expect(perms.canUpdateAutoApproveAllIncomingTransfers.length).toBe(1);
|
|
1433
|
+
});
|
|
1434
|
+
it('should convert UserPermissionsWithDetails using convert()', () => {
|
|
1435
|
+
const perms = new permissions_js_1.UserPermissionsWithDetails({
|
|
1436
|
+
canUpdateOutgoingApprovals: [
|
|
1437
|
+
new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
1438
|
+
toListId: 'All',
|
|
1439
|
+
initiatedByListId: 'All',
|
|
1440
|
+
approvalId: 'All',
|
|
1441
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1442
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1443
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1444
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1445
|
+
permanentlyForbiddenTimes: [],
|
|
1446
|
+
toList: allAddresses(),
|
|
1447
|
+
initiatedByList: allAddresses()
|
|
1448
|
+
})
|
|
1449
|
+
],
|
|
1450
|
+
canUpdateIncomingApprovals: [],
|
|
1451
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [],
|
|
1452
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [],
|
|
1453
|
+
canUpdateAutoApproveAllIncomingTransfers: []
|
|
1454
|
+
});
|
|
1455
|
+
const converted = perms.convert(string_numbers_js_1.Stringify);
|
|
1456
|
+
expect(converted.canUpdateOutgoingApprovals[0].tokenIds[0].start).toBe('1');
|
|
1457
|
+
});
|
|
1458
|
+
});
|
|
1459
|
+
describe('CollectionApprovalPermissionWithDetails - clone and convert', () => {
|
|
1460
|
+
it('should clone successfully', () => {
|
|
1461
|
+
const perm = new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1462
|
+
fromListId: 'All',
|
|
1463
|
+
toListId: 'All',
|
|
1464
|
+
initiatedByListId: 'All',
|
|
1465
|
+
approvalId: 'All',
|
|
1466
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1467
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1468
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1469
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1470
|
+
permanentlyForbiddenTimes: [],
|
|
1471
|
+
fromList: allAddresses(),
|
|
1472
|
+
toList: allAddresses(),
|
|
1473
|
+
initiatedByList: allAddresses()
|
|
1474
|
+
});
|
|
1475
|
+
const cloned = perm.clone();
|
|
1476
|
+
expect(cloned).toBeTruthy();
|
|
1477
|
+
expect(cloned.fromListId).toBe('All');
|
|
1478
|
+
});
|
|
1479
|
+
it('should convert to string type', () => {
|
|
1480
|
+
const perm = new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1481
|
+
fromListId: 'All',
|
|
1482
|
+
toListId: 'All',
|
|
1483
|
+
initiatedByListId: 'All',
|
|
1484
|
+
approvalId: 'All',
|
|
1485
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1486
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1487
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1488
|
+
permanentlyPermittedTimes: [{ start: 5n, end: 50n }],
|
|
1489
|
+
permanentlyForbiddenTimes: [],
|
|
1490
|
+
fromList: allAddresses(),
|
|
1491
|
+
toList: allAddresses(),
|
|
1492
|
+
initiatedByList: allAddresses()
|
|
1493
|
+
});
|
|
1494
|
+
const converted = perm.convert(string_numbers_js_1.Stringify);
|
|
1495
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('5');
|
|
1496
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1497
|
+
});
|
|
1498
|
+
});
|
|
1499
|
+
describe('UserIncomingApprovalPermissionWithDetails - clone and convert', () => {
|
|
1500
|
+
const makeIncomingWithDetails = () => new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
1501
|
+
fromListId: 'All',
|
|
1502
|
+
initiatedByListId: 'All',
|
|
1503
|
+
approvalId: 'All',
|
|
1504
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1505
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1506
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1507
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1508
|
+
permanentlyForbiddenTimes: [],
|
|
1509
|
+
fromList: allAddresses(),
|
|
1510
|
+
initiatedByList: allAddresses()
|
|
1511
|
+
});
|
|
1512
|
+
it('should clone successfully', () => {
|
|
1513
|
+
const perm = makeIncomingWithDetails();
|
|
1514
|
+
const cloned = perm.clone();
|
|
1515
|
+
expect(cloned).toBeTruthy();
|
|
1516
|
+
expect(cloned.fromListId).toBe('All');
|
|
1517
|
+
expect(cloned.fromList).toBeDefined();
|
|
1518
|
+
});
|
|
1519
|
+
it('should convert to string type', () => {
|
|
1520
|
+
const perm = makeIncomingWithDetails();
|
|
1521
|
+
const converted = perm.convert(string_numbers_js_1.Stringify);
|
|
1522
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1523
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('1');
|
|
1524
|
+
});
|
|
1525
|
+
it('should castToCollectionApprovalPermission with toList set', () => {
|
|
1526
|
+
const perm = makeIncomingWithDetails();
|
|
1527
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1528
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
1529
|
+
expect(casted.toListId).toBe(addr);
|
|
1530
|
+
expect(casted.toList).toBeDefined();
|
|
1531
|
+
});
|
|
1532
|
+
});
|
|
1533
|
+
describe('UserOutgoingApprovalPermissionWithDetails - clone and convert', () => {
|
|
1534
|
+
const makeOutgoingWithDetails = () => new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
1535
|
+
toListId: 'All',
|
|
1536
|
+
initiatedByListId: 'All',
|
|
1537
|
+
approvalId: 'All',
|
|
1538
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1539
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1540
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1541
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1542
|
+
permanentlyForbiddenTimes: [],
|
|
1543
|
+
toList: allAddresses(),
|
|
1544
|
+
initiatedByList: allAddresses()
|
|
1545
|
+
});
|
|
1546
|
+
it('should clone successfully', () => {
|
|
1547
|
+
const perm = makeOutgoingWithDetails();
|
|
1548
|
+
const cloned = perm.clone();
|
|
1549
|
+
expect(cloned).toBeTruthy();
|
|
1550
|
+
expect(cloned.toListId).toBe('All');
|
|
1551
|
+
expect(cloned.toList).toBeDefined();
|
|
1552
|
+
});
|
|
1553
|
+
it('should convert to string type', () => {
|
|
1554
|
+
const perm = makeOutgoingWithDetails();
|
|
1555
|
+
const converted = perm.convert(string_numbers_js_1.Stringify);
|
|
1556
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1557
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('1');
|
|
1558
|
+
});
|
|
1559
|
+
it('should castToCollectionApprovalPermission with fromList set', () => {
|
|
1560
|
+
const perm = makeOutgoingWithDetails();
|
|
1561
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1562
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
1563
|
+
expect(casted.fromListId).toBe(addr);
|
|
1564
|
+
expect(casted.fromList).toBeDefined();
|
|
1565
|
+
});
|
|
1566
|
+
});
|
|
1567
|
+
describe('CollectionApprovalPermission.check - extended error messages', () => {
|
|
1568
|
+
it('should include timeline times in error message when usesLists=true and forbidden', () => {
|
|
1569
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1570
|
+
const perm = new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1571
|
+
fromListId: 'All',
|
|
1572
|
+
toListId: addr,
|
|
1573
|
+
initiatedByListId: 'All',
|
|
1574
|
+
approvalId: 'All',
|
|
1575
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1576
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1577
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1578
|
+
permanentlyPermittedTimes: [],
|
|
1579
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1580
|
+
fromList: allAddresses(),
|
|
1581
|
+
toList: whitelistOf([addr]),
|
|
1582
|
+
initiatedByList: allAddresses()
|
|
1583
|
+
});
|
|
1584
|
+
const err = permissions_js_1.CollectionApprovalPermission.check([
|
|
1585
|
+
{
|
|
1586
|
+
tokenIds: uintRanges_js_1.UintRangeArray.From([{ start: 1n, end: 5n }]),
|
|
1587
|
+
ownershipTimes: fullRange(),
|
|
1588
|
+
transferTimes: fullRange(),
|
|
1589
|
+
toList: whitelistOf([addr]),
|
|
1590
|
+
fromList: allAddresses(),
|
|
1591
|
+
initiatedByList: allAddresses(),
|
|
1592
|
+
approvalIdList: allAddresses()
|
|
1593
|
+
}
|
|
1594
|
+
], [perm], 50n);
|
|
1595
|
+
expect(err).not.toBeNull();
|
|
1596
|
+
expect(err.message).toContain('forbidden');
|
|
1597
|
+
});
|
|
1598
|
+
});
|
|
1599
|
+
describe('validateUniversalPermissionUpdate - multiple missing and combined error', () => {
|
|
1600
|
+
it('should mention count when multiple permissions are missing', () => {
|
|
1601
|
+
const makeSimpleWithDetails = (tokenStart, tokenEnd) => new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1602
|
+
fromListId: 'All',
|
|
1603
|
+
toListId: 'All',
|
|
1604
|
+
initiatedByListId: 'All',
|
|
1605
|
+
approvalId: 'All',
|
|
1606
|
+
transferTimes: [{ start: 1n, end: 1n }],
|
|
1607
|
+
tokenIds: [{ start: tokenStart, end: tokenEnd }],
|
|
1608
|
+
ownershipTimes: [{ start: 1n, end: 1n }],
|
|
1609
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1610
|
+
permanentlyForbiddenTimes: [],
|
|
1611
|
+
fromList: allAddresses(),
|
|
1612
|
+
toList: allAddresses(),
|
|
1613
|
+
initiatedByList: allAddresses()
|
|
1614
|
+
});
|
|
1615
|
+
const oldPerms = [makeSimpleWithDetails(1n, 5n), makeSimpleWithDetails(10n, 15n)];
|
|
1616
|
+
const newPerms = [];
|
|
1617
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1618
|
+
expect(err).not.toBeNull();
|
|
1619
|
+
expect(err.message).toMatch(/along with|found in old/);
|
|
1620
|
+
});
|
|
1621
|
+
it('should produce combined permitted+forbidden error when both are being removed', () => {
|
|
1622
|
+
const makeApprovalWithBoth = (permitted, forbidden) => new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1623
|
+
fromListId: 'All',
|
|
1624
|
+
toListId: 'All',
|
|
1625
|
+
initiatedByListId: 'All',
|
|
1626
|
+
approvalId: 'All',
|
|
1627
|
+
transferTimes: [{ start: 1n, end: 1n }],
|
|
1628
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1629
|
+
ownershipTimes: [{ start: 1n, end: 1n }],
|
|
1630
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
1631
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e })),
|
|
1632
|
+
fromList: allAddresses(),
|
|
1633
|
+
toList: allAddresses(),
|
|
1634
|
+
initiatedByList: allAddresses()
|
|
1635
|
+
});
|
|
1636
|
+
const oldPerms = [makeApprovalWithBoth([[1n, 50n]], [[51n, 100n]])];
|
|
1637
|
+
const newPerms = [makeApprovalWithBoth([], [])];
|
|
1638
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1639
|
+
expect(err).not.toBeNull();
|
|
1640
|
+
expect(err.message).toMatch(/allowed|disApproved/i);
|
|
1641
|
+
});
|
|
1642
|
+
});
|
|
1643
|
+
describe('CollectionPermissionsWithDetails - constructor with canUpdateCollectionApprovals', () => {
|
|
1644
|
+
it('should map canUpdateCollectionApprovals to CollectionApprovalPermissionWithDetails (covers lines 1014-1023)', () => {
|
|
1645
|
+
const perms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
1646
|
+
canDeleteCollection: [],
|
|
1647
|
+
canArchiveCollection: [],
|
|
1648
|
+
canUpdateStandards: [],
|
|
1649
|
+
canUpdateCustomData: [],
|
|
1650
|
+
canUpdateManager: [],
|
|
1651
|
+
canUpdateCollectionMetadata: [],
|
|
1652
|
+
canUpdateValidTokenIds: [],
|
|
1653
|
+
canUpdateTokenMetadata: [],
|
|
1654
|
+
canUpdateCollectionApprovals: [
|
|
1655
|
+
new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1656
|
+
fromListId: 'All',
|
|
1657
|
+
toListId: 'All',
|
|
1658
|
+
initiatedByListId: 'All',
|
|
1659
|
+
approvalId: 'All',
|
|
1660
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1661
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1662
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1663
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1664
|
+
permanentlyForbiddenTimes: [],
|
|
1665
|
+
fromList: allAddresses(),
|
|
1666
|
+
toList: allAddresses(),
|
|
1667
|
+
initiatedByList: allAddresses()
|
|
1668
|
+
})
|
|
1669
|
+
],
|
|
1670
|
+
canAddMoreAliasPaths: [],
|
|
1671
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1672
|
+
});
|
|
1673
|
+
expect(perms.canUpdateCollectionApprovals.length).toBe(1);
|
|
1674
|
+
expect(perms.canUpdateCollectionApprovals[0].fromList).toBeDefined();
|
|
1675
|
+
expect(perms.canUpdateCollectionApprovals[0].permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1676
|
+
});
|
|
1677
|
+
it('should clone CollectionPermissionsWithDetails', () => {
|
|
1678
|
+
const perms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
1679
|
+
canDeleteCollection: [],
|
|
1680
|
+
canArchiveCollection: [],
|
|
1681
|
+
canUpdateStandards: [],
|
|
1682
|
+
canUpdateCustomData: [],
|
|
1683
|
+
canUpdateManager: [],
|
|
1684
|
+
canUpdateCollectionMetadata: [],
|
|
1685
|
+
canUpdateValidTokenIds: [],
|
|
1686
|
+
canUpdateTokenMetadata: [],
|
|
1687
|
+
canUpdateCollectionApprovals: [],
|
|
1688
|
+
canAddMoreAliasPaths: [],
|
|
1689
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1690
|
+
});
|
|
1691
|
+
const cloned = perms.clone();
|
|
1692
|
+
expect(cloned).toBeTruthy();
|
|
1693
|
+
});
|
|
1694
|
+
it('should convert CollectionPermissionsWithDetails (covers line 1019)', () => {
|
|
1695
|
+
const perms = new permissions_js_1.CollectionPermissionsWithDetails({
|
|
1696
|
+
canDeleteCollection: [],
|
|
1697
|
+
canArchiveCollection: [],
|
|
1698
|
+
canUpdateStandards: [],
|
|
1699
|
+
canUpdateCustomData: [],
|
|
1700
|
+
canUpdateManager: [
|
|
1701
|
+
new permissions_js_1.ActionPermission({
|
|
1702
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1703
|
+
permanentlyForbiddenTimes: []
|
|
1704
|
+
})
|
|
1705
|
+
],
|
|
1706
|
+
canUpdateCollectionMetadata: [],
|
|
1707
|
+
canUpdateValidTokenIds: [],
|
|
1708
|
+
canUpdateTokenMetadata: [],
|
|
1709
|
+
canUpdateCollectionApprovals: [
|
|
1710
|
+
new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1711
|
+
fromListId: 'All',
|
|
1712
|
+
toListId: 'All',
|
|
1713
|
+
initiatedByListId: 'All',
|
|
1714
|
+
approvalId: 'All',
|
|
1715
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1716
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1717
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1718
|
+
permanentlyPermittedTimes: [{ start: 5n, end: 50n }],
|
|
1719
|
+
permanentlyForbiddenTimes: [],
|
|
1720
|
+
fromList: allAddresses(),
|
|
1721
|
+
toList: allAddresses(),
|
|
1722
|
+
initiatedByList: allAddresses()
|
|
1723
|
+
})
|
|
1724
|
+
],
|
|
1725
|
+
canAddMoreAliasPaths: [],
|
|
1726
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1727
|
+
});
|
|
1728
|
+
const converted = perms.convert(string_numbers_js_1.Stringify);
|
|
1729
|
+
expect(converted.canUpdateManager[0].permanentlyPermittedTimes[0].start).toBe('1');
|
|
1730
|
+
expect(converted.canUpdateCollectionApprovals[0].permanentlyPermittedTimes[0].start).toBe('5');
|
|
1731
|
+
});
|
|
1732
|
+
});
|
|
1733
|
+
describe('getPermissionString branches - whitelist and address listing', () => {
|
|
1734
|
+
it('should produce error message with whitelist address info when whitelist=true', () => {
|
|
1735
|
+
const addr1 = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1736
|
+
const addr2 = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1737
|
+
const makeWithWhitelist = () => new permissions_js_1.CollectionApprovalPermissionWithDetails({
|
|
1738
|
+
fromListId: 'All',
|
|
1739
|
+
toListId: 'whitelist-test',
|
|
1740
|
+
initiatedByListId: 'All',
|
|
1741
|
+
approvalId: 'All',
|
|
1742
|
+
transferTimes: [{ start: 1n, end: 1n }],
|
|
1743
|
+
tokenIds: [{ start: 1n, end: 5n }],
|
|
1744
|
+
ownershipTimes: [{ start: 1n, end: 1n }],
|
|
1745
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1746
|
+
permanentlyForbiddenTimes: [],
|
|
1747
|
+
fromList: whitelistOf([addr1, addr2]),
|
|
1748
|
+
toList: whitelistOf([addr1, addr2]),
|
|
1749
|
+
initiatedByList: whitelistOf([addr1, addr2])
|
|
1750
|
+
});
|
|
1751
|
+
const oldPerms = [makeWithWhitelist()];
|
|
1752
|
+
const newPerms = [];
|
|
1753
|
+
const err = permissions_js_1.CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1754
|
+
expect(err).not.toBeNull();
|
|
1755
|
+
expect(err.message).toContain('found in old permissions');
|
|
1756
|
+
});
|
|
1757
|
+
});
|
|
1758
|
+
describe('UserOutgoingApprovalPermission', () => {
|
|
1759
|
+
const makeOutgoingPerm = (opts) => {
|
|
1760
|
+
return new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({
|
|
1761
|
+
toListId: 'All',
|
|
1762
|
+
initiatedByListId: 'All',
|
|
1763
|
+
approvalId: 'All',
|
|
1764
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1765
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1766
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1767
|
+
permanentlyPermittedTimes: (opts.permitted || []).map(([s, e]) => ({ start: s, end: e })),
|
|
1768
|
+
permanentlyForbiddenTimes: (opts.forbidden || []).map(([s, e]) => ({ start: s, end: e })),
|
|
1769
|
+
toList: allAddresses(),
|
|
1770
|
+
initiatedByList: allAddresses()
|
|
1771
|
+
});
|
|
1772
|
+
};
|
|
1773
|
+
describe('construction', () => {
|
|
1774
|
+
it('should create an instance', () => {
|
|
1775
|
+
const perm = makeOutgoingPerm({ permitted: [[1n, 100n]] });
|
|
1776
|
+
expect(perm).toBeTruthy();
|
|
1777
|
+
expect(perm.toListId).toBe('All');
|
|
1778
|
+
expect(perm.initiatedByListId).toBe('All');
|
|
1779
|
+
});
|
|
1780
|
+
});
|
|
1781
|
+
describe('castToCollectionApprovalPermission', () => {
|
|
1782
|
+
it('should cast with a valid address for from field', () => {
|
|
1783
|
+
const perm = makeOutgoingPerm({});
|
|
1784
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1785
|
+
const castedPerm = perm.castToCollectionApprovalPermission(addr);
|
|
1786
|
+
expect(castedPerm).toBeTruthy();
|
|
1787
|
+
expect(castedPerm.fromListId).toBe(addr);
|
|
1788
|
+
});
|
|
1789
|
+
it('should throw when using invalid dummy address "0x"', () => {
|
|
1790
|
+
const perm = makeOutgoingPerm({});
|
|
1791
|
+
expect(() => perm.castToCollectionApprovalPermission('0x')).toThrow('Invalid address list ID');
|
|
1792
|
+
});
|
|
1793
|
+
});
|
|
1794
|
+
describe('validateUpdate', () => {
|
|
1795
|
+
it('should allow identical outgoing approval permissions', () => {
|
|
1796
|
+
const perms = [makeOutgoingPerm({ permitted: [[1n, 100n]] })];
|
|
1797
|
+
const result = permissions_js_1.UserOutgoingApprovalPermission.validateUpdate(perms, perms);
|
|
1798
|
+
expect(result).toBeNull();
|
|
1799
|
+
});
|
|
1800
|
+
it('should reject shrinking permitted times', () => {
|
|
1801
|
+
const oldPerms = [makeOutgoingPerm({ permitted: [[1n, 100n]] })];
|
|
1802
|
+
const newPerms = [makeOutgoingPerm({ permitted: [[1n, 50n]] })];
|
|
1803
|
+
const result = permissions_js_1.UserOutgoingApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1804
|
+
expect(result).not.toBeNull();
|
|
1805
|
+
});
|
|
1806
|
+
});
|
|
1807
|
+
});
|
|
1808
|
+
describe('UserIncomingApprovalPermission', () => {
|
|
1809
|
+
const makeIncomingPerm = (opts) => {
|
|
1810
|
+
return new permissions_js_1.UserIncomingApprovalPermissionWithDetails({
|
|
1811
|
+
fromListId: 'All',
|
|
1812
|
+
initiatedByListId: 'All',
|
|
1813
|
+
approvalId: 'All',
|
|
1814
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1815
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1816
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1817
|
+
permanentlyPermittedTimes: (opts.permitted || []).map(([s, e]) => ({ start: s, end: e })),
|
|
1818
|
+
permanentlyForbiddenTimes: (opts.forbidden || []).map(([s, e]) => ({ start: s, end: e })),
|
|
1819
|
+
fromList: allAddresses(),
|
|
1820
|
+
initiatedByList: allAddresses()
|
|
1821
|
+
});
|
|
1822
|
+
};
|
|
1823
|
+
describe('construction', () => {
|
|
1824
|
+
it('should create an instance', () => {
|
|
1825
|
+
const perm = makeIncomingPerm({ permitted: [[1n, 100n]] });
|
|
1826
|
+
expect(perm).toBeTruthy();
|
|
1827
|
+
expect(perm.fromListId).toBe('All');
|
|
1828
|
+
});
|
|
1829
|
+
});
|
|
1830
|
+
describe('castToCollectionApprovalPermission', () => {
|
|
1831
|
+
it('should cast with a valid address for to field', () => {
|
|
1832
|
+
const perm = makeIncomingPerm({});
|
|
1833
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1834
|
+
const castedPerm = perm.castToCollectionApprovalPermission(addr);
|
|
1835
|
+
expect(castedPerm).toBeTruthy();
|
|
1836
|
+
expect(castedPerm.toListId).toBe(addr);
|
|
1837
|
+
});
|
|
1838
|
+
it('should throw when using invalid dummy address "0x"', () => {
|
|
1839
|
+
const perm = makeIncomingPerm({});
|
|
1840
|
+
expect(() => perm.castToCollectionApprovalPermission('0x')).toThrow('Invalid address list ID');
|
|
1841
|
+
});
|
|
1842
|
+
});
|
|
1843
|
+
describe('validateUpdate', () => {
|
|
1844
|
+
it('should allow identical incoming approval permissions', () => {
|
|
1845
|
+
const perms = [makeIncomingPerm({ permitted: [[1n, 100n]] })];
|
|
1846
|
+
const result = permissions_js_1.UserIncomingApprovalPermission.validateUpdate(perms, perms);
|
|
1847
|
+
expect(result).toBeNull();
|
|
1848
|
+
});
|
|
1849
|
+
it('should reject changing permitted to forbidden', () => {
|
|
1850
|
+
const oldPerms = [makeIncomingPerm({ permitted: [[1n, 100n]] })];
|
|
1851
|
+
const newPerms = [makeIncomingPerm({ forbidden: [[1n, 100n]] })];
|
|
1852
|
+
const result = permissions_js_1.UserIncomingApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1853
|
+
expect(result).not.toBeNull();
|
|
1854
|
+
});
|
|
1855
|
+
it('should allow extending forbidden times', () => {
|
|
1856
|
+
const oldPerms = [makeIncomingPerm({ forbidden: [[1n, 50n]] })];
|
|
1857
|
+
const newPerms = [makeIncomingPerm({ forbidden: [[1n, 100n]] })];
|
|
1858
|
+
const result = permissions_js_1.UserIncomingApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1859
|
+
expect(result).toBeNull();
|
|
1860
|
+
});
|
|
1861
|
+
});
|
|
1862
|
+
});
|
|
1863
|
+
describe('Permissions edge cases', () => {
|
|
1864
|
+
describe('Multiple permissions - first match only semantics', () => {
|
|
1865
|
+
it('should use first match when multiple action permissions overlap', () => {
|
|
1866
|
+
const perms = [
|
|
1867
|
+
new permissions_js_1.ActionPermission({
|
|
1868
|
+
permanentlyPermittedTimes: [],
|
|
1869
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
1870
|
+
}),
|
|
1871
|
+
new permissions_js_1.ActionPermission({
|
|
1872
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1873
|
+
permanentlyForbiddenTimes: []
|
|
1874
|
+
})
|
|
1875
|
+
];
|
|
1876
|
+
const err1 = permissions_js_1.ActionPermission.check(perms, 25n);
|
|
1877
|
+
expect(err1).not.toBeNull();
|
|
1878
|
+
const err2 = permissions_js_1.ActionPermission.check(perms, 75n);
|
|
1879
|
+
expect(err2).toBeNull();
|
|
1880
|
+
});
|
|
1881
|
+
});
|
|
1882
|
+
describe('convert method', () => {
|
|
1883
|
+
it('should convert ActionPermission number types', () => {
|
|
1884
|
+
const perm = new permissions_js_1.ActionPermission({
|
|
1885
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1886
|
+
permanentlyForbiddenTimes: []
|
|
1887
|
+
});
|
|
1888
|
+
const converted = perm.convert((val) => val.toString());
|
|
1889
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('1');
|
|
1890
|
+
expect(converted.permanentlyPermittedTimes[0].end).toBe('100');
|
|
1891
|
+
});
|
|
1892
|
+
it('should convert TokenIdsActionPermission number types', () => {
|
|
1893
|
+
const perm = new permissions_js_1.TokenIdsActionPermission({
|
|
1894
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1895
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1896
|
+
permanentlyForbiddenTimes: []
|
|
1897
|
+
});
|
|
1898
|
+
const converted = perm.convert((val) => val.toString());
|
|
1899
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1900
|
+
expect(converted.tokenIds[0].end).toBe('10');
|
|
1901
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('1');
|
|
1902
|
+
});
|
|
1903
|
+
it('should convert CollectionPermissions number types', () => {
|
|
1904
|
+
const perms = new permissions_js_1.CollectionPermissions({
|
|
1905
|
+
canDeleteCollection: [
|
|
1906
|
+
new permissions_js_1.ActionPermission({
|
|
1907
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1908
|
+
permanentlyForbiddenTimes: []
|
|
1909
|
+
})
|
|
1910
|
+
],
|
|
1911
|
+
canArchiveCollection: [],
|
|
1912
|
+
canUpdateStandards: [],
|
|
1913
|
+
canUpdateCustomData: [],
|
|
1914
|
+
canUpdateManager: [],
|
|
1915
|
+
canUpdateCollectionMetadata: [],
|
|
1916
|
+
canUpdateValidTokenIds: [],
|
|
1917
|
+
canUpdateTokenMetadata: [],
|
|
1918
|
+
canUpdateCollectionApprovals: [],
|
|
1919
|
+
canAddMoreAliasPaths: [],
|
|
1920
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1921
|
+
});
|
|
1922
|
+
const converted = perms.convert((val) => val.toString());
|
|
1923
|
+
expect(converted.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe('1');
|
|
1924
|
+
});
|
|
1925
|
+
});
|
|
1926
|
+
describe('toBech32Addresses', () => {
|
|
1927
|
+
it('should convert UserOutgoingApprovalPermission list IDs to bech32', () => {
|
|
1928
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1929
|
+
const perm = new permissions_js_1.UserOutgoingApprovalPermission({
|
|
1930
|
+
toListId: addr,
|
|
1931
|
+
initiatedByListId: 'All',
|
|
1932
|
+
approvalId: 'test',
|
|
1933
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1934
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1935
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1936
|
+
permanentlyPermittedTimes: [],
|
|
1937
|
+
permanentlyForbiddenTimes: []
|
|
1938
|
+
});
|
|
1939
|
+
const converted = perm.toBech32Addresses('bb');
|
|
1940
|
+
expect(converted).toBeTruthy();
|
|
1941
|
+
expect(typeof converted.toListId).toBe('string');
|
|
1942
|
+
});
|
|
1943
|
+
it('should convert UserIncomingApprovalPermission list IDs to bech32', () => {
|
|
1944
|
+
const addr = (0, addressLists_spec_js_1.genTestAddress)();
|
|
1945
|
+
const perm = new permissions_js_1.UserIncomingApprovalPermission({
|
|
1946
|
+
fromListId: addr,
|
|
1947
|
+
initiatedByListId: 'All',
|
|
1948
|
+
approvalId: 'test',
|
|
1949
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1950
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1951
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1952
|
+
permanentlyPermittedTimes: [],
|
|
1953
|
+
permanentlyForbiddenTimes: []
|
|
1954
|
+
});
|
|
1955
|
+
const converted = perm.toBech32Addresses('bb');
|
|
1956
|
+
expect(converted).toBeTruthy();
|
|
1957
|
+
expect(typeof converted.fromListId).toBe('string');
|
|
1958
|
+
});
|
|
1959
|
+
});
|
|
1960
|
+
describe('Frozen permissions (all-time forbidden)', () => {
|
|
1961
|
+
it('should permanently freeze an action by forbidding all times', () => {
|
|
1962
|
+
const perms = [
|
|
1963
|
+
new permissions_js_1.ActionPermission({
|
|
1964
|
+
permanentlyPermittedTimes: [],
|
|
1965
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
1966
|
+
})
|
|
1967
|
+
];
|
|
1968
|
+
for (const time of [1n, 100n, 1000000n, 18446744073709551615n]) {
|
|
1969
|
+
const err = permissions_js_1.ActionPermission.check(perms, time);
|
|
1970
|
+
expect(err).not.toBeNull();
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1973
|
+
it('should not be possible to unfreeze a permanently frozen permission', () => {
|
|
1974
|
+
const frozenPerms = [
|
|
1975
|
+
new permissions_js_1.ActionPermission({
|
|
1976
|
+
permanentlyPermittedTimes: [],
|
|
1977
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
1978
|
+
})
|
|
1979
|
+
];
|
|
1980
|
+
const unfrozenPerms = [
|
|
1981
|
+
new permissions_js_1.ActionPermission({
|
|
1982
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1983
|
+
permanentlyForbiddenTimes: []
|
|
1984
|
+
})
|
|
1985
|
+
];
|
|
1986
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(frozenPerms, unfrozenPerms);
|
|
1987
|
+
expect(err).not.toBeNull();
|
|
1988
|
+
});
|
|
1989
|
+
it('should not be possible to remove forbidden times from a frozen permission', () => {
|
|
1990
|
+
const frozenPerms = [
|
|
1991
|
+
new permissions_js_1.ActionPermission({
|
|
1992
|
+
permanentlyPermittedTimes: [],
|
|
1993
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
1994
|
+
})
|
|
1995
|
+
];
|
|
1996
|
+
const partiallyUnfrozenPerms = [
|
|
1997
|
+
new permissions_js_1.ActionPermission({
|
|
1998
|
+
permanentlyPermittedTimes: [],
|
|
1999
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 100n }]
|
|
2000
|
+
})
|
|
2001
|
+
];
|
|
2002
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(frozenPerms, partiallyUnfrozenPerms);
|
|
2003
|
+
expect(err).not.toBeNull();
|
|
2004
|
+
});
|
|
2005
|
+
});
|
|
2006
|
+
describe('Permanently permitted permissions (all-time permitted)', () => {
|
|
2007
|
+
it('should permanently allow an action by permitting all times', () => {
|
|
2008
|
+
const perms = [
|
|
2009
|
+
new permissions_js_1.ActionPermission({
|
|
2010
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
2011
|
+
permanentlyForbiddenTimes: []
|
|
2012
|
+
})
|
|
2013
|
+
];
|
|
2014
|
+
for (const time of [1n, 100n, 1000000n]) {
|
|
2015
|
+
const err = permissions_js_1.ActionPermission.check(perms, time);
|
|
2016
|
+
expect(err).toBeNull();
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
it('should not be possible to revoke a permanently permitted permission', () => {
|
|
2020
|
+
const permittedPerms = [
|
|
2021
|
+
new permissions_js_1.ActionPermission({
|
|
2022
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
2023
|
+
permanentlyForbiddenTimes: []
|
|
2024
|
+
})
|
|
2025
|
+
];
|
|
2026
|
+
const revokedPerms = [
|
|
2027
|
+
new permissions_js_1.ActionPermission({
|
|
2028
|
+
permanentlyPermittedTimes: [],
|
|
2029
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }]
|
|
2030
|
+
})
|
|
2031
|
+
];
|
|
2032
|
+
const err = permissions_js_1.ActionPermission.validateUpdate(permittedPerms, revokedPerms);
|
|
2033
|
+
expect(err).not.toBeNull();
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
describe('Mixed permitted and forbidden times', () => {
|
|
2037
|
+
it('should handle non-overlapping permitted and forbidden time ranges', () => {
|
|
2038
|
+
const perms = [
|
|
2039
|
+
new permissions_js_1.ActionPermission({
|
|
2040
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
2041
|
+
permanentlyForbiddenTimes: [{ start: 101n, end: 200n }]
|
|
2042
|
+
})
|
|
2043
|
+
];
|
|
2044
|
+
const err1 = permissions_js_1.ActionPermission.check(perms, 50n);
|
|
2045
|
+
expect(err1).toBeNull();
|
|
2046
|
+
const err2 = permissions_js_1.ActionPermission.check(perms, 150n);
|
|
2047
|
+
expect(err2).not.toBeNull();
|
|
2048
|
+
});
|
|
2049
|
+
});
|
|
2050
|
+
});
|
|
2051
|
+
//# sourceMappingURL=permissions.spec.js.map
|