1
1
import { initSimnet } from "@hirosystems/clarinet-sdk" ;
2
+ import { initializeClarityContext , initializeLocalContext } from "./invariant" ;
2
3
import {
3
4
buildRendezvousData ,
4
5
deployRendezvous ,
5
- deriveRendezvousName ,
6
6
filterRendezvousInterfaces ,
7
- getContractNameFromRendezvousId ,
8
- getInvariantContractSource ,
9
- initializeClarityContext ,
10
- initializeLocalContext ,
11
- scheduleRendezvous ,
12
- } from "./invariant" ;
13
- import {
14
7
getFunctionsFromContractInterfaces ,
15
- getSimnetContractSource ,
16
8
getSimnetDeployerContractsInterfaces ,
9
+ getTestContractSource ,
17
10
} from "./shared" ;
18
11
import { resolve } from "path" ;
19
12
import fs from "fs" ;
20
- import fc from "fast-check" ;
21
13
import { Cl } from "@stacks/transactions" ;
22
14
23
15
describe ( "File stream operations" , ( ) => {
@@ -30,15 +22,15 @@ describe("File stream operations", () => {
30
22
const sutContractsList = Array . from ( sutContractsInterfaces . keys ( ) ) ;
31
23
const expectedInvariantContractSources = sutContractsList . map (
32
24
( contractId ) => {
33
- const invariantContractName = `${ contractId . split ( "." ) [ 1 ] } .invariants ` ;
25
+ const invariantContractName = `${ contractId . split ( "." ) [ 1 ] } .tests ` ;
34
26
const invariantContractPath = `${ contractsPath } /${ invariantContractName } .clar` ;
35
27
return fs . readFileSync ( invariantContractPath ) . toString ( ) ;
36
28
}
37
29
) ;
38
30
39
31
// Act
40
32
const actualInvariantContractSources = sutContractsList . map ( ( contractId ) =>
41
- getInvariantContractSource ( contractsPath , contractId )
33
+ getTestContractSource ( contractsPath , contractId )
42
34
) ;
43
35
44
36
// Assert
@@ -49,115 +41,6 @@ describe("File stream operations", () => {
49
41
} ) ;
50
42
51
43
describe ( "Simnet contracts operations" , ( ) => {
52
- it ( "retrieves Rendezvous contracts data" , async ( ) => {
53
- // Arrange
54
- const manifestPath = resolve ( __dirname , "./example/Clarinet.toml" ) ;
55
- const contractsPath = resolve ( __dirname , "./example/contracts" ) ;
56
- const simnet = await initSimnet ( manifestPath ) ;
57
- const sutContractsInterfaces = getSimnetDeployerContractsInterfaces ( simnet ) ;
58
- const sutContractsList = Array . from ( sutContractsInterfaces . keys ( ) ) ;
59
-
60
- const expectedRendezvousData = sutContractsList . map ( ( contractId ) => {
61
- const sutContractSource = getSimnetContractSource ( simnet , contractId ) ;
62
- const invariantContractSource = getInvariantContractSource (
63
- contractsPath ,
64
- contractId
65
- ) ;
66
- const rendezvousSource = scheduleRendezvous (
67
- sutContractSource ! ,
68
- invariantContractSource
69
- ) ;
70
- const rendezvousName = deriveRendezvousName ( contractId ) ;
71
-
72
- return {
73
- rendezvousName,
74
- rendezvousSource,
75
- rendezvousContractId : `${ simnet . deployer } .${ rendezvousName } ` ,
76
- } ;
77
- } ) ;
78
-
79
- // Act
80
- const actualRendezvousData = sutContractsList . map ( ( contractId ) =>
81
- buildRendezvousData ( simnet , contractId , contractsPath )
82
- ) ;
83
-
84
- // Assert
85
- expect ( actualRendezvousData ) . toEqual ( expectedRendezvousData ) ;
86
- } ) ;
87
-
88
- it ( "deploys Rendezvous contracts to the simnet" , async ( ) => {
89
- // Arrange
90
- const manifestPath = resolve ( __dirname , "./example/Clarinet.toml" ) ;
91
- const contractsPath = resolve ( __dirname , "./example/contracts" ) ;
92
- const simnet = await initSimnet ( manifestPath ) ;
93
- const sutContractsInterfaces = getSimnetDeployerContractsInterfaces ( simnet ) ;
94
- const sutContractsList = Array . from ( sutContractsInterfaces . keys ( ) ) ;
95
- const rendezvousData = sutContractsList . map ( ( contractId ) =>
96
- buildRendezvousData ( simnet , contractId , contractsPath )
97
- ) ;
98
-
99
- // Act
100
- rendezvousData . forEach ( ( contractData ) => {
101
- deployRendezvous (
102
- simnet ,
103
- contractData . rendezvousName ,
104
- contractData . rendezvousSource
105
- ) ;
106
- } ) ;
107
-
108
- // Re-fetch contract interfaces to check after deployment
109
- const actualSimnetContractsInterfacesAfterDeploy =
110
- getSimnetDeployerContractsInterfaces ( simnet ) ;
111
- const actualSimnetContractsListAfterDeploy = Array . from (
112
- actualSimnetContractsInterfacesAfterDeploy . keys ( )
113
- ) ;
114
-
115
- // Assert
116
- // Check if all expected Rendezvous contracts are present in the result
117
- rendezvousData . forEach ( ( contractData ) => {
118
- expect ( actualSimnetContractsListAfterDeploy ) . toContain (
119
- contractData . rendezvousContractId
120
- ) ;
121
- } ) ;
122
-
123
- // Ensure there are exactly double the number of original contracts (pre-deployment and Rendezvous)
124
- expect ( actualSimnetContractsListAfterDeploy ) . toHaveLength (
125
- 2 * sutContractsList . length
126
- ) ;
127
- } ) ;
128
-
129
- it ( "correctly filters the Rendezvous contracts interfaces" , async ( ) => {
130
- // Arrange
131
- const manifestPath = resolve ( __dirname , "./example/Clarinet.toml" ) ;
132
- const contractsPath = resolve ( __dirname , "./example/contracts" ) ;
133
- const simnet = await initSimnet ( manifestPath ) ;
134
- const sutContractsInterfaces = getSimnetDeployerContractsInterfaces ( simnet ) ;
135
- const sutContractsList = Array . from ( sutContractsInterfaces . keys ( ) ) ;
136
- const expectedRendezvousList = sutContractsList
137
- . map ( ( contractId ) =>
138
- buildRendezvousData ( simnet , contractId , contractsPath )
139
- )
140
- . map ( ( contractData ) => {
141
- deployRendezvous (
142
- simnet ,
143
- contractData . rendezvousName ,
144
- contractData . rendezvousSource
145
- ) ;
146
- return contractData . rendezvousContractId ;
147
- } )
148
- . sort ( ) ;
149
-
150
- // Act
151
- const actualRendezvousList = Array . from (
152
- filterRendezvousInterfaces (
153
- getSimnetDeployerContractsInterfaces ( simnet )
154
- ) . keys ( )
155
- ) . sort ( ) ;
156
-
157
- // Assert
158
- expect ( actualRendezvousList ) . toEqual ( expectedRendezvousList ) ;
159
- } ) ;
160
-
161
44
it ( "correctly initializes the local context for a given functions map" , async ( ) => {
162
45
// Arrange
163
46
const manifestPath = resolve ( __dirname , "./example/Clarinet.toml" ) ;
@@ -243,89 +126,4 @@ describe("Simnet contracts operations", () => {
243
126
// Assert
244
127
expect ( actualContext ) . toEqual ( expectedContext ) ;
245
128
} ) ;
246
-
247
- it ( "retrieves the contract source from the simnet" , async ( ) => {
248
- // Arrange
249
- const manifestPath = resolve ( __dirname , "./example/Clarinet.toml" ) ;
250
- const simnet = await initSimnet ( manifestPath ) ;
251
- const sutContractsInterfaces = getSimnetDeployerContractsInterfaces ( simnet ) ;
252
- const sutContractsList = Array . from ( sutContractsInterfaces . keys ( ) ) ;
253
-
254
- const expectedContractSources = sutContractsList . map ( ( contractId ) =>
255
- simnet . getContractSource ( contractId )
256
- ) ;
257
-
258
- // Act
259
- const actualContractSources = sutContractsList . map ( ( contractId ) =>
260
- getSimnetContractSource ( simnet , contractId )
261
- ) ;
262
-
263
- // Assert
264
- expect ( actualContractSources ) . toEqual ( expectedContractSources ) ;
265
- } ) ;
266
- } ) ;
267
-
268
- describe ( "Successfully schedules rendez-vous" , ( ) => {
269
- const context = `(define-map context (string-ascii 100) {
270
- called: uint
271
- ;; other data
272
- })
273
-
274
- (define-public (update-context (function-name (string-ascii 100)) (called uint))
275
- (ok (map-set context function-name {called: called})))` ;
276
-
277
- it ( "adds context between contract and invariants" , ( ) => {
278
- fc . assert (
279
- // Arrange
280
- fc . property ( fc . string ( ) , fc . string ( ) , ( contract , invariants ) => {
281
- // Act
282
- const actual = scheduleRendezvous ( contract , invariants ) ;
283
- // Assert
284
- const expected = `${ contract } \n\n${ context } \n\n${ invariants } ` ;
285
- expect ( actual ) . toBe ( expected ) ;
286
- } )
287
- ) ;
288
- } ) ;
289
-
290
- it ( "derives the Rendezvous contract name" , ( ) => {
291
- const addressCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
292
- const contractNameCharset =
293
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" ;
294
- fc . assert (
295
- // Arrange
296
- fc . property (
297
- fc . stringOf ( fc . constantFrom ( ...addressCharset ) ) ,
298
- fc . stringOf ( fc . constantFrom ( ...contractNameCharset ) ) ,
299
- ( address , contractName ) => {
300
- // Act
301
- const actual = deriveRendezvousName ( `${ address } .${ contractName } ` ) ;
302
- // Assert
303
- const expected = `${ contractName } _rendezvous` ;
304
- expect ( actual ) . toBe ( expected ) ;
305
- }
306
- )
307
- ) ;
308
- } ) ;
309
-
310
- it ( "gets contract name from Rendezvous contract name" , ( ) => {
311
- const addressCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
312
- const contractNameCharset =
313
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" ;
314
- fc . assert (
315
- // Arrange
316
- fc . property (
317
- fc . stringOf ( fc . constantFrom ( ...addressCharset ) ) ,
318
- fc . stringOf ( fc . constantFrom ( ...contractNameCharset ) ) ,
319
- ( address , contractName ) => {
320
- const rendezvousId = `${ address } .${ contractName } _rendezvous` ;
321
-
322
- // Act
323
- const actual = getContractNameFromRendezvousId ( rendezvousId ) ;
324
-
325
- // Assert
326
- expect ( actual ) . toBe ( contractName ) ;
327
- }
328
- )
329
- ) ;
330
- } ) ;
331
129
} ) ;
0 commit comments