@@ -23,7 +23,7 @@ describe("parseTakerBidEvent", () => {
2323 // Sepolia exchange
2424 const exchange = getAddress ( "0xB1991E985197d14669852Be8e53ee95A1f4621c0" ) ;
2525 const minterAddress = getAddress ( faker . finance . ethereumAddress ( ) ) ;
26- const value = 20n ;
26+ const value = 500000000000n ;
2727
2828 const block : Block = {
2929 chainId,
@@ -40,35 +40,34 @@ describe("parseTakerBidEvent", () => {
4040 contracts_id : faker . string . uuid ( ) ,
4141 } ;
4242
43- let event : any ;
43+ beforeEach ( ( ) => { } ) ;
4444
45- beforeEach ( ( ) => {
46- event = {
47- address : getAddress ( faker . finance . ethereumAddress ( ) ) ,
48- params : {
49- nonceInvalidationParameters : {
50- orderHash : faker . string . hexadecimal ( { length : 64 } ) ,
51- orderNonce : faker . number . bigInt ( ) ,
52- isNonceInvalidated : true ,
53- } ,
54- bidUser : getAddress ( faker . finance . ethereumAddress ( ) ) ,
55- bidRecipient : getAddress ( faker . finance . ethereumAddress ( ) ) ,
56- strategyId : faker . number . bigInt ( ) ,
57- currency : getAddress ( faker . finance . ethereumAddress ( ) ) ,
58- collection : collection ,
59- itemIds : [ faker . number . bigInt ( ) ] ,
60- amounts : [ faker . number . bigInt ( ) ] ,
61- feeRecipients : [
62- getAddress ( "0xB522133dBd9C8B424429D89d821aeb2a115dB678" ) ,
63- getAddress ( "0x0000000000000000000000000000000000000000" ) ,
64- ] ,
65- feeAmounts : [ 495000000000n , 0n , 5000000000n ] ,
45+ const createEvent = ( tokenId : bigint ) => ( {
46+ address : getAddress ( faker . finance . ethereumAddress ( ) ) ,
47+ params : {
48+ nonceInvalidationParameters : {
49+ orderHash : faker . string . hexadecimal ( { length : 64 } ) ,
50+ orderNonce : faker . number . bigInt ( ) ,
51+ isNonceInvalidated : true ,
6652 } ,
67- blockNumber : faker . number . bigInt ( ) ,
68- transactionHash : faker . string . hexadecimal ( {
69- length : 64 ,
70- } ) as `0x${string } `,
71- } ;
53+ bidUser : getAddress ( faker . finance . ethereumAddress ( ) ) ,
54+ bidRecipient : getAddress ( faker . finance . ethereumAddress ( ) ) ,
55+ strategyId : faker . number . bigInt ( ) ,
56+ currency : getAddress ( faker . finance . ethereumAddress ( ) ) ,
57+ collection : collection ,
58+ itemIds : [ tokenId ] ,
59+ amounts : [ faker . number . bigInt ( ) ] ,
60+ feeRecipients : [
61+ getAddress ( "0xB522133dBd9C8B424429D89d821aeb2a115dB678" ) ,
62+ getAddress ( "0x0000000000000000000000000000000000000000" ) ,
63+ ] ,
64+ feeAmounts : [ 495000000000n , 0n , 5000000000n ] ,
65+ } ,
66+ blockNumber : faker . number . bigInt ( ) ,
67+ transactionHash : faker . string . hexadecimal ( {
68+ length : 64 ,
69+ } ) as `0x${string } `,
70+ logIndex : faker . number . int ( ) ,
7271 } ) ;
7372
7473 const createBatchValueTransferLog = ( ) => ( {
@@ -122,16 +121,16 @@ describe("parseTakerBidEvent", () => {
122121 removed : false ,
123122 } ) ;
124123
125- const createCurrencyLog = ( ) => ( {
126- eventName : "Transfer" ,
127- address : event . params . currency ,
128- topics : [
129- "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" ,
130- "0x000000000000000000000000c3593524e2744e547f013e17e6b0776bc27fc614" ,
131- "0x000000000000000000000000c3593524e2744e547f013e17e6b0776bc27fc614" ,
132- ] ,
133- data : "0x0000000000000000000000000000000000000000000000000000000000000014" ,
134- } ) ;
124+ // const createCurrencyLog = () => ({
125+ // eventName: "Transfer",
126+ // address: event.params.currency,
127+ // topics: [
128+ // "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
129+ // "0x000000000000000000000000c3593524e2744e547f013e17e6b0776bc27fc614",
130+ // "0x000000000000000000000000c3593524e2744e547f013e17e6b0776bc27fc614",
131+ // ],
132+ // data: "0x0000000000000000000000000000000000000000000000000000000000000014",
133+ // });
135134
136135 describe ( "hypercert ID construction" , ( ) => {
137136 it ( "correctly constructs hypercert ID from BatchValueTransfer event" , async ( ) => {
@@ -140,7 +139,10 @@ describe("parseTakerBidEvent", () => {
140139 logs : [ createBatchValueTransferLog ( ) , createExchangeLog ( ) ] ,
141140 } ) ;
142141
143- const [ bid ] = await parseTakerBidEvent ( { event, context } ) ;
142+ const [ bid ] = await parseTakerBidEvent ( {
143+ event : createEvent ( claimId + 1n ) ,
144+ context,
145+ } ) ;
144146
145147 expect ( bid . hypercert_id ) . toEqual ( `${ chainId } -${ collection } -${ claimId } ` ) ;
146148 } ) ;
@@ -154,7 +156,10 @@ describe("parseTakerBidEvent", () => {
154156 logs : [ createTransferSingleLog ( fractionId ) , createExchangeLog ( ) ] ,
155157 } ) ;
156158
157- const [ bid ] = await parseTakerBidEvent ( { event, context } ) ;
159+ const [ bid ] = await parseTakerBidEvent ( {
160+ event : createEvent ( fractionId ) ,
161+ context,
162+ } ) ;
158163
159164 expect ( bid . hypercert_id ) . toBe ( `${ chainId } -${ collection } -${ claimId } ` ) ;
160165 expect ( getHypercertTokenId ( fractionId ) ) . toBe ( claimId ) ;
@@ -166,27 +171,17 @@ describe("parseTakerBidEvent", () => {
166171 logs : [ createBatchValueTransferLog ( ) , createExchangeLog ( ) ] ,
167172 } ) ;
168173
169- const [ bid ] = await parseTakerBidEvent ( { event, context } ) ;
170-
171- expect ( bid . hypercert_id ) . toBe ( `${ chainId } -${ collection } -${ firstClaimId } ` ) ;
172- } ) ;
173-
174- it ( "throws when BatchValueTransfer has empty claimIDs array" , async ( ) => {
175- mocks . getTransactionReceipt . mockResolvedValue ( {
176- logs : [
177- {
178- ...createBatchValueTransferLog ( ) ,
179- args : { claimIDs : [ ] } ,
180- } ,
181- ] ,
174+ const [ bid ] = await parseTakerBidEvent ( {
175+ event : createEvent ( firstClaimId + 1n ) ,
176+ context,
182177 } ) ;
183178
184- await expect ( parseTakerBidEvent ( { event, context } ) ) . rejects . toThrowError (
185- "Failed to find claim ID in BatchValueTransfer or TransferSingle events" ,
186- ) ;
179+ expect ( bid . hypercert_id ) . toBe ( `${ chainId } -${ collection } -${ firstClaimId } ` ) ;
187180 } ) ;
188181
189182 it ( "throws when TransferSingle has invalid fraction token ID" , async ( ) => {
183+ const claimId = 238878221578498801351288974417101284442112n ;
184+ const event = createEvent ( claimId + 1n ) ;
190185 mocks . getTransactionReceipt . mockResolvedValue ( {
191186 logs : [ createTransferSingleLog ( 0n ) ] ,
192187 } ) ;
@@ -198,67 +193,17 @@ describe("parseTakerBidEvent", () => {
198193 } ) ;
199194
200195 describe ( "event parsing" , ( ) => {
201- it ( "successfully parses event with BatchValueTransfer log for ERC20 currency" , async ( ) => {
202- const claimId = 238878221578498801351288974417101284442112n ;
203- mocks . getTransactionReceipt . mockResolvedValue ( {
204- logs : [
205- createBatchValueTransferLog ( ) ,
206- createExchangeLog ( ) ,
207- createCurrencyLog ( ) ,
208- ] ,
209- } ) ;
210-
211- mocks . getTransaction . mockResolvedValue ( {
212- value,
213- } ) ;
214-
215- const [ bid ] = await parseTakerBidEvent ( { event, context } ) ;
216-
217- expect ( bid ) . toBeDefined ( ) ;
218- expect ( bid . buyer ) . toBe ( getAddress ( event . params . bidRecipient ) ) ;
219- expect ( bid . seller ) . toBe ( getAddress ( event . params . feeRecipients [ 0 ] ) ) ;
220- expect ( bid . fee_amounts ) . toEqual ( event . params . feeAmounts ) ;
221- expect ( bid . fee_recipients ) . toEqual ( event . params . feeRecipients ) ;
222- expect ( bid . currency_amount ) . toEqual ( value ) ;
223- } ) ;
224-
225- it ( "successfully parses event with BatchValueTransfer log for native currency" , async ( ) => {
226- const claimId = 238878221578498801351288974417101284442112n ;
227- mocks . getTransactionReceipt . mockResolvedValue ( {
228- logs : [ createBatchValueTransferLog ( ) , createExchangeLog ( ) ] ,
229- } ) ;
230-
231- const value = faker . number . bigInt ( ) ;
232- mocks . getTransaction . mockResolvedValue ( {
233- value,
234- } ) ;
235-
236- const [ bid ] = await parseTakerBidEvent ( {
237- event : {
238- ...event ,
239- params : { ...event . params , currency : zeroAddress } ,
240- } ,
241- context,
242- } ) ;
243-
244- expect ( bid ) . toBeDefined ( ) ;
245- expect ( bid . buyer ) . toBe ( getAddress ( event . params . bidRecipient ) ) ;
246- expect ( bid . seller ) . toBe ( getAddress ( event . params . feeRecipients [ 0 ] ) ) ;
247- expect ( bid . fee_amounts ) . toEqual ( event . params . feeAmounts ) ;
248- expect ( bid . fee_recipients ) . toEqual ( event . params . feeRecipients ) ;
249- expect ( bid . currency_amount ) . toEqual ( value ) ;
250- } ) ;
251-
252196 it ( "successfully parses event with TransferSingle log for ERC20 currency" , async ( ) => {
253197 const fractionId = 34368519059014784809800835350608589357056n ;
254198 mocks . getTransactionReceipt . mockResolvedValue ( {
255199 logs : [
256200 createTransferSingleLog ( fractionId ) ,
257201 createExchangeLog ( ) ,
258- createCurrencyLog ( ) ,
202+ // createCurrencyLog(),
259203 ] ,
260204 } ) ;
261205
206+ const event = createEvent ( fractionId ) ;
262207 const [ bid ] = await parseTakerBidEvent ( { event, context } ) ;
263208
264209 expect ( bid ) . toBeDefined ( ) ;
@@ -277,6 +222,7 @@ describe("parseTakerBidEvent", () => {
277222 value,
278223 } ) ;
279224
225+ const event = createEvent ( fractionId ) ;
280226 const [ bid ] = await parseTakerBidEvent ( {
281227 event : {
282228 ...event ,
@@ -294,27 +240,37 @@ describe("parseTakerBidEvent", () => {
294240 } ) ;
295241
296242 it ( "throws when no transfer logs are found" , async ( ) => {
243+ const claimId = 238878221578498801351288974417101284442112n ;
244+ const event = createEvent ( claimId + 1n ) ;
297245 mocks . getTransactionReceipt . mockResolvedValue ( { logs : [ ] } ) ;
298246 await expect (
299247 parseTakerBidEvent ( { event, context } ) ,
300248 ) . rejects . toThrowError ( ) ;
301249 } ) ;
302250
303251 it ( "throws when event has invalid addresses" , async ( ) => {
252+ const claimId = 238878221578498801351288974417101284442112n ;
253+ const event = createEvent ( claimId + 1n ) ;
254+ // @ts -expect-error invalid address
304255 event . params . collection = "invalid-address" ;
305256 await expect (
306257 parseTakerBidEvent ( { event, context } ) ,
307258 ) . rejects . toThrowError ( ) ;
308259 } ) ;
309260
310261 it ( "throws when required parameters are missing" , async ( ) => {
311- delete event . params . bidRecipient ;
262+ const claimId = 238878221578498801351288974417101284442112n ;
263+ const event = createEvent ( claimId + 1n ) ;
264+ // @ts -expect-error purporsefully invalid address
265+ event . params . bidRecipient = "invalid-address" ;
312266 await expect (
313267 parseTakerBidEvent ( { event, context } ) ,
314268 ) . rejects . toThrowError ( ) ;
315269 } ) ;
316270
317271 it ( "throws when arrays are empty" , async ( ) => {
272+ const claimId = 238878221578498801351288974417101284442112n ;
273+ const event = createEvent ( claimId + 1n ) ;
318274 event . params . itemIds = [ ] ;
319275 event . params . amounts = [ ] ;
320276 await expect (
@@ -323,6 +279,9 @@ describe("parseTakerBidEvent", () => {
323279 } ) ;
324280
325281 it ( "throws when transaction hash is invalid" , async ( ) => {
282+ const claimId = 238878221578498801351288974417101284442112n ;
283+ const event = createEvent ( claimId + 1n ) ;
284+ // @ts -expect-error purporsefully invalid transaction hash
326285 event . transactionHash = "invalid-hash" ;
327286 await expect (
328287 parseTakerBidEvent ( { event, context } ) ,
0 commit comments