11import { ProposalData } from '../fixtures' ;
22import { ProcessedVotingPowerHistory } from '@notification-system/anticapture-client' ;
3+ import { getAddress , isAddress } from 'viem' ;
34
45/**
56 * @notice Setup class for GraphQL API mocking in integration tests
67 * @dev Provides methods to mock different GraphQL endpoints with test data
78 */
89export class GraphQLMockSetup {
10+ /**
11+ * @notice Converts an address to checksummed format if valid
12+ * @dev Simulates API behavior of returning checksummed addresses
13+ */
14+ private static toChecksum ( address : string ) : string {
15+ if ( ! address || ! isAddress ( address ) ) {
16+ return address ;
17+ }
18+ try {
19+ return getAddress ( address ) ;
20+ } catch {
21+ return address ;
22+ }
23+ }
924 /**
1025 * @notice Transforms ProcessedVotingPowerHistory to raw GraphQL format
1126 */
1227 private static transformToRawGraphQLFormat ( votingPowerData : ProcessedVotingPowerHistory [ ] ) : any [ ] {
1328 return votingPowerData . map ( vp => ( {
14- accountId : vp . accountId ,
29+ accountId : this . toChecksum ( vp . accountId ) ,
1530 timestamp : vp . timestamp ,
1631 votingPower : vp . votingPower ,
1732 delta : vp . delta || null ,
1833 daoId : vp . daoId ,
1934 transactionHash : vp . transactionHash ,
2035 delegation : vp . delegation ? {
21- delegatorAccountId : vp . delegation . delegatorAccountId ,
36+ delegatorAccountId : this . toChecksum ( vp . delegation . delegatorAccountId ) ,
2237 delegatedValue : vp . delegation . delegatedValue
2338 } : null ,
2439 transfer : vp . transfer ? {
2540 amount : vp . transfer . amount ,
26- fromAccountId : vp . transfer . fromAccountId ,
27- toAccountId : vp . transfer . toAccountId
41+ fromAccountId : this . toChecksum ( vp . transfer . fromAccountId ) ,
42+ toAccountId : this . toChecksum ( vp . transfer . toAccountId )
2843 } : null
2944 } ) ) ;
3045 }
@@ -53,17 +68,27 @@ export class GraphQLMockSetup {
5368 if ( config ?. headers ?. [ 'anticapture-dao-id' ] ) {
5469 filtered = filtered . filter ( p => p . daoId === config . headers [ 'anticapture-dao-id' ] ) ;
5570 }
71+ // Convert proposer addresses to checksum format
72+ const checksummedProposals = filtered . map ( p => ( {
73+ ...p ,
74+ proposerAccountId : this . toChecksum ( p . proposerAccountId )
75+ } ) ) ;
5676 return Promise . resolve ( {
57- data : { data : { proposals : filtered } }
77+ data : { data : { proposals : checksummedProposals } }
5878 } ) ;
5979 }
6080
6181 // Handle single proposal
6282 if ( data . query ?. includes ( 'GetProposalById' ) ) {
6383 const proposalId = data . variables ?. id ;
6484 const proposal = proposals . find ( p => p . id === proposalId ) ;
85+ // Convert proposer address to checksum if proposal exists
86+ const checksummedProposal = proposal ? {
87+ ...proposal ,
88+ proposerAccountId : this . toChecksum ( proposal . proposerAccountId )
89+ } : null ;
6590 return Promise . resolve ( {
66- data : { data : { proposal : proposal || null } }
91+ data : { data : { proposal : checksummedProposal } }
6792 } ) ;
6893 }
6994
@@ -100,10 +125,11 @@ export class GraphQLMockSetup {
100125 }
101126
102127 // Filter by voterAccountId_in if provided
128+ // Now using exact comparison since AnticaptureClient normalizes addresses
103129 if ( voterAccountIdIn ) {
104130 filtered = filtered . filter ( ( v : any ) =>
105131 voterAccountIdIn . some ( ( addr : string ) =>
106- v . voterAccountId . toLowerCase ( ) === addr . toLowerCase ( )
132+ this . toChecksum ( v . voterAccountId ) === addr
107133 )
108134 ) ;
109135 }
@@ -115,8 +141,14 @@ export class GraphQLMockSetup {
115141 ) ;
116142 }
117143
144+ // Convert voter addresses to checksum format (simulating real API behavior)
145+ const checksummedVotes = filtered . map ( ( v : any ) => ( {
146+ ...v ,
147+ voterAccountId : this . toChecksum ( v . voterAccountId )
148+ } ) ) ;
149+
118150 return Promise . resolve ( {
119- data : { data : { votesOnchains : { items : filtered , totalCount : filtered . length } } }
151+ data : { data : { votesOnchains : { items : checksummedVotes , totalCount : checksummedVotes . length } } }
120152 } ) ;
121153 }
122154
0 commit comments