@@ -5672,7 +5672,7 @@ describe('V2 Wallet:', function () {
56725672 solInstructions : [ ] ,
56735673 recipients : testRecipients ,
56745674 } )
5675- . should . be . rejectedWith ( `'solInstructions' is a required parameter for customTx intent` ) ;
5675+ . should . be . rejectedWith ( `'solInstructions' or 'solVersionedTransactionData' is required for customTx intent` ) ;
56765676 } ) ;
56775677
56785678 it ( 'should support solInstruction for cold wallets' , async function ( ) {
@@ -5710,6 +5710,209 @@ describe('V2 Wallet:', function () {
57105710 } ) ;
57115711 } ) ;
57125712 } ) ;
5713+
5714+ describe ( 'prebuildTransaction with solVersionedTransactionData type' , function ( ) {
5715+ function getTestVersionedTransactionData ( ) {
5716+ return {
5717+ versionedInstructions : [
5718+ {
5719+ programIdIndex : 10 ,
5720+ accountKeyIndexes : [ 0 , 1 , 2 ] ,
5721+ data : '0102030405' ,
5722+ } ,
5723+ {
5724+ programIdIndex : 11 ,
5725+ accountKeyIndexes : [ 0 , 3 , 4 , 5 ] ,
5726+ data : '060708090a' ,
5727+ } ,
5728+ ] ,
5729+ addressLookupTables : [
5730+ {
5731+ accountKey : '2sk6bVhjN53hz7sqE72eqHvhPfSc1snZzsJR6yA5hF7j' ,
5732+ writableIndexes : [ 0 , 1 ] ,
5733+ readonlyIndexes : [ 2 , 3 ] ,
5734+ } ,
5735+ ] ,
5736+ staticAccountKeys : [
5737+ '5hr5fisPi6DXNuuRpm5XUbzpiEnmdyxXuBDTwzwZj5Pe' ,
5738+ '2sk6bVhjN53hz7sqE72eqHvhPfSc1snZzsJR6yA5hF7j' ,
5739+ '11111111111111111111111111111111' ,
5740+ ] ,
5741+ messageHeader : {
5742+ numRequiredSignatures : 1 ,
5743+ numReadonlySignedAccounts : 0 ,
5744+ numReadonlyUnsignedAccounts : 1 ,
5745+ } ,
5746+ } ;
5747+ }
5748+
5749+ it ( 'should call prebuildTxWithIntent with correct parameters for versioned transaction' , async function ( ) {
5750+ const testVersionedTransactionData = getTestVersionedTransactionData ( ) ;
5751+ const prebuildTxWithIntent = sandbox . stub ( TssUtils . prototype , 'prebuildTxWithIntent' ) ;
5752+ prebuildTxWithIntent . resolves ( txRequest ) ;
5753+ prebuildTxWithIntent . calledOnceWithExactly ( {
5754+ reqId,
5755+ intentType : 'customTx' ,
5756+ solVersionedTransactionData : testVersionedTransactionData ,
5757+ recipients : testRecipients ,
5758+ } ) ;
5759+
5760+ const txPrebuild = await tssSolWallet . prebuildTransaction ( {
5761+ reqId,
5762+ type : 'customTx' ,
5763+ solVersionedTransactionData : testVersionedTransactionData ,
5764+ recipients : testRecipients ,
5765+ } ) ;
5766+
5767+ txPrebuild . should . deepEqual ( {
5768+ walletId : tssSolWallet . id ( ) ,
5769+ wallet : tssSolWallet ,
5770+ txRequestId : 'id' ,
5771+ txHex : 'ababcdcd' ,
5772+ buildParams : {
5773+ type : 'customTx' ,
5774+ solVersionedTransactionData : testVersionedTransactionData ,
5775+ recipients : testRecipients ,
5776+ } ,
5777+ feeInfo : {
5778+ fee : 5000 ,
5779+ feeString : '5000' ,
5780+ } ,
5781+ } ) ;
5782+ } ) ;
5783+
5784+ it ( 'should handle solVersionedTransactionData with empty recipients' , async function ( ) {
5785+ const testVersionedTransactionData = getTestVersionedTransactionData ( ) ;
5786+ const prebuildTxWithIntent = sandbox . stub ( TssUtils . prototype , 'prebuildTxWithIntent' ) ;
5787+ prebuildTxWithIntent . resolves ( txRequest ) ;
5788+ prebuildTxWithIntent . calledOnceWithExactly ( {
5789+ reqId,
5790+ intentType : 'customTx' ,
5791+ solVersionedTransactionData : testVersionedTransactionData ,
5792+ recipients : [ ] ,
5793+ } ) ;
5794+
5795+ const txPrebuild = await tssSolWallet . prebuildTransaction ( {
5796+ reqId,
5797+ type : 'customTx' ,
5798+ solVersionedTransactionData : testVersionedTransactionData ,
5799+ } ) ;
5800+
5801+ txPrebuild . should . deepEqual ( {
5802+ walletId : tssSolWallet . id ( ) ,
5803+ wallet : tssSolWallet ,
5804+ txRequestId : 'id' ,
5805+ txHex : 'ababcdcd' ,
5806+ buildParams : {
5807+ type : 'customTx' ,
5808+ solVersionedTransactionData : testVersionedTransactionData ,
5809+ } ,
5810+ feeInfo : {
5811+ fee : 5000 ,
5812+ feeString : '5000' ,
5813+ } ,
5814+ } ) ;
5815+ } ) ;
5816+
5817+ it ( 'should handle solVersionedTransactionData with memo parameter' , async function ( ) {
5818+ const testVersionedTransactionData = getTestVersionedTransactionData ( ) ;
5819+ const prebuildTxWithIntent = sandbox . stub ( TssUtils . prototype , 'prebuildTxWithIntent' ) ;
5820+ prebuildTxWithIntent . resolves ( txRequest ) ;
5821+ prebuildTxWithIntent . calledOnceWithExactly ( {
5822+ reqId,
5823+ intentType : 'customTx' ,
5824+ solVersionedTransactionData : testVersionedTransactionData ,
5825+ recipients : testRecipients ,
5826+ memo : {
5827+ type : 'type' ,
5828+ value : 'test memo' ,
5829+ } ,
5830+ } ) ;
5831+
5832+ const txPrebuild = await tssSolWallet . prebuildTransaction ( {
5833+ reqId,
5834+ type : 'customTx' ,
5835+ solVersionedTransactionData : testVersionedTransactionData ,
5836+ recipients : testRecipients ,
5837+ memo : {
5838+ type : 'type' ,
5839+ value : 'test memo' ,
5840+ } ,
5841+ } ) ;
5842+
5843+ txPrebuild . should . deepEqual ( {
5844+ walletId : tssSolWallet . id ( ) ,
5845+ wallet : tssSolWallet ,
5846+ txRequestId : 'id' ,
5847+ txHex : 'ababcdcd' ,
5848+ buildParams : {
5849+ type : 'customTx' ,
5850+ solVersionedTransactionData : testVersionedTransactionData ,
5851+ recipients : testRecipients ,
5852+ memo : {
5853+ type : 'type' ,
5854+ value : 'test memo' ,
5855+ } ,
5856+ } ,
5857+ feeInfo : {
5858+ fee : 5000 ,
5859+ feeString : '5000' ,
5860+ } ,
5861+ } ) ;
5862+ } ) ;
5863+
5864+ it ( 'should handle solVersionedTransactionData with pending approval ID' , async function ( ) {
5865+ const testVersionedTransactionData = getTestVersionedTransactionData ( ) ;
5866+ const prebuildTxWithIntent = sandbox . stub ( TssUtils . prototype , 'prebuildTxWithIntent' ) ;
5867+ prebuildTxWithIntent . resolves ( { ...txRequest , state : 'pendingApproval' , pendingApprovalId : 'some-id' } ) ;
5868+ prebuildTxWithIntent . calledOnceWithExactly ( {
5869+ reqId,
5870+ intentType : 'customTx' ,
5871+ solVersionedTransactionData : testVersionedTransactionData ,
5872+ recipients : testRecipients ,
5873+ } ) ;
5874+
5875+ const txPrebuild = await custodialTssSolWallet . prebuildTransaction ( {
5876+ reqId,
5877+ type : 'customTx' ,
5878+ solVersionedTransactionData : testVersionedTransactionData ,
5879+ recipients : testRecipients ,
5880+ } ) ;
5881+
5882+ txPrebuild . should . deepEqual ( {
5883+ walletId : custodialTssSolWallet . id ( ) ,
5884+ wallet : custodialTssSolWallet ,
5885+ txRequestId : 'id' ,
5886+ txHex : 'ababcdcd' ,
5887+ pendingApprovalId : 'some-id' ,
5888+ buildParams : {
5889+ type : 'customTx' ,
5890+ solVersionedTransactionData : testVersionedTransactionData ,
5891+ recipients : testRecipients ,
5892+ } ,
5893+ feeInfo : {
5894+ fee : 5000 ,
5895+ feeString : '5000' ,
5896+ } ,
5897+ } ) ;
5898+ } ) ;
5899+
5900+ it ( 'should throw error for empty versionedInstructions array' , async function ( ) {
5901+ await tssSolWallet
5902+ . prebuildTransaction ( {
5903+ reqId,
5904+ type : 'customTx' ,
5905+ solVersionedTransactionData : {
5906+ versionedInstructions : [ ] ,
5907+ addressLookupTables : [ ] ,
5908+ staticAccountKeys : [ 'test' ] ,
5909+ messageHeader : { numRequiredSignatures : 1 , numReadonlySignedAccounts : 0 , numReadonlyUnsignedAccounts : 0 } ,
5910+ } ,
5911+ recipients : testRecipients ,
5912+ } )
5913+ . should . be . rejectedWith ( `'solInstructions' or 'solVersionedTransactionData' is required for customTx intent` ) ;
5914+ } ) ;
5915+ } ) ;
57135916 } ) ;
57145917
57155918 describe ( 'Aptos Custom transaction Flow' , function ( ) {
0 commit comments