Skip to content

Commit

Permalink
Add integration test for ADP-3359 (#4600)
Browse files Browse the repository at this point in the history
<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
✓ Self-review your changes to make sure nothing unexpected slipped
through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->

Showing that when foreign txs constructed in Mary and Babbage are sent
to `submitTxWithWid` then `ForeignTransaction` is emitted.

When foreign txs constructed in Babbage is sent through `postExternalTx`
it can be accepted or rejected depending how it is formed (in the case
added it ends up with 500 as expected).

But when foreign txs constructed in Mary is sent through
`postExternalTx` it will emit `UnsupportedEras` error as expected

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
adp-3359
<!-- Reference the Jira/GitHub issue that this PR relates to, and which
requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->
  • Loading branch information
paweljakubas authored May 23, 2024
2 parents 0d3a9b0 + c00a518 commit 67d134f
Showing 1 changed file with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import Cardano.Wallet.Api.Types.Error
, ApiErrorMissingWitnessesInTransaction (..)
, ApiErrorNoSuchPool (..)
, ApiErrorTxOutputLovelaceInsufficient (ApiErrorTxOutputLovelaceInsufficient)
, ApiErrorUnsupportedEra (..)
)
import Cardano.Wallet.Api.Types.Transaction
( ApiAddress (..)
Expand Down Expand Up @@ -217,7 +218,8 @@ import Control.Monad.Trans.Resource
( runResourceT
)
import Data.Aeson
( toJSON
( decode
, toJSON
, (.=)
)
import Data.Function
Expand Down Expand Up @@ -350,6 +352,7 @@ import qualified Cardano.Wallet.Api.Types.WalletAssets as ApiWalletAssets
import qualified Cardano.Wallet.Primitive.Types.AssetName as AssetName
import qualified Cardano.Wallet.Primitive.Types.TokenMap as TokenMap
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as BL
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import qualified Data.Percentage as Percentage
Expand Down Expand Up @@ -2962,6 +2965,107 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

foldM_ runStep txid steps

it "TRANS_NEW_SUBMIT_04 - Mary and Babbage foreign txs submitted" $ \ctx -> runResourceT $ do
wa <- fixtureWallet ctx

--- $ cardano-cli address key-gen --verification-key-file payment.vkey --signing-key-file payment.skey
--- $ cat payment.skey
--- {
--- "type": "PaymentSigningKeyShelley_ed25519",
--- "description": "Payment Signing Key",
--- "cborHex": "5820c18580391024aed84071bdbde7fba81c489a97813b45edd53ad2db5231bb0a69"
--- }
--- $ cat payment.vkey
--- {
--- "type": "PaymentVerificationKeyShelley_ed25519",
--- "description": "Payment Verification Key",
--- "cborHex": "58201a6c21bc45c5d7089685610db372f2d2f87873aaa687af21b6bd62e7055d2402"
--- }
--- $ cardano-cli address build --payment-verification-key-file payment.vkey --out-file payment.addr "--mainnet"
---
--- $ cardano-cli transaction build-raw \
--- > --fee 300000 \
--- > --tx-in "ab08ccdf5c62ad8008d0ac165b68ff714b88de19235a9bd65c731fc264125daf#0" \
--- > --tx-out $(cat payment.addr)+10000000 \
--- > --mary-era \
--- > --out-file tx.mary.raw
--- $ cardano-cli transaction sign \
--- > --tx-body-file tx.mary.raw \
--- > --signing-key-file payment.skey \
--- > --mainnet \
--- > --out-file tx.mary.signed
let maryCBOR =
"{\"transaction\":\"83a30081825820ab08ccdf5c62ad8008d0ac165b68f\
\f714b88de19235a9bd65c731fc264125daf00018182581d6121f322c97d028\
\7c6c3cfb06a984e75d50eac2a8e8ba33a71d8f8462a1a00989680021a00049\
\3e0a100818258201a6c21bc45c5d7089685610db372f2d2f87873aaa687af2\
\1b6bd62e7055d2402584029791f8f82d3413c93700ee63b86e3355880f4bda\
\b10893ad020358e04f78ef405bd031397dbbf311ab0297ed66196d6d57f662\
\aaab9e3610b2df03ccb38cc0df6\"}" :: BL.ByteString
let (Just submitMaryPayload) = decode @ApiSerialisedTransaction maryCBOR
let submitMaryPayload' =
NonJson $ BL.fromStrict $ view #serialisedTx $ getApiT $
view #serialisedTxSealed submitMaryPayload

--- $ cardano-cli transaction build-raw \
--- > --fee 300000 \
--- > --tx-in "ab08ccdf5c62ad8008d0ac165b68ff714b88de19235a9bd65c731fc264125daf#0" \
--- > --tx-out $(cat payment.addr)+10000000 \
--- > --mary-era \
--- > --out-file tx.babbage.raw
--- $ cardano-cli transaction sign \
--- > --tx-body-file tx.babbage.raw \
--- > --signing-key-file payment.skey \
--- > --mainnet \
--- > --out-file tx.babbage.signed
let babbageCBOR =
"{\"transaction\":\"84a30081825820ab08ccdf5c62ad8008d0ac165b68f\
\f714b88de19235a9bd65c731fc264125daf00018182581d6121f322c97d028\
\7c6c3cfb06a984e75d50eac2a8e8ba33a71d8f8462a1a00989680021a00049\
\3e0a100818258201a6c21bc45c5d7089685610db372f2d2f87873aaa687af2\
\1b6bd62e7055d2402584029791f8f82d3413c93700ee63b86e3355880f4bda\
\b10893ad020358e04f78ef405bd031397dbbf311ab0297ed66196d6d57f662\
\aaab9e3610b2df03ccb38cc0df5f6\"}" :: BL.ByteString
let (Just submitBabbagePayload) = decode @ApiSerialisedTransaction babbageCBOR
let submitBabbagePayload' =
NonJson $ BL.fromStrict $ view #serialisedTx $ getApiT $
view #serialisedTxSealed submitBabbagePayload

submittedMaryTx <- submitTxWithWid ctx wa submitMaryPayload
verify submittedMaryTx
[ expectResponseCode HTTP.status403
]
decodeErrorInfo submittedMaryTx `shouldBe` ForeignTransaction

submittedBabbageTx <- submitTxWithWid ctx wa submitBabbagePayload
verify submittedBabbageTx
[ expectResponseCode HTTP.status403
]
decodeErrorInfo submittedBabbageTx `shouldBe` ForeignTransaction

-- using external submit users can push txs that result in node errors
submittedBabbageTxExternal <- request @ApiTxId ctx
("POST", "v2/proxy/transactions")
(Headers [ ("Content-Type", "application/octet-stream") ])
submitBabbagePayload'
verify submittedBabbageTxExternal
[ expectResponseCode HTTP.status500
]

-- using external submit users cannot push txs to the node constructed in past eras
submittedMaryTxExternal <- request @ApiTxId ctx
("POST", "v2/proxy/transactions")
(Headers [ ("Content-Type", "application/octet-stream") ])
submitMaryPayload'
verify submittedMaryTxExternal
[ expectResponseCode HTTP.status403
]
let errInfo = UnsupportedEra (ApiErrorUnsupportedEra
{ unsupportedEra = ApiMary
, supportedEras = fromList [ApiBabbage,ApiConway]
})
decodeErrorInfo submittedMaryTxExternal `shouldBe` errInfo

it "TRANS_NEW_JOIN_01a - Can join stakepool, rejoin another and quit" $ \ctx -> runResourceT $ do
let initialAmt = 10 * minUTxOValue (_mainEra ctx)
src <- fixtureWalletWith @n ctx [initialAmt]
Expand Down

0 comments on commit 67d134f

Please sign in to comment.