@@ -691,6 +691,63 @@ describe("stackflow agent", () => {
691691 store . close ( ) ;
692692 } ) ;
693693
694+ it ( "rejects incoming transfer requests with actor mismatch" , ( ) => {
695+ const dbFile = tempDbFile ( "agent-sign-actor-mismatch" ) ;
696+ const store = new AgentStateStore ( { dbFile } ) ;
697+ const contractId = "ST1TESTABC.contract" ;
698+ const pipeKey = {
699+ "principal-1" : "ST1LOCAL" ,
700+ "principal-2" : "ST1OTHER" ,
701+ token : null ,
702+ } ;
703+ const pipeId = buildPipeId ( { contractId, pipeKey } ) ;
704+
705+ store . upsertTrackedPipe ( {
706+ pipeId,
707+ contractId,
708+ pipeKey,
709+ localPrincipal : "ST1LOCAL" ,
710+ counterpartyPrincipal : "ST1OTHER" ,
711+ token : null ,
712+ } ) ;
713+
714+ const agent = new StackflowAgentService ( {
715+ stateStore : store ,
716+ signer : {
717+ async sip018Sign ( ) {
718+ return "0x" + "44" . repeat ( 65 ) ;
719+ } ,
720+ async submitDispute ( ) {
721+ return { txid : "0x1" } ;
722+ } ,
723+ async callContract ( ) {
724+ return { ok : true } ;
725+ } ,
726+ } ,
727+ network : "devnet" ,
728+ } ) ;
729+
730+ const validation = agent . validateIncomingTransfer ( {
731+ pipeId,
732+ payload : {
733+ contractId,
734+ forPrincipal : "ST1LOCAL" ,
735+ withPrincipal : "ST1OTHER" ,
736+ token : null ,
737+ myBalance : "90" ,
738+ theirBalance : "10" ,
739+ nonce : "1" ,
740+ action : "1" ,
741+ actor : "ST1THIRD" ,
742+ theirSignature : "0x" + "22" . repeat ( 65 ) ,
743+ } ,
744+ } ) ;
745+
746+ expect ( validation . valid ) . toBe ( false ) ;
747+ expect ( validation . reason ) . toBe ( "actor-mismatch" ) ;
748+ store . close ( ) ;
749+ } ) ;
750+
694751 it ( "rejects incoming transfer requests with pipe id mismatch" , ( ) => {
695752 const dbFile = tempDbFile ( "agent-sign-pipeid-mismatch" ) ;
696753 const store = new AgentStateStore ( { dbFile } ) ;
0 commit comments