Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 81e3b2d

Browse files
committed
[CDEC-403] Remove partial field accessors from InductiveValidationError
1 parent 55fe2a3 commit 81e3b2d

File tree

1 file changed

+62
-57
lines changed

1 file changed

+62
-57
lines changed

wallet-new/test/unit/Wallet/Inductive/Validation.hs

+62-57
Original file line numberDiff line numberDiff line change
@@ -45,55 +45,46 @@ data ValidatedInductive h a = ValidatedInductive {
4545

4646
data InductiveValidationError h a =
4747
-- | Bootstrap transaction is invalid
48-
InductiveInvalidBoot {
49-
-- | The bootstrap transaction
50-
inductiveInvalidBoot :: Transaction h a
51-
52-
-- | The error message
53-
, inductiveInvalidError :: Text
54-
}
48+
-- InductiveInvalidBoot
49+
-- inductiveInvalidBoot = The bootstrap transaction
50+
-- inductiveInvalidError = The error message
51+
InductiveInvalidBoot !(Transaction h a) !Text
5552

5653
-- | Invalid transaction in the given block
57-
| InductiveInvalidApplyBlock {
58-
-- | The events leading up to the error
59-
inductiveInvalidEvents :: OldestFirst [] (WalletEvent h a)
60-
61-
-- | The transactions in the block we successfully validated
62-
, inductiveInvalidBlockPrefix :: OldestFirst [] (Transaction h a)
63-
64-
-- | The transaction that was invalid
65-
, inductiveInvalidTransaction :: Transaction h a
66-
67-
-- | The error message
68-
, inductiveInvalidError :: Text
69-
}
54+
-- InductiveInvalidApplyBlock
55+
-- inductiveInvalidEvents = The events leading up to the error
56+
-- inductiveInvalidBlockPrefix = The transactions in the block we
57+
-- successfully validated
58+
-- inductiveInvalidTransaction = The transaction that was invalid
59+
-- inductiveInvalidError = The error message
60+
| InductiveInvalidApplyBlock
61+
!(OldestFirst [] (WalletEvent h a))
62+
!(OldestFirst [] (Transaction h a))
63+
!(Transaction h a)
64+
!Text
7065

7166
-- | A 'NewPending' call was invalid because the input was already spent
72-
| InductiveInvalidNewPendingAlreadySpent {
73-
-- | The events leading up to the error
74-
inductiveInvalidEvents :: OldestFirst [] (WalletEvent h a)
75-
76-
-- | The transaction that was invalid
77-
, inductiveInvalidTransaction :: Transaction h a
78-
79-
-- | The specific input that was not valid
80-
, inductiveInvalidInput :: Input h a
81-
}
67+
-- InductiveInvalidNewPendingAlreadySpent
68+
-- inductiveInvalidEvents = The events leading up to the error
69+
-- inductiveInvalidTransaction = The transaction that was invalid
70+
-- inductiveInvalidInput = The specific input that was not valid
71+
| InductiveInvalidNewPendingAlreadySpent
72+
!(OldestFirst [] (WalletEvent h a))
73+
!(Transaction h a)
74+
!(Input h a)
8275

8376
-- | A 'NewPending' call was invalid because the input was not @ours@
84-
| InductiveInvalidNewPendingNotOurs {
85-
-- | The events leading up to the error
86-
inductiveInvalidEvents :: OldestFirst [] (WalletEvent h a)
87-
88-
-- | The transaction that was invalid
89-
, inductiveInvalidTransaction :: Transaction h a
77+
-- InductiveInvalidNewPendingNotOurs
78+
-- inductiveInvalidEvents = The events leading up to the error
79+
-- inductiveInvalidTransaction = The transaction that was invalid
80+
-- inductiveInvalidInput = The specific input that was not valid
81+
-- inductiveInvalidAddress = The address this input belonged to
82+
| InductiveInvalidNewPendingNotOurs
83+
!(OldestFirst [] (WalletEvent h a))
84+
!(Transaction h a)
85+
!(Input h a)
86+
!a
9087

91-
-- | The specific input that was not valid
92-
, inductiveInvalidInput :: Input h a
93-
94-
-- | The address this input belonged to
95-
, inductiveInvalidAddress :: a
96-
}
9788

9889
{-------------------------------------------------------------------------------
9990
Validation proper
@@ -150,19 +141,20 @@ inductiveIsValid Inductive{..} = do
150141
forM_ (zip inputs resolved) $ \(input, mAddr) ->
151142
case mAddr of
152143
Nothing ->
153-
throwError InductiveInvalidNewPendingAlreadySpent {
154-
inductiveInvalidEvents = toOldestFirst viEvents
155-
, inductiveInvalidTransaction = t
156-
, inductiveInvalidInput = input
157-
}
144+
throwError
145+
$ InductiveInvalidNewPendingAlreadySpent
146+
(toOldestFirst viEvents)
147+
t
148+
input
158149
Just addr ->
159150
unless (addr `Set.member` inductiveOurs) $
160-
throwError InductiveInvalidNewPendingNotOurs {
161-
inductiveInvalidEvents = toOldestFirst viEvents
162-
, inductiveInvalidTransaction = t
163-
, inductiveInvalidInput = input
164-
, inductiveInvalidAddress = addr
165-
}
151+
throwError
152+
$ InductiveInvalidNewPendingNotOurs
153+
(toOldestFirst viEvents)
154+
t
155+
input
156+
addr
157+
166158
goEvents es vi
167159

168160
goBlock :: OldestFirst [] (WalletEvent h a) -- Events leading to this point (for err msgs)
@@ -201,15 +193,21 @@ inductiveIsValid Inductive{..} = do
201193
-------------------------------------------------------------------------------}
202194

203195
instance (Hash h a, Buildable a) => Buildable (InductiveValidationError h a) where
204-
build InductiveInvalidBoot{..} = bprint
196+
build (InductiveInvalidBoot
197+
inductiveInvalidBoot
198+
inductiveInvalidError) = bprint
205199
( "InductiveInvalidBoot"
206200
% "{ boot: " % build
207201
% ", error: " % build
208202
% "}"
209203
)
210204
inductiveInvalidBoot
211205
inductiveInvalidError
212-
build InductiveInvalidApplyBlock{..} = bprint
206+
build (InductiveInvalidApplyBlock
207+
inductiveInvalidEvents
208+
inductiveInvalidBlockPrefix
209+
inductiveInvalidTransaction
210+
inductiveInvalidError) = bprint
213211
( "InductiveInvalidApplyBlock"
214212
% "{ events: " % build
215213
% ", blockPrefix: " % build
@@ -220,7 +218,10 @@ instance (Hash h a, Buildable a) => Buildable (InductiveValidationError h a) whe
220218
inductiveInvalidBlockPrefix
221219
inductiveInvalidTransaction
222220
inductiveInvalidError
223-
build InductiveInvalidNewPendingAlreadySpent{..} = bprint
221+
build (InductiveInvalidNewPendingAlreadySpent
222+
inductiveInvalidEvents
223+
inductiveInvalidTransaction
224+
inductiveInvalidInput) = bprint
224225
( "InductiveInvalidNewPendingAlreadySpent"
225226
% "{ events: " % build
226227
% ", transaction: " % build
@@ -230,7 +231,11 @@ instance (Hash h a, Buildable a) => Buildable (InductiveValidationError h a) whe
230231
inductiveInvalidEvents
231232
inductiveInvalidTransaction
232233
inductiveInvalidInput
233-
build InductiveInvalidNewPendingNotOurs{..} = bprint
234+
build (InductiveInvalidNewPendingNotOurs
235+
inductiveInvalidEvents
236+
inductiveInvalidTransaction
237+
inductiveInvalidInput
238+
inductiveInvalidAddress) = bprint
234239
( "InductiveInvalidNewPendingNotOurs"
235240
% "{ events: " % build
236241
% ", transaction: " % build

0 commit comments

Comments
 (0)