@@ -587,6 +587,7 @@ describe('Portal unit tests', () => {
587587 let inboxItem : PublicKey ;
588588 let payload : any ;
589589 let vaaBytes : Uint8Array ;
590+ let vaaKey : PublicKey ;
590591
591592 const redeem = (
592593 additionalAccounts : AccountMeta [ ] ,
@@ -616,6 +617,12 @@ describe('Portal unit tests', () => {
616617 return async function * redeemTxns ( ) {
617618 let i = 0 ;
618619 for await ( const tx of redeemTxs ) {
620+ // grab the calculated VAA key
621+ if ( i === 2 ) {
622+ const t = tx . transaction . transaction as Transaction ;
623+ vaaKey = t . instructions [ 0 ] . keys [ 3 ] . pubkey ;
624+ }
625+
619626 if ( ++ i === 4 ) {
620627 if ( skipRelease ) {
621628 continue ;
@@ -907,14 +914,30 @@ describe('Portal unit tests', () => {
907914 ) ;
908915
909916 // publish message and load in vaa body bytes
910- redeem ( additionalRedeemAccounts ( mint . publicKey , extMint . publicKey , extAta ) , undefined , true ) ;
917+ const getRedeemTxns = redeem (
918+ additionalRedeemAccounts ( mint . publicKey , extMint . publicKey , extAta ) ,
919+ undefined ,
920+ true ,
921+ ) ;
922+
923+ // execute first two then skip the rest
924+ let i = 0 ;
925+ for await ( const tx of getRedeemTxns ( ) ) {
926+ if ( i ++ < 2 ) {
927+ async function * yieldTx ( tx : SolanaUnsignedTransaction < 'Mainnet' , 'Solana' > ) {
928+ yield tx ;
929+ }
930+ await ssw ( ctx , yieldTx ( tx ) , signer ) ;
931+ }
932+ }
911933
912934 // check that first 64 bytes is the source and recipient manager
913935 const dest_manager = new PublicKey ( vaaBytes . slice ( 36 , 68 ) ) . toBase58 ( ) ;
914936 expect ( dest_manager ) . toBe ( config . PORTAL_PROGRAM_ID . toBase58 ( ) ) ;
915937
916- // add VAA header
938+ // add VAA header with eth header
917939 const vaaBody = Buffer . concat ( [ Buffer . alloc ( 51 ) , vaaBytes ] ) ;
940+ vaaBody . writeUInt8 ( 2 , 9 ) ;
918941
919942 const initIx = new TransactionInstruction ( {
920943 programId : ntt . program . programId ,
@@ -1041,7 +1064,7 @@ describe('Portal unit tests', () => {
10411064 expect ( data [ 0 ] ) . toBe ( 2 ) ; // Resolved Account
10421065
10431066 // send transaction to load in account data
1044- svm . sendTransaction ! ( tx ) ;
1067+ svm . sendTransaction ! ( tx ) . toString ( ) ;
10451068
10461069 // decode account data
10471070 const encoder = new BorshAccountsCoder ( resolverTypes ( ) ) ;
@@ -1051,13 +1074,20 @@ describe('Portal unit tests', () => {
10511074
10521075 const { instructions, address_lookup_tables } = resolveResult [ 0 ] . Resolved [ 0 ] [ 0 ] [ 0 ] ;
10531076
1077+ const resolveKey = ( key : PublicKey ) => {
1078+ const vaaPlaceholder = new PublicKey ( Buffer . from ( 'posted_vaa_000000000000000000000' ) ) ;
1079+ if ( key . equals ( payerPlaceholder ) ) return payer . publicKey ;
1080+ if ( key . equals ( vaaPlaceholder ) ) return vaaKey ;
1081+ return key ;
1082+ } ;
1083+
10541084 const redeemTx = new Transaction ( ) . add (
10551085 ...[ instructions [ 0 ] ] . map (
10561086 ( ix : any ) =>
10571087 new TransactionInstruction ( {
10581088 programId : ix . program_id ,
10591089 keys : ix . accounts . map ( ( acc : any ) => ( {
1060- pubkey : acc . pubkey . equals ( payerPlaceholder ) ? payer . publicKey : acc . pubkey ,
1090+ pubkey : resolveKey ( acc . pubkey ) ,
10611091 isSigner : acc . is_signer ,
10621092 isWritable : acc . is_writable ,
10631093 } ) ) ,
@@ -1071,6 +1101,8 @@ describe('Portal unit tests', () => {
10711101 redeemTx . sign ( payer ) ;
10721102 const redeemResult = svm . sendTransaction ! ( redeemTx ) ;
10731103
1104+ console . log ( 'Redeem tx' , JSON . stringify ( redeemTx , null , 2 ) ) ;
1105+
10741106 console . log ( 'Redeem result:' , redeemResult . toString ( ) ) ;
10751107 } ) ;
10761108
0 commit comments