@@ -25,13 +25,18 @@ import Cardano.Wallet.Api.Types
2525 , WalletStyle (.. )
2626 )
2727import Cardano.Wallet.Primitive.AddressDerivation
28- ( NetworkDiscriminant (.. ), PaymentAddress (.. ) )
28+ ( FromMnemonic (.. )
29+ , NetworkDiscriminant (.. )
30+ , Passphrase (.. )
31+ , PaymentAddress (.. )
32+ , hex
33+ )
2934import Cardano.Wallet.Primitive.AddressDerivation.Byron
30- ( ByronKey )
35+ ( ByronKey ( .. ), generateKeyFromSeed )
3136import Cardano.Wallet.Primitive.AddressDerivation.Icarus
3237 ( IcarusKey )
3338import Cardano.Wallet.Primitive.Mnemonic
34- ( entropyToMnemonic , genEntropy )
39+ ( entropyToMnemonic , genEntropy , mnemonicToText )
3540import Cardano.Wallet.Primitive.Types
3641 ( Address , Direction (.. ), TxStatus (.. ) )
3742import Control.Monad
@@ -52,6 +57,7 @@ import Test.Integration.Framework.DSL
5257 , Payload (.. )
5358 , TxDescription (.. )
5459 , between
60+ , emptyByronWalletFromXPrvWith
5561 , emptyIcarusWallet
5662 , emptyRandomWallet
5763 , eventually
@@ -65,6 +71,7 @@ import Test.Integration.Framework.DSL
6571 , fixturePassphrase
6672 , fixtureRandomWallet
6773 , fixtureRandomWalletAddrs
74+ , fixtureRandomWalletMws
6875 , fixtureRandomWalletWith
6976 , icarusAddresses
7077 , json
@@ -86,6 +93,8 @@ import Test.Integration.Framework.TestData
8693
8794import qualified Cardano.Wallet.Api.Link as Link
8895import qualified Data.Aeson as Aeson
96+ import qualified Data.ByteArray as BA
97+ import qualified Data.Text.Encoding as T
8998import qualified Network.HTTP.Types.Status as HTTP
9099
91100spec
@@ -96,53 +105,57 @@ spec
96105 , DecodeAddress n
97106 )
98107 => SpecWith (Context t )
99- spec = describe " BYRON_TXS" $ do
100- -- Random → Random
101- scenario_TRANS_CREATE_01_02 @ n fixtureRandomWallet
102- [ fixtureRandomWalletAddrs @ n
103- ]
108+ spec = do
109+ describe " BYRON_TXS" $ do
110+ -- Random → Random
111+ scenario_TRANS_CREATE_01_02 @ n fixtureRandomWallet
112+ [ fixtureRandomWalletAddrs @ n
113+ ]
104114
105- -- Random → [Random, Icarus]
106- scenario_TRANS_CREATE_01_02 @ n fixtureRandomWallet
107- [ fixtureRandomWalletAddrs @ n
108- , fixtureIcarusWalletAddrs @ n
109- ]
115+ -- Random → [Random, Icarus]
116+ scenario_TRANS_CREATE_01_02 @ n fixtureRandomWallet
117+ [ fixtureRandomWalletAddrs @ n
118+ , fixtureIcarusWalletAddrs @ n
119+ ]
110120
111- -- Icarus → Icarus
112- scenario_TRANS_CREATE_01_02 @ n fixtureIcarusWallet
113- [ fixtureIcarusWalletAddrs @ n
114- ]
121+ -- Icarus → Icarus
122+ scenario_TRANS_CREATE_01_02 @ n fixtureIcarusWallet
123+ [ fixtureIcarusWalletAddrs @ n
124+ ]
115125
116- -- Icarus → [Icarus, Random]
117- scenario_TRANS_CREATE_01_02 @ n fixtureRandomWallet
118- [ fixtureIcarusWalletAddrs @ n
119- , fixtureRandomWalletAddrs @ n
120- ]
126+ -- Icarus → [Icarus, Random]
127+ scenario_TRANS_CREATE_01_02 @ n fixtureRandomWallet
128+ [ fixtureIcarusWalletAddrs @ n
129+ , fixtureRandomWalletAddrs @ n
130+ ]
121131
122- scenario_TRANS_CREATE_02x @ n
132+ scenario_TRANS_CREATE_02x @ n
123133
124- -- TRANS_CREATE_03 requires actually being able to compute exact fees, which
125- -- is not really possible w/ cardano-node. So, skipping.
134+ -- TRANS_CREATE_03 requires actually being able to compute exact fees, which
135+ -- is not really possible w/ cardano-node. So, skipping.
126136
127- scenario_TRANS_CREATE_04a @ n
128- scenario_TRANS_CREATE_04b @ n
129- scenario_TRANS_CREATE_04c @ n
130- scenario_TRANS_CREATE_04d @ n
137+ scenario_TRANS_CREATE_04a @ n
138+ scenario_TRANS_CREATE_04b @ n
139+ scenario_TRANS_CREATE_04c @ n
140+ scenario_TRANS_CREATE_04d @ n
131141
132- scenario_TRANS_CREATE_07 @ n
142+ scenario_TRANS_CREATE_07 @ n
133143
134- scenario_TRANS_ESTIMATE_01_02 @ n fixtureRandomWallet
135- [ randomAddresses @ n . entropyToMnemonic <$> genEntropy
136- ]
144+ scenario_TRANS_ESTIMATE_01_02 @ n fixtureRandomWallet
145+ [ randomAddresses @ n . entropyToMnemonic <$> genEntropy
146+ ]
137147
138- scenario_TRANS_ESTIMATE_01_02 @ n fixtureIcarusWallet
139- [ icarusAddresses @ n . entropyToMnemonic <$> genEntropy
140- , icarusAddresses @ n . entropyToMnemonic <$> genEntropy
141- ]
148+ scenario_TRANS_ESTIMATE_01_02 @ n fixtureIcarusWallet
149+ [ icarusAddresses @ n . entropyToMnemonic <$> genEntropy
150+ , icarusAddresses @ n . entropyToMnemonic <$> genEntropy
151+ ]
142152
143- scenario_TRANS_ESTIMATE_04a @ n
144- scenario_TRANS_ESTIMATE_04b @ n
145- scenario_TRANS_ESTIMATE_04c @ n
153+ scenario_TRANS_ESTIMATE_04a @ n
154+ scenario_TRANS_ESTIMATE_04b @ n
155+ scenario_TRANS_ESTIMATE_04c @ n
156+
157+ describe " BYRON_RESTORATION" $ do
158+ scenario_RESTORE_01 @ n fixtureRandomWallet
146159
147160--
148161-- Scenarios
@@ -440,6 +453,85 @@ scenario_TRANS_CREATE_07 = it title $ \ctx -> do
440453 where
441454 title = " TRANS_CREATE_07 - Deleted wallet"
442455
456+ scenario_RESTORE_01
457+ :: forall (n :: NetworkDiscriminant ) t .
458+ ( DecodeAddress n
459+ , EncodeAddress n
460+ , PaymentAddress n ByronKey
461+ )
462+ => (Context t -> IO ApiByronWallet )
463+ -> SpecWith (Context t )
464+ scenario_RESTORE_01 fixtureSource = it title $ \ ctx -> do
465+ -- SETUP
466+ let amnt = 100_000 :: Natural
467+ wSrc <- fixtureSource ctx
468+ (wDest, payment, mnemonics) <- do
469+ (wDest, mnemonics) <- fixtureRandomWalletMws ctx
470+ let addrs = randomAddresses @ n mnemonics
471+ pure (wDest, mkPayment @ n (head addrs) amnt, mnemonics)
472+
473+ -- ACTION
474+ r <- postByronTransaction @ n ctx wSrc [payment] fixturePassphrase
475+
476+ -- ASSERTIONS
477+ let (feeMin, feeMax) = ctx ^. # _feeEstimator $ PaymentDescription
478+ { nInputs = 1
479+ , nOutputs = 1
480+ , nChanges = 1
481+ }
482+ verify r
483+ [ expectResponseCode HTTP. status202
484+ , expectField # amount $ between
485+ ( Quantity (feeMin + amnt)
486+ , Quantity (feeMax + amnt)
487+ )
488+ , expectField # direction (`shouldBe` ApiT Outgoing )
489+ , expectField # status (`shouldBe` ApiT Pending )
490+ ]
491+
492+ eventually " source balance decreases" $ do
493+ rSrc <- request @ ApiByronWallet ctx
494+ (Link. getWallet @ 'Byron wSrc) Default Empty
495+ verify rSrc
496+ [ expectField (# balance . # available) $ between
497+ ( Quantity (faucetAmt - amnt - feeMax)
498+ , Quantity (faucetAmt - amnt - feeMin)
499+ )
500+ ]
501+
502+ eventually " destination balance increases" $ do
503+ rDest <- request @ ApiByronWallet ctx
504+ (Link. getWallet @ 'Byron wDest) Default Empty
505+ verify rDest
506+ [ expectField (# balance . # available)
507+ (`shouldBe` Quantity (faucetAmt + amnt))
508+ ]
509+
510+ rd1 <- request
511+ @ ApiByronWallet ctx (Link. deleteWallet @ 'Byron wDest) Default Empty
512+ expectResponseCode @ IO HTTP. status204 rd1
513+
514+ let (Right seed) = fromMnemonic @ '[12 ] (mnemonicToText mnemonics)
515+ let rootXPrv = T. decodeUtf8 $ hex $ getKey $
516+ generateKeyFromSeed seed
517+ (Passphrase $ BA. convert $ T. encodeUtf8 fixturePassphrase)
518+ let passwHash =
519+ " 31347c387c317c2b6a6f747446495a6a566d586f43374c6c54425a576c\
520+ \597a425834515177666475467578436b4d485569733d7c78324d646738\
521+ \49554a3232507235676531393575445a76583646552b7757395a6a6a2f\
522+ \51303054356c654751794279732f7662753367526d726c316c657a7150\
523+ \43676d364e6758476d4d2f4b6438343265304b4945773d3d"
524+ wDestRestored <- emptyByronWalletFromXPrvWith ctx " random"
525+ (" Byron Wallet Restored" , rootXPrv, passwHash)
526+ eventually " destination balance increases" $ do
527+ rDest <- request @ ApiByronWallet ctx
528+ (Link. getWallet @ 'Byron wDestRestored) Default Empty
529+ verify rDest
530+ [ expectField (# balance . # available)
531+ (`shouldBe` Quantity (faucetAmt + amnt))
532+ ]
533+ where
534+ title = " BYRON_RESTORE_01 - one recipient"
443535
444536--
445537-- More Elaborated Fixtures
0 commit comments