From 395666513f67dedd0bc99dd4ad0c0bbc20473f4a Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 18 Nov 2020 16:38:36 +0100 Subject: [PATCH] Integration test: Delegating addresses API roundtrip --- .../Scenario/API/Shelley/Addresses.hs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Addresses.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Addresses.hs index 726e80b7fb6..5f68efc34cf 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Addresses.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Addresses.hs @@ -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 @@ -62,6 +67,7 @@ import Test.Integration.Framework.DSL , listAddresses , minUTxOValue , request + , unsafeRequest , verify , walletId ) @@ -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 @@ -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