11import { BlockNumber , stark } from '../src' ;
22import { toBN } from '../src/utils/number' ;
3- import {
4- IS_DEVNET ,
5- compiledErc20 ,
6- compiledOpenZeppelinAccount ,
7- getTestProvider ,
8- testIfNotDevnet ,
9- } from './fixtures' ;
3+ import { IS_DEVNET , compiledErc20 , compiledOpenZeppelinAccount , getTestProvider } from './fixtures' ;
104
115const { compileCalldata } = stark ;
126
@@ -15,86 +9,73 @@ const provider = getTestProvider();
159describe ( 'defaultProvider' , ( ) => {
1610 let exampleTransactionHash : string ;
1711 let exampleContractAddress : string ;
18- let exampleBlockHash : string ;
19- let exampleBlockNumber : BlockNumber ;
12+ const exampleBlockHash : string =
13+ '0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43' ;
14+ const exampleBlockNumber : BlockNumber = 102634 ;
15+
2016 beforeAll ( async ( ) => {
21- const { code , transaction_hash, address } = await provider . deployContract ( {
17+ const { transaction_hash, contract_address } = await provider . deployContract ( {
2218 contract : compiledErc20 ,
2319 } ) ;
24- expect ( code ) . toBe ( 'TRANSACTION_RECEIVED' ) ;
2520 await provider . waitForTransaction ( transaction_hash ) ;
2621 exampleTransactionHash = transaction_hash ;
27- exampleContractAddress = address ! ;
28- const transaction = await provider . getTransaction ( transaction_hash ) ;
29-
30- if ( transaction . status !== 'REJECTED' ) {
31- exampleBlockHash = transaction . block_hash ;
32- exampleBlockNumber = transaction . block_number ;
33- }
22+ exampleContractAddress = contract_address ;
3423 } ) ;
3524
36- describe ( 'feeder gateway endpoints' , ( ) => {
37- testIfNotDevnet ( 'getContractAddresses()' , async ( ) => {
38- // not supported in starknet-devnet
39- const { GpsStatementVerifier, Starknet } = await provider . getContractAddresses ( ) ;
40- expect ( typeof GpsStatementVerifier ) . toBe ( 'string' ) ;
41- expect ( typeof Starknet ) . toBe ( 'string' ) ;
42- } ) ;
25+ describe ( 'endpoints' , ( ) => {
4326 test ( `getBlock(blockHash=${ exampleBlockHash } , blockNumber=undefined)` , ( ) => {
4427 return expect ( provider . getBlock ( exampleBlockHash ) ) . resolves . not . toThrow ( ) ;
4528 } ) ;
29+
4630 test ( `getBlock(blockHash=undefined, blockNumber=${ exampleBlockNumber } )` , ( ) => {
4731 return expect ( provider . getBlock ( exampleBlockNumber ) ) . resolves . not . toThrow ( ) ;
4832 } ) ;
33+
4934 test ( 'getBlock(blockHash=undefined, blockNumber=null)' , async ( ) => {
5035 const block = await provider . getBlock ( ) ;
5136
5237 expect ( block ) . not . toBeNull ( ) ;
5338
54- const { block_number, timestamp } = block ;
39+ const { block_number, accepted_time } = block ;
5540
5641 expect ( typeof block_number ) . toEqual ( 'number' ) ;
5742
58- return expect ( typeof timestamp ) . toEqual ( 'number' ) ;
43+ return expect ( typeof accepted_time ) . toEqual ( 'number' ) ;
5944 } ) ;
45+
6046 test ( 'getBlock() -> { blockNumber }' , async ( ) => {
6147 const block = await provider . getBlock ( ) ;
6248 return expect ( block ) . toHaveProperty ( 'block_number' ) ;
6349 } ) ;
64- test ( 'getCode()' , ( ) => {
65- return expect ( provider . getCode ( exampleContractAddress , 36663 ) ) . resolves . not . toThrow ( ) ;
66- } ) ;
67- test ( 'getCode(blockHash=undefined, blockNumber=null)' , ( ) => {
68- return expect ( provider . getCode ( exampleContractAddress ) ) . resolves . not . toThrow ( ) ;
69- } ) ;
70- test ( 'getStorageAt() with "key" type of number' , ( ) => {
71- return expect ( provider . getStorageAt ( exampleContractAddress , 0 , 36663 ) ) . resolves . not . toThrow ( ) ;
72- } ) ;
73- test ( 'getStorageAt() with "key" type of string' , ( ) => {
74- return expect (
75- provider . getStorageAt ( exampleContractAddress , '0' , 36663 )
76- ) . resolves . not . toThrow ( ) ;
77- } ) ;
78- test ( 'getStorageAt() with "key" type of BN' , ( ) => {
79- return expect (
80- provider . getStorageAt ( exampleContractAddress , toBN ( '0x0' ) , 36663 )
81- ) . resolves . not . toThrow ( ) ;
82- } ) ;
83- test ( 'getStorageAt(blockHash=undefined, blockNumber=null)' , ( ) => {
84- return expect ( provider . getStorageAt ( exampleContractAddress , 0 ) ) . resolves . not . toThrow ( ) ;
85- } ) ;
86- test ( 'getTransactionStatus()' , async ( ) => {
87- return expect ( provider . getTransactionStatus ( exampleTransactionHash ) ) . resolves . not . toThrow ( ) ;
50+
51+ describe ( 'getStorageAt' , ( ) => {
52+ test ( 'with "key" type of number' , ( ) => {
53+ return expect (
54+ provider . getStorageAt ( exampleContractAddress , 0 , 36663 )
55+ ) . resolves . not . toThrow ( ) ;
56+ } ) ;
57+
58+ test ( '"key" type of string' , ( ) => {
59+ return expect (
60+ provider . getStorageAt ( exampleContractAddress , '0x0' , 36663 )
61+ ) . resolves . not . toThrow ( ) ;
62+ } ) ;
63+
64+ test ( 'with "key" type of BN' , ( ) => {
65+ return expect (
66+ provider . getStorageAt ( exampleContractAddress , toBN ( '0x0' ) , 36663 )
67+ ) . resolves . not . toThrow ( ) ;
68+ } ) ;
69+
70+ test ( '(blockHash=undefined, blockNumber=null)' , ( ) => {
71+ return expect ( provider . getStorageAt ( exampleContractAddress , 0 ) ) . resolves . not . toThrow ( ) ;
72+ } ) ;
8873 } ) ;
8974
9075 test ( 'getTransaction() - successful transaction' , async ( ) => {
9176 const transaction = await provider . getTransaction ( exampleTransactionHash ) ;
9277
93- expect ( transaction ) . not . toHaveProperty ( 'transaction_failure_reason' ) ;
94-
95- expect ( transaction . transaction ) . toHaveProperty ( 'transaction_hash' ) ;
96-
97- return expect ( transaction . status ) . not . toEqual ( 'REJECTED' ) ;
78+ expect ( transaction ) . toHaveProperty ( 'transaction_hash' ) ;
9879 } ) ;
9980
10081 test ( 'getTransactionReceipt() - successful transaction' , async ( ) => {
@@ -103,7 +84,7 @@ describe('defaultProvider', () => {
10384 return expect ( transactionReceipt ) . toHaveProperty ( 'actual_fee' ) ;
10485 } ) ;
10586
106- test ( 'callContract()' , ( ) => {
87+ test . only ( 'callContract()' , ( ) => {
10788 return expect (
10889 provider . callContract ( {
10990 contractAddress : exampleContractAddress ,
@@ -115,7 +96,7 @@ describe('defaultProvider', () => {
11596 ) . resolves . not . toThrow ( ) ;
11697 } ) ;
11798
118- test ( 'callContract() - gateway error' , async ( ) => {
99+ test . only ( 'callContract() - gateway error' , async ( ) => {
119100 const promise = provider . callContract ( {
120101 contractAddress : exampleContractAddress ,
121102 entrypoint : 'non_existent_entrypoint' ,
@@ -136,12 +117,6 @@ describe('defaultProvider', () => {
136117 ) ;
137118 }
138119 } ) ;
139-
140- test ( 'transaction trace' , async ( ) => {
141- const transactionTrace = await provider . getTransactionTrace ( exampleTransactionHash ) ;
142- expect ( transactionTrace ) . toHaveProperty ( 'function_invocation' ) ;
143- expect ( transactionTrace ) . toHaveProperty ( 'signature' ) ;
144- } ) ;
145120 } ) ;
146121
147122 describe ( 'addTransaction()' , ( ) => {
@@ -150,7 +125,6 @@ describe('defaultProvider', () => {
150125 contract : compiledErc20 ,
151126 } ) ;
152127
153- expect ( response . code ) . toBe ( 'TRANSACTION_RECEIVED' ) ;
154128 expect ( response . transaction_hash ) . toBeDefined ( ) ;
155129 expect ( response . class_hash ) . toBeDefined ( ) ;
156130 } ) ;
@@ -160,9 +134,8 @@ describe('defaultProvider', () => {
160134 contract : compiledOpenZeppelinAccount ,
161135 } ) ;
162136
163- expect ( response . code ) . toBe ( 'TRANSACTION_RECEIVED' ) ;
164137 expect ( response . transaction_hash ) . toBeDefined ( ) ;
165- expect ( response . address ) . toBeDefined ( ) ;
138+ expect ( response . contract_address ) . toBeDefined ( ) ;
166139 } ) ;
167140 } ) ;
168141} ) ;
0 commit comments