Skip to content

Commit

Permalink
use submitTxWithWid throughout TransactionNew
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jan 17, 2022
1 parent 8d88f78 commit a041d4c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 28 deletions.
Expand Up @@ -113,8 +113,6 @@ import Data.Aeson
( toJSON, (.=) )
import Data.Function
( (&) )
import Data.Functor
( void )
import Data.Generics.Internal.VL.Lens
( view, (^.) )
import Data.Generics.Sum
Expand Down Expand Up @@ -164,7 +162,6 @@ import Test.Integration.Framework.DSL
, rewardWallet
, selectCoins
, signTx
, submitTx
, submitTxWithWid
, unsafeRequest
, verify
Expand Down Expand Up @@ -295,7 +292,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
]

-- Submit tx
void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

-- Make sure only fee is deducted from fixtureWallet
eventually "Wallet balance is as expected" $ do
Expand Down Expand Up @@ -336,7 +337,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
]

-- Submit tx
void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

-- Make sure wallet balance is decreased by fee, since rewards = 0
eventually "Wallet balance is decreased by fee" $ do
Expand Down Expand Up @@ -388,7 +393,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
]

-- Submit tx
void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

-- Make sure wallet balance is increased by withdrawalAmt - fee
eventually "Wallet balance is increased by withdrawalAmt - fee" $ do
Expand Down Expand Up @@ -443,7 +452,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

-- Make sure wallet balance is increased by withdrawalAmt - fee
eventually "Wallet balance is increased by withdrawalAmt - fee" $ do
Expand Down Expand Up @@ -553,7 +566,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

eventually "Target wallet balance is decreased by amt + fee" $ do
rWa <- request @ApiWallet ctx
Expand Down Expand Up @@ -746,7 +763,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

eventually "Target wallet balance is increased by 2*amt" $ do
rWb <- request @ApiWallet ctx
Expand Down Expand Up @@ -872,7 +893,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

eventually "Target wallet balance is increased by amt and assets" $ do
rWb <- request @ApiWallet ctx
Expand Down Expand Up @@ -955,7 +980,12 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

txId <- submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]
let txId = getFromResponse (#id) submittedTx

outTxAmt <- eventually "Transactions is in ledger" $ do
let linkSrc = Link.getTransaction @'Shelley wa txId
Expand Down Expand Up @@ -1139,7 +1169,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

it "TRANS_NEW_VALIDITY_INTERVAL_01b - Validity interval with slot" $ \ctx -> runResourceT $ do
wa <- fixtureWallet ctx
Expand Down Expand Up @@ -1168,7 +1202,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

it "TRANS_NEW_VALIDITY_INTERVAL_02 - Validity interval second should be >= 0" $ \ctx -> runResourceT $ do

Expand Down Expand Up @@ -1314,7 +1352,12 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
let apiTx = getFromResponse #transaction rTx
signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]
-- Submit tx
txId <- submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]
let txId = getFromResponse (#id) submittedTx

eventually "Metadata is on-chain" $ do
rWa <- request @(ApiTransaction n) ctx
Expand Down Expand Up @@ -1820,11 +1863,16 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

let apiTx = getFromResponse #transaction rTx
signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]
txId <- submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]
let txId = getFromResponse (#id) submittedTx

waitForTxImmutability ctx
partialTx' <- PlutusScenario.pingPong_2 $ Aeson.object
[ "transactionId" .= view #id txId ]
[ "transactionId" .= txId ]
let toBalance' = Json (toJSON partialTx')

rTx' <- request @ApiSerialisedTransaction ctx
Expand Down Expand Up @@ -1861,7 +1909,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]

void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

it "TRANS_NEW_BALANCE_04a - \
\I get proper error message when payload is not hex or base64 encoded" $
Expand Down Expand Up @@ -1967,7 +2019,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
verify rDecodedTx hasExpectedFee

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]
void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

eventually "Wallet balance is as expected" $ do
rWa <- request @ApiWallet ctx
Expand Down Expand Up @@ -1998,7 +2054,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
request @ApiSerialisedTransaction ctx signEndpoint Default toSign

-- Submit tx
void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx w signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

it "TRANS_NEW_SIGN_02 - Rejects unsigned transaction" $ \ctx -> runResourceT $ do
w <- fixtureWallet ctx
Expand All @@ -2010,7 +2070,10 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
request @(ApiConstructTransaction n) ctx constructEndpoint Default payload

-- Submit tx
void $ submitTx ctx (ApiSerialisedTransaction sealedTx) [ expectResponseCode HTTP.status500 ]
submittedTx <- submitTxWithWid ctx w (ApiSerialisedTransaction sealedTx)
verify submittedTx
[ expectResponseCode HTTP.status500
]

it "TRANS_NEW_SIGN_03 - Sign withdrawals" $ \ctx -> runResourceT $ do
(w, _) <- rewardWallet ctx
Expand All @@ -2032,7 +2095,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
<$> request @ApiSerialisedTransaction ctx signEndpoint Default toSign

-- Submit tx
void $ submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx w signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]

it "TRANS_NEW_SIGN_04 - Sign extra required signatures" $ \ctx -> runResourceT $ do
(w, mw) <- second (unsafeMkMnemonic @15) <$> fixtureWalletWithMnemonics (Proxy @"shelley") ctx
Expand Down Expand Up @@ -2071,7 +2138,8 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
-- too small, which is good enough for this test... Yet really, we
-- should be able to construct transactions with extra signers from the
-- API!
void $ submitTx ctx signedTx
submittedTx <- submitTxWithWid ctx w signedTx
verify submittedTx
[ expectResponseCode HTTP.status500
, expectErrorMessage "FeeTooSmallUTxO"
]
Expand Down Expand Up @@ -2158,11 +2226,16 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
{ "transaction": #{sealedTx}
, "passphrase": #{fixturePassphrase}
}|]
(_, signedTx) <- Prelude.id <$>
(_, signedTx) <-
unsafeRequest @ApiSerialisedTransaction ctx signEndpoint toSign

-- Submit
txid <- submitTx ctx signedTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx w signedTx
verify submittedTx
[ expectSuccess
, expectResponseCode HTTP.status202
]
let txid = getFromResponse Prelude.id submittedTx

let runStep = \previous step -> do
waitForTxImmutability ctx
Expand All @@ -2178,11 +2251,16 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
{ "transaction": #{sealedTx'}
, "passphrase": #{fixturePassphrase}
}|]
(_, signedTx') <- Prelude.id <$>
(_, signedTx') <-
unsafeRequest @ApiSerialisedTransaction ctx signEndpoint toSign'

-- Submit
submitTx ctx signedTx' [ expectResponseCode HTTP.status202 ]
submittedTx' <- submitTxWithWid ctx w signedTx'
verify submittedTx'
[ expectSuccess
, expectResponseCode HTTP.status202
]
pure $ getFromResponse Prelude.id submittedTx'

foldM_ runStep txid steps
where
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -2392,8 +2392,8 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal

isInpOurs (WalletInput _) = True
isInpOurs _ = False
toTxInp (WalletInput (ApiWalletInput (ApiT txid) ix _ _ (Quantity _amt) _)) =
(TxIn txid ix, Coin 0) -- $ fromIntegral amt)
toTxInp (WalletInput (ApiWalletInput (ApiT txid) ix _ _ _ _)) =
(TxIn txid ix, Coin 0)
toTxInp _ = error "we should have only our inputs at this point"
getOurInps apiDecodedTx =
let generalInps = apiDecodedTx ^. #inputs
Expand Down

0 comments on commit a041d4c

Please sign in to comment.