Skip to content

Commit affd2ed

Browse files
committed
Add integration tests for postRandomWalletFromXPrv
1 parent d2fa0c9 commit affd2ed

File tree

1 file changed

+98
-6
lines changed
  • lib/core-integration/src/Test/Integration/Scenario/API/Byron

1 file changed

+98
-6
lines changed

lib/core-integration/src/Test/Integration/Scenario/API/Byron/Transactions.hs

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module Test.Integration.Scenario.API.Byron.Transactions
1616
import Prelude
1717

1818
import Cardano.Wallet.Api.Types
19-
( ApiAsset (..)
19+
( ApiAddress
20+
, ApiAsset (..)
2021
, ApiByronWallet
2122
, ApiFee (..)
2223
, ApiT (..)
@@ -41,25 +42,27 @@ import Cardano.Wallet.Primitive.Types.TokenPolicy
4142
import Cardano.Wallet.Primitive.Types.Tx
4243
( Direction (..), TxStatus (..) )
4344
import Cardano.Wallet.Unsafe
44-
( unsafeFromText )
45+
( unsafeFromHex, unsafeFromText )
4546
import Control.Monad
46-
( forM_ )
47+
( forM_, void )
4748
import Control.Monad.IO.Class
4849
( liftIO )
4950
import Control.Monad.Trans.Resource
5051
( runResourceT )
5152
import Data.Bifunctor
5253
( bimap )
5354
import Data.Generics.Internal.VL.Lens
54-
( (^.) )
55+
( view, (^.) )
5556
import Data.Quantity
5657
( Quantity (..) )
58+
import Data.Text
59+
( Text )
5760
import Data.Text.Class
5861
( fromText )
5962
import Numeric.Natural
6063
( Natural )
6164
import Test.Hspec
62-
( SpecWith, describe )
65+
( ActionWith, SpecWith, describe, pendingWith )
6366
import Test.Hspec.Expectations.Lifted
6467
( shouldBe, shouldNotBe )
6568
import Test.Hspec.Extra
@@ -69,6 +72,8 @@ import Test.Integration.Framework.DSL
6972
, Headers (..)
7073
, Payload (..)
7174
, between
75+
, emptyByronWalletFromXPrvWith
76+
, emptyByronWalletWith
7277
, emptyIcarusWallet
7378
, emptyRandomWallet
7479
, emptyWallet
@@ -99,11 +104,12 @@ import Test.Integration.Framework.DSL
99104
, request
100105
, toQueryString
101106
, verify
107+
, waitForTxImmutability
102108
, walletId
103109
, (.>=)
104110
)
105111
import Test.Integration.Framework.Request
106-
( RequestException )
112+
( RequestException, unsafeRequest )
107113
import Test.Integration.Framework.TestData
108114
( errMsg400StartTimeLaterThanEndTime
109115
, errMsg404NoAsset
@@ -117,6 +123,7 @@ import qualified Cardano.Wallet.Primitive.Types.TokenPolicy as TokenPolicy
117123
import qualified Data.ByteString as BS
118124
import qualified Data.ByteString.Char8 as B8
119125
import qualified Data.Text as T
126+
import qualified Data.Text.Encoding as T
120127
import qualified Network.HTTP.Types.Status as HTTP
121128

122129
data TestCase a = TestCase
@@ -595,3 +602,88 @@ spec = describe "BYRON_TRANSACTIONS" $ do
595602
r <- request @([ApiTransaction n]) ctx link Default Empty
596603
expectResponseCode HTTP.status404 r
597604
expectErrorMessage (errMsg404NoWallet $ w ^. walletId) r
605+
606+
-- Golden from https://github.com/input-output-hk/cardano-sl/pull/4278#issuecomment-600553878
607+
it "BYRON_SCRYPT_TRANS_CREATE_01 - wallet with password" $ \ctx -> do
608+
flip runByronScryptGolden ctx $ ByronScryptGolden
609+
{ mnemonic = T.words
610+
"inhale arm pilot fitness ceiling october donate \
611+
\between language all limit taxi"
612+
, encryptedRootXPrv =
613+
"f6e79f49b8999a39d7e970e42d0a91224ecacefc3aa1edb342f34eb8bc6c2f\
614+
\c63e743b862b312a6f92ba0161d4d53c3ee5a2bd8085476d9575765c49dcee\
615+
\cbe54b34ec47daf9b7ebc6bdb706622616451c000e85ba81c7449ae436a8cb\
616+
\bf3aab98e5cc704977bd11bb0ba8d5b5571a705704cb9334d27a048532eab4\
617+
\9a698c2d"
618+
, passwordHash =
619+
"31347c387c317c5743413633702f6a487a5777575278756756344e31685479\
620+
\3470646c6d4f76665177653863775a575472784f79773d3d7c796341722f61\
621+
\326f4f777a736e4e746f4e655049416e4f6b7978426549494a6b59623039574\
622+
\b564a7159493d"
623+
, password = T.pack . B8.unpack $ unsafeFromHex
624+
"00000000000000000000000000000000000000\
625+
\50415441544520504154415445"
626+
}
627+
-- Golden from https://github.com/input-output-hk/cardano-sl/pull/4278#issuecomment-600553878
628+
it "BYRON_SCRYPT_TRANS_CREATE_02 - wallet without password" $
629+
runByronScryptGolden ByronScryptGolden
630+
{ mnemonic = T.words
631+
"marriage blouse orbit quarter treat series release sing lava \
632+
\spice surface rule"
633+
, encryptedRootXPrv =
634+
"38e8de9c583441213fe34eecc4e28265267466877ba4048e3ab1fa99563669\
635+
\47aefaf5ba9779db67eead7fc9cd1354b994a5d8d9cd40ab874bfeb1b33649\
636+
\280cd33651377731e0e59e0233425a55257782c5adaa768da0567f43c1c6c0\
637+
\c18766ed0a547bb34eb472c120b170a8640279832ddf18002887f03c15dea5\
638+
\9705422d"
639+
, passwordHash =
640+
"31347c387c317c574342652b796362417576356c2b4258676a344a314c6343\
641+
\675375414c2f5653393661364e576a2b7550766655513d3d7c6f7846366549\
642+
\39734151444e6f38395147747366324e653937426338372b484b6b41377567\
643+
\72752f5970673d"
644+
, password = ""
645+
}
646+
where
647+
runByronScryptGolden :: ByronScryptGolden -> ActionWith Context
648+
runByronScryptGolden golden ctx = runResourceT $ do
649+
wFaucet <- fixtureRandomWallet ctx
650+
651+
wMnemonic <- emptyByronWalletWith ctx "random"
652+
("Random Wallet", mnemonic golden, fixturePassphrase)
653+
654+
let pay amt pwd src dest = do
655+
addr <- view #id . snd
656+
<$> unsafeRequest @(ApiAddress n) ctx
657+
(Link.postRandomAddress dest)
658+
(Json [json| { "passphrase": #{fixturePassphrase} }|])
659+
660+
payload <- mkTxPayloadMA @n addr amt [] pwd
661+
rtx <- request @(ApiTransaction n) ctx
662+
(Link.createTransactionOld @'Byron src) Default payload
663+
expectResponseCode HTTP.status202 rtx
664+
665+
let ada = 1_000_000
666+
667+
pay (100 * ada) fixturePassphrase wFaucet wMnemonic
668+
669+
void $ request @() ctx
670+
(Link.deleteWallet @'Byron wMnemonic) Default Empty
671+
672+
wKey <- emptyByronWalletFromXPrvWith ctx "random"
673+
("Random Wallet", encryptedRootXPrv golden, passwordHash golden)
674+
675+
liftIO $ waitForTxImmutability ctx
676+
677+
pay (99 * ada) (password golden) wKey wFaucet
678+
679+
data ByronScryptGolden = ByronScryptGolden
680+
{ encryptedRootXPrv :: Text
681+
-- ^ Encrypted XPrv extracted from cardano-sl
682+
, passwordHash :: Text
683+
-- ^ Password hash extracted from cardano-sl
684+
, password :: Text
685+
-- ^ Password used when spending funds.
686+
, mnemonic :: [Text]
687+
-- ^ Corresponding mnemonic for reference
688+
}
689+

0 commit comments

Comments
 (0)