Skip to content

Commit

Permalink
Merge pull request #3257 from input-output-hk/jonathanknowles/ADP-1596/…
Browse files Browse the repository at this point in the history
…simple-metadata

Fixes for ADP-1596
  • Loading branch information
paolino committed May 6, 2022
1 parent 2eb1d58 commit c9e4807
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 158 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,3 @@ lib/shelley/test/data/balanceTx/**/actual
### Docs build
/_build/
.vscode/settings.json



24 changes: 12 additions & 12 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ import Cardano.Wallet.Api.Types
, WalletPutPassphraseData (..)
, fmtAllowedWords
)
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataWithSchema )
import Cardano.Wallet.Orphans
()
import Cardano.Wallet.Primitive.AddressDerivation
Expand Down Expand Up @@ -324,8 +326,6 @@ import UnliftIO.Exception
import qualified Cardano.BM.Configuration.Model as CM
import qualified Cardano.BM.Data.BackendKind as CM
import qualified Cardano.BM.Data.Observable as Obs
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataWithSchema )
import qualified Command.Key as Key
import qualified Command.RecoveryPhrase as RecoveryPhrase
import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -733,9 +733,9 @@ data TransactionFeatures = NoShelleyFeatures | ShelleyFeatures

-- | which json schema to use for output, True is simple
metadataSchemaOption :: Parser Bool
metadataSchemaOption = switch
metadataSchemaOption = switch
do long "simple-metadata"
<> help "output metadata json in no-schema encoding"
<> help "output metadata json in no-schema encoding"

-- | cardano-wallet transaction
cmdTransaction
Expand Down Expand Up @@ -869,8 +869,10 @@ cmdTransactionList mkTxClient =
<*> optional timeRangeStartOption
<*> optional timeRangeEndOption
<*> optional sortOrderOption
<*> metadataSchemaOption
exec (TransactionListArgs wPort wId mTimeRangeStart mTimeRangeEnd mOrder metadataSchema) =
<*> metadataSchemaOption
exec
(TransactionListArgs
wPort wId mTimeRangeStart mTimeRangeEnd mOrder metadataSchema) =
runClient wPort Aeson.encodePretty $ listTransactions
mkTxClient
(ApiT wId)
Expand Down Expand Up @@ -940,16 +942,14 @@ cmdTransactionGet mkClient =
cmd = fmap exec $ TransactionGetArgs
<$> portOption
<*> walletIdArgument
<*> transactionIdArgument
<*> metadataSchemaOption
<*> transactionIdArgument
<*> metadataSchemaOption
exec (TransactionGetArgs wPort wId txId metadataSchema ) = do
runClient wPort Aeson.encodePretty $ getTransaction mkClient
(ApiT wId)
metadataSchema
metadataSchema
(ApiTxId $ ApiT $ getTxId txId)



{-------------------------------------------------------------------------------
Commands - 'address'
-------------------------------------------------------------------------------}
Expand Down Expand Up @@ -1455,7 +1455,7 @@ metadataOption :: Parser (Maybe TxMetadataWithSchema)
metadataOption = option txMetadataReader $ mempty
<> long "metadata"
<> metavar "JSON"
<> value Nothing
<> value Nothing
<> help ("Application-specific transaction metadata as a JSON object. "
<> "The value must match the schema defined in the "
<> "cardano-wallet OpenAPI specification.")
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/test/data/Cardano/CLISpec/transaction get --help
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Usage: transaction get [--port INT] WALLET_ID TRANSACTION_ID
Usage: transaction get [--port INT] WALLET_ID TRANSACTION_ID
[--simple-metadata]
Get a transaction with specified id.

Expand Down
4 changes: 2 additions & 2 deletions lib/cli/test/data/Cardano/CLISpec/transaction list --help
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Usage: transaction list [--port INT] WALLET_ID [--start TIME]
[--end TIME] [--order ORDER]
Usage: transaction list [--port INT] WALLET_ID [--start TIME]
[--end TIME] [--order ORDER]
[--simple-metadata]
List the transactions associated with a wallet.

Expand Down
19 changes: 11 additions & 8 deletions lib/cli/test/unit/Cardano/CLISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import Cardano.Wallet.Api.Client
, transactionClient
, walletClient
)
import Cardano.Wallet.Api.Types.SchemaMetadata
( detailedMetadata, noSchemaMetadata )
import Cardano.Wallet.Primitive.Types
( PoolMetadataSource )
import Cardano.Wallet.Primitive.Types.Tx
Expand Down Expand Up @@ -98,8 +100,6 @@ import UnliftIO.MVar
import UnliftIO.Temporary
( withSystemTempDirectory )

import Cardano.Wallet.Api.Types.SchemaMetadata
( detailedMetadata, noSchemaMetadata )
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
Expand Down Expand Up @@ -255,7 +255,8 @@ spec = do
describe "Tx Metadata JSON option" $ do
let parse arg = execParserPure defaultPrefs
(info metadataOption mempty) ["--metadata", arg]
let md = detailedMetadata (TxMetadata (Map.singleton 42 (TxMetaText "hi")))
let md = detailedMetadata
(TxMetadata (Map.singleton 42 (TxMetaText "hi")))
let ok ex (Success res) = ex == res
ok _ _ = False
let err (Failure _) = True
Expand All @@ -271,8 +272,10 @@ spec = do
, ("null 3", "{ }", ok (Just (detailedMetadata mempty)))
]
describe "Tx No-Schema Metadata JSON option" $ do
let parse arg = execParserPure defaultPrefs (info metadataOption mempty) ["--metadata", arg]
let md = noSchemaMetadata (TxMetadata (Map.singleton 42 (TxMetaText "hi")))
let parse arg = execParserPure
defaultPrefs (info metadataOption mempty) ["--metadata", arg]
let md = noSchemaMetadata
(TxMetadata (Map.singleton 42 (TxMetaText "hi")))
let ok ex (Success res) = ex == res
ok _ _ = False
let err (Failure _) = True
Expand All @@ -285,10 +288,10 @@ spec = do
, ("invalid", "{ \"json\": true }", err)
, ("null 1", "{ \"0\": null }", err)
, ("null 2", "null", ok Nothing)
, ("null 3", "{ }", ok $ Just $ detailedMetadata mempty) -- this is the default parsing success
]
-- this is the default parsing success:
, ("null 3", "{ }", ok $ Just $ detailedMetadata mempty)


]

describe "Tx TTL option" $ do
let parse arg = execParserPure defaultPrefs
Expand Down
4 changes: 2 additions & 2 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,7 @@ postTransactionFeeViaCLI ctx args = cardanoWalletCLI $ join
listTransactionsViaCLI
:: forall r s m. (CmdResult r, HasType (Port "wallet") s, MonadIO m)
=> s
-> Bool
-> Bool
-> [String]
-> m r
listTransactionsViaCLI ctx metadataSchema args = cardanoWalletCLI $ join
Expand Down Expand Up @@ -2840,7 +2840,7 @@ getTransactionViaCLI
=> s
-> String
-> String
-> Bool
-> Bool
-> m r
getTransactionViaCLI ctx wid tid metadataSchema = cardanoWalletCLI $ join
[ ["transaction", "get"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import Data.Text
( Text )
import Data.Text.Class
( showT, toText )
import Data.Tuple.Extra
( both )
import Numeric.Natural
( Natural )
import Test.Hspec
Expand Down Expand Up @@ -154,8 +156,6 @@ import qualified Cardano.Wallet.Api.Link as Link
import qualified Data.ByteString as BS
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Tuple.Extra
( both )
import qualified Network.HTTP.Types.Status as HTTP

spec :: forall n.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import Cardano.Wallet.Api.Types
, insertedAt
, pendingSince
)
import Cardano.Wallet.Api.Types.SchemaMetadata
( detailedMetadata )
import Cardano.Wallet.Primitive.AddressDerivation
( PaymentAddress )
import Cardano.Wallet.Primitive.AddressDerivation.Icarus
Expand Down Expand Up @@ -179,7 +181,6 @@ import qualified Data.List.NonEmpty as NE
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Network.HTTP.Types.Status as HTTP
import Cardano.Wallet.Api.Types.SchemaMetadata (detailedMetadata)

data TestCase a = TestCase
{ query :: T.Text
Expand Down Expand Up @@ -958,7 +959,10 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
}
]

it "TRANSMETA_CREATE_02a - Transaction with invalid metadata" $ \ctx -> runResourceT $ do
it "TRANSMETA_CREATE_02a - \
\Transaction with invalid metadata" $
\ctx -> runResourceT $ do

(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let amt = minUTxOValue (_mainEra ctx) :: Natural

Expand All @@ -972,8 +976,11 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do

expectResponseCode HTTP.status400 r
expectErrorMessage errMsg400TxMetadataStringTooLong r

it "TRANSMETA_CREATE_02b - Transaction with invalid no-schema metadata" $ \ctx -> runResourceT $ do

it "TRANSMETA_CREATE_02b - \
\Transaction with invalid no-schema metadata" $
\ctx -> runResourceT $ do

(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
let amt = minUTxOValue (_mainEra ctx) :: Natural

Expand All @@ -989,7 +996,6 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
Default
payload


expectResponseCode HTTP.status400 r
expectErrorMessage errMsg400TxMetadataStringTooLong r

Expand All @@ -1013,7 +1019,10 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
expectResponseCode HTTP.status403 r
expectErrorMessage errMsg403TxTooBig r

it "TRANSMETA_ESTIMATE_01a - fee estimation includes metadata" $ \ctx -> runResourceT $ do
it "TRANSMETA_ESTIMATE_01a - \
\fee estimation includes metadata" $
\ctx -> runResourceT $ do

(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = minUTxOValue (_mainEra ctx) :: Natural

Expand Down Expand Up @@ -1041,7 +1050,10 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
, expectField (#estimatedMax . #getQuantity) (.< feeEstMax)
]

it "TRANSMETA_ESTIMATE_01b - fee estimation includes no-schema metadata" $ \ctx -> runResourceT $ do
it "TRANSMETA_ESTIMATE_01b - \
\fee estimation includes no-schema metadata" $
\ctx -> runResourceT $ do

(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = minUTxOValue (_mainEra ctx) :: Natural

Expand Down Expand Up @@ -1079,7 +1091,10 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
, expectField (#estimatedMax . #getQuantity) (.< feeEstMax)
]

it "TRANSMETA_ESTIMATE_02a - fee estimation with invalid metadata" $ \ctx -> runResourceT $ do
it "TRANSMETA_ESTIMATE_02a - \
\fee estimation with invalid metadata" $
\ctx -> runResourceT $ do

(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = minUTxOValue (_mainEra ctx) :: Natural

Expand All @@ -1093,8 +1108,11 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do

expectResponseCode HTTP.status400 r
expectErrorMessage errMsg400TxMetadataStringTooLong r

it "TRANSMETA_ESTIMATE_02b - fee estimation with invalid no-schema metadata" $ \ctx -> runResourceT $ do

it "TRANSMETA_ESTIMATE_02b - \
\fee estimation with invalid no-schema metadata" $
\ctx -> runResourceT $ do

(wa, wb) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx
let amt = minUTxOValue (_mainEra ctx) :: Natural

Expand Down Expand Up @@ -1685,7 +1703,8 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do

eventually "Transactions are available and in ledger" $ do
-- Verify Tx in source wallet is Outgoing and InLedger
let linkSrc = Link.getTransaction @'Shelley wSrc (ApiTxId txid) False
let linkSrc = Link.getTransaction @'Shelley
wSrc (ApiTxId txid) False
r1 <- request @(ApiTransaction n) ctx linkSrc Default Empty
verify r1
[ expectResponseCode HTTP.status200
Expand All @@ -1694,7 +1713,8 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
]

-- Verify Tx in destination wallet is Incoming and InLedger
let linkDest = Link.getTransaction @'Shelley wDest (ApiTxId txid) False
let linkDest = Link.getTransaction
@'Shelley wDest (ApiTxId txid) False
r2 <- request @(ApiTransaction n) ctx linkDest Default Empty
verify r2
[ expectResponseCode HTTP.status200
Expand Down Expand Up @@ -1727,7 +1747,8 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
]

let txid = Hash $ BS.pack $ replicate 32 1
let link = Link.getTransaction @'Shelley wSrc (ApiTxId $ ApiT txid) False
let link = Link.getTransaction @'Shelley
wSrc (ApiTxId $ ApiT txid) False
r <- request @(ApiTransaction n) ctx link Default Empty
expectResponseCode HTTP.status404 r
expectErrorMessage (errMsg404CannotFindTx $ toText txid) r
Expand Down Expand Up @@ -1908,7 +1929,7 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do

eventually "withdrawal transaction is listed on other" $ do
rTxOther <- request @(ApiTransaction n) ctx
(Link.getTransaction @'Shelley wOther tid False) Default payload
(Link.getTransaction @'Shelley wOther tid False) Default payload
verify rTxOther
[ expectResponseCode
HTTP.status200
Expand Down
Loading

0 comments on commit c9e4807

Please sign in to comment.