@@ -212,20 +212,36 @@ describe('rpc-multi-trees', () => {
212212 const prePayerAccounts = await rpc . getCompressedAccountsByOwner (
213213 payer . publicKey ,
214214 ) ;
215-
216- const proofs = await rpc . getMultipleCompressedAccountProofs (
217- prePayerAccounts . items . map ( account => bn ( account . hash ) ) ,
215+ let hashes = prePayerAccounts . items . map ( account =>
216+ bn ( account . hash ) ,
217+ ) ;
218+ const proofs = await rpc . getMultipleCompressedAccountProofs ( hashes ) ;
219+
220+ // Create hash -> account map since proof order may not match input order
221+ const accountByHash = new Map (
222+ prePayerAccounts . items . map ( acc => [
223+ bn ( acc . hash ) . toString ( ) ,
224+ acc ,
225+ ] ) ,
218226 ) ;
219227
220228 proofs . forEach ( ( proof , index ) => {
221- const expectedTree =
222- prePayerAccounts . items [ index ] . treeInfo . tree ;
229+ // Match proof to account by hash, not by index
230+ const matchingAccount = accountByHash . get (
231+ bn ( proof . hash ) . toString ( ) ,
232+ ) ;
233+ if ( ! matchingAccount ) {
234+ throw new Error (
235+ `No matching account found for proof hash ${ bn ( proof . hash ) . toString ( ) } ` ,
236+ ) ;
237+ }
238+
239+ const expectedTree = matchingAccount . treeInfo . tree ;
223240 const actualTree = proof . treeInfo . tree ;
224- const expectedQueue =
225- prePayerAccounts . items [ index ] . treeInfo . queue ;
241+ const expectedQueue = matchingAccount . treeInfo . queue ;
226242 const actualQueue = proof . treeInfo . queue ;
227-
228- console . log ( `Iteration ${ round + 1 } , Account ${ index } :` ) ;
243+ console . log ( `.hash: ${ bn ( proof . hash ) . toString ( ) } ` ) ;
244+ console . log ( `Iteration ${ round + 1 } , Proof ${ index } :` ) ;
229245 console . log (
230246 ` Expected tree (from getCompressedAccountsByOwner): ${ expectedTree . toBase58 ( ) } ` ,
231247 ) ;
0 commit comments