@movebridge/testing 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +33 -12
- package/dist/index.mjs +33 -13
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -280,8 +280,7 @@ declare const PREDEFINED_SCHEMAS: {
|
|
|
280
280
|
payload: {
|
|
281
281
|
function: string;
|
|
282
282
|
typeArguments: string[];
|
|
283
|
-
|
|
284
|
-
type: "entry_function_payload";
|
|
283
|
+
functionArguments: unknown[];
|
|
285
284
|
};
|
|
286
285
|
hash: string;
|
|
287
286
|
sender: string;
|
|
@@ -294,13 +293,11 @@ declare const PREDEFINED_SCHEMAS: {
|
|
|
294
293
|
payload: Struct<{
|
|
295
294
|
function: string;
|
|
296
295
|
typeArguments: string[];
|
|
297
|
-
|
|
298
|
-
type: "entry_function_payload";
|
|
296
|
+
functionArguments: unknown[];
|
|
299
297
|
}, {
|
|
300
|
-
type: Struct<"entry_function_payload", "entry_function_payload">;
|
|
301
298
|
function: Struct<string, null>;
|
|
302
299
|
typeArguments: Struct<string[], Struct<string, null>>;
|
|
303
|
-
|
|
300
|
+
functionArguments: Struct<unknown[], Struct<unknown, null>>;
|
|
304
301
|
}>;
|
|
305
302
|
timestamp: Struct<string, null>;
|
|
306
303
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -280,8 +280,7 @@ declare const PREDEFINED_SCHEMAS: {
|
|
|
280
280
|
payload: {
|
|
281
281
|
function: string;
|
|
282
282
|
typeArguments: string[];
|
|
283
|
-
|
|
284
|
-
type: "entry_function_payload";
|
|
283
|
+
functionArguments: unknown[];
|
|
285
284
|
};
|
|
286
285
|
hash: string;
|
|
287
286
|
sender: string;
|
|
@@ -294,13 +293,11 @@ declare const PREDEFINED_SCHEMAS: {
|
|
|
294
293
|
payload: Struct<{
|
|
295
294
|
function: string;
|
|
296
295
|
typeArguments: string[];
|
|
297
|
-
|
|
298
|
-
type: "entry_function_payload";
|
|
296
|
+
functionArguments: unknown[];
|
|
299
297
|
}, {
|
|
300
|
-
type: Struct<"entry_function_payload", "entry_function_payload">;
|
|
301
298
|
function: Struct<string, null>;
|
|
302
299
|
typeArguments: Struct<string[], Struct<string, null>>;
|
|
303
|
-
|
|
300
|
+
functionArguments: Struct<unknown[], Struct<unknown, null>>;
|
|
304
301
|
}>;
|
|
305
302
|
timestamp: Struct<string, null>;
|
|
306
303
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -109,10 +109,9 @@ function createFaker(options) {
|
|
|
109
109
|
sender: `0x${randomHex(64)}`,
|
|
110
110
|
sequenceNumber: randomSequenceNumber(),
|
|
111
111
|
payload: {
|
|
112
|
-
type: "entry_function_payload",
|
|
113
112
|
function: `0x${randomHex(64)}::module::function`,
|
|
114
113
|
typeArguments: [],
|
|
115
|
-
|
|
114
|
+
functionArguments: []
|
|
116
115
|
},
|
|
117
116
|
timestamp: randomTimestamp()
|
|
118
117
|
};
|
|
@@ -673,18 +672,41 @@ function validatePayload(payload) {
|
|
|
673
672
|
{ argument: "payload", value: payload }
|
|
674
673
|
);
|
|
675
674
|
}
|
|
676
|
-
if (payload.
|
|
675
|
+
if (!FUNCTION_REGEX.test(payload.function)) {
|
|
676
|
+
throw new import_core3.MovementError(
|
|
677
|
+
`Invalid function identifier: ${payload.function}`,
|
|
678
|
+
"INVALID_ARGUMENT",
|
|
679
|
+
{
|
|
680
|
+
argument: "function",
|
|
681
|
+
value: payload.function,
|
|
682
|
+
expectedFormat: "0xADDRESS::module::function"
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
if (!Array.isArray(payload.typeArguments)) {
|
|
687
|
+
throw new import_core3.MovementError(
|
|
688
|
+
"typeArguments must be an array",
|
|
689
|
+
"INVALID_ARGUMENT",
|
|
690
|
+
{ argument: "typeArguments", value: payload.typeArguments }
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
for (let i = 0; i < payload.typeArguments.length; i++) {
|
|
694
|
+
if (typeof payload.typeArguments[i] !== "string") {
|
|
695
|
+
throw new import_core3.MovementError(
|
|
696
|
+
`typeArguments[${i}] must be a string`,
|
|
697
|
+
"INVALID_ARGUMENT",
|
|
698
|
+
{ argument: `typeArguments[${i}]`, value: payload.typeArguments[i] }
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (!Array.isArray(payload.functionArguments)) {
|
|
677
703
|
throw new import_core3.MovementError(
|
|
678
|
-
|
|
704
|
+
"functionArguments must be an array",
|
|
679
705
|
"INVALID_ARGUMENT",
|
|
680
|
-
{ argument: "
|
|
706
|
+
{ argument: "functionArguments", value: payload.functionArguments }
|
|
681
707
|
);
|
|
682
708
|
}
|
|
683
|
-
return
|
|
684
|
-
function: payload.function,
|
|
685
|
-
typeArguments: payload.typeArguments,
|
|
686
|
-
arguments: payload.arguments
|
|
687
|
-
});
|
|
709
|
+
return true;
|
|
688
710
|
}
|
|
689
711
|
function validateAmount(amount) {
|
|
690
712
|
if (typeof amount !== "string") {
|
|
@@ -738,10 +760,9 @@ var PREDEFINED_SCHEMAS = {
|
|
|
738
760
|
sender: (0, import_superstruct.string)(),
|
|
739
761
|
sequenceNumber: (0, import_superstruct.string)(),
|
|
740
762
|
payload: (0, import_superstruct.object)({
|
|
741
|
-
type: (0, import_superstruct.literal)("entry_function_payload"),
|
|
742
763
|
function: (0, import_superstruct.string)(),
|
|
743
764
|
typeArguments: (0, import_superstruct.array)((0, import_superstruct.string)()),
|
|
744
|
-
|
|
765
|
+
functionArguments: (0, import_superstruct.array)((0, import_superstruct.unknown)())
|
|
745
766
|
}),
|
|
746
767
|
timestamp: (0, import_superstruct.string)()
|
|
747
768
|
}),
|
package/dist/index.mjs
CHANGED
|
@@ -65,10 +65,9 @@ function createFaker(options) {
|
|
|
65
65
|
sender: `0x${randomHex(64)}`,
|
|
66
66
|
sequenceNumber: randomSequenceNumber(),
|
|
67
67
|
payload: {
|
|
68
|
-
type: "entry_function_payload",
|
|
69
68
|
function: `0x${randomHex(64)}::module::function`,
|
|
70
69
|
typeArguments: [],
|
|
71
|
-
|
|
70
|
+
functionArguments: []
|
|
72
71
|
},
|
|
73
72
|
timestamp: randomTimestamp()
|
|
74
73
|
};
|
|
@@ -629,18 +628,41 @@ function validatePayload(payload) {
|
|
|
629
628
|
{ argument: "payload", value: payload }
|
|
630
629
|
);
|
|
631
630
|
}
|
|
632
|
-
if (payload.
|
|
631
|
+
if (!FUNCTION_REGEX.test(payload.function)) {
|
|
632
|
+
throw new MovementError3(
|
|
633
|
+
`Invalid function identifier: ${payload.function}`,
|
|
634
|
+
"INVALID_ARGUMENT",
|
|
635
|
+
{
|
|
636
|
+
argument: "function",
|
|
637
|
+
value: payload.function,
|
|
638
|
+
expectedFormat: "0xADDRESS::module::function"
|
|
639
|
+
}
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
if (!Array.isArray(payload.typeArguments)) {
|
|
643
|
+
throw new MovementError3(
|
|
644
|
+
"typeArguments must be an array",
|
|
645
|
+
"INVALID_ARGUMENT",
|
|
646
|
+
{ argument: "typeArguments", value: payload.typeArguments }
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
for (let i = 0; i < payload.typeArguments.length; i++) {
|
|
650
|
+
if (typeof payload.typeArguments[i] !== "string") {
|
|
651
|
+
throw new MovementError3(
|
|
652
|
+
`typeArguments[${i}] must be a string`,
|
|
653
|
+
"INVALID_ARGUMENT",
|
|
654
|
+
{ argument: `typeArguments[${i}]`, value: payload.typeArguments[i] }
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!Array.isArray(payload.functionArguments)) {
|
|
633
659
|
throw new MovementError3(
|
|
634
|
-
|
|
660
|
+
"functionArguments must be an array",
|
|
635
661
|
"INVALID_ARGUMENT",
|
|
636
|
-
{ argument: "
|
|
662
|
+
{ argument: "functionArguments", value: payload.functionArguments }
|
|
637
663
|
);
|
|
638
664
|
}
|
|
639
|
-
return
|
|
640
|
-
function: payload.function,
|
|
641
|
-
typeArguments: payload.typeArguments,
|
|
642
|
-
arguments: payload.arguments
|
|
643
|
-
});
|
|
665
|
+
return true;
|
|
644
666
|
}
|
|
645
667
|
function validateAmount(amount) {
|
|
646
668
|
if (typeof amount !== "string") {
|
|
@@ -689,7 +711,6 @@ import {
|
|
|
689
711
|
array,
|
|
690
712
|
record,
|
|
691
713
|
unknown,
|
|
692
|
-
literal,
|
|
693
714
|
nullable,
|
|
694
715
|
validate
|
|
695
716
|
} from "superstruct";
|
|
@@ -704,10 +725,9 @@ var PREDEFINED_SCHEMAS = {
|
|
|
704
725
|
sender: string(),
|
|
705
726
|
sequenceNumber: string(),
|
|
706
727
|
payload: object({
|
|
707
|
-
type: literal("entry_function_payload"),
|
|
708
728
|
function: string(),
|
|
709
729
|
typeArguments: array(string()),
|
|
710
|
-
|
|
730
|
+
functionArguments: array(unknown())
|
|
711
731
|
}),
|
|
712
732
|
timestamp: string()
|
|
713
733
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movebridge/testing",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Testing utilities for MoveBridge SDK - mocks, validators, fakers, and test harness",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"superstruct": "^1.0.3",
|
|
20
|
-
"@movebridge/core": "0.0
|
|
20
|
+
"@movebridge/core": "0.2.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"fast-check": "^3.14.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"typescript": "^5.3.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@movebridge/core": ">=0.0
|
|
28
|
+
"@movebridge/core": ">=0.1.0"
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|
|
31
31
|
"movement",
|