Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tx metadata tests #2110

Merged
merged 4 commits into from
Sep 4, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ spec = do
(#balance . #available)
(`shouldBe` Quantity (faucetAmt - feeEstMax - amt)) ra2

it "TRANS_CREATE_10 - Transaction with metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
it "TRANSMETA_CREATE_01 - Transaction with metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = (1 :: Natural)

basePayload <- mkTxPayload ctx wb amt fixturePassphrase
Expand All @@ -574,19 +574,57 @@ spec = do
]

eventually "metadata is confirmed in transaction list" $ do
let link = Link.listTransactions @'Shelley wa
rb <- request @([ApiTransaction n]) ctx link Default Empty
verify rb
-- on src wallet
let linkSrcList = Link.listTransactions @'Shelley wa
rla <- request @([ApiTransaction n]) ctx linkSrcList Default Empty
verify rla
[ expectResponseCode HTTP.status200
, expectListField 0 (#status . #getApiT) (`shouldBe` InLedger)
, expectListField 0 (#direction . #getApiT) (`shouldBe` Outgoing)
, expectListField 0
(#metadata . #getApiTxMetadata)
(`shouldBe` Just (ApiT expected))
]
-- on dst wallet
let linkDstList = Link.listTransactions @'Shelley wb
rlb <- request @([ApiTransaction n]) ctx linkDstList Default Empty
verify rlb
[ expectResponseCode HTTP.status200
, expectListField 0 (#status . #getApiT) (`shouldBe` InLedger)
, expectListField 0 (#direction . #getApiT) (`shouldBe` Incoming)
, expectListField 0
(#metadata . #getApiTxMetadata)
(`shouldBe` Just (ApiT expected))
]

it "TRANS_CREATE_11 - Transaction with invalid metadata" $ \ctx -> do
let txid = getFromResponse #id ra
eventually "metadata is confirmed in transaction get" $ do
-- on src wallet
let linkSrc = Link.getTransaction @'Shelley wa (ApiTxId txid)
rg1 <- request @(ApiTransaction n) ctx linkSrc Default Empty
verify rg1
[ expectResponseCode HTTP.status200
, expectField (#direction . #getApiT) (`shouldBe` Outgoing)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField
(#metadata . #getApiTxMetadata)
(`shouldBe` Just (ApiT expected))
]
-- on dst wallet
let linkDst = Link.getTransaction @'Shelley wb (ApiTxId txid)
rg2 <- request @(ApiTransaction n) ctx linkDst Default Empty
verify rg2
[ expectResponseCode HTTP.status200
, expectField (#direction . #getApiT) (`shouldBe` Incoming)
, expectField (#status . #getApiT) (`shouldBe` InLedger)
, expectField
(#metadata . #getApiTxMetadata)
(`shouldBe` Just (ApiT expected))
]

it "TRANSMETA_CREATE_02 - Transaction with invalid metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let amt = (1 :: Natural)
let amt = (1_000_000 :: Natural)

basePayload <- mkTxPayload ctx wb amt fixturePassphrase

Expand All @@ -599,9 +637,9 @@ spec = do
expectResponseCode @IO HTTP.status400 r
expectErrorMessage errMsg400TxMetadataStringTooLong r

it "TRANS_CREATE_12 - Transaction with too much metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let amt = (1 :: Natural)
it "TRANSMETA_CREATE_03 - Transaction with too much metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = (1_000_000 :: Natural)

basePayload <- mkTxPayload ctx wb amt fixturePassphrase

Expand All @@ -618,9 +656,9 @@ spec = do
expectResponseCode @IO HTTP.status400 r
expectErrorMessage errMsg400TxTooLarge r

it "TRANS_ESTIMATE_xxx - fee estimation includes metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let amt = (1 :: Natural)
it "TRANSMETA_ESTIMATE_01 - fee estimation includes metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = (1_000_000 :: Natural)

payload <- mkTxPayload ctx wb amt fixturePassphrase

Expand All @@ -646,6 +684,40 @@ spec = do
, expectField (#estimatedMax . #getQuantity) (.< feeEstMax)
]

it "TRANSMETA_ESTIMATE_02 - fee estimation with invalid metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = (1_000_000 :: Natural)

basePayload <- mkTxPayload ctx wb amt fixturePassphrase

let txMeta = Aeson.object ["1" .= T.replicate 65 "a"]
let payload = addTxMetadata txMeta basePayload

r <- request @ApiFee ctx
(Link.getTransactionFee @'Shelley wa) Default payload

expectResponseCode @IO HTTP.status400 r
expectErrorMessage errMsg400TxMetadataStringTooLong r

it "TRANSMETA_ESTIMATE_03 - fee estimation with too much metadata" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = (1_000_000 :: Natural)

basePayload <- mkTxPayload ctx wb amt fixturePassphrase

-- This will encode to at least 8k of CBOR. The max tx size for the
-- integration tests cluster is 4k.
let txMeta = Aeson.object
[ (toText @Int i, Aeson.String (T.replicate 64 "a"))
| i <- [0..127] ]
let payload = addTxMetadata txMeta basePayload
print payload
r <- request @ApiFee ctx
(Link.getTransactionFee @'Shelley wa) Default payload

expectResponseCode @IO HTTP.status400 r
expectErrorMessage errMsg400TxTooLarge r

describe "TRANS_ESTIMATE_08 - Bad payload" $ do
let matrix =
[ ( "empty payload", NonJson "" )
Expand Down