Skip to content

Commit

Permalink
- Add ByronWallets tests to Shelley integration suite. - Make `Todo c…
Browse files Browse the repository at this point in the history
…omment` which tests to enable when Byron addresses/transactions are supported on the cardano-node. - temporarily move BYRON_RESTORE special cases involving restoring 'funky' ledger and icarus wallets to Transactions so we can run ByronWallet tests on Shelley integration suite
  • Loading branch information
Piotr Stachyra committed Jun 12, 2020
1 parent 5e2f26c commit 5c25b01
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand All @@ -20,21 +21,27 @@ import Control.Monad
( forM_ )
import Data.Generics.Internal.VL.Lens
( (^.) )
import Data.Quantity
( Quantity (..) )
import Data.Text.Class
( fromText )
import Test.Hspec
( SpecWith, describe, it )
( SpecWith, describe, it, shouldBe )
import Test.Integration.Framework.DSL
( Context
, Headers (..)
, Payload (..)
, emptyIcarusWallet
, emptyRandomWallet
, expectErrorMessage
, expectField
, expectListSize
, expectResponseCode
, faucetAmt
, fixtureIcarusWallet
, fixturePassphrase
, fixtureRandomWallet
, json
, request
, toQueryString
, verify
Expand All @@ -58,6 +65,53 @@ spec :: forall n t.
( DecodeAddress n
) => SpecWith (Context t)
spec = do

it "BYRON_RESTORE_08 - Icarus wallet with high indexes" $ \ctx -> do
-- NOTE
-- Special Icarus mnemonic where address indexes are all after the index
-- 500. Because we don't have the whole history, restoring sequential
-- wallets like Icarus ones is tricky from just a snapshot and we need
-- to use arbitrarily big address pool gaps.
let mnemonics =
[ "erosion", "ahead", "vibrant", "air", "day"
, "timber", "thunder", "general", "dice", "into"
, "chest", "enrich", "social", "neck", "shine"
] :: [T.Text]
let payload = Json [json| {
"name": "High Index Wallet",
"mnemonic_sentence": #{mnemonics},
"passphrase": #{fixturePassphrase},
"style": "icarus"
} |]

r <- request @ApiByronWallet ctx (Link.postWallet @'Byron) Default payload
verify r
[ expectResponseCode @IO HTTP.status201
, expectField (#balance . #available) (`shouldBe` Quantity faucetAmt)
]

it "BYRON_RESTORE_09 - Ledger wallet" $ \ctx -> do
-- NOTE
-- Special legacy wallets where addresses have been generated from a
-- seed derived using the auxiliary method used by Ledger.
let mnemonics =
[ "vague" , "wrist" , "poet" , "crazy" , "danger" , "dinner"
, "grace" , "home" , "naive" , "unfold" , "april" , "exile"
, "relief" , "rifle" , "ranch" , "tone" , "betray" , "wrong"
] :: [T.Text]
let payload = Json [json| {
"name": "Ledger Wallet",
"mnemonic_sentence": #{mnemonics},
"passphrase": #{fixturePassphrase},
"style": "ledger"
} |]

r <- request @ApiByronWallet ctx (Link.postWallet @'Byron) Default payload
verify r
[ expectResponseCode @IO HTTP.status201
, expectField (#balance . #available) (`shouldBe` Quantity faucetAmt)
]

it "BYRON_TX_LIST_01 - 0 txs on empty Byron wallet"
$ \ctx -> forM_ [emptyRandomWallet, emptyIcarusWallet] $ \emptyByronWallet -> do
w <- emptyByronWallet ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import Test.Integration.Framework.DSL
, expectListSize
, expectResponseCode
, expectWalletUTxO
, faucetAmt
, fixturePassphrase
, fixturePassphraseEncrypted
, getFromResponse
Expand Down Expand Up @@ -319,52 +318,6 @@ spec = do
@ApiByronWallet ctx (Link.postWallet @'Byron) Default payload
verify r expectations

it "BYRON_RESTORE_08 - Icarus wallet with high indexes" $ \ctx -> do
-- NOTE
-- Special Icarus mnemonic where address indexes are all after the index
-- 500. Because we don't have the whole history, restoring sequential
-- wallets like Icarus ones is tricky from just a snapshot and we need
-- to use arbitrarily big address pool gaps.
let mnemonics =
[ "erosion", "ahead", "vibrant", "air", "day"
, "timber", "thunder", "general", "dice", "into"
, "chest", "enrich", "social", "neck", "shine"
] :: [Text]
let payload = Json [json| {
"name": "High Index Wallet",
"mnemonic_sentence": #{mnemonics},
"passphrase": #{fixturePassphrase},
"style": "icarus"
} |]

r <- request @ApiByronWallet ctx (Link.postWallet @'Byron) Default payload
verify r
[ expectResponseCode @IO HTTP.status201
, expectField (#balance . #available) (`shouldBe` Quantity faucetAmt)
]

it "BYRON_RESTORE_09 - Ledger wallet" $ \ctx -> do
-- NOTE
-- Special legacy wallets where addresses have been generated from a
-- seed derived using the auxiliary method used by Ledger.
let mnemonics =
[ "vague" , "wrist" , "poet" , "crazy" , "danger" , "dinner"
, "grace" , "home" , "naive" , "unfold" , "april" , "exile"
, "relief" , "rifle" , "ranch" , "tone" , "betray" , "wrong"
] :: [Text]
let payload = Json [json| {
"name": "Ledger Wallet",
"mnemonic_sentence": #{mnemonics},
"passphrase": #{fixturePassphrase},
"style": "ledger"
} |]

r <- request @ApiByronWallet ctx (Link.postWallet @'Byron) Default payload
verify r
[ expectResponseCode @IO HTTP.status201
, expectField (#balance . #available) (`shouldBe` Quantity faucetAmt)
]

it "BYRON_UPDATE_NAME_01 - Update names of wallets" $ \ctx ->
forM_ [ (emptyRandomWallet ctx, "Random Wallet")
, (emptyIcarusWallet ctx, "Icarus Wallet")
Expand Down
10 changes: 8 additions & 2 deletions lib/shelley/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ import qualified Cardano.Wallet.Api.Link as Link
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Test.Integration.Scenario.API.Byron.Migrations as ByronMigrations
-- TODO: enable when byron transactions/addresses supported in the cardano-node
-- import qualified Test.Integration.Scenario.API.Byron.Addresses as ByronAddresses
-- import qualified Test.Integration.Scenario.API.Byron.Migrations as ByronMigrations
-- import qualified Test.Integration.Byron.Scenario.API.Transactions as ByronTransactions
-- import qualified Test.Integration.Scenario.API.Byron.Transactions as ByronTransactionsCommon
-- import qualified Test.Integration.Scenario.API.Byron.HWWallets as ByronHWWallets
import qualified Test.Integration.Scenario.API.Byron.Wallets as ByronWallets
import qualified Test.Integration.Scenario.API.Network as Network
import qualified Test.Integration.Scenario.API.Shelley.Addresses as Addresses
import qualified Test.Integration.Scenario.API.Shelley.HWWallets as HWWallets
Expand Down Expand Up @@ -141,7 +147,7 @@ main = withUtf8Encoding $ withLogging Nothing Info $ \(_, tr) -> do
specWithServer tr $ do
describe "API Specifications" $ do
Addresses.spec @n
ByronMigrations.spec @n
ByronWallets.spec @n
Migrations.spec @n
Transactions.spec @n
Wallets.spec @n
Expand Down

0 comments on commit 5c25b01

Please sign in to comment.