@@ -25,10 +25,6 @@ describe("Payload Id", () => {
25
25
chai . expect ( payloadId ( ) . toString ( ) . length ) . to . equal ( 16 ) ;
26
26
} ) ;
27
27
28
- it ( "returns a bigint with 19 digits" , ( ) => {
29
- chai . expect ( getBigIntRpcId ( ) . toString ( ) . length ) . to . equal ( 19 ) ;
30
- } ) ;
31
-
32
28
// Context: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
33
29
it ( "returns a safe integer" , ( ) => {
34
30
chai . expect ( Number . isSafeInteger ( payloadId ( ) ) ) . to . be . true ;
@@ -46,4 +42,67 @@ describe("Payload Id", () => {
46
42
const duplicates = findDuplicates ( results ) ;
47
43
chai . expect ( duplicates . length === 0 ) . to . be . true ;
48
44
} ) ;
45
+
46
+ it ( "generates increasing values when called within same tick" , ( ) => {
47
+ let i = 0 ;
48
+ while ( i ++ < 10000 ) {
49
+ const value1 = payloadId ( ) ;
50
+ const value2 = payloadId ( ) ;
51
+ const value3 = payloadId ( ) ;
52
+ const value4 = payloadId ( ) ;
53
+ if ( value1 >= value2 || value2 >= value3 || value3 >= value4 ) {
54
+ chai . assert . fail ( "Not increasing values" ) ;
55
+ }
56
+ }
57
+ chai . assert . isOk ( "Pass" ) ;
58
+ } ) ;
59
+
60
+ it ( "generates non-repeating values when called within same tick" , ( ) => {
61
+ let i = 0 ;
62
+ while ( i ++ < 10000 ) {
63
+ const values = [ payloadId ( ) , payloadId ( ) , payloadId ( ) , payloadId ( ) ] ;
64
+ const set = new Set ( values ) ;
65
+ if ( set . size !== values . length ) {
66
+ chai . assert . fail ( "Not unique values" ) ;
67
+ }
68
+ }
69
+ chai . assert . isOk ( "Pass" ) ;
70
+ } ) ;
71
+ } ) ;
72
+
73
+ describe ( "Get BigInt Rpc Id" , ( ) => {
74
+ it ( "returns a bigint" , ( ) => {
75
+ const value = getBigIntRpcId ( ) ;
76
+ chai . expect ( typeof value === "bigint" ) . to . be . true ;
77
+ } ) ;
78
+
79
+ it ( "returns a bigint with 19 digits" , ( ) => {
80
+ chai . expect ( getBigIntRpcId ( ) . toString ( ) . length ) . to . equal ( 19 ) ;
81
+ } ) ;
82
+
83
+ it ( "generates increasing values when called within same tick" , ( ) => {
84
+ let i = 0 ;
85
+ while ( i ++ < 10000 ) {
86
+ const value1 = getBigIntRpcId ( ) ;
87
+ const value2 = getBigIntRpcId ( ) ;
88
+ const value3 = getBigIntRpcId ( ) ;
89
+ const value4 = getBigIntRpcId ( ) ;
90
+ if ( value1 >= value2 || value2 >= value3 || value3 >= value4 ) {
91
+ chai . assert . fail ( "Not increasing values" ) ;
92
+ }
93
+ }
94
+ chai . assert . isOk ( "Pass" ) ;
95
+ } ) ;
96
+
97
+ it ( "generates non-repeating values when called within same tick" , ( ) => {
98
+ let i = 0 ;
99
+ while ( i ++ < 10000 ) {
100
+ const values = [ getBigIntRpcId ( ) , getBigIntRpcId ( ) , getBigIntRpcId ( ) , getBigIntRpcId ( ) ] ;
101
+ const set = new Set ( values ) ;
102
+ if ( set . size !== values . length ) {
103
+ chai . assert . fail ( "Not unique values" ) ;
104
+ }
105
+ }
106
+ chai . assert . isOk ( "Pass" ) ;
107
+ } ) ;
49
108
} ) ;
0 commit comments