@@ -6,7 +6,24 @@ import {
66} from '@requestnetwork/types' ;
77import { TronERC20FeeProxyPaymentDetector } from '../../src/tron/tron-fee-proxy-detector' ;
88
9+ // Mock the hasura-client module so we can control getHasuraClient's return value
10+ jest . mock ( '../../src/tron/retrievers/hasura-client' , ( ) => {
11+ const actual = jest . requireActual ( '../../src/tron/retrievers/hasura-client' ) ;
12+ return {
13+ ...actual ,
14+ getHasuraClient : jest . fn ( actual . getHasuraClient ) ,
15+ } ;
16+ } ) ;
17+
18+ import { getHasuraClient } from '../../src/tron/retrievers/hasura-client' ;
19+ const mockedGetHasuraClient = getHasuraClient as jest . MockedFunction < typeof getHasuraClient > ;
20+
921describe ( 'TronERC20FeeProxyPaymentDetector' , ( ) => {
22+ afterEach ( ( ) => {
23+ jest . restoreAllMocks ( ) ;
24+ mockedGetHasuraClient . mockReset ( ) ;
25+ } ) ;
26+
1027 describe ( 'getDeploymentInformation' , ( ) => {
1128 it ( 'should return correct address for TRON mainnet' , ( ) => {
1229 const info = TronERC20FeeProxyPaymentDetector . getDeploymentInformation ( 'tron' ) ;
@@ -38,13 +55,10 @@ describe('TronERC20FeeProxyPaymentDetector', () => {
3855 fromStorageCurrency : jest . fn ( ) ,
3956 } ;
4057
41- const mockGetSubgraphClient = jest . fn ( ) ;
42-
4358 it ( 'should create detector for TRON network' , ( ) => {
4459 const detector = new TronERC20FeeProxyPaymentDetector ( {
4560 advancedLogic : mockAdvancedLogic as any ,
4661 currencyManager : mockCurrencyManager as any ,
47- getSubgraphClient : mockGetSubgraphClient ,
4862 network : 'tron' ,
4963 } ) ;
5064
@@ -55,7 +69,6 @@ describe('TronERC20FeeProxyPaymentDetector', () => {
5569 const detector = new TronERC20FeeProxyPaymentDetector ( {
5670 advancedLogic : mockAdvancedLogic as any ,
5771 currencyManager : mockCurrencyManager as any ,
58- getSubgraphClient : mockGetSubgraphClient ,
5972 network : 'nile' ,
6073 } ) ;
6174
@@ -64,23 +77,6 @@ describe('TronERC20FeeProxyPaymentDetector', () => {
6477 } ) ;
6578
6679 describe ( 'extractEvents' , ( ) => {
67- const mockPayment = {
68- amount : '1000000' ,
69- block : 63208800 ,
70- txHash : 'abc123def456' ,
71- feeAmount : '10000' ,
72- feeAddress : 'TFeeAddress1234567890123456789012' ,
73- from : 'TFromAddress1234567890123456789012' ,
74- timestamp : 1700000000 ,
75- tokenAddress : 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' ,
76- } ;
77-
78- const mockSubgraphClient = {
79- GetTronPayments : jest . fn ( ) . mockResolvedValue ( { payments : [ mockPayment ] } ) ,
80- GetTronPaymentsAnyToken : jest . fn ( ) . mockResolvedValue ( { payments : [ mockPayment ] } ) ,
81- options : { } ,
82- } ;
83-
8480 const mockAdvancedLogic = {
8581 getFeeProxyContractErc20ForNetwork : jest . fn ( ) . mockReturnValue ( undefined ) ,
8682 extensions : {
@@ -102,13 +98,13 @@ describe('TronERC20FeeProxyPaymentDetector', () => {
10298 } ) ,
10399 } ;
104100
105- it ( 'should throw error when subgraph client is not available' , async ( ) => {
106- const mockGetSubgraphClient = jest . fn ( ) . mockReturnValue ( undefined ) ;
101+ it ( 'should throw error when Hasura client is not available' , async ( ) => {
102+ // Mock getHasuraClient to return undefined (simulating misconfiguration)
103+ mockedGetHasuraClient . mockReturnValue ( undefined ) ;
107104
108105 const detector = new TronERC20FeeProxyPaymentDetector ( {
109106 advancedLogic : mockAdvancedLogic as any ,
110107 currencyManager : mockCurrencyManager as any ,
111- getSubgraphClient : mockGetSubgraphClient ,
112108 network : 'tron' ,
113109 } ) ;
114110
@@ -127,16 +123,13 @@ describe('TronERC20FeeProxyPaymentDetector', () => {
127123 'tron' as CurrencyTypes . TronChainName ,
128124 { version : '0.1.0' } as ExtensionTypes . IState ,
129125 ) ,
130- ) . rejects . toThrow ( 'Could not get a TheGraph-based info retriever ' ) ;
126+ ) . rejects . toThrow ( 'Could not get a Hasura client for TRON chain tron ' ) ;
131127 } ) ;
132128
133129 it ( 'should return empty events when toAddress is undefined' , async ( ) => {
134- const mockGetSubgraphClient = jest . fn ( ) . mockReturnValue ( mockSubgraphClient ) ;
135-
136130 const detector = new TronERC20FeeProxyPaymentDetector ( {
137131 advancedLogic : mockAdvancedLogic as any ,
138132 currencyManager : mockCurrencyManager as any ,
139- getSubgraphClient : mockGetSubgraphClient ,
140133 network : 'tron' ,
141134 } ) ;
142135
@@ -159,12 +152,9 @@ describe('TronERC20FeeProxyPaymentDetector', () => {
159152 } ) ;
160153
161154 it ( 'should throw NetworkNotSupported for unsupported chains' , async ( ) => {
162- const mockGetSubgraphClient = jest . fn ( ) . mockReturnValue ( mockSubgraphClient ) ;
163-
164155 const detector = new TronERC20FeeProxyPaymentDetector ( {
165156 advancedLogic : mockAdvancedLogic as any ,
166157 currencyManager : mockCurrencyManager as any ,
167- getSubgraphClient : mockGetSubgraphClient ,
168158 network : 'tron' ,
169159 } ) ;
170160
0 commit comments