1- import { BlockNumber , GetBlockResponse , stark } from '../src' ;
1+ import {
2+ BlockNumber ,
3+ DeclareContractResponse ,
4+ DeployContractResponse ,
5+ GetBlockResponse ,
6+ SequencerProvider ,
7+ stark ,
8+ } from '../src' ;
29import { toBN } from '../src/utils/number' ;
3- import { IS_DEVNET , compiledErc20 , compiledOpenZeppelinAccount , getTestProvider } from './fixtures' ;
10+ import {
11+ IS_DEVNET ,
12+ compiledErc20 ,
13+ compiledOpenZeppelinAccount ,
14+ getTestProvider ,
15+ getTestRpcProvider ,
16+ } from './fixtures' ;
417
518const { compileCalldata } = stark ;
619
7- const provider = getTestProvider ( ) ;
20+ const testProvider = getTestProvider ( ) ;
821
922describe ( 'defaultProvider' , ( ) => {
1023 let exampleTransactionHash : string ;
@@ -15,25 +28,25 @@ describe('defaultProvider', () => {
1528 let exampleBlockHash ! : string ;
1629
1730 beforeAll ( async ( ) => {
18- const { transaction_hash, contract_address } = await provider . deployContract ( {
31+ const { transaction_hash, contract_address } = await testProvider . deployContract ( {
1932 contract : compiledErc20 ,
2033 } ) ;
21- await provider . waitForTransaction ( transaction_hash ) ;
34+ await testProvider . waitForTransaction ( transaction_hash ) ;
2235 exampleTransactionHash = transaction_hash ;
2336 exampleContractAddress = contract_address ;
2437
25- exampleBlock = await provider . getBlock ( ) ;
38+ exampleBlock = await testProvider . getBlock ( ) ;
2639 exampleBlockHash = exampleBlock . block_hash ;
2740 exampleBlockNumber = exampleBlock . block_number ;
2841 } ) ;
2942
3043 describe ( 'endpoints' , ( ) => {
3144 test ( `getBlock(blockHash=undefined, blockNumber=${ exampleBlockNumber } )` , ( ) => {
32- return expect ( provider . getBlock ( exampleBlockNumber ) ) . resolves . not . toThrow ( ) ;
45+ return expect ( testProvider . getBlock ( exampleBlockNumber ) ) . resolves . not . toThrow ( ) ;
3346 } ) ;
3447
3548 test ( `getBlock(blockHash=${ exampleBlockHash } , blockNumber=undefined)` , ( ) => {
36- return expect ( provider . getBlock ( exampleBlockHash ) ) . resolves . not . toThrow ( ) ;
49+ return expect ( testProvider . getBlock ( exampleBlockHash ) ) . resolves . not . toThrow ( ) ;
3750 } ) ;
3851
3952 test ( 'getBlock(blockHash=undefined, blockNumber=null)' , async ( ) => {
@@ -47,49 +60,49 @@ describe('defaultProvider', () => {
4760 } ) ;
4861
4962 test ( 'getBlock() -> { blockNumber }' , async ( ) => {
50- const block = await provider . getBlock ( ) ;
63+ const block = await testProvider . getBlock ( ) ;
5164 return expect ( block ) . toHaveProperty ( 'block_number' ) ;
5265 } ) ;
5366
5467 describe ( 'getStorageAt' , ( ) => {
5568 test ( 'with "key" type of number' , ( ) => {
5669 return expect (
57- provider . getStorageAt ( exampleContractAddress , 0 , 36663 )
70+ testProvider . getStorageAt ( exampleContractAddress , 0 , 36663 )
5871 ) . resolves . not . toThrow ( ) ;
5972 } ) ;
6073
6174 test ( '"key" type of string' , ( ) => {
6275 return expect (
63- provider . getStorageAt ( exampleContractAddress , '0x0' , 36663 )
76+ testProvider . getStorageAt ( exampleContractAddress , '0x0' , 36663 )
6477 ) . resolves . not . toThrow ( ) ;
6578 } ) ;
6679
6780 test ( 'with "key" type of BN' , ( ) => {
6881 return expect (
69- provider . getStorageAt ( exampleContractAddress , toBN ( '0x0' ) , 36663 )
82+ testProvider . getStorageAt ( exampleContractAddress , toBN ( '0x0' ) , 36663 )
7083 ) . resolves . not . toThrow ( ) ;
7184 } ) ;
7285
7386 test ( '(blockHash=undefined, blockNumber=null)' , ( ) => {
74- return expect ( provider . getStorageAt ( exampleContractAddress , 0 ) ) . resolves . not . toThrow ( ) ;
87+ return expect ( testProvider . getStorageAt ( exampleContractAddress , 0 ) ) . resolves . not . toThrow ( ) ;
7588 } ) ;
7689 } ) ;
7790
7891 test ( 'getTransaction() - successful transaction' , async ( ) => {
79- const transaction = await provider . getTransaction ( exampleTransactionHash ) ;
92+ const transaction = await testProvider . getTransaction ( exampleTransactionHash ) ;
8093
8194 expect ( transaction ) . toHaveProperty ( 'transaction_hash' ) ;
8295 } ) ;
8396
8497 test ( 'getTransactionReceipt() - successful transaction' , async ( ) => {
85- const transactionReceipt = await provider . getTransactionReceipt ( exampleTransactionHash ) ;
98+ const transactionReceipt = await testProvider . getTransactionReceipt ( exampleTransactionHash ) ;
8699
87100 return expect ( transactionReceipt ) . toHaveProperty ( 'actual_fee' ) ;
88101 } ) ;
89102
90103 test ( 'callContract()' , ( ) => {
91104 return expect (
92- provider . callContract ( {
105+ testProvider . callContract ( {
93106 contractAddress : exampleContractAddress ,
94107 entrypoint : 'balance_of' ,
95108 calldata : compileCalldata ( {
@@ -100,7 +113,7 @@ describe('defaultProvider', () => {
100113 } ) ;
101114
102115 test ( 'callContract() - gateway error' , async ( ) => {
103- const promise = provider . callContract ( {
116+ const promise = testProvider . callContract ( {
104117 contractAddress : exampleContractAddress ,
105118 entrypoint : 'non_existent_entrypoint' ,
106119 calldata : compileCalldata ( {
@@ -124,7 +137,7 @@ describe('defaultProvider', () => {
124137
125138 describe ( 'addTransaction()' , ( ) => {
126139 test ( 'declareContract()' , async ( ) => {
127- const response = await provider . declareContract ( {
140+ const response = await testProvider . declareContract ( {
128141 contract : compiledErc20 ,
129142 } ) ;
130143
@@ -133,12 +146,197 @@ describe('defaultProvider', () => {
133146 } ) ;
134147
135148 test ( 'deployContract()' , async ( ) => {
136- const response = await provider . deployContract ( {
149+ const response = await testProvider . deployContract ( {
137150 contract : compiledOpenZeppelinAccount ,
138151 } ) ;
139152
140153 expect ( response . transaction_hash ) . toBeDefined ( ) ;
141154 expect ( response . contract_address ) . toBeDefined ( ) ;
142155 } ) ;
143156 } ) ;
157+
158+ describe . each ( [
159+ { name : 'RPC' , provider : getTestRpcProvider ( ) } ,
160+ { name : 'Sequencer' , provider : new SequencerProvider ( ) } ,
161+ ] ) ( '$name provider' , ( { name, provider } ) => {
162+ describe ( `Provider methods: ${ name } ` , ( ) => {
163+ describe ( 'getBlock' , ( ) => {
164+ test ( 'pending' , async ( ) => {
165+ const latestBlock = await provider . getBlock ( ) ;
166+ expect ( latestBlock ) . toHaveProperty ( 'block_hash' ) ;
167+ expect ( latestBlock ) . toHaveProperty ( 'parent_hash' ) ;
168+ expect ( latestBlock ) . toHaveProperty ( 'block_number' ) ;
169+ expect ( latestBlock ) . toHaveProperty ( 'status' ) ;
170+ expect ( latestBlock ) . toHaveProperty ( 'sequencer' ) ;
171+ expect ( latestBlock ) . toHaveProperty ( 'new_root' ) ;
172+ expect ( latestBlock ) . toHaveProperty ( 'old_root' ) ;
173+ expect ( latestBlock ) . toHaveProperty ( 'accepted_time' ) ;
174+ expect ( latestBlock ) . toHaveProperty ( 'gas_price' ) ;
175+ expect ( latestBlock ) . toHaveProperty ( 'transactions' ) ;
176+ expect ( Array . isArray ( latestBlock . transactions ) ) . toBe ( true ) ;
177+ } ) ;
178+
179+ test ( 'Block Hash 0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43' , async ( ) => {
180+ const block = await provider . getBlock (
181+ '0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43'
182+ ) ;
183+
184+ expect ( block ) . toHaveProperty ( 'block_hash' ) ;
185+ expect ( block ) . toHaveProperty ( 'parent_hash' ) ;
186+ expect ( block ) . toHaveProperty ( 'block_number' ) ;
187+ expect ( block ) . toHaveProperty ( 'status' ) ;
188+ expect ( block ) . toHaveProperty ( 'sequencer' ) ;
189+ expect ( block ) . toHaveProperty ( 'new_root' ) ;
190+ expect ( block ) . toHaveProperty ( 'old_root' ) ;
191+ expect ( block ) . toHaveProperty ( 'accepted_time' ) ;
192+ expect ( block ) . toHaveProperty ( 'gas_price' ) ;
193+ expect ( block ) . toHaveProperty ( 'transactions' ) ;
194+ expect ( Array . isArray ( block . transactions ) ) . toBe ( true ) ;
195+ } ) ;
196+
197+ test ( 'Block Number 102634' , async ( ) => {
198+ const block = await provider . getBlock ( 102634 ) ;
199+ expect ( block ) . toHaveProperty ( 'block_hash' ) ;
200+ expect ( block ) . toHaveProperty ( 'parent_hash' ) ;
201+ expect ( block ) . toHaveProperty ( 'block_number' ) ;
202+ expect ( block ) . toHaveProperty ( 'status' ) ;
203+ expect ( block ) . toHaveProperty ( 'sequencer' ) ;
204+ expect ( block ) . toHaveProperty ( 'new_root' ) ;
205+ expect ( block ) . toHaveProperty ( 'old_root' ) ;
206+ expect ( block ) . toHaveProperty ( 'accepted_time' ) ;
207+ expect ( block ) . toHaveProperty ( 'gas_price' ) ;
208+ expect ( block ) . toHaveProperty ( 'transactions' ) ;
209+ expect ( Array . isArray ( block . transactions ) ) . toBe ( true ) ;
210+ } ) ;
211+ } ) ;
212+
213+ describe ( 'getStorageAt' , ( ) => {
214+ test ( 'pending' , async ( ) => {
215+ const storage = await provider . getStorageAt (
216+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166' ,
217+ 0
218+ ) ;
219+ expect ( typeof storage ) . toBe ( 'string' ) ;
220+ } ) ;
221+
222+ test ( 'Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8' , async ( ) => {
223+ const storage = await provider . getStorageAt (
224+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166' ,
225+ 0 ,
226+ '0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64'
227+ ) ;
228+ expect ( typeof storage ) . toBe ( 'string' ) ;
229+ } ) ;
230+ } ) ;
231+
232+ describe ( 'getTransaction' , ( ) => {
233+ test ( 'Deploy Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' , async ( ) => {
234+ const transaction = await provider . getTransaction (
235+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
236+ ) ;
237+
238+ expect ( transaction . transaction_hash ) . toBeTruthy ( ) ;
239+ expect ( transaction . contract_address ) . toBeTruthy ( ) ;
240+ } ) ;
241+
242+ test ( 'Invoke Transaction Hash 0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b' , async ( ) => {
243+ const transaction = await provider . getTransaction (
244+ '0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b'
245+ ) ;
246+
247+ expect ( transaction . transaction_hash ) . toBeTruthy ( ) ;
248+ expect ( transaction . contract_address ) . toBeTruthy ( ) ;
249+ expect ( Array . isArray ( transaction . calldata ) ) . toBe ( true ) ;
250+ expect ( transaction . entry_point_selector ) . toBeTruthy ( ) ;
251+ expect ( Array . isArray ( transaction . signature ) ) . toBe ( true ) ;
252+ expect ( transaction . max_fee ) . toBeTruthy ( ) ;
253+ } ) ;
254+
255+ test ( 'Declare Transaction Hash 0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea' , async ( ) => {
256+ const transaction = await provider . getTransaction (
257+ '0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea'
258+ ) ;
259+
260+ expect ( transaction . max_fee ) . toBeTruthy ( ) ;
261+ expect ( transaction . transaction_hash ) . toBeTruthy ( ) ;
262+ expect ( transaction ) . toHaveProperty ( 'nonce' ) ;
263+ expect ( transaction ) . toHaveProperty ( 'sender_address' ) ;
264+ expect ( transaction ) . toHaveProperty ( 'version' ) ;
265+ } ) ;
266+ } ) ;
267+
268+ describe ( 'getTransactionReceipt' , ( ) => {
269+ test ( 'Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' , async ( ) => {
270+ const receipt = await provider . getTransactionReceipt (
271+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
272+ ) ;
273+
274+ expect ( receipt ) . toHaveProperty ( 'transaction_hash' ) ;
275+ expect ( receipt ) . toHaveProperty ( 'status' ) ;
276+ expect ( receipt ) . toHaveProperty ( 'status_data' ) ;
277+ expect ( receipt ) . toHaveProperty ( 'messages_sent' ) ;
278+ expect ( receipt ) . toHaveProperty ( 'l1_origin_message' ) ;
279+ expect ( receipt ) . toHaveProperty ( 'events' ) ;
280+ } ) ;
281+ } ) ;
282+
283+ describe ( 'Contract methods' , ( ) => {
284+ let contractAddress : string ;
285+ let deployResponse : DeployContractResponse ;
286+ let declareResponse : DeclareContractResponse ;
287+
288+ beforeAll ( async ( ) => {
289+ deployResponse = await provider . deployContract ( { contract : compiledErc20 } ) ;
290+ contractAddress = deployResponse . contract_address ;
291+ declareResponse = await provider . declareContract ( { contract : compiledErc20 } ) ;
292+ await Promise . all ( [
293+ provider . waitForTransaction ( deployResponse . transaction_hash ) ,
294+ provider . waitForTransaction ( declareResponse . transaction_hash ) ,
295+ ] ) ;
296+ } ) ;
297+
298+ describe ( 'deployContract' , ( ) => {
299+ test ( 'response' , ( ) => {
300+ expect ( deployResponse . contract_address ) . toBeTruthy ( ) ;
301+ expect ( deployResponse . transaction_hash ) . toBeTruthy ( ) ;
302+ } ) ;
303+ } ) ;
304+
305+ describe ( 'declareContract' , ( ) => {
306+ test ( 'response' , async ( ) => {
307+ expect ( declareResponse . class_hash ) . toBeTruthy ( ) ;
308+ expect ( declareResponse . transaction_hash ) . toBeTruthy ( ) ;
309+ } ) ;
310+ } ) ;
311+
312+ describe ( 'getClassAt' , ( ) => {
313+ test ( 'response' , async ( ) => {
314+ // Hardcoded contract address as RPC node is throwing "Contract not found" error
315+ const classResponse = await provider . getClassAt ( contractAddress ) ;
316+
317+ expect ( classResponse ) . toHaveProperty ( 'program' ) ;
318+ expect ( classResponse ) . toHaveProperty ( 'entry_points_by_type' ) ;
319+ } ) ;
320+ } ) ;
321+
322+ describe ( 'callContract' , ( ) => {
323+ test ( 'result' , ( ) => {
324+ return expect (
325+ provider
326+ . callContract ( {
327+ contractAddress : deployResponse . contract_address ,
328+ entrypoint : 'balance_of' ,
329+ calldata : compileCalldata ( {
330+ user : '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b' ,
331+ } ) ,
332+ } )
333+ . then ( ( res ) => {
334+ expect ( Array . isArray ( res . result ) ) . toBe ( true ) ;
335+ } )
336+ ) . resolves . not . toThrow ( ) ;
337+ } ) ;
338+ } ) ;
339+ } ) ;
340+ } ) ;
341+ } ) ;
144342} ) ;
0 commit comments