@@ -14,7 +14,6 @@ import Prelude
1414
1515import Cardano.Wallet.Api.Types
1616 ( ApiT (.. )
17- , WalletPostData (.. )
1817 )
1918import Cardano.Wallet.Api.Types.BlockHeader
2019 ( ApiBlockHeader (.. )
@@ -28,6 +27,9 @@ import Cardano.Wallet.Primitive.Types.Hash
2827import Cardano.Wallet.Unsafe
2928 ( unsafeFromText
3029 )
30+ import Data.Generics.Product
31+ ( HasField
32+ )
3133import Data.Quantity
3234 ( Quantity (.. )
3335 )
@@ -58,11 +60,14 @@ import Test.Integration.Framework.DSL.Wallet
5860 , createARandomWallet
5961 , createARandomWalletWithMnemonics
6062 , createWalletFromMnemonics
63+ , createWalletFromXPub
6164 , deleteWallet
6265 , fundWallet
6366 , named
6467 , waitUntilStateIsReady
6568 , withApiWallet
69+ , withRestorationMode
70+ , xPubOfMnemonics
6671 )
6772
6873import qualified Cardano.Wallet.Api.Clients.Network as C
@@ -71,7 +76,8 @@ import qualified Cardano.Wallet.Read as Read
7176spec :: SpecWith Context
7277spec = describe " restoration of wallets" $ do
7378 itM " WALLET_RESTORE_0.1 create a wallet restoring from tip" $ do
74- Partial w <- createARandomWallet $ named " Wallet from tip" . restoringFromTip
79+ Partial w <-
80+ createARandomWallet $ named " Wallet from tip" . restoringFromTip
7581 over w $ do
7682 waitUntilStateIsReady
7783 withApiWallet $ balanceIs 0
@@ -182,7 +188,9 @@ spec = describe "restoration of wallets" $ do
182188 ApiBlockHeader
183189 { slotNo = Quantity 0
184190 , blockHeight = Quantity 0
185- , headerHash = unsafeFromText " 39d89a1e837e968ba35370be47cdfcbfd193cd992fdeed557b77c49b77ee59cf"
191+ , headerHash =
192+ unsafeFromText
193+ " 39d89a1e837e968ba35370be47cdfcbfd193cd992fdeed557b77c49b77ee59cf"
186194 }
187195 w <- createARandomWallet (restoringFromCheckpoint cp)
188196 clientError w $ do
@@ -193,21 +201,83 @@ spec = describe "restoration of wallets" $ do
193201 \The block at slot number 0 \
194202 \and hash 39d89a1e837e968ba35370be47cdfcbfd193cd992fdeed557b77c49b77ee59cf \
195203 \does not exist."
204+ itM
205+ " WALLET_RESTORE_0.9 create an account wallet from the tip \
206+ \ignores past transactions"
207+ $ do
208+ Partial (genesisClone, mnemonics) <-
209+ createARandomWalletWithMnemonics
210+ $ named " Account from genesis" . restoringFromTip
211+ let xpub = xPubOfMnemonics mnemonics
212+ over genesisClone $ do
213+ waitUntilStateIsReady
214+ fundWallet 42_000_000
215+ withApiWallet $ balanceIs 42_000_000
216+ deleteWallet
217+ Partial tipClone <-
218+ createWalletFromXPub xpub
219+ $ named " Account from tip" . restoringFromTip
220+ over tipClone $ do
221+ waitUntilStateIsReady
222+ withApiWallet $ balanceIs 0
223+ itM
224+ " WALLET_RESTORE_0.10 create an account wallet from the genesis \
225+ \capture the past transactions"
226+ $ do
227+ Partial (genesisClone, mnemonics) <-
228+ createARandomWalletWithMnemonics
229+ $ named " Account from genesis" . restoringFromTip
230+ let xpub = xPubOfMnemonics mnemonics
231+ over genesisClone $ do
232+ waitUntilStateIsReady
233+ fundWallet 42_000_000
234+ withApiWallet $ balanceIs 42_000_000
235+ deleteWallet
236+ Partial tipClone <-
237+ createWalletFromXPub xpub
238+ $ named " Account from genesis second take" . restoringFromGenesis
239+ over tipClone $ do
240+ waitUntilStateIsReady
241+ withApiWallet $ balanceIs 42_000_000
242+ itM
243+ " WALLET_RESTORE_0.11 create an account wallet from checkpoint \
244+ \capture the past transactions"
245+ $ do
246+ Partial (genesisClone, mnemonics) <-
247+ createARandomWalletWithMnemonics
248+ $ named " Account from genesis" . restoringFromTip
249+ let xpub = xPubOfMnemonics mnemonics
250+ over genesisClone $ do
251+ waitUntilStateIsReady
252+ Partial cp <- request C. blocksLatestHeader
253+ waitSomeEpochs 2
254+ over genesisClone $ do
255+ fundWallet 42_000_000
256+ withApiWallet $ balanceIs 42_000_000
257+ deleteWallet
258+ Partial tipClone <-
259+ createWalletFromXPub xpub
260+ $ named " Account from a block" . restoringFromCheckpoint cp
261+ over tipClone $ do
262+ waitUntilStateIsReady
263+ withApiWallet $ balanceIs 42_000_000
196264
197- setRestorationMode :: RestorationMode -> Patch WalletPostData
198- setRestorationMode rm wd = wd{restorationMode = Just $ ApiT rm}
199-
200- restoringFromTip :: Patch WalletPostData
201- restoringFromTip = setRestorationMode RestoreFromTip
265+ restoringFromTip
266+ :: HasField " restorationMode" a a b (Maybe (ApiT RestorationMode ))
267+ => Patch a
268+ restoringFromTip = withRestorationMode RestoreFromTip
202269
203- restoringFromGenesis :: Patch WalletPostData
204- restoringFromGenesis = setRestorationMode RestoreFromGenesis
270+ restoringFromGenesis
271+ :: HasField " restorationMode" a a b (Maybe (ApiT RestorationMode ))
272+ => Patch a
273+ restoringFromGenesis = withRestorationMode RestoreFromGenesis
205274
206275restoringFromCheckpoint
207- :: ApiBlockHeader
208- -> Patch WalletPostData
276+ :: HasField " restorationMode" a a b (Maybe (ApiT RestorationMode ))
277+ => ApiBlockHeader
278+ -> Patch a
209279restoringFromCheckpoint cp =
210- setRestorationMode
280+ withRestorationMode
211281 $ RestoreFromBlock
212282 (Read. SlotNo $ fromIntegral $ getQuantity $ slotNo cp)
213283 (toRawHeaderHash $ headerHash cp)
0 commit comments