From 6f36bbf1782fca9870385bb014d9122e7afda5c3 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Thu, 15 Sep 2022 12:11:47 +0200 Subject: [PATCH 1/6] remove byron tx integration test file --- .../Scenario/API/Byron/TransactionsNew.hs | 452 ------------------ 1 file changed, 452 deletions(-) delete mode 100644 lib/core-integration/src/Test/Integration/Scenario/API/Byron/TransactionsNew.hs diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/TransactionsNew.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/TransactionsNew.hs deleted file mode 100644 index 9b28afffea6..00000000000 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/TransactionsNew.hs +++ /dev/null @@ -1,452 +0,0 @@ -{-# LANGUAGE AllowAmbiguousTypes #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE NumericUnderscores #-} -{-# LANGUAGE OverloadedLabels #-} -{-# LANGUAGE QuasiQuotes #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeFamilies #-} - -module Test.Integration.Scenario.API.Byron.TransactionsNew - ( spec - ) where - -import Prelude - -import Cardano.Wallet.Api.Types - ( ApiByronWallet - , ApiConstructTransaction - , ApiT (..) - , ApiWallet - , DecodeAddress - , DecodeStakeAddress - , EncodeAddress (..) - , WalletStyle (..) - ) -import Cardano.Wallet.Primitive.AddressDerivation - ( Depth (..), PaymentAddress ) -import Cardano.Wallet.Primitive.AddressDerivation.Byron - ( ByronKey ) -import Cardano.Wallet.Primitive.AddressDerivation.Icarus - ( IcarusKey ) -import Cardano.Wallet.Primitive.Types.Address - ( Address (..) ) -import Control.Monad - ( forM_ ) -import Control.Monad.IO.Unlift - ( MonadUnliftIO (..), liftIO ) -import Control.Monad.Trans.Resource - ( runResourceT ) -import Data.Generics.Internal.VL.Lens - ( (^.) ) -import Data.Proxy - ( Proxy ) -import Data.Text - ( Text ) -import Numeric.Natural - ( Natural ) -import Test.Hspec - ( SpecWith, describe, pendingWith ) -import Test.Hspec.Expectations.Lifted - ( shouldNotBe, shouldSatisfy ) -import Test.Hspec.Extra - ( it ) -import Test.Integration.Framework.DSL - ( Context (..) - , Headers (..) - , Payload (..) - , emptyIcarusWallet - , emptyRandomWallet - , emptyWallet - , expectErrorMessage - , expectField - , expectResponseCode - , expectSuccess - , fixtureIcarusWallet - , fixtureIcarusWalletWith - , fixtureMultiAssetIcarusWallet - , fixtureMultiAssetRandomWallet - , fixtureRandomWallet - , fixtureRandomWalletWith - , json - , listAddresses - , minUTxOValue - , pickAnAsset - , request - , verify - ) -import Test.Integration.Framework.TestData - ( errMsg403Fee - , errMsg403InvalidConstructTx - , errMsg403MinUTxOValue - , errMsg403NotEnoughMoney - ) - -import qualified Cardano.Wallet.Api.Link as Link -import qualified Network.HTTP.Types.Status as HTTP - -spec :: forall n. - ( DecodeAddress n - , DecodeStakeAddress n - , EncodeAddress n - , PaymentAddress n ByronKey 'CredFromKeyK - , PaymentAddress n IcarusKey 'CredFromKeyK - ) => SpecWith Context -spec = describe "NEW_BYRON_TRANSACTIONS" $ do - - describe "BYRON_TRANS_NEW_CREATE_01a - Empty payload is not allowed" $ - forM_ [ (fixtureRandomWallet, "Byron fixture wallet") - , (fixtureIcarusWallet, "Icarus fixture wallet")] $ - \(srcFixture, name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron fixture wallet returns 500" - - wa <- srcFixture ctx - let emptyPayload = Json [json|{}|] - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) - Default emptyPayload - verify rTx - [ expectResponseCode HTTP.status403 - , expectErrorMessage errMsg403InvalidConstructTx - ] - - describe "BYRON_TRANS_NEW_CREATE_01c - No payload is bad request" $ - forM_ [ (fixtureRandomWallet, "Byron fixture wallet") - , (fixtureIcarusWallet, "Icarus fixture wallet")] $ - \(srcFixture, name) -> it name $ \ctx -> runResourceT $ do - - wa <- srcFixture ctx - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default Empty - verify rTx - [ expectResponseCode HTTP.status400 - ] - - describe "BYRON_TRANS_NEW_CREATE_04 - Single Output Transaction" $ - forM_ [(fixtureRandomWallet, "Byron wallet"), - (fixtureIcarusWallet, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet returns 403 (invalid_wallet_type)" - - - (wByron, wShelley) <- (,) <$> srcFixture ctx <*> emptyWallet ctx - addrs <- listAddresses @n ctx wShelley - - let amt = minUTxOValue (_mainEra ctx) :: Natural - let destination = (addrs !! 1) ^. #id - let payload = Json [json|{ - "payments": [{ - "address": #{destination}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }] - }|] - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wByron) Default payload - verify rTx - [ expectSuccess - , expectResponseCode HTTP.status202 - , expectField (#coinSelection . #inputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #outputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #change) (`shouldSatisfy` (not . null)) - ] - - describe "BYRON_TRANS_NEW_CREATE_04c - Can't cover fee" $ - forM_ [(fixtureRandomWalletWith @n, "Byron wallet"), - (fixtureIcarusWalletWith @n, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet as expected" - - wa <- srcFixture ctx [minUTxOValue (_mainEra ctx) + 1] - wb <- emptyWallet ctx - - payload <- liftIO $ mkTxPayload ctx wb (minUTxOValue (_mainEra ctx)) - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectResponseCode HTTP.status403 - , expectErrorMessage errMsg403Fee - ] - - describe "BYRON_TRANS_NEW_CREATE_04d - Not enough money" $ - forM_ [(fixtureRandomWalletWith @n, "Byron wallet"), - (fixtureIcarusWalletWith @n, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet as expected" - - let minUTxOValue' = minUTxOValue (_mainEra ctx) - let (srcAmt, reqAmt) = (minUTxOValue', 2 * minUTxOValue') - wa <- srcFixture ctx [srcAmt] - wb <- emptyWallet ctx - - payload <- liftIO $ mkTxPayload ctx wb reqAmt - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectResponseCode HTTP.status403 - , expectErrorMessage errMsg403NotEnoughMoney - ] - - describe "BYRON_TRANS_NEW_CREATE_04d - Not enough money emptyWallet" $ - forM_ [(emptyRandomWallet, "Empty Byron wallet"), - (emptyIcarusWallet, "Empty Icarus wallet")] $ - \(emptySrcWallet,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet as expected" - - wa <- emptySrcWallet ctx - wb <- emptyWallet ctx - - payload <- liftIO $ mkTxPayload ctx wb (minUTxOValue (_mainEra ctx)) - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectResponseCode HTTP.status403 - , expectErrorMessage errMsg403NotEnoughMoney - ] - - describe "BYRON_TRANS_NEW_CREATE_04e - Multiple Output Tx to single wallet" $ - forM_ [(fixtureRandomWallet, "Byron wallet"), - (fixtureIcarusWallet, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet returns 403 (invalid_wallet_type)" - - wa <- srcFixture ctx - wb <- emptyWallet ctx - addrs <- listAddresses @n ctx wb - - let amt = minUTxOValue (_mainEra ctx) :: Natural - let destination1 = (addrs !! 1) ^. #id - let destination2 = (addrs !! 2) ^. #id - let payload = Json [json|{ - "payments": [{ - "address": #{destination1}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }, - { - "address": #{destination2}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }] - }|] - - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectSuccess - , expectResponseCode HTTP.status202 - , expectField (#coinSelection . #inputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #outputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #change) (`shouldSatisfy` (not . null)) - ] - -- TODO: now we should sign it and send it in two steps, - -- make sure it is delivered - -- make sure balance is updated accordingly on src and dst wallets - - describe "BYRON_TRANS_NEW_ASSETS_CREATE_01a - Multi-asset tx with Ada" $ - forM_ [(fixtureMultiAssetRandomWallet @n, "Byron wallet"), - (fixtureMultiAssetIcarusWallet @n, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet returns 403 (invalid_wallet_type)" - - wa <- srcFixture ctx - wb <- emptyWallet ctx - ra <- request @ApiByronWallet ctx (Link.getWallet @'Byron wa) Default Empty - let (_, Right wal) = ra - - -- pick out an asset to send - let assetsSrc = wal ^. #assets . #total . #getApiT - assetsSrc `shouldNotBe` mempty - let val = minUTxOValue (_mainEra ctx) <$ pickAnAsset assetsSrc - - -- create payload - addrs <- listAddresses @n ctx wb - let destination = (addrs !! 1) ^. #id - let amt = 2 * minUTxOValue (_mainEra ctx) - payload <- mkTxPayloadMA @n destination amt [val] - - --construct transaction - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectSuccess - , expectResponseCode HTTP.status202 - , expectField (#coinSelection . #inputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #outputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #change) (`shouldSatisfy` (not . null)) - ] - -- TODO: now we should sign it and send it in two steps - -- make sure it is delivered - -- make sure balance is updated accordingly on src and dst wallets - - describe "BYRON_TRANS_NEW_ASSETS_CREATE_01b - Multi-asset tx with not enough Ada" $ - forM_ [(fixtureMultiAssetRandomWallet @n, "Byron wallet"), - (fixtureMultiAssetIcarusWallet @n, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet as expected" - - wa <- srcFixture ctx - wb <- emptyWallet ctx - ra <- request @ApiByronWallet ctx (Link.getWallet @'Byron wa) Default Empty - let (_, Right wal) = ra - - -- pick out an asset to send - let assetsSrc = wal ^. #assets . #total . #getApiT - assetsSrc `shouldNotBe` mempty - let val = minUTxOValue (_mainEra ctx) <$ pickAnAsset assetsSrc - - -- create payload - addrs <- listAddresses @n ctx wb - let destination = (addrs !! 1) ^. #id - let amt = minUTxOValue (_mainEra ctx) - payload <- mkTxPayloadMA @n destination amt [val] - - --construct transaction - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectResponseCode HTTP.status403 - , expectErrorMessage errMsg403MinUTxOValue - ] - - describe "BYRON_TRANS_NEW_ASSETS_CREATE_01c - Multi-asset tx without Ada" $ - forM_ [(fixtureMultiAssetRandomWallet @n, "Byron wallet"), - (fixtureMultiAssetIcarusWallet @n, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet returns 403 (invalid_wallet_type)" - - wa <- srcFixture ctx - wb <- emptyWallet ctx - ra <- request @ApiByronWallet ctx (Link.getWallet @'Byron wa) Default Empty - let (_, Right wal) = ra - - -- pick out an asset to send - let assetsSrc = wal ^. #assets . #total . #getApiT - assetsSrc `shouldNotBe` mempty - let val = minUTxOValue (_mainEra ctx) <$ pickAnAsset assetsSrc - - -- create payload - addrs <- listAddresses @n ctx wb - let destination = (addrs !! 1) ^. #id - let amt = 0 - payload <- mkTxPayloadMA @n destination amt [val] - - --construct transaction - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectSuccess - , expectResponseCode HTTP.status202 - , expectField (#coinSelection . #inputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #outputs) (`shouldSatisfy` (not . null)) - , expectField (#coinSelection . #change) (`shouldSatisfy` (not . null)) - ] - -- TODO: now we should sign it and send it in two steps - -- make sure it is delivered - -- make sure balance is updated accordingly on src and dst wallets - - describe "BYRON_TRANS_NEW_ASSETS_CREATE_01d - Multi-asset tx with not enough assets" $ - forM_ [(fixtureMultiAssetRandomWallet @n, "Byron wallet"), - (fixtureMultiAssetIcarusWallet @n, "Icarus wallet")] $ - \(srcFixture,name) -> it name $ \ctx -> runResourceT $ do - - liftIO $ pendingWith "Byron wallet returns 500, Icarus wallet as expected" - - wa <- srcFixture ctx - wb <- emptyWallet ctx - ra <- request @ApiByronWallet ctx (Link.getWallet @'Byron wa) Default Empty - let (_, Right wal) = ra - - -- pick out an asset to send - let assetsSrc = wal ^. #assets . #total . #getApiT - assetsSrc `shouldNotBe` mempty - let minUTxOValue' = minUTxOValue (_mainEra ctx) - let val = (minUTxOValue' * minUTxOValue') <$ pickAnAsset assetsSrc - - -- create payload - addrs <- listAddresses @n ctx wb - let destination = (addrs !! 1) ^. #id - let amt = 0 - payload <- mkTxPayloadMA @n destination amt [val] - - --construct transaction - rTx <- request @(ApiConstructTransaction n) ctx - (Link.createUnsignedTransaction @'Byron wa) Default payload - verify rTx - [ expectResponseCode HTTP.status403 - , expectErrorMessage errMsg403NotEnoughMoney - ] - - where - -- Construct a JSON payment request for the given quantity of lovelace. - mkTxPayload - :: MonadUnliftIO m - => Context - -> ApiWallet - -> Natural - -> m Payload - mkTxPayload ctx wDest amt = do - addrs <- listAddresses @n ctx wDest - let destination = (addrs !! 1) ^. #id - return $ Json [json|{ - "payments": [{ - "address": #{destination}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }] - }|] - - -- Like mkTxPayload, except that assets are included in the payment. - -- Asset amounts are specified by ((PolicyId Hex, AssetName Hex), amount). - mkTxPayloadMA - :: forall l m. - ( DecodeAddress l - , DecodeStakeAddress l - , EncodeAddress l - , MonadUnliftIO m - ) - => (ApiT Address, Proxy l) - -> Natural - -> [((Text, Text), Natural)] - -> m Payload - mkTxPayloadMA destination coin val = do - let assetJson ((pid, name), q) = [json|{ - "policy_id": #{pid}, - "asset_name": #{name}, - "quantity": #{q} - }|] - return $ Json [json|{ - "payments": [{ - "address": #{destination}, - "amount": { - "quantity": #{coin}, - "unit": "lovelace" - }, - "assets": #{map assetJson val} - }] - }|] From 005edfd3ded5dc8621451a9256f796bd8bbaa085 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Thu, 15 Sep 2022 12:47:44 +0200 Subject: [PATCH 2/6] add integration test showing the failure case --- .../Scenario/API/Shared/Wallets.hs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs index b77de8e38a2..9063721d25d 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs @@ -27,6 +27,7 @@ import Cardano.Wallet.Api.Types ( ApiAccountKeyShared (..) , ApiActiveSharedWallet , ApiAddress + , ApiAddress , ApiFee (..) , ApiSharedWallet (..) , ApiT (..) @@ -42,14 +43,18 @@ import Cardano.Wallet.Compat ( (^?) ) import Cardano.Wallet.Primitive.AddressDerivation ( DerivationIndex (..), Role (..) ) +import Cardano.Wallet.Primitive.AddressDiscovery.Sequential + ( defaultAddressPoolGap, getAddressPoolGap ) import Cardano.Wallet.Primitive.AddressDiscovery.Shared ( CredentialType (..) ) import Cardano.Wallet.Primitive.Passphrase ( Passphrase (..) ) import Cardano.Wallet.Primitive.SyncProgress ( SyncProgress (..) ) +import Cardano.Wallet.Primitive.Types.Address + ( AddressState (..) ) import Control.Monad - ( forM ) + ( forM, forM_ ) import Control.Monad.IO.Class ( liftIO ) import Control.Monad.Trans.Resource @@ -818,6 +823,11 @@ spec = describe "SHARED_WALLETS" $ do let cosignerKeysPost = pendingWal ^. #paymentScriptTemplate liftIO $ cosigners cosignerKeysPost `shouldBe` Map.fromList [(Cosigner 0,accXPub0)] + rAddrsPending <- request @[ApiAddress n] ctx + (Link.listAddresses @'Shared pendingWal) Default Empty + expectResponseCode HTTP.status200 rAddrsPending + expectListSize 0 rAddrsPending + let payloadPatch = Json [json| { "cosigner#1": #{accXPubTxt1} } |] @@ -828,6 +838,14 @@ spec = describe "SHARED_WALLETS" $ do let cosignerKeysPatch = activeWal ^. #paymentScriptTemplate liftIO $ cosigners cosignerKeysPatch `shouldBe` Map.fromList [(Cosigner 0,accXPub0), (Cosigner 1,accXPub1)] + rAddrsActive <- request @[ApiAddress n] ctx + (Link.listAddresses @'Shared activeWal) Default Empty + expectResponseCode HTTP.status200 rAddrsActive + let g = fromIntegral $ getAddressPoolGap defaultAddressPoolGap + expectListSize g rAddrsActive + forM_ [0..(g-1)] $ \addrNum -> do + expectListField addrNum (#state . #getApiT) (`shouldBe` Unused) rAddrsActive + it "SHARED_WALLETS_PATCH_02 - Add cosigner for delegation script template" $ \ctx -> runResourceT $ do [(accXPub0, accXPubTxt0),(accXPub1,accXPubTxt1)] <- liftIO $ genXPubs 2 let payloadCreate = Json [json| { From 89855dd1670c03f0278859efd127fb7676fc3b93 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Fri, 16 Sep 2022 12:48:06 +0200 Subject: [PATCH 3/6] updateCosigners behaving properly when active transition --- lib/core/src/Cardano/Wallet.hs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/core/src/Cardano/Wallet.hs b/lib/core/src/Cardano/Wallet.hs index d5c6d7df388..07fa03769a0 100644 --- a/lib/core/src/Cardano/Wallet.hs +++ b/lib/core/src/Cardano/Wallet.hs @@ -229,7 +229,7 @@ import Cardano.Crypto.Wallet import Cardano.Slotting.Slot ( SlotNo (..) ) import Cardano.Wallet.Address.Book - ( AddressBookIso, Prologue (..), getPrologue ) + ( AddressBookIso, Prologue (..), getDiscoveries, getPrologue ) import Cardano.Wallet.Checkpoints ( DeltaCheckpoints (..) , SparseCheckpointsConfig (..) @@ -610,6 +610,7 @@ import qualified Cardano.Api.Shelley as Cardano import qualified Cardano.Crypto.Wallet as CC import qualified Cardano.Wallet.Checkpoints.Policy as CP import qualified Cardano.Wallet.CoinSelection as CS +import qualified Cardano.Wallet.DB.WalletState as WS import qualified Cardano.Wallet.Primitive.AddressDiscovery.Random as Rnd import qualified Cardano.Wallet.Primitive.AddressDiscovery.Sequential as Seq import qualified Cardano.Wallet.Primitive.AddressDiscovery.Shared as Shared @@ -3551,18 +3552,35 @@ updateCosigner -> Cosigner -> CredentialType -> ExceptT ErrAddCosignerKey IO () -updateCosigner ctx wid cosignerXPub cosigner cred = db & \DBLayer{..} -> +updateCosigner ctx wid cosignerXPub cosigner cred = db & \DBLayer{..} -> do + cp <- withExceptT ErrAddCosignerKeyNoSuchWallet + $ mapExceptT atomically + $ withNoSuchWallet wid + $ readCheckpoint wid ExceptT $ atomically $ modifyDBMaybe walletsDB $ adjustNoSuchWallet wid ErrAddCosignerKeyNoSuchWallet - updateCosigner' + (updateCosigner' cp) where db = ctx ^. dbLayer @_ @s @k - updateCosigner' wallet = + updateCosigner' cp wallet = case addCosignerAccXPub (cosigner, cosignerXPub) cred s0 of Left err -> Left $ ErrAddCosignerKey err - Right s1 -> Right ([ReplacePrologue $ getPrologue s1], ()) + Right s1 -> case ready s1 of + Shared.Pending -> + Right (prologueUpdate s1, ()) + Shared.Active _ -> + Right (prologueUpdate s1 ++ discoveriesUpdate s1, ()) where s0 = getState $ getLatest wallet + prologueUpdate s = + [ReplacePrologue $ getPrologue s] + wc@(WS.WalletCheckpoint bh utxo' _) = snd $ fromWallet cp + discoveriesUpdate s = + [ UpdateCheckpoints + [ PutCheckpoint (getSlot wc) + (WS.WalletCheckpoint bh utxo' (getDiscoveries s)) + ] + ] -- NOTE -- Addresses coming from the transaction history might be base (having payment credential) or From 7adcdbe08531e441f6f5c097de449bad87544334 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Fri, 16 Sep 2022 12:54:04 +0200 Subject: [PATCH 4/6] add test for active wallet from xprv --- .../Test/Integration/Scenario/API/Shared/Wallets.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs index 9063721d25d..193906b6614 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs @@ -572,10 +572,18 @@ spec = describe "SHARED_WALLETS" $ do [ expectResponseCode HTTP.status201 ] - let walWithSelf = getFromResponse id rPostWithSelf + let walWithSelf@(ApiSharedWallet (Right activeWal)) = getFromResponse id rPostWithSelf getWalletIdFromSharedWallet walWithSelf `shouldBe` getWalletIdFromSharedWallet wal + rAddrsActive <- request @[ApiAddress n] ctx + (Link.listAddresses @'Shared activeWal) Default Empty + expectResponseCode HTTP.status200 rAddrsActive + let g = fromIntegral $ getAddressPoolGap defaultAddressPoolGap + expectListSize g rAddrsActive + forM_ [0..(g-1)] $ \addrNum -> do + expectListField addrNum (#state . #getApiT) (`shouldBe` Unused) rAddrsActive + it "SHARED_WALLETS_CREATE_06 - Create an active shared wallet from account xpub with self" $ \ctx -> runResourceT $ do (_, accXPubTxt):_ <- liftIO $ genXPubs 1 let payload = Json [json| { From 052a68aa7db9b45c36ea8c9c22dd4c1f5e9fb74a Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Fri, 16 Sep 2022 12:57:47 +0200 Subject: [PATCH 5/6] add test for active wallet from account xpub --- .../Integration/Scenario/API/Shared/Wallets.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs index 193906b6614..951dbe4886e 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shared/Wallets.hs @@ -572,7 +572,8 @@ spec = describe "SHARED_WALLETS" $ do [ expectResponseCode HTTP.status201 ] - let walWithSelf@(ApiSharedWallet (Right activeWal)) = getFromResponse id rPostWithSelf + let walWithSelf@(ApiSharedWallet (Right activeWal)) = + getFromResponse id rPostWithSelf getWalletIdFromSharedWallet walWithSelf `shouldBe` getWalletIdFromSharedWallet wal @@ -631,10 +632,19 @@ spec = describe "SHARED_WALLETS" $ do [ expectResponseCode HTTP.status201 ] - let walWithSelf = getFromResponse id rPostWithSelf + let walWithSelf@(ApiSharedWallet (Right activeWal)) = + getFromResponse id rPostWithSelf getWalletIdFromSharedWallet walWithSelf `shouldBe` getWalletIdFromSharedWallet wal + rAddrsActive <- request @[ApiAddress n] ctx + (Link.listAddresses @'Shared activeWal) Default Empty + expectResponseCode HTTP.status200 rAddrsActive + let g = fromIntegral $ getAddressPoolGap defaultAddressPoolGap + expectListSize g rAddrsActive + forM_ [0..(g-1)] $ \addrNum -> do + expectListField addrNum (#state . #getApiT) (`shouldBe` Unused) rAddrsActive + it "SHARED_WALLETS_CREATE_07 - Incorrect script template due to NoCosignerInScript" $ \ctx -> runResourceT $ do (_, accXPubTxt):_ <- liftIO $ genXPubs 1 let payload = Json [json| { From 6bbdc8d45293e193d5193a51854439494332ca54 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 16 Sep 2022 14:24:55 +0200 Subject: [PATCH 6/6] Additional checks for listing addresses in e2e tests --- test/e2e/spec/shared_spec.rb | 59 +++++++++++++++++++++++++++++++----- test/e2e/spec/spec_helper.rb | 16 ++++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/test/e2e/spec/shared_spec.rb b/test/e2e/spec/shared_spec.rb index c9eccddd0be..6644b9cc803 100644 --- a/test/e2e/spec/shared_spec.rb +++ b/test/e2e/spec/shared_spec.rb @@ -172,6 +172,9 @@ m24 = mnemonic_sentence(24) acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/0H") incomplete_wid = create_incomplete_shared_wallet(m24, '0H', acc_xpub) + addr = SHARED.addresses.list(incomplete_wid) + expect(addr).to be_correct_and_respond 200 + expect(addr.size).to eq 0 acc_xpub_upd = cardano_address_get_acc_xpub(mnemonic_sentence(24), "1854H/1815H/0H") @@ -183,6 +186,9 @@ expect(update_payment).to be_correct_and_respond 200 expect(SHARED.wallets.get(incomplete_wid)['state']['status']).to eq 'incomplete' expect(SHARED.wallets.get(incomplete_wid)).to be_correct_and_respond 200 + addr = SHARED.addresses.list(incomplete_wid) + expect(addr).to be_correct_and_respond 200 + expect(addr.size).to eq 0 update_delegation = SHARED.wallets.update_delegation_script(incomplete_wid, "cosigner#1", @@ -193,6 +199,9 @@ SHARED.wallets.get(incomplete_wid)['state']['status'] != 'incomplete' end expect(SHARED.wallets.list).to be_correct_and_respond 200 + addr = SHARED.addresses.list(incomplete_wid) + expect(addr).to be_correct_and_respond 200 + expect(addr.size).to eq 20 end it "Create / update partially / get / list / delete" do @@ -468,36 +477,70 @@ m24 = mnemonic_sentence(24) acc_ix = '0H' acc_xpub = cardano_address_get_acc_xpub(m24, "1854H/1815H/#{acc_ix}") - active_wid = create_incomplete_shared_wallet(acc_xpub, acc_ix, "self") + incomplete_wid = create_incomplete_shared_wallet(acc_xpub, acc_ix, "self") - a = SHARED.addresses.list(active_wid) + a = SHARED.addresses.list(incomplete_wid) expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 - a = SHARED.addresses.list(active_wid, { state: "used" }) + a = SHARED.addresses.list(incomplete_wid, { state: "used" }) expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 - a = SHARED.addresses.list(active_wid, { state: "unused" }) + a = SHARED.addresses.list(incomplete_wid, { state: "unused" }) + expect(a).to be_correct_and_respond 200 + expect(a.size).to be 0 + + acc_xpub = cardano_address_get_acc_xpub(mnemonic_sentence(24), "1854H/1815H/0H") + patch_incomplete_shared_wallet(incomplete_wid, + {"cosigner#1" => acc_xpub}, + {"cosigner#1" => acc_xpub}) + + a = SHARED.addresses.list(incomplete_wid) + expect(a).to be_correct_and_respond 200 + expect(a.size).to be 20 + + a = SHARED.addresses.list(incomplete_wid, { state: "used" }) expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 + + a = SHARED.addresses.list(incomplete_wid, { state: "unused" }) + expect(a).to be_correct_and_respond 200 + expect(a.size).to be 20 end it "Lists empty addresses on incomplete shared wallet - from mnemonics" do m24 = mnemonic_sentence(24) - active_wid = create_incomplete_shared_wallet(m24, '0H', "self") + incomplete_wid = create_incomplete_shared_wallet(m24, '0H', "self") - a = SHARED.addresses.list(active_wid) + a = SHARED.addresses.list(incomplete_wid) expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 - a = SHARED.addresses.list(active_wid, { state: "used" }) + a = SHARED.addresses.list(incomplete_wid, { state: "used" }) expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 - a = SHARED.addresses.list(active_wid, { state: "unused" }) + a = SHARED.addresses.list(incomplete_wid, { state: "unused" }) expect(a).to be_correct_and_respond 200 expect(a.size).to be 0 + + acc_xpub = cardano_address_get_acc_xpub(mnemonic_sentence(24), "1854H/1815H/0H") + patch_incomplete_shared_wallet(incomplete_wid, + {"cosigner#1" => acc_xpub}, + {"cosigner#1" => acc_xpub}) + + a = SHARED.addresses.list(incomplete_wid) + expect(a).to be_correct_and_respond 200 + expect(a.size).to be 20 + + a = SHARED.addresses.list(incomplete_wid, { state: "used" }) + expect(a).to be_correct_and_respond 200 + expect(a.size).to be 0 + + a = SHARED.addresses.list(incomplete_wid, { state: "unused" }) + expect(a).to be_correct_and_respond 200 + expect(a.size).to be 20 end end diff --git a/test/e2e/spec/spec_helper.rb b/test/e2e/spec/spec_helper.rb index ea9991f3e89..c168f219f26 100644 --- a/test/e2e/spec/spec_helper.rb +++ b/test/e2e/spec/spec_helper.rb @@ -130,6 +130,22 @@ def create_incomplete_shared_wallet(m, acc_ix, acc_xpub) WalletFactory.create(:shared, payload)['id'] end +def patch_incomplete_shared_wallet(wid, payment_patch, deleg_patch) + if payment_patch + p_upd = SHARED.wallets.update_payment_script(wid, + payment_patch.keys.first, + payment_patch.values.first) + expect(p_upd).to be_correct_and_respond 200 + end + + if deleg_patch + d_upd = SHARED.wallets.update_delegation_script(wid, + deleg_patch.keys.first, + deleg_patch.values.first) + expect(d_upd).to be_correct_and_respond 200 + end +end + def create_active_shared_wallet(m, acc_ix, acc_xpub) script_template = { 'cosigners' => { 'cosigner#0' => acc_xpub },