Skip to content

Commit e3a3d5e

Browse files
committed
add second integration test
1 parent c8e89ed commit e3a3d5e

File tree

1 file changed

+66
-1
lines changed
  • lib/byron/test/integration/Test/Integration/Byron/Scenario/API

1 file changed

+66
-1
lines changed

lib/byron/test/integration/Test/Integration/Byron/Scenario/API/Transactions.hs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import Numeric.Natural
5151
( Natural )
5252
import Test.Hspec
5353
( SpecWith, describe, it, shouldBe )
54+
import Test.Integration.Faucet
55+
( nextWallet )
5456
import Test.Integration.Framework.DSL
5557
( Context
5658
, Headers (..)
@@ -157,6 +159,7 @@ spec = do
157159

158160
describe "BYRON_RESTORATION" $ do
159161
scenario_RESTORE_01 @n fixtureRandomWallet
162+
scenario_RESTORE_02 @n fixtureRandomWallet (fixtureRandomWalletAddrs @n)
160163

161164
--
162165
-- Scenarios
@@ -526,7 +529,69 @@ scenario_RESTORE_01 fixtureSource = it title $ \ctx -> do
526529
(`shouldBe` Quantity (faucetAmt + amnt))
527530
]
528531
where
529-
title = "BYRON_RESTORE_01 - one recipient"
532+
title = "BYRON_RESTORE_01 - can restore recipient wallet from xprv"
533+
534+
scenario_RESTORE_02
535+
:: forall (n :: NetworkDiscriminant) t.
536+
( DecodeAddress n
537+
, EncodeAddress n
538+
)
539+
=> (Context t -> IO ApiByronWallet)
540+
-> (Context t -> IO (ApiByronWallet, [Address]))
541+
-> SpecWith (Context t)
542+
scenario_RESTORE_02 fixtureSource fixtureTarget = it title $ \ctx -> do
543+
-- SETUP
544+
let amnt = 100_000 :: Natural
545+
mnemonics <- mnemonicToText <$> nextWallet @"random" (_faucet ctx)
546+
let (Right seed) = fromMnemonic @'[12] mnemonics
547+
let rootXPrv = T.decodeUtf8 $ hex $ getKey $
548+
generateKeyFromSeed seed
549+
(Passphrase $ BA.convert $ T.encodeUtf8 fixturePassphrase)
550+
wSrc <- emptyByronWalletFromXPrvWith ctx "random"
551+
("Byron Wallet Restored", rootXPrv, fixturePassphraseEncrypted)
552+
553+
(wDest, payment) <- do
554+
(wDest, addrs) <- fixtureTarget ctx
555+
pure (wDest, mkPayment @n (head addrs) amnt)
556+
557+
-- ACTION
558+
r <- postByronTransaction @n ctx wSrc [payment] fixturePassphrase
559+
560+
-- ASSERTIONS
561+
let (feeMin, feeMax) = ctx ^. #_feeEstimator $ PaymentDescription
562+
{ nInputs = 1
563+
, nOutputs = 1
564+
, nChanges = 1
565+
}
566+
verify r
567+
[ expectResponseCode HTTP.status202
568+
, expectField #amount $ between
569+
( Quantity (feeMin + amnt)
570+
, Quantity (feeMax + amnt)
571+
)
572+
, expectField #direction (`shouldBe` ApiT Outgoing)
573+
, expectField #status (`shouldBe` ApiT Pending)
574+
]
575+
576+
eventually "source balance decreases" $ do
577+
rSrc <- request @ApiByronWallet ctx
578+
(Link.getWallet @'Byron wSrc) Default Empty
579+
verify rSrc
580+
[ expectField (#balance . #available) $ between
581+
( Quantity (faucetAmt - amnt - feeMax)
582+
, Quantity (faucetAmt - amnt - feeMin)
583+
)
584+
]
585+
586+
eventually "destination balance increases" $ do
587+
rDest <- request @ApiByronWallet ctx
588+
(Link.getWallet @'Byron wDest) Default Empty
589+
verify rDest
590+
[ expectField (#balance . #available)
591+
(`shouldBe` Quantity (faucetAmt + amnt))
592+
]
593+
where
594+
title = "BYRON_RESTORE_02 - can send tx from restored wallet from xprv"
530595

531596
--
532597
-- More Elaborated Fixtures

0 commit comments

Comments
 (0)