Skip to content

Commit

Permalink
Integration test: Delegating addresses API roundtrip
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Nov 18, 2020
1 parent a604358 commit 3956665
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ import Cardano.Wallet.Api.Types
( AnyAddress
, ApiAddress
, ApiTransaction
, ApiVerificationKey
, ApiWallet
, DecodeAddress
, DecodeStakeAddress
, EncodeAddress
, WalletStyle (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..), DerivationIndex (..) )
import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
( defaultAddressPoolGap, getAddressPoolGap )
import Cardano.Wallet.Primitive.Types
( AddressState (..) )
import Control.Monad
( forM_ )
( forM, forM_ )
import Control.Monad.IO.Class
( liftIO )
import Control.Monad.Trans.Resource
( runResourceT )
import Data.Aeson
Expand Down Expand Up @@ -62,6 +67,7 @@ import Test.Integration.Framework.DSL
, listAddresses
, minUTxOValue
, request
, unsafeRequest
, verify
, walletId
)
Expand All @@ -73,6 +79,7 @@ import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Lens as Aeson
import qualified Data.Text as T
import qualified Network.HTTP.Types.Status as HTTP
import qualified Test.Hspec.Expectations.Lifted as Expectations

spec :: forall n t.
( DecodeAddress n
Expand Down Expand Up @@ -519,6 +526,33 @@ spec = describe "SHELLEY_ADDRESSES" $ do
"addr1y9qthemrg5kczwfjjnahwt65elhrl95e9hcgufnajtp6wfffxzlhgvlzh\
\6drdsm04j43jk2wpsnqw7uketsgelghm3lsch4g8t" :: Text
validateAddr r goldenAddr

it "ANY_ADDRESS_POST_12 - Delegating addresses API roundtrip" $ \ctx -> runResourceT $ do
w <- emptyWallet ctx

-- Generate first 20 addresses using payment and stake keys derived from
-- wallet API
let indexes = [0..19]
generatedAddresses <- forM indexes $ \index -> do
let paymentPath = Link.getWalletKey w UtxoExternal (DerivationIndex index)
(_, paymentKey) <- unsafeRequest @ApiVerificationKey ctx paymentPath Empty

let stakePath = Link.getWalletKey w MutableAccount (DerivationIndex 0)
(_, stakeKey) <- unsafeRequest @ApiVerificationKey ctx stakePath Empty

let payload = Json [json|{
"payment": #{paymentKey},
"stake": #{stakeKey}
}|]
(_, addr) <- unsafeRequest @AnyAddress ctx Link.postAnyAddress payload
pure (addr ^. #payload)

-- Make sure the same addresses are already available in the wallet
addrs <- listAddresses @n ctx w
forM_ (zip (fmap fromIntegral indexes) generatedAddresses)
$ \(idx, genAddr) -> do
let walAddr = fst (addrs !! idx ^. #id) ^. (#getApiT . #unAddress)
walAddr `Expectations.shouldBe` genAddr
where
validateAddr resp expected = do
let addr = getFromResponse id resp
Expand Down

0 comments on commit 3956665

Please sign in to comment.