@@ -20,6 +20,8 @@ import {
20
20
compiledComplexSierra ,
21
21
compiledHelloSierra ,
22
22
compiledHelloSierraCasm ,
23
+ describeIfDevnetSequencer ,
24
+ describeIfSequencerGoerli ,
23
25
getTestAccount ,
24
26
getTestProvider ,
25
27
} from './fixtures' ;
@@ -36,13 +38,31 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
36
38
let cairo1Contract : TypedContract < typeof tAbi > ;
37
39
initializeMatcher ( expect ) ;
38
40
39
- xtest ( 'Declare & deploy v2 - Hello Cairo 1 contract' , async ( ) => {
41
+ beforeAll ( async ( ) => {
42
+ dd = await account . declareAndDeploy ( {
43
+ contract : compiledHelloSierra ,
44
+ casm : compiledHelloSierraCasm ,
45
+ } ) ;
46
+
47
+ cairo1Contract = new Contract (
48
+ compiledHelloSierra . abi ,
49
+ dd . deploy . contract_address ,
50
+ account
51
+ ) . typed ( tAbi ) ;
52
+ } ) ;
53
+
54
+ test ( 'Declare & deploy v2 - Hello Cairo 1 contract' , async ( ) => {
40
55
expect ( dd . declare ) . toMatchSchemaRef ( 'DeclareContractResponse' ) ;
41
56
expect ( dd . deploy ) . toMatchSchemaRef ( 'DeployContractUDCResponse' ) ;
42
57
expect ( cairo1Contract ) . toBeInstanceOf ( Contract ) ;
43
58
} ) ;
44
59
45
- xtest ( 'ContractFactory on Cairo1' , async ( ) => {
60
+ test ( 'getCairoVersion' , async ( ) => {
61
+ const version1 = await cairo1Contract . getVersion ( ) ;
62
+ expect ( version1 ) . toEqual ( { cairo : '1' , compiler : '1' } ) ;
63
+ } ) ;
64
+
65
+ test ( 'ContractFactory on Cairo1' , async ( ) => {
46
66
const c1CFactory = new ContractFactory ( {
47
67
compiledContract : compiledHelloSierra ,
48
68
casm : compiledHelloSierraCasm ,
@@ -67,53 +87,53 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
67
87
} ) ;
68
88
} ) ;
69
89
70
- xtest ( 'deployContract Cairo1' , async ( ) => {
90
+ test ( 'deployContract Cairo1' , async ( ) => {
71
91
const deploy = await account . deployContract ( {
72
92
classHash : dd . deploy . classHash ,
73
93
} ) ;
74
94
expect ( deploy ) . toHaveProperty ( 'address' ) ;
75
95
} ) ;
76
96
77
- xtest ( 'GetClassByHash' , async ( ) => {
97
+ test ( 'GetClassByHash' , async ( ) => {
78
98
const classResponse = await provider . getClassByHash ( dd . deploy . classHash ) ;
79
99
expect ( classResponse ) . toMatchSchemaRef ( 'SierraContractClass' ) ;
80
100
} ) ;
81
101
82
- xtest ( 'GetClassAt' , async ( ) => {
102
+ test ( 'GetClassAt' , async ( ) => {
83
103
const classResponse = await provider . getClassAt ( dd . deploy . contract_address ) ;
84
104
expect ( classResponse ) . toMatchSchemaRef ( 'SierraContractClass' ) ;
85
105
} ) ;
86
106
87
- xtest ( 'isCairo1' , async ( ) => {
107
+ test ( 'isCairo1' , async ( ) => {
88
108
const isContractCairo1 = cairo1Contract . isCairo1 ( ) ;
89
109
expect ( isContractCairo1 ) . toBe ( true ) ;
90
110
const isAbiCairo1 = isCairo1Abi ( cairo1Contract . abi ) ;
91
111
expect ( isAbiCairo1 ) . toBe ( true ) ;
92
112
} ) ;
93
113
94
- xtest ( 'Cairo 1 Contract Interaction - skip invoke validation & call parsing' , async ( ) => {
114
+ test ( 'Cairo 1 Contract Interaction - skip invoke validation & call parsing' , async ( ) => {
95
115
const tx = await cairo1Contract . increase_balance (
96
116
CallData . compile ( {
97
117
amount : 100 ,
98
118
} )
99
119
) ;
100
120
await account . waitForTransaction ( tx . transaction_hash ) ;
101
121
102
- // const balance = await cairo1Contract.get_balance({
103
- // parseResponse: false,
104
- // });
122
+ const balance = await cairo1Contract . get_balance ( {
123
+ parseResponse : false ,
124
+ } ) ;
105
125
106
- // expect(num.toBigInt(balance[0] )).toBe(100n);
126
+ expect ( num . toBigInt ( balance ) ) . toBe ( 100n ) ;
107
127
} ) ;
108
128
109
- xtest ( 'Cairo 1 Contract Interaction - felt252' , async ( ) => {
129
+ test ( 'Cairo 1 Contract Interaction - felt252' , async ( ) => {
110
130
const tx = await cairo1Contract . increase_balance ( 100 ) ;
111
131
await account . waitForTransaction ( tx . transaction_hash ) ;
112
132
const balance = await cairo1Contract . get_balance ( ) ;
113
133
expect ( balance ) . toBe ( 200n ) ;
114
134
} ) ;
115
135
116
- xtest ( 'Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128' , async ( ) => {
136
+ test ( 'Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128' , async ( ) => {
117
137
const tx = await cairo1Contract . increase_balance_u8 ( 255n ) ;
118
138
await account . waitForTransaction ( tx . transaction_hash ) ;
119
139
const balance = await cairo1Contract . get_balance_u8 ( ) ;
@@ -129,7 +149,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
129
149
expect ( result ) . toBe ( 256n ) ;
130
150
} ) ;
131
151
132
- xtest ( 'Cairo 1 - uint256' , async ( ) => {
152
+ test ( 'Cairo 1 - uint256' , async ( ) => {
133
153
// defined as number
134
154
const result = await cairo1Contract . test_u256 ( 2n ** 256n - 2n ) ;
135
155
expect ( result ) . toBe ( 2n ** 256n - 1n ) ;
@@ -139,7 +159,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
139
159
expect ( result1 ) . toBe ( 2n ** 256n - 1n ) ;
140
160
} ) ;
141
161
142
- xtest ( 'Cairo 1 Contract Interaction - bool' , async ( ) => {
162
+ test ( 'Cairo 1 Contract Interaction - bool' , async ( ) => {
143
163
const cdata = CallData . compile ( { false : false , true : true } ) ;
144
164
expect ( cdata ) . toEqual ( [ '0' , '1' ] ) ;
145
165
@@ -162,15 +182,15 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
162
182
expect ( status ) . toBe ( true ) ;
163
183
} ) ;
164
184
165
- xtest ( 'Cairo 1 Contract Interaction - ContractAddress' , async ( ) => {
185
+ test ( 'Cairo 1 Contract Interaction - ContractAddress' , async ( ) => {
166
186
const tx = await cairo1Contract . set_ca ( '123' ) ;
167
187
await account . waitForTransaction ( tx . transaction_hash ) ;
168
188
const status = await cairo1Contract . get_ca ( ) ;
169
189
170
190
expect ( status ) . toBe ( 123n ) ;
171
191
} ) ;
172
192
173
- xtest ( 'Cairo1 simple getStorageAt variables retrieval' , async ( ) => {
193
+ test ( 'Cairo1 simple getStorageAt variables retrieval' , async ( ) => {
174
194
// u8
175
195
let tx = await cairo1Contract . increase_balance ( 100 ) ;
176
196
await account . waitForTransaction ( tx . transaction_hash ) ;
@@ -211,12 +231,12 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
211
231
// TODO: Complex mapping - https://docs.starknet.io/documentation/architecture_and_concepts/Contracts/contract-storage/
212
232
} ) ;
213
233
214
- xtest ( 'Cairo 1 Contract Interaction - echo flat un-named un-nested tuple' , async ( ) => {
234
+ test ( 'Cairo 1 Contract Interaction - echo flat un-named un-nested tuple' , async ( ) => {
215
235
const status = await cairo1Contract . echo_un_tuple ( [ 77 , 123 ] ) ;
216
236
expect ( Object . values ( status ) ) . toEqual ( [ 77n , 123n ] ) ;
217
237
} ) ;
218
238
219
- xtest ( 'Cairo 1 Contract Interaction - echo flat un-nested Array u8, uint256, bool' , async ( ) => {
239
+ test ( 'Cairo 1 Contract Interaction - echo flat un-nested Array u8, uint256, bool' , async ( ) => {
220
240
const status = await cairo1Contract . echo_array ( [ 123 , 55 , 77 , 255 ] ) ;
221
241
expect ( status ) . toEqual ( [ 123n , 55n , 77n , 255n ] ) ;
222
242
@@ -237,14 +257,14 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
237
257
expect ( status2 ) . toEqual ( [ true , true , false , false ] ) ;
238
258
} ) ;
239
259
240
- xtest ( 'Cairo 1 Contract Interaction - echo flat un-nested Struct' , async ( ) => {
260
+ test ( 'Cairo 1 Contract Interaction - echo flat un-nested Struct' , async ( ) => {
241
261
const status = await cairo1Contract . echo_struct ( {
242
262
val : 'simple' ,
243
263
} ) ;
244
264
expect ( shortString . decodeShortString ( status . val as string ) ) . toBe ( 'simple' ) ;
245
265
} ) ;
246
266
247
- xtest ( 'Cairo 1 more complex structs' , async ( ) => {
267
+ test ( 'Cairo 1 more complex structs' , async ( ) => {
248
268
const tx = await cairo1Contract . set_bet ( ) ;
249
269
await account . waitForTransaction ( tx . transaction_hash ) ;
250
270
const status = await cairo1Contract . get_bet (
@@ -277,7 +297,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
277
297
expect ( expected ) . toEqual ( status ) ;
278
298
} ) ;
279
299
280
- xtest ( 'C1 Array 2D' , async ( ) => {
300
+ test ( 'C1 Array 2D' , async ( ) => {
281
301
const cd = CallData . compile ( {
282
302
test : [
283
303
[ 1 , 2 ] ,
@@ -313,7 +333,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
313
333
expect ( result1 ) . toEqual ( result11 ) ;
314
334
} ) ;
315
335
316
- xtest ( 'mix tuples' , async ( ) => {
336
+ test ( 'mix tuples' , async ( ) => {
317
337
const res = await cairo1Contract . array_bool_tuple ( [ 1 , 2 , 3 ] , true ) ;
318
338
expect ( res ) . toEqual ( {
319
339
0 : [ 1n , 2n , 3n , 1n , 2n ] ,
@@ -330,7 +350,7 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
330
350
} ) ;
331
351
} ) ;
332
352
333
- xtest ( 'myCallData.compile for Cairo 1' , async ( ) => {
353
+ test ( 'myCallData.compile for Cairo 1' , async ( ) => {
334
354
const myFalseUint256 = { high : 1 , low : 23456 } ; // wrong order
335
355
type Order2 = {
336
356
p1 : BigNumberish ;
@@ -475,67 +495,72 @@ describe('TS validation for API & Contract interactions - tests skipped', () =>
475
495
expect ( callDataFromArray ) . toStrictEqual ( expectedResult ) ;
476
496
} ) ;
477
497
478
- xtest ( 'getCompiledClassByClassHash' , async ( ) => {
479
- const compiledClass = await ( provider as SequencerProvider ) . getCompiledClassByClassHash (
480
- dd . deploy . classHash
481
- ) ;
482
- expect ( compiledClass ) . toMatchSchemaRef ( 'CompiledClass' ) ;
498
+ describeIfDevnetSequencer ( 'Sequencer only' , ( ) => {
499
+ test ( 'getCompiledClassByClassHash' , async ( ) => {
500
+ const compiledClass = await ( provider as SequencerProvider ) . getCompiledClassByClassHash (
501
+ dd . deploy . classHash
502
+ ) ;
503
+ expect ( compiledClass ) . toMatchSchemaRef ( 'CompiledClass' ) ;
504
+ } ) ;
483
505
} ) ;
484
506
} ) ;
485
507
486
- describe ( 'TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped' , ( ) => {
487
- const provider = getTestProvider ( ) as SequencerProvider ;
488
- const classHash : any = '0x028b6f2ee9ae00d55a32072d939a55a6eb522974a283880f3c73a64c2f9fd6d6' ;
489
- const contractAddress : any = '0x771bbe2ba64fa5ab52f0c142b4296fc67460a3a2372b4cdce752c620e3e8194' ;
490
- let cairo1Contract : TypedContract < typeof tAbi > ;
491
- initializeMatcher ( expect ) ;
492
-
493
- xtest ( 'getCompiledClassByClassHash' , async ( ) => {
494
- const compiledClass = await provider . getCompiledClassByClassHash ( classHash ) ;
495
- expect ( compiledClass ) . toMatchSchemaRef ( 'CompiledClass' ) ;
496
- } ) ;
508
+ describeIfSequencerGoerli ( 'Cairo1 Testnet' , ( ) => {
509
+ describe ( 'TS validation for Sequencer API - C1 T2 C:0x771bbe2ba64f... - tests skipped' , ( ) => {
510
+ const provider = getTestProvider ( ) as SequencerProvider ;
511
+ const classHash : any = '0x028b6f2ee9ae00d55a32072d939a55a6eb522974a283880f3c73a64c2f9fd6d6' ;
512
+ const contractAddress : any =
513
+ '0x771bbe2ba64fa5ab52f0c142b4296fc67460a3a2372b4cdce752c620e3e8194' ;
514
+ let cairo1Contract : TypedContract < typeof tAbi > ;
515
+ initializeMatcher ( expect ) ;
516
+
517
+ test ( 'getCompiledClassByClassHash' , async ( ) => {
518
+ const compiledClass = await provider . getCompiledClassByClassHash ( classHash ) ;
519
+ expect ( compiledClass ) . toMatchSchemaRef ( 'CompiledClass' ) ;
520
+ } ) ;
497
521
498
- xtest ( 'GetClassByHash' , async ( ) => {
499
- const classResponse = await provider . getClassByHash ( classHash ) ;
500
- expect ( classResponse ) . toMatchSchemaRef ( 'SierraContractClass' ) ;
501
- } ) ;
522
+ test ( 'GetClassByHash' , async ( ) => {
523
+ const classResponse = await provider . getClassByHash ( classHash ) ;
524
+ expect ( classResponse ) . toMatchSchemaRef ( 'SierraContractClass' ) ;
525
+ } ) ;
502
526
503
- xtest ( 'GetClassAt' , async ( ) => {
504
- const classResponse = await provider . getClassAt ( contractAddress ) ;
505
- expect ( classResponse ) . toMatchSchemaRef ( 'SierraContractClass' ) ;
506
- } ) ;
527
+ test ( 'GetClassAt' , async ( ) => {
528
+ const classResponse = await provider . getClassAt ( contractAddress ) ;
529
+ expect ( classResponse ) . toMatchSchemaRef ( 'SierraContractClass' ) ;
530
+ } ) ;
507
531
508
- xtest ( 'Cairo 1 Contract Interaction - felt252' , async ( ) => {
509
- const result = await cairo1Contract . test_felt252 ( 100 ) ;
510
- expect ( result ) . toBe ( 101n ) ;
511
- } ) ;
532
+ test ( 'Cairo 1 Contract Interaction - felt252' , async ( ) => {
533
+ const result = await cairo1Contract . test_felt252 ( 100 ) ;
534
+ expect ( result ) . toBe ( 101n ) ;
535
+ } ) ;
512
536
513
- xtest ( 'Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128' , async ( ) => {
514
- const r1 = await cairo1Contract . test_u8 ( 100n ) ;
515
- expect ( r1 ) . toBe ( 107n ) ;
516
- const r2 = await cairo1Contract . test_u16 ( 100n ) ;
517
- expect ( r2 ) . toBe ( 106n ) ;
518
- const r3 = await cairo1Contract . test_u32 ( 100n ) ;
519
- expect ( r3 ) . toBe ( 104n ) ;
520
- const r4 = await cairo1Contract . test_u64 ( 255n ) ;
521
- expect ( r4 ) . toBe ( 258n ) ;
522
- const r5 = await cairo1Contract . test_u128 ( 255n ) ;
523
- expect ( r5 ) . toBe ( 257n ) ;
524
- } ) ;
537
+ test ( 'Cairo 1 Contract Interaction - uint 8, 16, 32, 64, 128' , async ( ) => {
538
+ const r1 = await cairo1Contract . test_u8 ( 100n ) ;
539
+ expect ( r1 ) . toBe ( 107n ) ;
540
+ const r2 = await cairo1Contract . test_u16 ( 100n ) ;
541
+ expect ( r2 ) . toBe ( 106n ) ;
542
+ const r3 = await cairo1Contract . test_u32 ( 100n ) ;
543
+ expect ( r3 ) . toBe ( 104n ) ;
544
+ const r4 = await cairo1Contract . test_u64 ( 255n ) ;
545
+ expect ( r4 ) . toBe ( 258n ) ;
546
+ const r5 = await cairo1Contract . test_u128 ( 255n ) ;
547
+ expect ( r5 ) . toBe ( 257n ) ;
548
+ } ) ;
525
549
526
- xtest ( 'Cairo 1 - uint256 struct' , async ( ) => {
527
- const myUint256 = uint256 ( 2n ** 256n - 2n ) ;
528
- const result = await cairo1Contract . test_u256 ( myUint256 ) ;
529
- expect ( result ) . toBe ( 2n ** 256n - 1n ) ;
530
- } ) ;
550
+ test ( 'Cairo 1 - uint256 struct' , async ( ) => {
551
+ const myUint256 = uint256 ( 2n ** 256n - 2n ) ;
552
+ const result = await cairo1Contract . test_u256 ( myUint256 ) ;
553
+ expect ( result ) . toBe ( 2n ** 256n - 1n ) ;
554
+ } ) ;
531
555
532
- xtest ( 'Cairo 1 - uint256 by a bignumber' , async ( ) => {
533
- const result = await cairo1Contract . test_u256 ( 2n ** 256n - 2n ) ;
534
- expect ( result ) . toBe ( 2n ** 256n - 1n ) ;
535
- } ) ;
556
+ test ( 'Cairo 1 - uint256 by a bignumber' , async ( ) => {
557
+ const result = await cairo1Contract . test_u256 ( 2n ** 256n - 2n ) ;
558
+ expect ( result ) . toBe ( 2n ** 256n - 1n ) ;
559
+ } ) ;
536
560
537
- xtest ( 'Cairo 1 Contract Interaction - bool' , async ( ) => {
538
- const tx = await cairo1Contract . test_bool ( ) ;
539
- expect ( tx ) . toBe ( true ) ;
561
+ test ( 'Cairo 1 Contract Interaction - bool' , async ( ) => {
562
+ const tx = await cairo1Contract . test_bool ( ) ;
563
+ expect ( tx ) . toBe ( true ) ;
564
+ } ) ;
540
565
} ) ;
541
566
} ) ;
0 commit comments