bitbadgesjs-sdk 0.31.1 → 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.spec.js +1069 -0
- package/dist/cjs/core/permissions.spec.js.map +1 -1
- package/dist/cjs/core/transfers.spec.js +524 -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.spec.js +1069 -0
- package/dist/esm/core/permissions.spec.js.map +1 -1
- package/dist/esm/core/transfers.spec.js +525 -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
|
@@ -2,6 +2,7 @@ import { genTestAddress } from './addressLists.spec.js';
|
|
|
2
2
|
import { AddressList } from './addressLists.js';
|
|
3
3
|
import { ActionPermission, TokenIdsActionPermission, CollectionApprovalPermission, CollectionApprovalPermissionWithDetails, CollectionPermissions, CollectionPermissionsWithDetails, UserPermissions, UserPermissionsWithDetails, UserOutgoingApprovalPermission, UserOutgoingApprovalPermissionWithDetails, UserIncomingApprovalPermission, UserIncomingApprovalPermissionWithDetails } from './permissions.js';
|
|
4
4
|
import { UintRangeArray } from './uintRanges.js';
|
|
5
|
+
import { BigIntify, Stringify } from '../common/string-numbers.js';
|
|
5
6
|
BigInt.prototype.toJSON = function () {
|
|
6
7
|
return this.toString();
|
|
7
8
|
};
|
|
@@ -684,6 +685,1074 @@ describe('CollectionPermissions', () => {
|
|
|
684
685
|
});
|
|
685
686
|
});
|
|
686
687
|
});
|
|
688
|
+
describe('UserOutgoingApprovalPermission', () => {
|
|
689
|
+
const makeOutgoing = (permitted = [], forbidden = []) => new UserOutgoingApprovalPermission({
|
|
690
|
+
toListId: 'All',
|
|
691
|
+
initiatedByListId: 'All',
|
|
692
|
+
approvalId: 'All',
|
|
693
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
694
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
695
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
696
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
697
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
698
|
+
});
|
|
699
|
+
describe('construction', () => {
|
|
700
|
+
it('should create with all required fields', () => {
|
|
701
|
+
const perm = makeOutgoing([[1n, 100n]]);
|
|
702
|
+
expect(perm).toBeTruthy();
|
|
703
|
+
expect(perm.toListId).toBe('All');
|
|
704
|
+
expect(perm.initiatedByListId).toBe('All');
|
|
705
|
+
expect(perm.approvalId).toBe('All');
|
|
706
|
+
expect(perm.transferTimes.length).toBe(1);
|
|
707
|
+
expect(perm.tokenIds.length).toBe(1);
|
|
708
|
+
expect(perm.ownershipTimes.length).toBe(1);
|
|
709
|
+
expect(perm.permanentlyPermittedTimes.length).toBe(1);
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
describe('convert', () => {
|
|
713
|
+
it('should convert number type to string', () => {
|
|
714
|
+
const perm = makeOutgoing([[1n, 50n]]);
|
|
715
|
+
const stringified = perm.convert(Stringify);
|
|
716
|
+
expect(stringified.tokenIds[0].start).toBe('1');
|
|
717
|
+
expect(stringified.tokenIds[0].end).toBe('18446744073709551615');
|
|
718
|
+
expect(stringified.permanentlyPermittedTimes[0].start).toBe('1');
|
|
719
|
+
expect(stringified.permanentlyPermittedTimes[0].end).toBe('50');
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
describe('toProto / fromProto', () => {
|
|
723
|
+
it('should round-trip through proto', () => {
|
|
724
|
+
const perm = makeOutgoing([[10n, 200n]]);
|
|
725
|
+
const proto = perm.toProto();
|
|
726
|
+
expect(proto).toBeTruthy();
|
|
727
|
+
const restored = UserOutgoingApprovalPermission.fromProto(proto, BigIntify);
|
|
728
|
+
expect(restored.toListId).toBe('All');
|
|
729
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
730
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(200n);
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
describe('fromJson / fromJsonString', () => {
|
|
734
|
+
it('should round-trip through JSON', () => {
|
|
735
|
+
const perm = makeOutgoing([[5n, 50n]]);
|
|
736
|
+
const jsonVal = perm.toProto().toJson();
|
|
737
|
+
const restored = UserOutgoingApprovalPermission.fromJson(jsonVal, BigIntify);
|
|
738
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
739
|
+
});
|
|
740
|
+
it('should round-trip through JSON string', () => {
|
|
741
|
+
const perm = makeOutgoing([], [[1n, 100n]]);
|
|
742
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
743
|
+
const restored = UserOutgoingApprovalPermission.fromJsonString(jsonStr, BigIntify);
|
|
744
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
745
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(100n);
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
describe('castToCollectionApprovalPermission', () => {
|
|
749
|
+
it('should cast to CollectionApprovalPermission with given fromListId', () => {
|
|
750
|
+
const perm = makeOutgoing([[1n, 100n]]);
|
|
751
|
+
const addr = genTestAddress();
|
|
752
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
753
|
+
expect(casted.fromListId).toBe(addr);
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
describe('toBech32Addresses', () => {
|
|
757
|
+
it('should convert listIds to bech32', () => {
|
|
758
|
+
const perm = makeOutgoing();
|
|
759
|
+
expect(() => perm.toBech32Addresses('bb')).not.toThrow();
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
describe('validateUpdate', () => {
|
|
763
|
+
it('should allow identical outgoing permissions', () => {
|
|
764
|
+
const makeWithDetails = (permitted) => new UserOutgoingApprovalPermissionWithDetails({
|
|
765
|
+
toListId: 'All',
|
|
766
|
+
initiatedByListId: 'All',
|
|
767
|
+
approvalId: 'All',
|
|
768
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
769
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
770
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
771
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
772
|
+
permanentlyForbiddenTimes: [],
|
|
773
|
+
toList: allAddresses(),
|
|
774
|
+
initiatedByList: allAddresses()
|
|
775
|
+
});
|
|
776
|
+
const perms = [makeWithDetails([[1n, 100n]])];
|
|
777
|
+
const err = UserOutgoingApprovalPermission.validateUpdate(perms, perms);
|
|
778
|
+
expect(err).toBeNull();
|
|
779
|
+
});
|
|
780
|
+
it('should reject removing outgoing permission', () => {
|
|
781
|
+
const makeWithDetails = () => new UserOutgoingApprovalPermissionWithDetails({
|
|
782
|
+
toListId: 'All',
|
|
783
|
+
initiatedByListId: 'All',
|
|
784
|
+
approvalId: 'All',
|
|
785
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
786
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
787
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
788
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
789
|
+
permanentlyForbiddenTimes: [],
|
|
790
|
+
toList: allAddresses(),
|
|
791
|
+
initiatedByList: allAddresses()
|
|
792
|
+
});
|
|
793
|
+
const err = UserOutgoingApprovalPermission.validateUpdate([makeWithDetails()], []);
|
|
794
|
+
expect(err).not.toBeNull();
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
describe('check', () => {
|
|
798
|
+
it('should return null when outgoing approval is permitted', () => {
|
|
799
|
+
const perm = new UserOutgoingApprovalPermissionWithDetails({
|
|
800
|
+
toListId: 'All',
|
|
801
|
+
initiatedByListId: 'All',
|
|
802
|
+
approvalId: 'All',
|
|
803
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
804
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
805
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
806
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
807
|
+
permanentlyForbiddenTimes: [],
|
|
808
|
+
toList: allAddresses(),
|
|
809
|
+
initiatedByList: allAddresses()
|
|
810
|
+
});
|
|
811
|
+
const err = UserOutgoingApprovalPermission.check([
|
|
812
|
+
{
|
|
813
|
+
tokenIds: UintRangeArray.From([{ start: 1n, end: 5n }]),
|
|
814
|
+
ownershipTimes: fullRange(),
|
|
815
|
+
transferTimes: fullRange(),
|
|
816
|
+
toList: allAddresses(),
|
|
817
|
+
fromList: allAddresses(),
|
|
818
|
+
initiatedByList: allAddresses(),
|
|
819
|
+
approvalIdList: allAddresses(),
|
|
820
|
+
amountTrackerIdList: allAddresses(),
|
|
821
|
+
challengeTrackerIdList: allAddresses()
|
|
822
|
+
}
|
|
823
|
+
], [perm], 50n);
|
|
824
|
+
expect(err).toBeNull();
|
|
825
|
+
});
|
|
826
|
+
it('should return error when outgoing approval is forbidden', () => {
|
|
827
|
+
const perm = new UserOutgoingApprovalPermissionWithDetails({
|
|
828
|
+
toListId: 'All',
|
|
829
|
+
initiatedByListId: 'All',
|
|
830
|
+
approvalId: 'All',
|
|
831
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
832
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
833
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
834
|
+
permanentlyPermittedTimes: [],
|
|
835
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
836
|
+
toList: allAddresses(),
|
|
837
|
+
initiatedByList: allAddresses()
|
|
838
|
+
});
|
|
839
|
+
const err = UserOutgoingApprovalPermission.check([
|
|
840
|
+
{
|
|
841
|
+
tokenIds: UintRangeArray.From([{ start: 1n, end: 5n }]),
|
|
842
|
+
ownershipTimes: fullRange(),
|
|
843
|
+
transferTimes: fullRange(),
|
|
844
|
+
toList: allAddresses(),
|
|
845
|
+
fromList: allAddresses(),
|
|
846
|
+
initiatedByList: allAddresses(),
|
|
847
|
+
approvalIdList: allAddresses(),
|
|
848
|
+
amountTrackerIdList: allAddresses(),
|
|
849
|
+
challengeTrackerIdList: allAddresses()
|
|
850
|
+
}
|
|
851
|
+
], [perm], 50n);
|
|
852
|
+
expect(err).not.toBeNull();
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
describe('UserIncomingApprovalPermission', () => {
|
|
857
|
+
const makeIncoming = (permitted = [], forbidden = []) => new UserIncomingApprovalPermission({
|
|
858
|
+
fromListId: 'All',
|
|
859
|
+
initiatedByListId: 'All',
|
|
860
|
+
approvalId: 'All',
|
|
861
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
862
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
863
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
864
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
865
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
866
|
+
});
|
|
867
|
+
describe('construction', () => {
|
|
868
|
+
it('should create with all required fields', () => {
|
|
869
|
+
const perm = makeIncoming([[1n, 100n]]);
|
|
870
|
+
expect(perm).toBeTruthy();
|
|
871
|
+
expect(perm.fromListId).toBe('All');
|
|
872
|
+
expect(perm.initiatedByListId).toBe('All');
|
|
873
|
+
expect(perm.approvalId).toBe('All');
|
|
874
|
+
expect(perm.permanentlyPermittedTimes.length).toBe(1);
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
describe('convert', () => {
|
|
878
|
+
it('should convert to string type', () => {
|
|
879
|
+
const perm = makeIncoming([[1n, 50n]]);
|
|
880
|
+
const stringified = perm.convert(Stringify);
|
|
881
|
+
expect(stringified.tokenIds[0].start).toBe('1');
|
|
882
|
+
expect(stringified.permanentlyPermittedTimes[0].end).toBe('50');
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
describe('toProto / fromProto', () => {
|
|
886
|
+
it('should round-trip through proto', () => {
|
|
887
|
+
const perm = makeIncoming([[10n, 200n]]);
|
|
888
|
+
const proto = perm.toProto();
|
|
889
|
+
const restored = UserIncomingApprovalPermission.fromProto(proto, BigIntify);
|
|
890
|
+
expect(restored.fromListId).toBe('All');
|
|
891
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
892
|
+
});
|
|
893
|
+
});
|
|
894
|
+
describe('fromJson / fromJsonString', () => {
|
|
895
|
+
it('should round-trip through JSON', () => {
|
|
896
|
+
const perm = makeIncoming([[5n, 50n]]);
|
|
897
|
+
const jsonVal = perm.toProto().toJson();
|
|
898
|
+
const restored = UserIncomingApprovalPermission.fromJson(jsonVal, BigIntify);
|
|
899
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
900
|
+
});
|
|
901
|
+
it('should round-trip through JSON string', () => {
|
|
902
|
+
const perm = makeIncoming([], [[1n, 100n]]);
|
|
903
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
904
|
+
const restored = UserIncomingApprovalPermission.fromJsonString(jsonStr, BigIntify);
|
|
905
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
906
|
+
});
|
|
907
|
+
});
|
|
908
|
+
describe('castToCollectionApprovalPermission', () => {
|
|
909
|
+
it('should cast to CollectionApprovalPermission with given toListId', () => {
|
|
910
|
+
const perm = makeIncoming([[1n, 100n]]);
|
|
911
|
+
const addr = genTestAddress();
|
|
912
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
913
|
+
expect(casted.toListId).toBe(addr);
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
describe('toBech32Addresses', () => {
|
|
917
|
+
it('should not throw when converting reserved list IDs', () => {
|
|
918
|
+
const perm = makeIncoming();
|
|
919
|
+
expect(() => perm.toBech32Addresses('bb')).not.toThrow();
|
|
920
|
+
});
|
|
921
|
+
});
|
|
922
|
+
describe('validateUpdate', () => {
|
|
923
|
+
it('should allow identical incoming permissions', () => {
|
|
924
|
+
const makeWithDetails = () => new UserIncomingApprovalPermissionWithDetails({
|
|
925
|
+
fromListId: 'All',
|
|
926
|
+
initiatedByListId: 'All',
|
|
927
|
+
approvalId: 'All',
|
|
928
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
929
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
930
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
931
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
932
|
+
permanentlyForbiddenTimes: [],
|
|
933
|
+
fromList: allAddresses(),
|
|
934
|
+
initiatedByList: allAddresses()
|
|
935
|
+
});
|
|
936
|
+
const perms = [makeWithDetails()];
|
|
937
|
+
const err = UserIncomingApprovalPermission.validateUpdate(perms, perms);
|
|
938
|
+
expect(err).toBeNull();
|
|
939
|
+
});
|
|
940
|
+
it('should reject removing incoming permission', () => {
|
|
941
|
+
const makeWithDetails = () => new UserIncomingApprovalPermissionWithDetails({
|
|
942
|
+
fromListId: 'All',
|
|
943
|
+
initiatedByListId: 'All',
|
|
944
|
+
approvalId: 'All',
|
|
945
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
946
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
947
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
948
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
949
|
+
permanentlyForbiddenTimes: [],
|
|
950
|
+
fromList: allAddresses(),
|
|
951
|
+
initiatedByList: allAddresses()
|
|
952
|
+
});
|
|
953
|
+
const err = UserIncomingApprovalPermission.validateUpdate([makeWithDetails()], []);
|
|
954
|
+
expect(err).not.toBeNull();
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
describe('check', () => {
|
|
958
|
+
it('should return null when incoming approval is permitted', () => {
|
|
959
|
+
const perm = new UserIncomingApprovalPermissionWithDetails({
|
|
960
|
+
fromListId: 'All',
|
|
961
|
+
initiatedByListId: 'All',
|
|
962
|
+
approvalId: 'All',
|
|
963
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
964
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
965
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
966
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
967
|
+
permanentlyForbiddenTimes: [],
|
|
968
|
+
fromList: allAddresses(),
|
|
969
|
+
initiatedByList: allAddresses()
|
|
970
|
+
});
|
|
971
|
+
const err = UserIncomingApprovalPermission.check([
|
|
972
|
+
{
|
|
973
|
+
tokenIds: fullRange(),
|
|
974
|
+
ownershipTimes: fullRange(),
|
|
975
|
+
transferTimes: fullRange(),
|
|
976
|
+
toList: allAddresses(),
|
|
977
|
+
fromList: allAddresses(),
|
|
978
|
+
initiatedByList: allAddresses(),
|
|
979
|
+
approvalIdList: allAddresses(),
|
|
980
|
+
amountTrackerIdList: allAddresses(),
|
|
981
|
+
challengeTrackerIdList: allAddresses()
|
|
982
|
+
}
|
|
983
|
+
], [perm], 50n);
|
|
984
|
+
expect(err).toBeNull();
|
|
985
|
+
});
|
|
986
|
+
it('should return error when incoming approval is forbidden', () => {
|
|
987
|
+
const perm = new UserIncomingApprovalPermissionWithDetails({
|
|
988
|
+
fromListId: 'All',
|
|
989
|
+
initiatedByListId: 'All',
|
|
990
|
+
approvalId: 'All',
|
|
991
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
992
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
993
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
994
|
+
permanentlyPermittedTimes: [],
|
|
995
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
996
|
+
fromList: allAddresses(),
|
|
997
|
+
initiatedByList: allAddresses()
|
|
998
|
+
});
|
|
999
|
+
const err = UserIncomingApprovalPermission.check([
|
|
1000
|
+
{
|
|
1001
|
+
tokenIds: fullRange(),
|
|
1002
|
+
ownershipTimes: fullRange(),
|
|
1003
|
+
transferTimes: fullRange(),
|
|
1004
|
+
toList: allAddresses(),
|
|
1005
|
+
fromList: allAddresses(),
|
|
1006
|
+
initiatedByList: allAddresses(),
|
|
1007
|
+
approvalIdList: allAddresses(),
|
|
1008
|
+
amountTrackerIdList: allAddresses(),
|
|
1009
|
+
challengeTrackerIdList: allAddresses()
|
|
1010
|
+
}
|
|
1011
|
+
], [perm], 50n);
|
|
1012
|
+
expect(err).not.toBeNull();
|
|
1013
|
+
});
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
describe('CollectionPermissions - serialization', () => {
|
|
1017
|
+
const makeEmpty = () => CollectionPermissions.InitEmpty();
|
|
1018
|
+
describe('convert', () => {
|
|
1019
|
+
it('should convert all fields when they contain data (covers map bodies in convert)', () => {
|
|
1020
|
+
const perms = new CollectionPermissions({
|
|
1021
|
+
canDeleteCollection: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 1n, end: 50n }], permanentlyForbiddenTimes: [] })],
|
|
1022
|
+
canArchiveCollection: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 2n, end: 3n }], permanentlyForbiddenTimes: [] })],
|
|
1023
|
+
canUpdateStandards: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 4n, end: 5n }], permanentlyForbiddenTimes: [] })],
|
|
1024
|
+
canUpdateCustomData: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 6n, end: 7n }], permanentlyForbiddenTimes: [] })],
|
|
1025
|
+
canUpdateManager: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 8n, end: 9n }], permanentlyForbiddenTimes: [] })],
|
|
1026
|
+
canUpdateCollectionMetadata: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 10n, end: 11n }], permanentlyForbiddenTimes: [] })],
|
|
1027
|
+
canUpdateValidTokenIds: [new TokenIdsActionPermission({ tokenIds: [{ start: 1n, end: 5n }], permanentlyPermittedTimes: [{ start: 1n, end: 10n }], permanentlyForbiddenTimes: [] })],
|
|
1028
|
+
canUpdateTokenMetadata: [new TokenIdsActionPermission({ tokenIds: [{ start: 6n, end: 10n }], permanentlyPermittedTimes: [], permanentlyForbiddenTimes: [{ start: 1n, end: 100n }] })],
|
|
1029
|
+
canUpdateCollectionApprovals: [],
|
|
1030
|
+
canAddMoreAliasPaths: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 20n, end: 30n }], permanentlyForbiddenTimes: [] })],
|
|
1031
|
+
canAddMoreCosmosCoinWrapperPaths: [new ActionPermission({ permanentlyPermittedTimes: [{ start: 40n, end: 50n }], permanentlyForbiddenTimes: [] })]
|
|
1032
|
+
});
|
|
1033
|
+
const converted = perms.convert(Stringify);
|
|
1034
|
+
expect(converted.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe('1');
|
|
1035
|
+
expect(converted.canArchiveCollection[0].permanentlyPermittedTimes[0].start).toBe('2');
|
|
1036
|
+
expect(converted.canUpdateStandards[0].permanentlyPermittedTimes[0].start).toBe('4');
|
|
1037
|
+
expect(converted.canUpdateCustomData[0].permanentlyPermittedTimes[0].start).toBe('6');
|
|
1038
|
+
expect(converted.canUpdateManager[0].permanentlyPermittedTimes[0].start).toBe('8');
|
|
1039
|
+
expect(converted.canUpdateCollectionMetadata[0].permanentlyPermittedTimes[0].start).toBe('10');
|
|
1040
|
+
expect(converted.canUpdateValidTokenIds[0].tokenIds[0].start).toBe('1');
|
|
1041
|
+
expect(converted.canUpdateTokenMetadata[0].permanentlyForbiddenTimes[0].start).toBe('1');
|
|
1042
|
+
expect(converted.canAddMoreAliasPaths[0].permanentlyPermittedTimes[0].start).toBe('20');
|
|
1043
|
+
expect(converted.canAddMoreCosmosCoinWrapperPaths[0].permanentlyPermittedTimes[0].start).toBe('40');
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
describe('toProto / fromProto', () => {
|
|
1047
|
+
it('should round-trip empty permissions through proto', () => {
|
|
1048
|
+
const perms = makeEmpty();
|
|
1049
|
+
const proto = perms.toProto();
|
|
1050
|
+
const restored = CollectionPermissions.fromProto(proto, BigIntify);
|
|
1051
|
+
expect(restored).toBeTruthy();
|
|
1052
|
+
expect(restored.canDeleteCollection.length).toBe(0);
|
|
1053
|
+
expect(restored.canUpdateManager.length).toBe(0);
|
|
1054
|
+
});
|
|
1055
|
+
it('should round-trip permissions with data through proto', () => {
|
|
1056
|
+
const perms = new CollectionPermissions({
|
|
1057
|
+
canDeleteCollection: [
|
|
1058
|
+
new ActionPermission({
|
|
1059
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1060
|
+
permanentlyForbiddenTimes: []
|
|
1061
|
+
})
|
|
1062
|
+
],
|
|
1063
|
+
canArchiveCollection: [],
|
|
1064
|
+
canUpdateStandards: [],
|
|
1065
|
+
canUpdateCustomData: [],
|
|
1066
|
+
canUpdateManager: [
|
|
1067
|
+
new ActionPermission({
|
|
1068
|
+
permanentlyPermittedTimes: [],
|
|
1069
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
1070
|
+
})
|
|
1071
|
+
],
|
|
1072
|
+
canUpdateCollectionMetadata: [],
|
|
1073
|
+
canUpdateValidTokenIds: [
|
|
1074
|
+
new TokenIdsActionPermission({
|
|
1075
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1076
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1077
|
+
permanentlyForbiddenTimes: []
|
|
1078
|
+
})
|
|
1079
|
+
],
|
|
1080
|
+
canUpdateTokenMetadata: [],
|
|
1081
|
+
canUpdateCollectionApprovals: [],
|
|
1082
|
+
canAddMoreAliasPaths: [],
|
|
1083
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1084
|
+
});
|
|
1085
|
+
const proto = perms.toProto();
|
|
1086
|
+
const restored = CollectionPermissions.fromProto(proto, BigIntify);
|
|
1087
|
+
expect(restored.canDeleteCollection.length).toBe(1);
|
|
1088
|
+
expect(restored.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1089
|
+
expect(restored.canDeleteCollection[0].permanentlyPermittedTimes[0].end).toBe(100n);
|
|
1090
|
+
expect(restored.canUpdateManager.length).toBe(1);
|
|
1091
|
+
expect(restored.canUpdateManager[0].permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
1092
|
+
expect(restored.canUpdateValidTokenIds.length).toBe(1);
|
|
1093
|
+
expect(restored.canUpdateValidTokenIds[0].tokenIds[0].start).toBe(1n);
|
|
1094
|
+
});
|
|
1095
|
+
});
|
|
1096
|
+
describe('fromJson / fromJsonString', () => {
|
|
1097
|
+
it('should round-trip through JSON', () => {
|
|
1098
|
+
const perms = new CollectionPermissions({
|
|
1099
|
+
canDeleteCollection: [
|
|
1100
|
+
new ActionPermission({
|
|
1101
|
+
permanentlyPermittedTimes: [{ start: 10n, end: 20n }],
|
|
1102
|
+
permanentlyForbiddenTimes: []
|
|
1103
|
+
})
|
|
1104
|
+
],
|
|
1105
|
+
canArchiveCollection: [],
|
|
1106
|
+
canUpdateStandards: [],
|
|
1107
|
+
canUpdateCustomData: [],
|
|
1108
|
+
canUpdateManager: [],
|
|
1109
|
+
canUpdateCollectionMetadata: [],
|
|
1110
|
+
canUpdateValidTokenIds: [],
|
|
1111
|
+
canUpdateTokenMetadata: [],
|
|
1112
|
+
canUpdateCollectionApprovals: [],
|
|
1113
|
+
canAddMoreAliasPaths: [],
|
|
1114
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1115
|
+
});
|
|
1116
|
+
const jsonVal = perms.toProto().toJson();
|
|
1117
|
+
const restored = CollectionPermissions.fromJson(jsonVal, BigIntify);
|
|
1118
|
+
expect(restored.canDeleteCollection[0].permanentlyPermittedTimes[0].start).toBe(10n);
|
|
1119
|
+
});
|
|
1120
|
+
it('should round-trip through JSON string', () => {
|
|
1121
|
+
const perms = makeEmpty();
|
|
1122
|
+
const jsonStr = perms.toProto().toJsonString();
|
|
1123
|
+
const restored = CollectionPermissions.fromJsonString(jsonStr, BigIntify);
|
|
1124
|
+
expect(restored.canDeleteCollection.length).toBe(0);
|
|
1125
|
+
});
|
|
1126
|
+
});
|
|
1127
|
+
describe('toBech32Addresses', () => {
|
|
1128
|
+
it('should run without throwing for empty permissions', () => {
|
|
1129
|
+
const perms = makeEmpty();
|
|
1130
|
+
expect(() => perms.toBech32Addresses('bb')).not.toThrow();
|
|
1131
|
+
});
|
|
1132
|
+
it('should convert collection approval permission addresses', () => {
|
|
1133
|
+
const perms = new CollectionPermissions({
|
|
1134
|
+
canDeleteCollection: [],
|
|
1135
|
+
canArchiveCollection: [],
|
|
1136
|
+
canUpdateStandards: [],
|
|
1137
|
+
canUpdateCustomData: [],
|
|
1138
|
+
canUpdateManager: [],
|
|
1139
|
+
canUpdateCollectionMetadata: [],
|
|
1140
|
+
canUpdateValidTokenIds: [],
|
|
1141
|
+
canUpdateTokenMetadata: [],
|
|
1142
|
+
canUpdateCollectionApprovals: [
|
|
1143
|
+
new CollectionApprovalPermission({
|
|
1144
|
+
fromListId: 'All',
|
|
1145
|
+
toListId: 'All',
|
|
1146
|
+
initiatedByListId: 'All',
|
|
1147
|
+
approvalId: 'All',
|
|
1148
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1149
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1150
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1151
|
+
permanentlyPermittedTimes: [],
|
|
1152
|
+
permanentlyForbiddenTimes: []
|
|
1153
|
+
})
|
|
1154
|
+
],
|
|
1155
|
+
canAddMoreAliasPaths: [],
|
|
1156
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1157
|
+
});
|
|
1158
|
+
expect(() => perms.toBech32Addresses('bb')).not.toThrow();
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
describe('validateUpdate - more permission types', () => {
|
|
1162
|
+
const makePerms = (opts) => new CollectionPermissionsWithDetails({
|
|
1163
|
+
canDeleteCollection: [],
|
|
1164
|
+
canArchiveCollection: [],
|
|
1165
|
+
canUpdateStandards: [],
|
|
1166
|
+
canUpdateCustomData: [],
|
|
1167
|
+
canUpdateManager: [],
|
|
1168
|
+
canUpdateCollectionMetadata: [],
|
|
1169
|
+
canUpdateValidTokenIds: opts.canUpdateValidTokenIds || [],
|
|
1170
|
+
canUpdateTokenMetadata: [],
|
|
1171
|
+
canUpdateCollectionApprovals: opts.canUpdateCollectionApprovals || [],
|
|
1172
|
+
canAddMoreAliasPaths: [],
|
|
1173
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1174
|
+
});
|
|
1175
|
+
it('should reject removing canUpdateValidTokenIds permission', () => {
|
|
1176
|
+
const oldPerms = makePerms({
|
|
1177
|
+
canUpdateValidTokenIds: [
|
|
1178
|
+
new TokenIdsActionPermission({
|
|
1179
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1180
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1181
|
+
permanentlyForbiddenTimes: []
|
|
1182
|
+
})
|
|
1183
|
+
]
|
|
1184
|
+
});
|
|
1185
|
+
const newPerms = makePerms({});
|
|
1186
|
+
const err = CollectionPermissionsWithDetails.validateUpdate(oldPerms, newPerms);
|
|
1187
|
+
expect(err).not.toBeNull();
|
|
1188
|
+
});
|
|
1189
|
+
it('should allow adding canUpdateValidTokenIds when previously empty', () => {
|
|
1190
|
+
const oldPerms = makePerms({});
|
|
1191
|
+
const newPerms = makePerms({
|
|
1192
|
+
canUpdateValidTokenIds: [
|
|
1193
|
+
new TokenIdsActionPermission({
|
|
1194
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1195
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1196
|
+
permanentlyForbiddenTimes: []
|
|
1197
|
+
})
|
|
1198
|
+
]
|
|
1199
|
+
});
|
|
1200
|
+
const err = CollectionPermissionsWithDetails.validateUpdate(oldPerms, newPerms);
|
|
1201
|
+
expect(err).toBeNull();
|
|
1202
|
+
});
|
|
1203
|
+
});
|
|
1204
|
+
});
|
|
1205
|
+
describe('CollectionApprovalPermission - serialization', () => {
|
|
1206
|
+
const makeApprovalBase = (permitted = [], forbidden = []) => new CollectionApprovalPermission({
|
|
1207
|
+
fromListId: 'All',
|
|
1208
|
+
toListId: 'All',
|
|
1209
|
+
initiatedByListId: 'All',
|
|
1210
|
+
approvalId: 'All',
|
|
1211
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1212
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1213
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1214
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
1215
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
1216
|
+
});
|
|
1217
|
+
it('should round-trip through proto', () => {
|
|
1218
|
+
const perm = makeApprovalBase([[10n, 50n]]);
|
|
1219
|
+
const proto = perm.toProto();
|
|
1220
|
+
const restored = CollectionApprovalPermission.fromProto(proto, BigIntify);
|
|
1221
|
+
expect(restored.fromListId).toBe('All');
|
|
1222
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(10n);
|
|
1223
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(50n);
|
|
1224
|
+
});
|
|
1225
|
+
it('should round-trip through JSON', () => {
|
|
1226
|
+
const perm = makeApprovalBase([[5n, 100n]]);
|
|
1227
|
+
const jsonVal = perm.toProto().toJson();
|
|
1228
|
+
const restored = CollectionApprovalPermission.fromJson(jsonVal, BigIntify);
|
|
1229
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
1230
|
+
});
|
|
1231
|
+
it('should round-trip through JSON string', () => {
|
|
1232
|
+
const perm = makeApprovalBase([], [[1n, 200n]]);
|
|
1233
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
1234
|
+
const restored = CollectionApprovalPermission.fromJsonString(jsonStr, BigIntify);
|
|
1235
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
1236
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(200n);
|
|
1237
|
+
});
|
|
1238
|
+
it('should toBech32Addresses without throwing', () => {
|
|
1239
|
+
const perm = makeApprovalBase();
|
|
1240
|
+
expect(() => perm.toBech32Addresses('bb')).not.toThrow();
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
describe('TokenIdsActionPermission - serialization', () => {
|
|
1244
|
+
const makePerm = (permitted = [], forbidden = []) => new TokenIdsActionPermission({
|
|
1245
|
+
tokenIds: [{ start: 1n, end: 100n }],
|
|
1246
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
1247
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e }))
|
|
1248
|
+
});
|
|
1249
|
+
it('should round-trip through proto', () => {
|
|
1250
|
+
const perm = makePerm([[1n, 50n]]);
|
|
1251
|
+
const proto = perm.toProto();
|
|
1252
|
+
const restored = TokenIdsActionPermission.fromProto(proto, BigIntify);
|
|
1253
|
+
expect(restored.tokenIds[0].start).toBe(1n);
|
|
1254
|
+
expect(restored.tokenIds[0].end).toBe(100n);
|
|
1255
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1256
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(50n);
|
|
1257
|
+
});
|
|
1258
|
+
it('should round-trip through JSON', () => {
|
|
1259
|
+
const perm = makePerm([[5n, 80n]]);
|
|
1260
|
+
const jsonVal = perm.toProto().toJson();
|
|
1261
|
+
const restored = TokenIdsActionPermission.fromJson(jsonVal, BigIntify);
|
|
1262
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(80n);
|
|
1263
|
+
});
|
|
1264
|
+
it('should round-trip through JSON string', () => {
|
|
1265
|
+
const perm = makePerm([], [[10n, 20n]]);
|
|
1266
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
1267
|
+
const restored = TokenIdsActionPermission.fromJsonString(jsonStr, BigIntify);
|
|
1268
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(10n);
|
|
1269
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(20n);
|
|
1270
|
+
});
|
|
1271
|
+
});
|
|
1272
|
+
describe('ActionPermission - serialization', () => {
|
|
1273
|
+
it('should round-trip through proto', () => {
|
|
1274
|
+
const perm = new ActionPermission({
|
|
1275
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1276
|
+
permanentlyForbiddenTimes: [{ start: 200n, end: 300n }]
|
|
1277
|
+
});
|
|
1278
|
+
const proto = perm.toProto();
|
|
1279
|
+
const restored = ActionPermission.fromProto(proto, BigIntify);
|
|
1280
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1281
|
+
expect(restored.permanentlyPermittedTimes[0].end).toBe(100n);
|
|
1282
|
+
expect(restored.permanentlyForbiddenTimes[0].start).toBe(200n);
|
|
1283
|
+
});
|
|
1284
|
+
it('should round-trip through JSON', () => {
|
|
1285
|
+
const perm = new ActionPermission({
|
|
1286
|
+
permanentlyPermittedTimes: [{ start: 5n, end: 50n }],
|
|
1287
|
+
permanentlyForbiddenTimes: []
|
|
1288
|
+
});
|
|
1289
|
+
const jsonVal = perm.toProto().toJson();
|
|
1290
|
+
const restored = ActionPermission.fromJson(jsonVal, BigIntify);
|
|
1291
|
+
expect(restored.permanentlyPermittedTimes[0].start).toBe(5n);
|
|
1292
|
+
});
|
|
1293
|
+
it('should round-trip through JSON string', () => {
|
|
1294
|
+
const perm = new ActionPermission({
|
|
1295
|
+
permanentlyPermittedTimes: [],
|
|
1296
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 10n }]
|
|
1297
|
+
});
|
|
1298
|
+
const jsonStr = perm.toProto().toJsonString();
|
|
1299
|
+
const restored = ActionPermission.fromJsonString(jsonStr, BigIntify);
|
|
1300
|
+
expect(restored.permanentlyForbiddenTimes[0].end).toBe(10n);
|
|
1301
|
+
});
|
|
1302
|
+
});
|
|
1303
|
+
describe('UserPermissions - serialization', () => {
|
|
1304
|
+
it('should round-trip empty permissions through proto', () => {
|
|
1305
|
+
const perms = UserPermissions.InitEmpty();
|
|
1306
|
+
const proto = perms.toProto();
|
|
1307
|
+
const restored = UserPermissions.fromProto(proto, BigIntify);
|
|
1308
|
+
expect(restored.canUpdateOutgoingApprovals.length).toBe(0);
|
|
1309
|
+
expect(restored.canUpdateIncomingApprovals.length).toBe(0);
|
|
1310
|
+
});
|
|
1311
|
+
it('should round-trip full UserPermissions with actual data through proto (covers fromProto map bodies)', () => {
|
|
1312
|
+
const perms = new UserPermissions({
|
|
1313
|
+
canUpdateOutgoingApprovals: [
|
|
1314
|
+
new UserOutgoingApprovalPermission({
|
|
1315
|
+
toListId: 'All',
|
|
1316
|
+
initiatedByListId: 'All',
|
|
1317
|
+
approvalId: 'All',
|
|
1318
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1319
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1320
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1321
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1322
|
+
permanentlyForbiddenTimes: []
|
|
1323
|
+
})
|
|
1324
|
+
],
|
|
1325
|
+
canUpdateIncomingApprovals: [
|
|
1326
|
+
new UserIncomingApprovalPermission({
|
|
1327
|
+
fromListId: 'All',
|
|
1328
|
+
initiatedByListId: 'All',
|
|
1329
|
+
approvalId: 'All',
|
|
1330
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1331
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1332
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1333
|
+
permanentlyPermittedTimes: [],
|
|
1334
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }]
|
|
1335
|
+
})
|
|
1336
|
+
],
|
|
1337
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [
|
|
1338
|
+
new ActionPermission({
|
|
1339
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1340
|
+
permanentlyForbiddenTimes: []
|
|
1341
|
+
})
|
|
1342
|
+
],
|
|
1343
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [
|
|
1344
|
+
new ActionPermission({
|
|
1345
|
+
permanentlyPermittedTimes: [],
|
|
1346
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 10n }]
|
|
1347
|
+
})
|
|
1348
|
+
],
|
|
1349
|
+
canUpdateAutoApproveAllIncomingTransfers: [
|
|
1350
|
+
new ActionPermission({
|
|
1351
|
+
permanentlyPermittedTimes: [{ start: 10n, end: 20n }],
|
|
1352
|
+
permanentlyForbiddenTimes: []
|
|
1353
|
+
})
|
|
1354
|
+
]
|
|
1355
|
+
});
|
|
1356
|
+
const proto = perms.toProto();
|
|
1357
|
+
const restored = UserPermissions.fromProto(proto, BigIntify);
|
|
1358
|
+
expect(restored.canUpdateOutgoingApprovals.length).toBe(1);
|
|
1359
|
+
expect(restored.canUpdateOutgoingApprovals[0].permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1360
|
+
expect(restored.canUpdateIncomingApprovals.length).toBe(1);
|
|
1361
|
+
expect(restored.canUpdateIncomingApprovals[0].permanentlyForbiddenTimes[0].start).toBe(1n);
|
|
1362
|
+
expect(restored.canUpdateAutoApproveSelfInitiatedOutgoingTransfers.length).toBe(1);
|
|
1363
|
+
expect(restored.canUpdateAutoApproveSelfInitiatedOutgoingTransfers[0].permanentlyPermittedTimes[0].end).toBe(100n);
|
|
1364
|
+
expect(restored.canUpdateAutoApproveSelfInitiatedIncomingTransfers.length).toBe(1);
|
|
1365
|
+
expect(restored.canUpdateAutoApproveAllIncomingTransfers.length).toBe(1);
|
|
1366
|
+
expect(restored.canUpdateAutoApproveAllIncomingTransfers[0].permanentlyPermittedTimes[0].start).toBe(10n);
|
|
1367
|
+
});
|
|
1368
|
+
it('should round-trip through JSON', () => {
|
|
1369
|
+
const perms = UserPermissions.InitEmpty();
|
|
1370
|
+
const jsonVal = perms.toProto().toJson();
|
|
1371
|
+
const restored = UserPermissions.fromJson(jsonVal, BigIntify);
|
|
1372
|
+
expect(restored).toBeTruthy();
|
|
1373
|
+
});
|
|
1374
|
+
it('should round-trip through JSON string', () => {
|
|
1375
|
+
const perms = UserPermissions.InitEmpty();
|
|
1376
|
+
const jsonStr = perms.toProto().toJsonString();
|
|
1377
|
+
const restored = UserPermissions.fromJsonString(jsonStr, BigIntify);
|
|
1378
|
+
expect(restored).toBeTruthy();
|
|
1379
|
+
});
|
|
1380
|
+
it('should toBech32Addresses without throwing on empty permissions', () => {
|
|
1381
|
+
const perms = UserPermissions.InitEmpty();
|
|
1382
|
+
expect(() => perms.toBech32Addresses('bb')).not.toThrow();
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
describe('UserPermissionsWithDetails - constructor with data', () => {
|
|
1386
|
+
it('should map all arrays when constructed with non-empty data (covers constructor map bodies)', () => {
|
|
1387
|
+
const makeOutgoingWithDetails = () => new UserOutgoingApprovalPermissionWithDetails({
|
|
1388
|
+
toListId: 'All',
|
|
1389
|
+
initiatedByListId: 'All',
|
|
1390
|
+
approvalId: 'All',
|
|
1391
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1392
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1393
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1394
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1395
|
+
permanentlyForbiddenTimes: [],
|
|
1396
|
+
toList: allAddresses(),
|
|
1397
|
+
initiatedByList: allAddresses()
|
|
1398
|
+
});
|
|
1399
|
+
const makeIncomingWithDetails = () => new UserIncomingApprovalPermissionWithDetails({
|
|
1400
|
+
fromListId: 'All',
|
|
1401
|
+
initiatedByListId: 'All',
|
|
1402
|
+
approvalId: 'All',
|
|
1403
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1404
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1405
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1406
|
+
permanentlyPermittedTimes: [],
|
|
1407
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 50n }],
|
|
1408
|
+
fromList: allAddresses(),
|
|
1409
|
+
initiatedByList: allAddresses()
|
|
1410
|
+
});
|
|
1411
|
+
const perms = new UserPermissionsWithDetails({
|
|
1412
|
+
canUpdateOutgoingApprovals: [makeOutgoingWithDetails()],
|
|
1413
|
+
canUpdateIncomingApprovals: [makeIncomingWithDetails()],
|
|
1414
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [
|
|
1415
|
+
new ActionPermission({ permanentlyPermittedTimes: [{ start: 1n, end: 100n }], permanentlyForbiddenTimes: [] })
|
|
1416
|
+
],
|
|
1417
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [
|
|
1418
|
+
new ActionPermission({ permanentlyPermittedTimes: [], permanentlyForbiddenTimes: [{ start: 1n, end: 10n }] })
|
|
1419
|
+
],
|
|
1420
|
+
canUpdateAutoApproveAllIncomingTransfers: [
|
|
1421
|
+
new ActionPermission({ permanentlyPermittedTimes: [{ start: 10n, end: 20n }], permanentlyForbiddenTimes: [] })
|
|
1422
|
+
]
|
|
1423
|
+
});
|
|
1424
|
+
expect(perms.canUpdateOutgoingApprovals.length).toBe(1);
|
|
1425
|
+
expect(perms.canUpdateOutgoingApprovals[0].toList).toBeDefined();
|
|
1426
|
+
expect(perms.canUpdateIncomingApprovals.length).toBe(1);
|
|
1427
|
+
expect(perms.canUpdateIncomingApprovals[0].fromList).toBeDefined();
|
|
1428
|
+
expect(perms.canUpdateAutoApproveSelfInitiatedOutgoingTransfers.length).toBe(1);
|
|
1429
|
+
expect(perms.canUpdateAutoApproveSelfInitiatedIncomingTransfers.length).toBe(1);
|
|
1430
|
+
expect(perms.canUpdateAutoApproveAllIncomingTransfers.length).toBe(1);
|
|
1431
|
+
});
|
|
1432
|
+
it('should convert UserPermissionsWithDetails using convert()', () => {
|
|
1433
|
+
const perms = new UserPermissionsWithDetails({
|
|
1434
|
+
canUpdateOutgoingApprovals: [
|
|
1435
|
+
new UserOutgoingApprovalPermissionWithDetails({
|
|
1436
|
+
toListId: 'All',
|
|
1437
|
+
initiatedByListId: 'All',
|
|
1438
|
+
approvalId: 'All',
|
|
1439
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1440
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1441
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1442
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1443
|
+
permanentlyForbiddenTimes: [],
|
|
1444
|
+
toList: allAddresses(),
|
|
1445
|
+
initiatedByList: allAddresses()
|
|
1446
|
+
})
|
|
1447
|
+
],
|
|
1448
|
+
canUpdateIncomingApprovals: [],
|
|
1449
|
+
canUpdateAutoApproveSelfInitiatedOutgoingTransfers: [],
|
|
1450
|
+
canUpdateAutoApproveSelfInitiatedIncomingTransfers: [],
|
|
1451
|
+
canUpdateAutoApproveAllIncomingTransfers: []
|
|
1452
|
+
});
|
|
1453
|
+
const converted = perms.convert(Stringify);
|
|
1454
|
+
expect(converted.canUpdateOutgoingApprovals[0].tokenIds[0].start).toBe('1');
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
describe('CollectionApprovalPermissionWithDetails - clone and convert', () => {
|
|
1458
|
+
it('should clone successfully', () => {
|
|
1459
|
+
const perm = new CollectionApprovalPermissionWithDetails({
|
|
1460
|
+
fromListId: 'All',
|
|
1461
|
+
toListId: 'All',
|
|
1462
|
+
initiatedByListId: 'All',
|
|
1463
|
+
approvalId: 'All',
|
|
1464
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1465
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1466
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1467
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1468
|
+
permanentlyForbiddenTimes: [],
|
|
1469
|
+
fromList: allAddresses(),
|
|
1470
|
+
toList: allAddresses(),
|
|
1471
|
+
initiatedByList: allAddresses()
|
|
1472
|
+
});
|
|
1473
|
+
const cloned = perm.clone();
|
|
1474
|
+
expect(cloned).toBeTruthy();
|
|
1475
|
+
expect(cloned.fromListId).toBe('All');
|
|
1476
|
+
});
|
|
1477
|
+
it('should convert to string type', () => {
|
|
1478
|
+
const perm = new CollectionApprovalPermissionWithDetails({
|
|
1479
|
+
fromListId: 'All',
|
|
1480
|
+
toListId: 'All',
|
|
1481
|
+
initiatedByListId: 'All',
|
|
1482
|
+
approvalId: 'All',
|
|
1483
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1484
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1485
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1486
|
+
permanentlyPermittedTimes: [{ start: 5n, end: 50n }],
|
|
1487
|
+
permanentlyForbiddenTimes: [],
|
|
1488
|
+
fromList: allAddresses(),
|
|
1489
|
+
toList: allAddresses(),
|
|
1490
|
+
initiatedByList: allAddresses()
|
|
1491
|
+
});
|
|
1492
|
+
const converted = perm.convert(Stringify);
|
|
1493
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('5');
|
|
1494
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1495
|
+
});
|
|
1496
|
+
});
|
|
1497
|
+
describe('UserIncomingApprovalPermissionWithDetails - clone and convert', () => {
|
|
1498
|
+
const makeIncomingWithDetails = () => new UserIncomingApprovalPermissionWithDetails({
|
|
1499
|
+
fromListId: 'All',
|
|
1500
|
+
initiatedByListId: 'All',
|
|
1501
|
+
approvalId: 'All',
|
|
1502
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1503
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1504
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1505
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1506
|
+
permanentlyForbiddenTimes: [],
|
|
1507
|
+
fromList: allAddresses(),
|
|
1508
|
+
initiatedByList: allAddresses()
|
|
1509
|
+
});
|
|
1510
|
+
it('should clone successfully', () => {
|
|
1511
|
+
const perm = makeIncomingWithDetails();
|
|
1512
|
+
const cloned = perm.clone();
|
|
1513
|
+
expect(cloned).toBeTruthy();
|
|
1514
|
+
expect(cloned.fromListId).toBe('All');
|
|
1515
|
+
expect(cloned.fromList).toBeDefined();
|
|
1516
|
+
});
|
|
1517
|
+
it('should convert to string type', () => {
|
|
1518
|
+
const perm = makeIncomingWithDetails();
|
|
1519
|
+
const converted = perm.convert(Stringify);
|
|
1520
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1521
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('1');
|
|
1522
|
+
});
|
|
1523
|
+
it('should castToCollectionApprovalPermission with toList set', () => {
|
|
1524
|
+
const perm = makeIncomingWithDetails();
|
|
1525
|
+
const addr = genTestAddress();
|
|
1526
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
1527
|
+
expect(casted.toListId).toBe(addr);
|
|
1528
|
+
expect(casted.toList).toBeDefined();
|
|
1529
|
+
});
|
|
1530
|
+
});
|
|
1531
|
+
describe('UserOutgoingApprovalPermissionWithDetails - clone and convert', () => {
|
|
1532
|
+
const makeOutgoingWithDetails = () => new UserOutgoingApprovalPermissionWithDetails({
|
|
1533
|
+
toListId: 'All',
|
|
1534
|
+
initiatedByListId: 'All',
|
|
1535
|
+
approvalId: 'All',
|
|
1536
|
+
transferTimes: [{ start: 1n, end: 100n }],
|
|
1537
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1538
|
+
ownershipTimes: [{ start: 1n, end: 100n }],
|
|
1539
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 50n }],
|
|
1540
|
+
permanentlyForbiddenTimes: [],
|
|
1541
|
+
toList: allAddresses(),
|
|
1542
|
+
initiatedByList: allAddresses()
|
|
1543
|
+
});
|
|
1544
|
+
it('should clone successfully', () => {
|
|
1545
|
+
const perm = makeOutgoingWithDetails();
|
|
1546
|
+
const cloned = perm.clone();
|
|
1547
|
+
expect(cloned).toBeTruthy();
|
|
1548
|
+
expect(cloned.toListId).toBe('All');
|
|
1549
|
+
expect(cloned.toList).toBeDefined();
|
|
1550
|
+
});
|
|
1551
|
+
it('should convert to string type', () => {
|
|
1552
|
+
const perm = makeOutgoingWithDetails();
|
|
1553
|
+
const converted = perm.convert(Stringify);
|
|
1554
|
+
expect(converted.tokenIds[0].start).toBe('1');
|
|
1555
|
+
expect(converted.permanentlyPermittedTimes[0].start).toBe('1');
|
|
1556
|
+
});
|
|
1557
|
+
it('should castToCollectionApprovalPermission with fromList set', () => {
|
|
1558
|
+
const perm = makeOutgoingWithDetails();
|
|
1559
|
+
const addr = genTestAddress();
|
|
1560
|
+
const casted = perm.castToCollectionApprovalPermission(addr);
|
|
1561
|
+
expect(casted.fromListId).toBe(addr);
|
|
1562
|
+
expect(casted.fromList).toBeDefined();
|
|
1563
|
+
});
|
|
1564
|
+
});
|
|
1565
|
+
describe('CollectionApprovalPermission.check - extended error messages', () => {
|
|
1566
|
+
it('should include timeline times in error message when usesLists=true and forbidden', () => {
|
|
1567
|
+
const addr = genTestAddress();
|
|
1568
|
+
const perm = new CollectionApprovalPermissionWithDetails({
|
|
1569
|
+
fromListId: 'All',
|
|
1570
|
+
toListId: addr,
|
|
1571
|
+
initiatedByListId: 'All',
|
|
1572
|
+
approvalId: 'All',
|
|
1573
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1574
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1575
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1576
|
+
permanentlyPermittedTimes: [],
|
|
1577
|
+
permanentlyForbiddenTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1578
|
+
fromList: allAddresses(),
|
|
1579
|
+
toList: whitelistOf([addr]),
|
|
1580
|
+
initiatedByList: allAddresses()
|
|
1581
|
+
});
|
|
1582
|
+
const err = CollectionApprovalPermission.check([
|
|
1583
|
+
{
|
|
1584
|
+
tokenIds: UintRangeArray.From([{ start: 1n, end: 5n }]),
|
|
1585
|
+
ownershipTimes: fullRange(),
|
|
1586
|
+
transferTimes: fullRange(),
|
|
1587
|
+
toList: whitelistOf([addr]),
|
|
1588
|
+
fromList: allAddresses(),
|
|
1589
|
+
initiatedByList: allAddresses(),
|
|
1590
|
+
approvalIdList: allAddresses()
|
|
1591
|
+
}
|
|
1592
|
+
], [perm], 50n);
|
|
1593
|
+
expect(err).not.toBeNull();
|
|
1594
|
+
expect(err.message).toContain('forbidden');
|
|
1595
|
+
});
|
|
1596
|
+
});
|
|
1597
|
+
describe('validateUniversalPermissionUpdate - multiple missing and combined error', () => {
|
|
1598
|
+
it('should mention count when multiple permissions are missing', () => {
|
|
1599
|
+
const makeSimpleWithDetails = (tokenStart, tokenEnd) => new CollectionApprovalPermissionWithDetails({
|
|
1600
|
+
fromListId: 'All',
|
|
1601
|
+
toListId: 'All',
|
|
1602
|
+
initiatedByListId: 'All',
|
|
1603
|
+
approvalId: 'All',
|
|
1604
|
+
transferTimes: [{ start: 1n, end: 1n }],
|
|
1605
|
+
tokenIds: [{ start: tokenStart, end: tokenEnd }],
|
|
1606
|
+
ownershipTimes: [{ start: 1n, end: 1n }],
|
|
1607
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1608
|
+
permanentlyForbiddenTimes: [],
|
|
1609
|
+
fromList: allAddresses(),
|
|
1610
|
+
toList: allAddresses(),
|
|
1611
|
+
initiatedByList: allAddresses()
|
|
1612
|
+
});
|
|
1613
|
+
const oldPerms = [makeSimpleWithDetails(1n, 5n), makeSimpleWithDetails(10n, 15n)];
|
|
1614
|
+
const newPerms = [];
|
|
1615
|
+
const err = CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1616
|
+
expect(err).not.toBeNull();
|
|
1617
|
+
expect(err.message).toMatch(/along with|found in old/);
|
|
1618
|
+
});
|
|
1619
|
+
it('should produce combined permitted+forbidden error when both are being removed', () => {
|
|
1620
|
+
const makeApprovalWithBoth = (permitted, forbidden) => new CollectionApprovalPermissionWithDetails({
|
|
1621
|
+
fromListId: 'All',
|
|
1622
|
+
toListId: 'All',
|
|
1623
|
+
initiatedByListId: 'All',
|
|
1624
|
+
approvalId: 'All',
|
|
1625
|
+
transferTimes: [{ start: 1n, end: 1n }],
|
|
1626
|
+
tokenIds: [{ start: 1n, end: 10n }],
|
|
1627
|
+
ownershipTimes: [{ start: 1n, end: 1n }],
|
|
1628
|
+
permanentlyPermittedTimes: permitted.map(([s, e]) => ({ start: s, end: e })),
|
|
1629
|
+
permanentlyForbiddenTimes: forbidden.map(([s, e]) => ({ start: s, end: e })),
|
|
1630
|
+
fromList: allAddresses(),
|
|
1631
|
+
toList: allAddresses(),
|
|
1632
|
+
initiatedByList: allAddresses()
|
|
1633
|
+
});
|
|
1634
|
+
const oldPerms = [makeApprovalWithBoth([[1n, 50n]], [[51n, 100n]])];
|
|
1635
|
+
const newPerms = [makeApprovalWithBoth([], [])];
|
|
1636
|
+
const err = CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1637
|
+
expect(err).not.toBeNull();
|
|
1638
|
+
expect(err.message).toMatch(/allowed|disApproved/i);
|
|
1639
|
+
});
|
|
1640
|
+
});
|
|
1641
|
+
describe('CollectionPermissionsWithDetails - constructor with canUpdateCollectionApprovals', () => {
|
|
1642
|
+
it('should map canUpdateCollectionApprovals to CollectionApprovalPermissionWithDetails (covers lines 1014-1023)', () => {
|
|
1643
|
+
const perms = new CollectionPermissionsWithDetails({
|
|
1644
|
+
canDeleteCollection: [],
|
|
1645
|
+
canArchiveCollection: [],
|
|
1646
|
+
canUpdateStandards: [],
|
|
1647
|
+
canUpdateCustomData: [],
|
|
1648
|
+
canUpdateManager: [],
|
|
1649
|
+
canUpdateCollectionMetadata: [],
|
|
1650
|
+
canUpdateValidTokenIds: [],
|
|
1651
|
+
canUpdateTokenMetadata: [],
|
|
1652
|
+
canUpdateCollectionApprovals: [
|
|
1653
|
+
new CollectionApprovalPermissionWithDetails({
|
|
1654
|
+
fromListId: 'All',
|
|
1655
|
+
toListId: 'All',
|
|
1656
|
+
initiatedByListId: 'All',
|
|
1657
|
+
approvalId: 'All',
|
|
1658
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1659
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1660
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1661
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1662
|
+
permanentlyForbiddenTimes: [],
|
|
1663
|
+
fromList: allAddresses(),
|
|
1664
|
+
toList: allAddresses(),
|
|
1665
|
+
initiatedByList: allAddresses()
|
|
1666
|
+
})
|
|
1667
|
+
],
|
|
1668
|
+
canAddMoreAliasPaths: [],
|
|
1669
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1670
|
+
});
|
|
1671
|
+
expect(perms.canUpdateCollectionApprovals.length).toBe(1);
|
|
1672
|
+
expect(perms.canUpdateCollectionApprovals[0].fromList).toBeDefined();
|
|
1673
|
+
expect(perms.canUpdateCollectionApprovals[0].permanentlyPermittedTimes[0].start).toBe(1n);
|
|
1674
|
+
});
|
|
1675
|
+
it('should clone CollectionPermissionsWithDetails', () => {
|
|
1676
|
+
const perms = new CollectionPermissionsWithDetails({
|
|
1677
|
+
canDeleteCollection: [],
|
|
1678
|
+
canArchiveCollection: [],
|
|
1679
|
+
canUpdateStandards: [],
|
|
1680
|
+
canUpdateCustomData: [],
|
|
1681
|
+
canUpdateManager: [],
|
|
1682
|
+
canUpdateCollectionMetadata: [],
|
|
1683
|
+
canUpdateValidTokenIds: [],
|
|
1684
|
+
canUpdateTokenMetadata: [],
|
|
1685
|
+
canUpdateCollectionApprovals: [],
|
|
1686
|
+
canAddMoreAliasPaths: [],
|
|
1687
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1688
|
+
});
|
|
1689
|
+
const cloned = perms.clone();
|
|
1690
|
+
expect(cloned).toBeTruthy();
|
|
1691
|
+
});
|
|
1692
|
+
it('should convert CollectionPermissionsWithDetails (covers line 1019)', () => {
|
|
1693
|
+
const perms = new CollectionPermissionsWithDetails({
|
|
1694
|
+
canDeleteCollection: [],
|
|
1695
|
+
canArchiveCollection: [],
|
|
1696
|
+
canUpdateStandards: [],
|
|
1697
|
+
canUpdateCustomData: [],
|
|
1698
|
+
canUpdateManager: [
|
|
1699
|
+
new ActionPermission({
|
|
1700
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1701
|
+
permanentlyForbiddenTimes: []
|
|
1702
|
+
})
|
|
1703
|
+
],
|
|
1704
|
+
canUpdateCollectionMetadata: [],
|
|
1705
|
+
canUpdateValidTokenIds: [],
|
|
1706
|
+
canUpdateTokenMetadata: [],
|
|
1707
|
+
canUpdateCollectionApprovals: [
|
|
1708
|
+
new CollectionApprovalPermissionWithDetails({
|
|
1709
|
+
fromListId: 'All',
|
|
1710
|
+
toListId: 'All',
|
|
1711
|
+
initiatedByListId: 'All',
|
|
1712
|
+
approvalId: 'All',
|
|
1713
|
+
transferTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1714
|
+
tokenIds: [{ start: 1n, end: 18446744073709551615n }],
|
|
1715
|
+
ownershipTimes: [{ start: 1n, end: 18446744073709551615n }],
|
|
1716
|
+
permanentlyPermittedTimes: [{ start: 5n, end: 50n }],
|
|
1717
|
+
permanentlyForbiddenTimes: [],
|
|
1718
|
+
fromList: allAddresses(),
|
|
1719
|
+
toList: allAddresses(),
|
|
1720
|
+
initiatedByList: allAddresses()
|
|
1721
|
+
})
|
|
1722
|
+
],
|
|
1723
|
+
canAddMoreAliasPaths: [],
|
|
1724
|
+
canAddMoreCosmosCoinWrapperPaths: []
|
|
1725
|
+
});
|
|
1726
|
+
const converted = perms.convert(Stringify);
|
|
1727
|
+
expect(converted.canUpdateManager[0].permanentlyPermittedTimes[0].start).toBe('1');
|
|
1728
|
+
expect(converted.canUpdateCollectionApprovals[0].permanentlyPermittedTimes[0].start).toBe('5');
|
|
1729
|
+
});
|
|
1730
|
+
});
|
|
1731
|
+
describe('getPermissionString branches - whitelist and address listing', () => {
|
|
1732
|
+
it('should produce error message with whitelist address info when whitelist=true', () => {
|
|
1733
|
+
const addr1 = genTestAddress();
|
|
1734
|
+
const addr2 = genTestAddress();
|
|
1735
|
+
const makeWithWhitelist = () => new CollectionApprovalPermissionWithDetails({
|
|
1736
|
+
fromListId: 'All',
|
|
1737
|
+
toListId: 'whitelist-test',
|
|
1738
|
+
initiatedByListId: 'All',
|
|
1739
|
+
approvalId: 'All',
|
|
1740
|
+
transferTimes: [{ start: 1n, end: 1n }],
|
|
1741
|
+
tokenIds: [{ start: 1n, end: 5n }],
|
|
1742
|
+
ownershipTimes: [{ start: 1n, end: 1n }],
|
|
1743
|
+
permanentlyPermittedTimes: [{ start: 1n, end: 100n }],
|
|
1744
|
+
permanentlyForbiddenTimes: [],
|
|
1745
|
+
fromList: whitelistOf([addr1, addr2]),
|
|
1746
|
+
toList: whitelistOf([addr1, addr2]),
|
|
1747
|
+
initiatedByList: whitelistOf([addr1, addr2])
|
|
1748
|
+
});
|
|
1749
|
+
const oldPerms = [makeWithWhitelist()];
|
|
1750
|
+
const newPerms = [];
|
|
1751
|
+
const err = CollectionApprovalPermission.validateUpdate(oldPerms, newPerms);
|
|
1752
|
+
expect(err).not.toBeNull();
|
|
1753
|
+
expect(err.message).toContain('found in old permissions');
|
|
1754
|
+
});
|
|
1755
|
+
});
|
|
687
1756
|
describe('UserOutgoingApprovalPermission', () => {
|
|
688
1757
|
const makeOutgoingPerm = (opts) => {
|
|
689
1758
|
return new UserOutgoingApprovalPermissionWithDetails({
|