@@ -157,6 +157,8 @@ describe("Voting", () => {
157157
158158 // Cast votes for each poll with different outcomes
159159 const voteOutcomes = [ true , false , true ] ; // Different outcomes for each poll
160+ let firstPollPDA : PublicKey ;
161+ let firstVoterRecordPDA : PublicKey ;
160162 for ( let i = 0 ; i < POLL_IDS . length ; i ++ ) {
161163 const POLL_ID = POLL_IDS [ i ] ;
162164 const vote = BigInt ( voteOutcomes [ i ] ) ;
@@ -182,6 +184,11 @@ describe("Voting", () => {
182184 program . programId
183185 ) ;
184186
187+ if ( i === 0 ) {
188+ firstPollPDA = pollPDA ;
189+ firstVoterRecordPDA = voterRecordPDA ;
190+ }
191+
185192 const voteComputationOffset = new anchor . BN ( randomBytes ( 8 ) , "hex" ) ;
186193
187194 const queueVoteSig = await program . methods
@@ -234,22 +241,12 @@ describe("Voting", () => {
234241 }
235242
236243 // Test double-vote prevention: attempt to vote again on the first poll
244+ // Reuse firstPollPDA and firstVoterRecordPDA derived during the voting loop
237245 console . log ( "\n--- Testing double-vote prevention ---" ) ;
238246 const DOUBLE_VOTE_POLL_ID = POLL_IDS [ 0 ] ;
239247 const doubleVoteNonce = randomBytes ( 16 ) ;
240248 const doubleVoteCiphertext = cipher . encrypt ( [ BigInt ( true ) ] , doubleVoteNonce ) ;
241249
242- const doubleVotePollIdBuffer = Buffer . alloc ( 4 ) ;
243- doubleVotePollIdBuffer . writeUInt32LE ( DOUBLE_VOTE_POLL_ID ) ;
244- const [ doubleVotePollPDA ] = PublicKey . findProgramAddressSync (
245- [ Buffer . from ( "poll" ) , owner . publicKey . toBuffer ( ) , doubleVotePollIdBuffer ] ,
246- program . programId
247- ) ;
248- const [ doubleVoteVoterRecordPDA ] = PublicKey . findProgramAddressSync (
249- [ Buffer . from ( "voter" ) , doubleVotePollPDA . toBuffer ( ) , owner . publicKey . toBuffer ( ) ] ,
250- program . programId
251- ) ;
252-
253250 const doubleVoteComputationOffset = new anchor . BN ( randomBytes ( 8 ) , "hex" ) ;
254251
255252 try {
@@ -277,8 +274,8 @@ describe("Voting", () => {
277274 Buffer . from ( getCompDefAccOffset ( "vote" ) ) . readUInt32LE ( )
278275 ) ,
279276 authority : owner . publicKey ,
280- pollAcc : doubleVotePollPDA ,
281- voterRecord : doubleVoteVoterRecordPDA ,
277+ pollAcc : firstPollPDA ,
278+ voterRecord : firstVoterRecordPDA ,
282279 } )
283280 . rpc ( {
284281 preflightCommitment : "confirmed" ,
0 commit comments