@@ -85,7 +85,38 @@ describe('InputAdded', () => {
85
85
const mockChainStorage = new Map < string , Chain > ( ) ;
86
86
const expectedChain = { id : sepolia . id . toString ( ) } ;
87
87
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
+
88
103
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
+
89
120
inputAdded = new InputAdded (
90
121
mockTokenStorage ,
91
122
mockDepositStorage ,
@@ -97,15 +128,6 @@ describe('InputAdded', () => {
97
128
mockErc1155DepositStorage ,
98
129
mockChainStorage ,
99
130
) ;
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 ( ) ;
109
131
} ) ;
110
132
111
133
afterEach ( ( ) => {
@@ -114,6 +136,7 @@ describe('InputAdded', () => {
114
136
115
137
describe ( 'handle' , async ( ) => {
116
138
test ( 'should ignore events other than InputAdded' , async ( ) => {
139
+ mockApplicationStorage . clear ( ) ;
117
140
await inputAdded . handle ( logs [ 1 ] , block , ctx ) ;
118
141
expect ( mockInputStorage . size ) . toBe ( 0 ) ;
119
142
expect ( mockApplicationStorage . size ) . toBe ( 0 ) ;
@@ -126,19 +149,21 @@ describe('InputAdded', () => {
126
149
expect ( mockInputStorage . size ) . toBe ( 1 ) ;
127
150
} ) ;
128
151
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 ( ) ;
130
154
await inputAdded . handle ( logs [ 0 ] , block , ctx ) ;
131
155
132
- const timestamp = BigInt ( logs [ 0 ] . block . timestamp ) / 1000n ;
133
-
134
156
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
+ ) ;
142
167
} ) ;
143
168
144
169
test ( 'should throw error when chain-id information is not available in the Log ' , async ( ) => {
@@ -332,13 +357,21 @@ describe('InputAdded', () => {
332
357
describe ( 'ERC-1155 deposits' , ( ) => {
333
358
const tokenAddress = `${ sepolia . id } -0x2960f4db2b0993ae5b59bc4a0f5ec7a1767e905e` ;
334
359
360
+ beforeEach ( ( ) => {
361
+ // add pre created valid apps
362
+ const appOne = buildValidApplication (
363
+ '0x4ca2f6935200b9a782a78f408f640f17b29809d8' ,
364
+ ) ;
365
+
366
+ mockApplicationStorage . set ( appOne . id , appOne ) ;
367
+ } ) ;
368
+
335
369
afterEach ( ( ) => {
336
370
vi . clearAllMocks ( ) ;
337
371
} ) ;
338
372
339
373
test ( 'should store the token information' , async ( ) => {
340
374
expect ( mockMultiTokenStorage . size ) . toBe ( 0 ) ;
341
-
342
375
await inputAdded . handle ( logErc1155SingleTransfer , block , ctx ) ;
343
376
344
377
expect ( mockMultiTokenStorage . size ) . toBe ( 1 ) ;
0 commit comments