@@ -101,99 +101,134 @@ export const erc20Request: ClientTypes.IRequestData = {
101101} ;
102102
103103describe ( 'deploySingleRequestProxy' , ( ) => {
104- it ( 'should throw error if payment network not supported' , async ( ) => {
105- // Create a request with an unsupported payment network
106- const invalidPaymentRequestNetwork = {
107- ...baseRequest ,
108- currency : 'ETH-private' ,
109- currencyInfo : {
110- network : 'private' as CurrencyTypes . ChainName ,
111- type : RequestLogicTypes . CURRENCY . ETH ,
112- value : RequestLogicTypes . CURRENCY . ETH ,
113- } ,
114- version : '2.0.3' ,
115- extensions : {
116- [ ExtensionTypes . PAYMENT_NETWORK_ID . ANY_DECLARATIVE ] : {
117- events : [ ] ,
118- id : ExtensionTypes . PAYMENT_NETWORK_ID . ANY_DECLARATIVE ,
119- type : ExtensionTypes . TYPE . PAYMENT_NETWORK ,
120- values : { } ,
121- version : '0.1.0' ,
104+ describe ( 'deploySingleRequestProxy' , ( ) => {
105+ it ( 'should throw error if payment network not supported' , async ( ) => {
106+ // Create a request with an unsupported payment network
107+ const invalidPaymentRequestNetwork = {
108+ ...baseRequest ,
109+ currency : 'ETH-private' ,
110+ currencyInfo : {
111+ network : 'private' as CurrencyTypes . ChainName ,
112+ type : RequestLogicTypes . CURRENCY . ETH ,
113+ value : RequestLogicTypes . CURRENCY . ETH ,
122114 } ,
123- } ,
124- } ;
125-
126- await expect ( deploySingleRequestProxy ( invalidPaymentRequestNetwork , wallet ) ) . rejects . toThrow (
127- 'Unsupported payment network' ,
128- ) ;
129- } ) ;
130-
131- it ( 'should throw error if request has no network' , async ( ) => {
132- const invalidRequestWithoutNetwork = { ...ethRequest , currencyInfo : { } } ;
133-
134- // @ts -expect-error: Request with empty currencyInfo
135- await expect ( deploySingleRequestProxy ( invalidRequestWithoutNetwork , wallet ) ) . rejects . toThrow (
136- 'Payment chain not found' ,
137- ) ;
138- } ) ;
139-
140- it ( 'should throw error if request has no payee' , async ( ) => {
141- const invalidRequestWithoutPayee = { ...ethRequest , payee : { } } ;
142-
143- // @ts -expect-error: Request with empty payee
144- await expect ( deploySingleRequestProxy ( invalidRequestWithoutPayee , wallet ) ) . rejects . toThrow (
145- 'Payee not found' ,
146- ) ;
147- } ) ;
148-
149- it ( 'should throw error if request has no network values' , async ( ) => {
150- const invalidRequestWithoutNetworkValues = {
151- ...ethRequest ,
152- extensions : {
153- [ ExtensionTypes . PAYMENT_NETWORK_ID . ETH_FEE_PROXY_CONTRACT ] : {
154- ...ethRequest . extensions [ ExtensionTypes . PAYMENT_NETWORK_ID . ETH_FEE_PROXY_CONTRACT ] ,
155- values : { } ,
115+ version : '2.0.3' ,
116+ extensions : {
117+ [ ExtensionTypes . PAYMENT_NETWORK_ID . ANY_DECLARATIVE ] : {
118+ events : [ ] ,
119+ id : ExtensionTypes . PAYMENT_NETWORK_ID . ANY_DECLARATIVE ,
120+ type : ExtensionTypes . TYPE . PAYMENT_NETWORK ,
121+ values : { } ,
122+ version : '0.1.0' ,
123+ } ,
156124 } ,
157- } ,
158- } ;
159-
160- await expect (
161- deploySingleRequestProxy ( invalidRequestWithoutNetworkValues , wallet ) ,
162- ) . rejects . toThrow ( 'Invalid payment network values' ) ;
163- } ) ;
164-
165- it ( 'should deploy EthereumSingleRequestProxy and emit event' , async ( ) => {
166- const singleRequestProxyFactory = singleRequestProxyFactoryArtifact . connect ( 'private' , wallet ) ;
167-
168- // Get the initial event count
169- const initialEventCount = await provider . getBlockNumber ( ) ;
170-
171- const proxyAddress = await deploySingleRequestProxy ( ethRequest , wallet ) ;
172-
173- expect ( proxyAddress ) . toBeDefined ( ) ;
174- expect ( typeof proxyAddress ) . toBe ( 'string' ) ;
175- expect ( proxyAddress ) . toMatch ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / ) ;
176-
177- // Get the latest events
178- const latestBlock = await provider . getBlockNumber ( ) ;
179- const events = await singleRequestProxyFactory . queryFilter (
180- singleRequestProxyFactory . filters . EthereumSingleRequestProxyCreated ( ) ,
181- initialEventCount ,
182- latestBlock ,
183- ) ;
184-
185- // Check if the event was emitted with the correct parameters
186- const event = events . find ( ( e ) => e . args ?. proxyAddress === proxyAddress ) ;
187- expect ( event ) . toBeDefined ( ) ;
188- expect ( event ?. args ?. payee ) . toBe ( paymentAddress ) ;
189- expect ( event ?. args ?. paymentReference ) . toBeDefined ( ) ;
190- } ) ;
191-
192- it ( 'should throw an error if the request has no extension' , async ( ) => {
193- const invalidRequest = { ...ethRequest , extensions : { } } ;
194-
195- await expect ( deploySingleRequestProxy ( invalidRequest , wallet ) ) . rejects . toThrow (
196- 'Unsupported payment network' ,
197- ) ;
125+ } ;
126+
127+ await expect ( deploySingleRequestProxy ( invalidPaymentRequestNetwork , wallet ) ) . rejects . toThrow (
128+ 'Unsupported payment network' ,
129+ ) ;
130+ } ) ;
131+
132+ it ( 'should throw error if request has no network' , async ( ) => {
133+ const invalidRequestWithoutNetwork = { ...ethRequest , currencyInfo : { } } ;
134+
135+ // @ts -expect-error: Request with empty currencyInfo
136+ await expect ( deploySingleRequestProxy ( invalidRequestWithoutNetwork , wallet ) ) . rejects . toThrow (
137+ 'Payment chain not found' ,
138+ ) ;
139+ } ) ;
140+
141+ it ( 'should throw error if request has no payee' , async ( ) => {
142+ const invalidRequestWithoutPayee = { ...ethRequest , payee : { } } ;
143+
144+ // @ts -expect-error: Request with empty payee
145+ await expect ( deploySingleRequestProxy ( invalidRequestWithoutPayee , wallet ) ) . rejects . toThrow (
146+ 'Payee not found' ,
147+ ) ;
148+ } ) ;
149+
150+ it ( 'should throw error if request has no network values' , async ( ) => {
151+ const invalidRequestWithoutNetworkValues = {
152+ ...ethRequest ,
153+ extensions : {
154+ [ ExtensionTypes . PAYMENT_NETWORK_ID . ETH_FEE_PROXY_CONTRACT ] : {
155+ ...ethRequest . extensions [ ExtensionTypes . PAYMENT_NETWORK_ID . ETH_FEE_PROXY_CONTRACT ] ,
156+ values : { } ,
157+ } ,
158+ } ,
159+ } ;
160+
161+ await expect (
162+ deploySingleRequestProxy ( invalidRequestWithoutNetworkValues , wallet ) ,
163+ ) . rejects . toThrow ( 'Invalid payment network values' ) ;
164+ } ) ;
165+
166+ it ( 'should throw an error if the request has no extension' , async ( ) => {
167+ const invalidRequest = { ...ethRequest , extensions : { } } ;
168+
169+ await expect ( deploySingleRequestProxy ( invalidRequest , wallet ) ) . rejects . toThrow (
170+ 'Unsupported payment network' ,
171+ ) ;
172+ } ) ;
173+
174+ it ( 'should deploy EthereumSingleRequestProxy and emit event' , async ( ) => {
175+ const singleRequestProxyFactory = singleRequestProxyFactoryArtifact . connect (
176+ 'private' ,
177+ wallet ,
178+ ) ;
179+
180+ // Get the initial event count
181+ const initialEventCount = await provider . getBlockNumber ( ) ;
182+
183+ const proxyAddress = await deploySingleRequestProxy ( ethRequest , wallet ) ;
184+
185+ expect ( proxyAddress ) . toBeDefined ( ) ;
186+ expect ( typeof proxyAddress ) . toBe ( 'string' ) ;
187+ expect ( proxyAddress ) . toMatch ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / ) ;
188+
189+ // Get the latest events
190+ const latestBlock = await provider . getBlockNumber ( ) ;
191+ const events = await singleRequestProxyFactory . queryFilter (
192+ singleRequestProxyFactory . filters . EthereumSingleRequestProxyCreated ( ) ,
193+ initialEventCount ,
194+ latestBlock ,
195+ ) ;
196+
197+ // Check if the event was emitted with the correct parameters
198+ const event = events . find ( ( e ) => e . args ?. proxyAddress === proxyAddress ) ;
199+ expect ( event ) . toBeDefined ( ) ;
200+ expect ( event ?. args ?. payee ) . toBe ( paymentAddress ) ;
201+ expect ( event ?. args ?. paymentReference ) . toBeDefined ( ) ;
202+ } ) ;
203+
204+ it ( 'should deploy ERC20SingleRequestProxy and emit event' , async ( ) => {
205+ const singleRequestProxyFactory = singleRequestProxyFactoryArtifact . connect (
206+ 'private' ,
207+ wallet ,
208+ ) ;
209+
210+ // Get the initial event count
211+ const initialEventCount = await provider . getBlockNumber ( ) ;
212+
213+ const proxyAddress = await deploySingleRequestProxy ( erc20Request , wallet ) ;
214+
215+ expect ( proxyAddress ) . toBeDefined ( ) ;
216+ expect ( typeof proxyAddress ) . toBe ( 'string' ) ;
217+ expect ( proxyAddress ) . toMatch ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / ) ;
218+
219+ // Get the latest events
220+ const latestBlock = await provider . getBlockNumber ( ) ;
221+ const events = await singleRequestProxyFactory . queryFilter (
222+ singleRequestProxyFactory . filters . EthereumSingleRequestProxyCreated ( ) ,
223+ initialEventCount ,
224+ latestBlock ,
225+ ) ;
226+
227+ // Check if the event was emitted with the correct parameters
228+ const event = events . find ( ( e ) => e . args ?. proxyAddress === proxyAddress ) ;
229+ expect ( event ) . toBeDefined ( ) ;
230+ expect ( event ?. args ?. payee ) . toBe ( paymentAddress ) ;
231+ expect ( event ?. args ?. paymentReference ) . toBeDefined ( ) ;
232+ } ) ;
198233 } ) ;
199234} ) ;
0 commit comments