Skip to content

Commit 30ea64d

Browse files
committed
add second integration test
compilation correction
1 parent c8e89ed commit 30ea64d

File tree

1 file changed

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

1 file changed

+66
-2
lines changed

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

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ 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
55-
( Context
57+
( Context (..)
5658
, Headers (..)
5759
, Payload (..)
5860
, TxDescription (..)
@@ -157,6 +159,7 @@ spec = do
157159

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

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

531595
--
532596
-- More Elaborated Fixtures

0 commit comments

Comments
 (0)