@@ -85,7 +85,38 @@ describe('InputAdded', () => {
8585 const mockChainStorage = new Map < string , Chain > ( ) ;
8686 const expectedChain = { id : sepolia . id . toString ( ) } ;
8787
88+ const buildValidApplication = ( address : string ) => ( {
89+ id : `${ sepolia . id } -${ address } -v1` ,
90+ address : `${ address } ` ,
91+ timestamp : BigInt ( logs [ 0 ] . block . timestamp ) / 1000n ,
92+ chain : expectedChain ,
93+ rollupVersion : 'v1' ,
94+ factory : {
95+ id : '11155111-0x7122cd1221c20892234186facfe8615e6743ab02' ,
96+ address : '0x7122cd1221c20892234186facfe8615e6743ab02' ,
97+ chain : {
98+ id : '11155111' ,
99+ } ,
100+ } ,
101+ } ) ;
102+
88103 beforeEach ( ( ) => {
104+ mockTokenStorage . clear ( ) ;
105+ mockDepositStorage . clear ( ) ;
106+ mockApplicationStorage . clear ( ) ;
107+ mockInputStorage . clear ( ) ;
108+ mockNftStorage . clear ( ) ;
109+ mockErc721DepositStorage . clear ( ) ;
110+ mockMultiTokenStorage . clear ( ) ;
111+ mockErc1155DepositStorage . clear ( ) ;
112+
113+ // add pre created valid apps
114+ const appOne = buildValidApplication (
115+ '0x0be010fa7e70d74fa8b6729fe1ae268787298f54' ,
116+ ) ;
117+
118+ mockApplicationStorage . set ( appOne . id , appOne ) ;
119+
89120 inputAdded = new InputAdded (
90121 mockTokenStorage ,
91122 mockDepositStorage ,
@@ -97,15 +128,6 @@ describe('InputAdded', () => {
97128 mockErc1155DepositStorage ,
98129 mockChainStorage ,
99130 ) ;
100-
101- mockTokenStorage . clear ( ) ;
102- mockDepositStorage . clear ( ) ;
103- mockApplicationStorage . clear ( ) ;
104- mockInputStorage . clear ( ) ;
105- mockNftStorage . clear ( ) ;
106- mockErc721DepositStorage . clear ( ) ;
107- mockMultiTokenStorage . clear ( ) ;
108- mockErc1155DepositStorage . clear ( ) ;
109131 } ) ;
110132
111133 afterEach ( ( ) => {
@@ -114,6 +136,7 @@ describe('InputAdded', () => {
114136
115137 describe ( 'handle' , async ( ) => {
116138 test ( 'should ignore events other than InputAdded' , async ( ) => {
139+ mockApplicationStorage . clear ( ) ;
117140 await inputAdded . handle ( logs [ 1 ] , block , ctx ) ;
118141 expect ( mockInputStorage . size ) . toBe ( 0 ) ;
119142 expect ( mockApplicationStorage . size ) . toBe ( 0 ) ;
@@ -126,19 +149,21 @@ describe('InputAdded', () => {
126149 expect ( mockInputStorage . size ) . toBe ( 1 ) ;
127150 } ) ;
128151
129- test ( 'when creating a non-existing app it should also set the timestamp in seconds' , async ( ) => {
152+ test ( 'should ignore inputs to non-existing applications' , async ( ) => {
153+ mockApplicationStorage . clear ( ) ;
130154 await inputAdded . handle ( logs [ 0 ] , block , ctx ) ;
131155
132- const timestamp = BigInt ( logs [ 0 ] . block . timestamp ) / 1000n ;
133-
134156 const [ application ] = mockApplicationStorage . values ( ) ;
135- expect ( application ) . toEqual ( {
136- id : `${ sepolia . id } -0x0be010fa7e70d74fa8b6729fe1ae268787298f54-v1` ,
137- address : '0x0be010fa7e70d74fa8b6729fe1ae268787298f54' ,
138- timestamp,
139- chain : expectedChain ,
140- rollupVersion : 'v1' ,
141- } ) ;
157+ expect ( application ) . toEqual ( undefined ) ;
158+
159+ expect ( ctx . log . warn ) . toHaveBeenCalledTimes ( 2 ) ;
160+ expect ( ctx . log . warn ) . toHaveBeenCalledWith (
161+ '11155111-0x0be010fa7e70d74fa8b6729fe1ae268787298f54-v1 (Application) not found' ,
162+ ) ;
163+
164+ expect ( ctx . log . warn ) . toHaveBeenCalledWith (
165+ 'Ignoring event(InputAdded v1) [index: 1]' ,
166+ ) ;
142167 } ) ;
143168
144169 test ( 'should throw error when chain-id information is not available in the Log ' , async ( ) => {
@@ -332,13 +357,21 @@ describe('InputAdded', () => {
332357 describe ( 'ERC-1155 deposits' , ( ) => {
333358 const tokenAddress = `${ sepolia . id } -0x2960f4db2b0993ae5b59bc4a0f5ec7a1767e905e` ;
334359
360+ beforeEach ( ( ) => {
361+ // add pre created valid apps
362+ const appOne = buildValidApplication (
363+ '0x4ca2f6935200b9a782a78f408f640f17b29809d8' ,
364+ ) ;
365+
366+ mockApplicationStorage . set ( appOne . id , appOne ) ;
367+ } ) ;
368+
335369 afterEach ( ( ) => {
336370 vi . clearAllMocks ( ) ;
337371 } ) ;
338372
339373 test ( 'should store the token information' , async ( ) => {
340374 expect ( mockMultiTokenStorage . size ) . toBe ( 0 ) ;
341-
342375 await inputAdded . handle ( logErc1155SingleTransfer , block , ctx ) ;
343376
344377 expect ( mockMultiTokenStorage . size ) . toBe ( 1 ) ;
0 commit comments