@@ -6,7 +6,52 @@ import {
66} from '@rabbitholegg/questdk-plugin-utils'
77import { apply } from '@rabbitholegg/questdk'
88import { type Address } from 'viem'
9- import { describe , expect , test } from 'vitest'
9+ import { describe , expect , test , vi , beforeEach , afterEach } from 'vitest'
10+ import * as utils from './utils'
11+
12+ vi . mock ( 'viem' , ( ) => {
13+ const mockClient = {
14+ simulateContract : vi . fn ( ) . mockResolvedValue ( {
15+ request : {
16+ address : '0xD77269c83AAB591Ca834B3687E1f4164B2fF25f5' ,
17+ value : 999999999995328000n ,
18+ functionName : 'mint' ,
19+ args : [ 2000n ] ,
20+ account : '0x000000000000000000000000000000000000dEaD' ,
21+ } ,
22+ result : undefined ,
23+ } ) ,
24+ multicall : vi
25+ . fn ( )
26+ . mockResolvedValue ( [
27+ { result : '0x0000000000000000000000000000000000000000' } ,
28+ { result : 100n } ,
29+ { result : 69n } ,
30+ ] ) ,
31+ }
32+
33+ return {
34+ createPublicClient : ( ) => mockClient ,
35+ zeroAddress : '0x0000000000000000000000000000000000000000' ,
36+ http : vi . fn ( ) ,
37+ encodeFunctionData : vi
38+ . fn ( )
39+ . mockReturnValue (
40+ '0xa0712d6800000000000000000000000000000000000000000000000000028fbee4d84c00' ,
41+ ) ,
42+ chainId : vi . fn ( ) . mockReturnValue ( 1 ) ,
43+ }
44+ } )
45+
46+ vi . mock ( './utils' , ( ) => {
47+ return {
48+ getContractData : vi . fn ( ) . mockResolvedValue ( {
49+ erc20Address : '0x0000000000000000000000000000000000000000' as Address ,
50+ minPurchaseSeconds : 100n ,
51+ tps : 69n ,
52+ } ) ,
53+ }
54+ } )
1055
1156describe ( 'Given the fabric plugin' , ( ) => {
1257 describe ( 'When handling the mint action' , ( ) => {
@@ -23,12 +68,14 @@ describe('Given the fabric plugin', () => {
2368 } else {
2469 // if to is an object, it should have a logical operator as the only key
2570 expect ( filter . to ) . toBeTypeOf ( 'object' )
71+ // @ts -ignore to is on the filter object
2672 expect ( Object . keys ( filter . to ) ) . toHaveLength ( 1 )
2773 expect (
2874 [ '$or' , '$and' ] . some ( ( prop ) =>
2975 Object . hasOwnProperty . call ( filter . to , prop ) ,
3076 ) ,
3177 ) . to . be . true
78+ // @ts -ignore to is on the filter object
3279 expect ( Object . values ( filter . to ) [ 0 ] ) . to . satisfy ( ( arr : string [ ] ) =>
3380 arr . every ( ( val ) => val . match ( / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / ) ) ,
3481 )
@@ -48,6 +95,7 @@ describe('Given the fabric plugin', () => {
4895 const { transaction, description, params } = testCase
4996 test ( description , async ( ) => {
5097 const filter = await mint ( params )
98+ // @ts -ignore transaction is on the test case
5199 expect ( apply ( transaction , filter ) ) . to . be . true
52100 } )
53101 } )
@@ -59,6 +107,7 @@ describe('Given the fabric plugin', () => {
59107 test ( description , async ( ) => {
60108 try {
61109 const filter = await mint ( params )
110+ // @ts -ignore transaction is on the test case
62111 const result = apply ( transaction , filter )
63112 expect ( result ) . toBe ( false )
64113 } catch ( error ) {
@@ -73,11 +122,11 @@ describe('Given the fabric plugin', () => {
73122describe ( 'Given the getFee function' , ( ) => {
74123 test ( 'should return the correct project + action fee for a 721 mint' , async ( ) => {
75124 const contractAddress : Address =
76- '0xd77269c83aab591ca834b3687e1f4164b2ff25f5 '
77- const mintParams = { chainId : Chains . SEPOLIA , contractAddress, amount : 1n }
125+ '0x3db5bc85fb89c59d7d03e1dda7ee4563f9c54270 '
126+ const mintParams = { chainId : Chains . BASE , contractAddress, amount : 1n }
78127 const fee = await getFees ( mintParams )
79128 expect ( fee . projectFee ) . equals ( 0n )
80- expect ( fee . actionFee ) . equals ( 499999999997664000n )
129+ expect ( fee . actionFee ) . equals ( 6900n )
81130 } )
82131} )
83132
@@ -105,6 +154,27 @@ describe('Given the getMintIntent function', () => {
105154} )
106155
107156describe ( 'simulateMint function' , ( ) => {
157+ beforeEach ( ( ) => {
158+ vi . spyOn ( utils , 'getContractData' ) . mockImplementation ( async ( chainId ) => {
159+ if ( chainId === Chains . SEPOLIA ) {
160+ return {
161+ erc20Address : '0x0000000000000000000000000000000000000000' as Address ,
162+ minPurchaseSeconds : 100n ,
163+ tps : 10n ,
164+ }
165+ }
166+ return {
167+ erc20Address : '0x0000000000000000000000000000000000000000' as Address ,
168+ minPurchaseSeconds : 100n ,
169+ tps : 10n ,
170+ }
171+ } )
172+ } )
173+
174+ afterEach ( ( ) => {
175+ vi . restoreAllMocks ( )
176+ } )
177+
108178 test ( 'should simulate a mint' , async ( ) => {
109179 const mint : MintIntentParams = {
110180 chainId : Chains . SEPOLIA ,
@@ -119,5 +189,11 @@ describe('simulateMint function', () => {
119189 const request = result . request
120190 expect ( request . address ) . toBe ( mint . contractAddress )
121191 expect ( request . value ) . toBe ( value )
192+
193+ expect ( utils . getContractData ) . toHaveBeenCalledWith (
194+ Chains . SEPOLIA ,
195+ mint . contractAddress ,
196+ undefined ,
197+ )
122198 } )
123199} )
0 commit comments