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.
Files changed (99) hide show
  1. package/dist/cjs/api-indexer/BitBadgesCollection.d.ts +1 -0
  2. package/dist/cjs/api-indexer/BitBadgesCollection.d.ts.map +1 -1
  3. package/dist/cjs/api-indexer/BitBadgesCollection.js +4 -1
  4. package/dist/cjs/api-indexer/BitBadgesCollection.js.map +1 -1
  5. package/dist/cjs/core/approval-utils.spec.d.ts +2 -0
  6. package/dist/cjs/core/approval-utils.spec.d.ts.map +1 -0
  7. package/dist/cjs/core/approval-utils.spec.js +240 -0
  8. package/dist/cjs/core/approval-utils.spec.js.map +1 -0
  9. package/dist/cjs/core/approvals.spec.js +96 -0
  10. package/dist/cjs/core/approvals.spec.js.map +1 -1
  11. package/dist/cjs/core/bids.spec.d.ts +2 -0
  12. package/dist/cjs/core/bids.spec.d.ts.map +1 -0
  13. package/dist/cjs/core/bids.spec.js +201 -0
  14. package/dist/cjs/core/bids.spec.js.map +1 -0
  15. package/dist/cjs/core/blockin.spec.d.ts +2 -0
  16. package/dist/cjs/core/blockin.spec.d.ts.map +1 -0
  17. package/dist/cjs/core/blockin.spec.js +163 -0
  18. package/dist/cjs/core/blockin.spec.js.map +1 -0
  19. package/dist/cjs/core/coin.spec.d.ts +2 -0
  20. package/dist/cjs/core/coin.spec.d.ts.map +1 -0
  21. package/dist/cjs/core/coin.spec.js +80 -0
  22. package/dist/cjs/core/coin.spec.js.map +1 -0
  23. package/dist/cjs/core/cosmos-wrappers.spec.d.ts +2 -0
  24. package/dist/cjs/core/cosmos-wrappers.spec.d.ts.map +1 -0
  25. package/dist/cjs/core/cosmos-wrappers.spec.js +623 -0
  26. package/dist/cjs/core/cosmos-wrappers.spec.js.map +1 -0
  27. package/dist/cjs/core/managersplitter.spec.d.ts +2 -0
  28. package/dist/cjs/core/managersplitter.spec.d.ts.map +1 -0
  29. package/dist/cjs/core/managersplitter.spec.js +170 -0
  30. package/dist/cjs/core/managersplitter.spec.js.map +1 -0
  31. package/dist/cjs/core/overlaps.spec.js +201 -0
  32. package/dist/cjs/core/overlaps.spec.js.map +1 -1
  33. package/dist/cjs/core/permission-utils.spec.d.ts +2 -0
  34. package/dist/cjs/core/permission-utils.spec.d.ts.map +1 -0
  35. package/dist/cjs/core/permission-utils.spec.js +192 -0
  36. package/dist/cjs/core/permission-utils.spec.js.map +1 -0
  37. package/dist/cjs/core/permissions.spec.js +1069 -0
  38. package/dist/cjs/core/permissions.spec.js.map +1 -1
  39. package/dist/cjs/core/transfers.spec.js +524 -0
  40. package/dist/cjs/core/transfers.spec.js.map +1 -1
  41. package/dist/cjs/core/userBalances.spec.d.ts +2 -0
  42. package/dist/cjs/core/userBalances.spec.d.ts.map +1 -0
  43. package/dist/cjs/core/userBalances.spec.js +184 -0
  44. package/dist/cjs/core/userBalances.spec.js.map +1 -0
  45. package/dist/cjs/core/validate-utils.spec.d.ts +2 -0
  46. package/dist/cjs/core/validate-utils.spec.d.ts.map +1 -0
  47. package/dist/cjs/core/validate-utils.spec.js +202 -0
  48. package/dist/cjs/core/validate-utils.spec.js.map +1 -0
  49. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  50. package/dist/esm/api-indexer/BitBadgesCollection.d.ts +1 -0
  51. package/dist/esm/api-indexer/BitBadgesCollection.d.ts.map +1 -1
  52. package/dist/esm/api-indexer/BitBadgesCollection.js +4 -1
  53. package/dist/esm/api-indexer/BitBadgesCollection.js.map +1 -1
  54. package/dist/esm/core/approval-utils.spec.d.ts +2 -0
  55. package/dist/esm/core/approval-utils.spec.d.ts.map +1 -0
  56. package/dist/esm/core/approval-utils.spec.js +238 -0
  57. package/dist/esm/core/approval-utils.spec.js.map +1 -0
  58. package/dist/esm/core/approvals.spec.js +97 -1
  59. package/dist/esm/core/approvals.spec.js.map +1 -1
  60. package/dist/esm/core/bids.spec.d.ts +2 -0
  61. package/dist/esm/core/bids.spec.d.ts.map +1 -0
  62. package/dist/esm/core/bids.spec.js +199 -0
  63. package/dist/esm/core/bids.spec.js.map +1 -0
  64. package/dist/esm/core/blockin.spec.d.ts +2 -0
  65. package/dist/esm/core/blockin.spec.d.ts.map +1 -0
  66. package/dist/esm/core/blockin.spec.js +161 -0
  67. package/dist/esm/core/blockin.spec.js.map +1 -0
  68. package/dist/esm/core/coin.spec.d.ts +2 -0
  69. package/dist/esm/core/coin.spec.d.ts.map +1 -0
  70. package/dist/esm/core/coin.spec.js +78 -0
  71. package/dist/esm/core/coin.spec.js.map +1 -0
  72. package/dist/esm/core/cosmos-wrappers.spec.d.ts +2 -0
  73. package/dist/esm/core/cosmos-wrappers.spec.d.ts.map +1 -0
  74. package/dist/esm/core/cosmos-wrappers.spec.js +621 -0
  75. package/dist/esm/core/cosmos-wrappers.spec.js.map +1 -0
  76. package/dist/esm/core/managersplitter.spec.d.ts +2 -0
  77. package/dist/esm/core/managersplitter.spec.d.ts.map +1 -0
  78. package/dist/esm/core/managersplitter.spec.js +168 -0
  79. package/dist/esm/core/managersplitter.spec.js.map +1 -0
  80. package/dist/esm/core/overlaps.spec.js +202 -1
  81. package/dist/esm/core/overlaps.spec.js.map +1 -1
  82. package/dist/esm/core/permission-utils.spec.d.ts +2 -0
  83. package/dist/esm/core/permission-utils.spec.d.ts.map +1 -0
  84. package/dist/esm/core/permission-utils.spec.js +190 -0
  85. package/dist/esm/core/permission-utils.spec.js.map +1 -0
  86. package/dist/esm/core/permissions.spec.js +1069 -0
  87. package/dist/esm/core/permissions.spec.js.map +1 -1
  88. package/dist/esm/core/transfers.spec.js +525 -1
  89. package/dist/esm/core/transfers.spec.js.map +1 -1
  90. package/dist/esm/core/userBalances.spec.d.ts +2 -0
  91. package/dist/esm/core/userBalances.spec.d.ts.map +1 -0
  92. package/dist/esm/core/userBalances.spec.js +182 -0
  93. package/dist/esm/core/userBalances.spec.js.map +1 -0
  94. package/dist/esm/core/validate-utils.spec.d.ts +2 -0
  95. package/dist/esm/core/validate-utils.spec.d.ts.map +1 -0
  96. package/dist/esm/core/validate-utils.spec.js +200 -0
  97. package/dist/esm/core/validate-utils.spec.js.map +1 -0
  98. package/dist/esm/tsconfig-esm.build.tsbuildinfo +1 -1
  99. package/package.json +4 -5
@@ -4,6 +4,7 @@ const addressLists_spec_js_1 = require("./addressLists.spec.js");
4
4
  const addressLists_js_1 = require("./addressLists.js");
5
5
  const permissions_js_1 = require("./permissions.js");
6
6
  const uintRanges_js_1 = require("./uintRanges.js");
7
+ const string_numbers_js_1 = require("../common/string-numbers.js");
7
8
  BigInt.prototype.toJSON = function () {
8
9
  return this.toString();
9
10
  };
@@ -686,6 +687,1074 @@ describe('CollectionPermissions', () => {
686
687
  });
687
688
  });
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
+ });
689
1758
  describe('UserOutgoingApprovalPermission', () => {
690
1759
  const makeOutgoingPerm = (opts) => {
691
1760
  return new permissions_js_1.UserOutgoingApprovalPermissionWithDetails({