From ed611249dc8649e63d8fbd7becade288039b7d4c Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Mon, 26 Oct 2020 08:32:51 +0000 Subject: [PATCH 1/2] Remove redundant comment about empty transaction output lists. It's now been established that having an empty list of outputs is perfectly reasonable. An example of this is a transaction that includes just a delegation certificate. --- lib/core/src/Cardano/Wallet/Api/Types.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/Api/Types.hs b/lib/core/src/Cardano/Wallet/Api/Types.hs index 758c68a520c..3b30e73c402 100644 --- a/lib/core/src/Cardano/Wallet/Api/Types.hs +++ b/lib/core/src/Cardano/Wallet/Api/Types.hs @@ -649,9 +649,6 @@ data ApiTransaction (n :: NetworkDiscriminant) = ApiTransaction , depth :: !(Maybe (Quantity "block" Natural)) , direction :: !(ApiT Direction) , inputs :: ![ApiTxInput n] - -- TODO: Investigate whether the list of outputs should be non-empty, and - -- if so, whether the 'outputs' field can be encoded as a non-empty list. - -- See: https://jira.iohk.io/browse/ADP-400 , outputs :: ![AddressAmount (ApiT Address, Proxy n)] , withdrawals :: ![ApiWithdrawal n] , status :: !(ApiT TxStatus) From bb6c319b530df53dec46f580b9ebfb837ec7cf7a Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Mon, 26 Oct 2020 08:53:31 +0000 Subject: [PATCH 2/2] Generate possibly-empty lists of outputs in `Arbitrary ApiTransaction`. --- .../test/unit/Cardano/Wallet/Api/TypesSpec.hs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs b/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs index e1a0d46c785..23a2edeb7ec 100644 --- a/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs @@ -197,8 +197,6 @@ import Data.FileEmbed ( embedFile, makeRelativeToProject ) import Data.Function ( (&) ) -import Data.Generics.Internal.VL.Lens - ( view ) import Data.List ( foldl' ) import Data.List.NonEmpty @@ -1462,10 +1460,7 @@ instance Arbitrary ApiTxMetadata where shrink = genericShrink instance Arbitrary (ApiTransaction t) where - shrink = filter outputsNonEmpty . genericShrink - where - outputsNonEmpty :: ApiTransaction t -> Bool - outputsNonEmpty = (not . null) . view #outputs + shrink = genericShrink arbitrary = do txStatus <- arbitrary txInsertedAt <- case txStatus of @@ -1497,15 +1492,8 @@ instance Arbitrary (ApiTransaction t) where where genInputs = Test.QuickCheck.scale (`mod` 3) arbitrary - -- Note that the generated list of outputs must be non-empty in order - -- to be consistent with the specification. - -- - -- Ideally, we should encode this restriction in the type system. - -- - -- See https://jira.iohk.io/browse/ADP-400. - genOutputs = (:) - <$> arbitrary - <*> Test.QuickCheck.scale (`mod` 3) arbitrary + genOutputs = + Test.QuickCheck.scale (`mod` 3) arbitrary genWithdrawals = Test.QuickCheck.scale (`mod` 3) arbitrary