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

simple metadata format in some transaction endpoints #3253

Merged
merged 30 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a63867a
add endpoints support for simple metadata
paolino May 6, 2022
3e64cc8
fix openapi definitions regarding metadata values
paolino May 6, 2022
3817fd0
fix TypesSpec to load the new simple-metadata schema
paolino May 6, 2022
4773231
replace golden test value for transaction cli help
paolino May 6, 2022
a3ef2cc
Merge pull request #3257 from input-output-hk/jonathanknowles/ADP-159…
paolino May 6, 2022
0a1e85f
rm BlockArguments use
paolino May 6, 2022
84857f9
Fix golden files
sevanspowell May 6, 2022
94fc3f7
remove Bool switch in transaction CLI to select metadata schema
paolino May 6, 2022
38681f1
Add a Shelley mnemonic
sevanspowell May 6, 2022
b11a636
Add more Shelly mnemonics as a buffer
sevanspowell May 6, 2022
dfc4ed4
Add documentation for no more wallets test error
sevanspowell May 6, 2022
d643736
Try adding even more seq test faucets
Anviking May 6, 2022
56ff1be
add swagger documentation for get and list transaction parameters
paolino May 6, 2022
9eedf60
Mark Plutus currency test pending due to flakiness
Anviking May 6, 2022
98c1a43
Use longer timouet in STAKE_POOLS_SMASH_01
Anviking May 6, 2022
638b853
refresh golden file ApiTransactionTestnet0.json
paolino May 6, 2022
f204601
Formatting fixes.
jonathanknowles May 9, 2022
420e01a
Tweak language in integration test comments.
jonathanknowles May 9, 2022
85a1b42
Use `TxMetadataSchema` type in `{getTransactions,listTransactions}`.
jonathanknowles May 9, 2022
7017ea5
Use `TxMetadataSchema` type in `Api.Link.listTransactions`.
jonathanknowles May 10, 2022
d5373b7
Remove metadata schema parameter from `Api.Link.getTransaction`.
jonathanknowles May 10, 2022
ec10f95
Use consistent parameter order in CLI and API for `getTransaction`.
jonathanknowles May 10, 2022
a48ea8a
Use `TxMetadataSchema` type in `Api.Client`.
jonathanknowles May 10, 2022
24bb60c
Use `TxMetadataSchema` type in `listTransactionsViaCLI`.
jonathanknowles May 10, 2022
b06e5da
Use `TxMetadataSchema` in `getTransactionViaCLI`.
jonathanknowles May 10, 2022
e4e724d
Add JSON roundtrip test for `TxMetadataWithSchema`.
jonathanknowles May 10, 2022
7a42cb2
Merge pull request #3270 from input-output-hk/jonathanknowles/ADP-159…
jonathanknowles May 10, 2022
00213c9
remove duplicate MetadataSchema datatype
paolino May 10, 2022
15a841e
Update lib/core-integration/src/Test/Integration/Scenario/CLI/Shelley…
paolino May 10, 2022
c1e8181
apply stylistic suggestions
paolino May 10, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ lib/shelley/test/data/balanceTx/**/actual

### Docs build
/_build/
.vscode/settings.json
20 changes: 20 additions & 0 deletions docs/contributing/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ The default log level for log files is Info.
Only Error level logs are shown on stdout during test execution. To
change this, set the `*_MIN_SEVERITY` variables shown above.

#### Common Failures and Resolution

##### No More Wallets

If your test fails with something like:

```
user error (No more faucet wallet available in MVar!)
```

Generate more wallet mnemonics and populate the appropriate list in `lib/core-integration/src/Test/Integration/Faucet.hs`.

Generate new mnemonics with:

```
nix build .#cardano-wallet
# Size may vary depending on which array you need to add to.
./result/bin/cardano-wallet recovery-phrase generate --size 15
```

## Mock servers

Use the `cardano-wallet:mock-token-metadata-server` executable as a
Expand Down
33 changes: 24 additions & 9 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ import Cardano.Wallet.Api.Types
, ApiPostRandomAddressData (..)
, ApiT (..)
, ApiTxId (ApiTxId)
, ApiTxMetadata (..)
, ApiWallet
, Base (Base16)
, ByronWalletPostData (..)
Expand All @@ -162,6 +161,8 @@ import Cardano.Wallet.Api.Types
, WalletPutPassphraseData (..)
, fmtAllowedWords
)
import Cardano.Wallet.Api.Types.SchemaMetadata
( TxMetadataSchema (..), TxMetadataWithSchema )
import Cardano.Wallet.Orphans
()
import Cardano.Wallet.Primitive.AddressDerivation
Expand Down Expand Up @@ -729,6 +730,12 @@ cmdWalletGetUtxoStatistics mkClient =
data TransactionFeatures = NoShelleyFeatures | ShelleyFeatures
deriving (Show, Eq)

-- | which json schema to use for output, True is simple
metadataSchemaOption :: Parser TxMetadataSchema
metadataSchemaOption = flag TxMetadataDetailedSchema TxMetadataNoSchema
$ long "simple-metadata"
<> help "output metadata json in no-schema encoding"

-- | cardano-wallet transaction
cmdTransaction
:: ToJSON wallet
Expand Down Expand Up @@ -760,7 +767,7 @@ data TransactionCreateArgs t = TransactionCreateArgs
{ _port :: Port "Wallet"
, _id :: WalletId
, _payments :: NonEmpty Text
, _metadata :: ApiTxMetadata
, _metadata :: Maybe TxMetadataWithSchema
, _timeToLive :: Maybe (Quantity "second" NominalDiffTime)
}

Expand All @@ -783,7 +790,7 @@ cmdTransactionCreate isShelley mkTxClient mkWalletClient =
<$> portOption
<*> walletIdArgument
<*> fmap NE.fromList (some paymentOption)
<*> whenShelley (ApiTxMetadata Nothing) metadataOption isShelley
<*> whenShelley Nothing metadataOption isShelley
<*> whenShelley Nothing timeToLiveOption isShelley
exec (TransactionCreateArgs wPort wId wAddressAmounts md ttl) = do
wPayments <- either (fail . getTextDecodingError) pure $
Expand Down Expand Up @@ -819,7 +826,7 @@ cmdTransactionFees isShelley mkTxClient mkWalletClient =
<$> portOption
<*> walletIdArgument
<*> fmap NE.fromList (some paymentOption)
<*> whenShelley (ApiTxMetadata Nothing) metadataOption isShelley
<*> whenShelley Nothing metadataOption isShelley
<*> whenShelley Nothing timeToLiveOption isShelley
exec (TransactionCreateArgs wPort wId wAddressAmounts md ttl) = do
wPayments <- either (fail . getTextDecodingError) pure $
Expand All @@ -845,6 +852,7 @@ data TransactionListArgs = TransactionListArgs
, _timeRangeStart :: Maybe Iso8601Time
, _timeRangeEnd :: Maybe Iso8601Time
, _sortOrder :: Maybe SortOrder
, _schema :: TxMetadataSchema
}

cmdTransactionList
Expand All @@ -860,13 +868,17 @@ cmdTransactionList mkTxClient =
<*> optional timeRangeStartOption
<*> optional timeRangeEndOption
<*> optional sortOrderOption
exec (TransactionListArgs wPort wId mTimeRangeStart mTimeRangeEnd mOrder) =
<*> metadataSchemaOption
exec
(TransactionListArgs
wPort wId mTimeRangeStart mTimeRangeEnd mOrder metadataSchema) =
runClient wPort Aeson.encodePretty $ listTransactions
mkTxClient
(ApiT wId)
mTimeRangeStart
mTimeRangeEnd
(ApiT <$> mOrder)
(metadataSchema == TxMetadataNoSchema)

-- | Arguments for 'transaction submit' command
data TransactionSubmitArgs = TransactionSubmitArgs
Expand Down Expand Up @@ -916,6 +928,7 @@ data TransactionGetArgs = TransactionGetArgs
{ _port :: Port "Wallet"
, _wid :: WalletId
, _txid :: TxId
, _schema :: TxMetadataSchema
}

cmdTransactionGet
Expand All @@ -929,10 +942,12 @@ cmdTransactionGet mkClient =
<$> portOption
<*> walletIdArgument
<*> transactionIdArgument
exec (TransactionGetArgs wPort wId txId) = do
<*> metadataSchemaOption
exec (TransactionGetArgs wPort wId txId metadataSchema ) = do
runClient wPort Aeson.encodePretty $ getTransaction mkClient
(ApiT wId)
(ApiTxId $ ApiT $ getTxId txId)
metadataSchema

{-------------------------------------------------------------------------------
Commands - 'address'
Expand Down Expand Up @@ -1435,16 +1450,16 @@ transactionSubmitPayloadArgument = argumentT $ mempty
-- | [--metadata=JSON]
--
-- Note: we decode the JSON just so that we can validate more client-side.
metadataOption :: Parser ApiTxMetadata
metadataOption :: Parser (Maybe TxMetadataWithSchema)
paolino marked this conversation as resolved.
Show resolved Hide resolved
metadataOption = option txMetadataReader $ mempty
<> long "metadata"
<> metavar "JSON"
<> value (ApiTxMetadata 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.")

txMetadataReader :: ReadM ApiTxMetadata
txMetadataReader :: ReadM (Maybe TxMetadataWithSchema)
txMetadataReader = eitherReader (Aeson.eitherDecode' . BL8.pack)

-- | [--ttl=DURATION]
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/test/data/Cardano/CLISpec/transaction get --help
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
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.

Available options:
-h,--help Show this help text
--port INT port used for serving the wallet API.
(default: 8090)
--simple-metadata output metadata json in no-schema
encoding
5 changes: 4 additions & 1 deletion lib/cli/test/data/Cardano/CLISpec/transaction list --help
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Usage: transaction list [--port INT] WALLET_ID [--start TIME]
[--end TIME] [--order ORDER]
[--end TIME] [--order ORDER]
[--simple-metadata]
List the transactions associated with a wallet.

Available options:
Expand All @@ -14,3 +15,5 @@ Available options:
2016-11-21T10:15:00Z).
--order ORDER specifies a sort order, either
'ascending' or 'descending'.
--simple-metadata output metadata json in no-schema
encoding
32 changes: 27 additions & 5 deletions lib/cli/test/unit/Cardano/CLISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import Cardano.Wallet.Api.Client
, transactionClient
, walletClient
)
import Cardano.Wallet.Api.Types
( ApiT (..), ApiTxMetadata (..) )
import Cardano.Wallet.Api.Types.SchemaMetadata
( detailedMetadata, noSchemaMetadata )
import Cardano.Wallet.Primitive.Types
( PoolMetadataSource )
import Cardano.Wallet.Primitive.Types.Tx
Expand Down Expand Up @@ -255,8 +255,9 @@ spec = do
describe "Tx Metadata JSON option" $ do
let parse arg = execParserPure defaultPrefs
(info metadataOption mempty) ["--metadata", arg]
let md = ApiT (TxMetadata (Map.singleton 42 (TxMetaText "hi")))
let ok ex (Success res) = ex == getApiTxMetadata res
let md = detailedMetadata
(TxMetadata (Map.singleton 42 (TxMetaText "hi")))
let ok ex (Success res) = ex == res
ok _ _ = False
let err (Failure _) = True
err _ = False
Expand All @@ -268,7 +269,28 @@ spec = do
, ("invalid", "{ \"json\": true }", err)
, ("null 1", "{ \"0\": null }", err)
, ("null 2", "null", ok Nothing)
, ("null 3", "{ }", ok (Just (ApiT mempty)))
, ("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 ok ex (Success res) = ex == res
ok _ _ = False
let err (Failure _) = True
err _ = False
mapM_
(\(desc, arg, tst) -> it desc (parse arg `shouldSatisfy` tst))
[ ("valid", "{ \"42\": \"hi\" }", ok $ Just md)
, ("malformed", "testing", err)
, ("malformed trailing", "{ \"0\": \"\" } arstneio", err)
, ("invalid", "{ \"json\": true }", err)
, ("null 1", "{ \"0\": null }", err)
, ("null 2", "null", ok Nothing)
-- this is the default parsing success:
, ("null 3", "{ }", ok $ Just $ detailedMetadata mempty)

]

describe "Tx TTL option" $ do
Expand Down
Loading