diff --git a/lib/core-integration/src/Test/Integration/Framework/TestData.hs b/lib/core-integration/src/Test/Integration/Framework/TestData.hs index 92d0e0a764d..2a72ffb654a 100644 --- a/lib/core-integration/src/Test/Integration/Framework/TestData.hs +++ b/lib/core-integration/src/Test/Integration/Framework/TestData.hs @@ -101,6 +101,7 @@ module Test.Integration.Framework.TestData , errMsg403TemplateInvalidDuplicateXPub , errMsg403TemplateInvalidScript , errMsg403InvalidConstructTx + , errMsg403ForeignTransaction ) where import Prelude @@ -637,6 +638,13 @@ errMsg400ScriptNotUniformRoles :: String errMsg400ScriptNotUniformRoles = "All keys of a script must have the same role: either payment or delegation." +errMsg403ForeignTransaction :: String +errMsg403ForeignTransaction = mconcat + [ "The transaction to be submitted is foreign to the current wallet " + , "and cannot be sent. Submit a transaction that has either input, output " + , "or withdrawal belonging to the wallet." + ] + -------------------------------------------------------------------------------- -- Transaction metadata -------------------------------------------------------------------------------- diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs index d95b4b6adc9..79f72c06041 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs @@ -174,6 +174,7 @@ import Test.Integration.Framework.DSL import Test.Integration.Framework.TestData ( errMsg403Collateral , errMsg403Fee + , errMsg403ForeignTransaction , errMsg403InvalidConstructTx , errMsg403MinUTxOValue , errMsg403NotDelegating @@ -2155,7 +2156,8 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do ] forM_ scenarios $ \(title, foreignWallet) -> it title $ \ctx -> runResourceT $ do wa <- fixtureWallet ctx - wb <- foreignWallet ctx + wb <- fixtureWallet ctx + wF <- foreignWallet ctx -- Construct tx payload <- mkTxPayload ctx wb $ minUTxOValue (_mainEra ctx) @@ -2172,12 +2174,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do signedTx <- getFromResponse Prelude.id <$> request @ApiSerialisedTransaction ctx signEndpoint Default toSign - -- Submit tx (from wb) - submittedTx <- submitTxWithWid ctx wb signedTx + -- Submit tx (from wF) + submittedTx <- submitTxWithWid ctx wF signedTx verify submittedTx [ expectResponseCode HTTP.status403 - , expectErrorMessage "Transaction cannot be submitted as it is foreign to\ - \ this wallet. Please submit it from the wallet it belongs to." + , expectErrorMessage errMsg403ForeignTransaction ] describe "TRANS_NEW_SUBMIT_02 - Submitting on foreign Byron wallet is forbidden" $ do diff --git a/lib/core/src/Cardano/Wallet/Api/Server.hs b/lib/core/src/Cardano/Wallet/Api/Server.hs index b86e14fc3c3..46915034856 100644 --- a/lib/core/src/Cardano/Wallet/Api/Server.hs +++ b/lib/core/src/Cardano/Wallet/Api/Server.hs @@ -2349,6 +2349,8 @@ submitTransaction submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT sealedTx)) = do ttl <- liftIO $ W.getTxExpiry ti Nothing apiDecoded <- decodeTransaction @_ @s @k @n ctx apiw apitx + when (isForeign apiDecoded) $ + liftHandler $ throwE ErrSubmitTransactionForeignWallet let ourOuts = getOurOuts apiDecoded let ourInps = getOurInps apiDecoded @@ -2370,7 +2372,6 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal nl = ctx ^. networkLayer ti = timeInterpreter nl - isOutOurs (WalletOutput _) = True isOutOurs _ = False toTxOut (WalletOutput (ApiWalletOutput (ApiT addr, _) (Quantity amt) (ApiT tmap) _)) = @@ -2399,6 +2400,20 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal let generalInps = apiDecodedTx ^. #inputs in map toTxInp $ filter isInpOurs generalInps + isForeign apiDecodedTx = + let generalInps = apiDecodedTx ^. #inputs + generalWdrls = apiDecodedTx ^. #withdrawals + generalOuts = apiDecodedTx ^. #outputs + isInpForeign (WalletInput _) = False + isInpForeign _ = True + isOutForeign (WalletOutput _) = False + isOutForeign _ = True + isWdrlForeign (ApiWithdrawalGeneral _ _ context) = context == External + in + all isInpForeign generalInps && + all isOutForeign generalOuts && + all isWdrlForeign generalWdrls + joinStakePool :: forall ctx s n k. ( ctx ~ ApiLayer s k