From 8c9bee447d9b154a439cb40bdaa35615409fba89 Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Thu, 2 Jul 2020 14:11:36 +0200 Subject: [PATCH] Add pending test that wallet with existing stake key can delegate STAKE_POOLS_JOIN_05 This is a pending regression test for "Cannot join pool with ITN rewards wallet on shelley testnet" --- .../Scenario/API/Shelley/StakePools.hs | 26 ++++++ lib/shelley/cardano-wallet-shelley.cabal | 2 + .../Cardano/Wallet/Shelley/Compatibility.hs | 12 +++ .../src/Cardano/Wallet/Shelley/Transaction.hs | 2 + .../data/cardano-node-shelley/genesis.yaml | 5 ++ lib/shelley/test/integration/Main.hs | 87 +++++++++++++++---- nix/.stack.nix/cardano-wallet-shelley.nix | 2 + 7 files changed, 119 insertions(+), 17 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/StakePools.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/StakePools.hs index 8c2810de81f..fb95a021624 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/StakePools.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/StakePools.hs @@ -3,6 +3,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedLabels #-} +{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} @@ -48,6 +49,8 @@ import Data.Quantity ( Quantity (..) ) import Data.Set ( Set ) +import Data.Text + ( Text ) import Data.Text.Class ( toText ) import Test.Hspec @@ -71,6 +74,7 @@ import Test.Integration.Framework.DSL , fixtureWalletWith , getSlotParams , joinStakePool + , json , mkEpochInfo , notDelegating , quitStakePool @@ -334,6 +338,28 @@ spec = do -- (`shouldBe` reward) -- ] + it "STAKE_POOLS_JOIN_05 - Can join when stake key already exists" $ \ctx -> do + pendingWith "tracking stake key registrations" + let (walletWithPreRegKey:: [Text]) = + [ "over", "decorate", "flock", "badge", "beauty" + , "stamp" , "chest", "owner", "excess", "omit" + , "bid", "raccoon", "spin" , "reduce", "rival" + ] + let payload = Json [json| { + "name": "Wallet with pre-registered stake key", + "mnemonic_sentence": #{walletWithPreRegKey}, + "passphrase": "Secure Passphrase" + } |] + (_, w) <- unsafeRequest @ApiWallet ctx (Link.postWallet @'Shelley) payload + pool:_ <- map (view #id) . snd + <$> unsafeRequest @[ApiStakePool] ctx (Link.listStakePools arbitraryStake) Empty + + joinStakePool @n ctx pool (w, passwd)>>= flip verify + [ expectResponseCode HTTP.status202 + , expectField (#status . #getApiT) (`shouldBe` Pending) + , expectField (#direction . #getApiT) (`shouldBe` Outgoing) + ] + describe "STAKE_POOLS_JOIN_01x - Fee boundary values" $ do it "STAKE_POOLS_JOIN_01x - \ \I can join if I have just the right amount" $ \ctx -> do diff --git a/lib/shelley/cardano-wallet-shelley.cabal b/lib/shelley/cardano-wallet-shelley.cabal index b13fa5cb086..69e4725e140 100644 --- a/lib/shelley/cardano-wallet-shelley.cabal +++ b/lib/shelley/cardano-wallet-shelley.cabal @@ -187,6 +187,8 @@ test-suite integration , async , bytestring , cardano-wallet-cli + , cardano-addresses + , cardano-slotting , cardano-wallet-core , cardano-wallet-core-integration , cardano-wallet-launcher diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs index e8ad0b6fc21..42fa813cdff 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs @@ -38,6 +38,7 @@ module Cardano.Wallet.Shelley.Compatibility -- * Genesis , emptyGenesis , genesisTip + , initialFundsPseudoTxIn -- * Conversions , toShelleyHash @@ -618,6 +619,14 @@ fromShelleyTxIn (SL.TxIn txid ix) = unsafeCast :: Natural -> Word32 unsafeCast = fromIntegral +-- | Create a TxIn pointing to the initial funds in the genesis file. +initialFundsPseudoTxIn :: W.Address -> W.TxIn +initialFundsPseudoTxIn = + fromShelleyTxIn + . SL.initialFundsPseudoTxIn @TPraosStandardCrypto + . fromMaybe (error "initialFundsPseudoTxIn: invalid addr") + . toShelleyAddress + fromShelleyTxOut :: SL.TxOut crypto -> W.TxOut fromShelleyTxOut (SL.TxOut addr amount) = W.TxOut (fromShelleyAddress addr) (fromShelleyCoin amount) @@ -626,6 +635,9 @@ fromShelleyAddress :: SL.Addr crypto -> W.Address fromShelleyAddress = W.Address . SL.serialiseAddr +toShelleyAddress :: O.Crypto crypto => W.Address -> Maybe (SL.Addr crypto) +toShelleyAddress = SL.deserialiseAddr . W.unAddress + fromShelleyCoin :: SL.Coin -> W.Coin fromShelleyCoin (SL.Coin c) = W.Coin $ unsafeCast c where diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs index a180c753e4d..d0a8f4572e2 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs @@ -31,6 +31,8 @@ module Cardano.Wallet.Shelley.Transaction , mkWitness , realFee , mkTx + , TxPayload (..) + , emptyTxPayload ) where import Prelude diff --git a/lib/shelley/test/data/cardano-node-shelley/genesis.yaml b/lib/shelley/test/data/cardano-node-shelley/genesis.yaml index 451cd700a92..62fbf0d786a 100644 --- a/lib/shelley/test/data/cardano-node-shelley/genesis.yaml +++ b/lib/shelley/test/data/cardano-node-shelley/genesis.yaml @@ -1427,3 +1427,8 @@ initialFunds: - 610cdec48bb2168dbaa18f5a7e67ede598449e3783891f926d99c7ace8: 1 - 61d1e87828a2ff41f11e575e7827d0c38f48f2bf6778b359042c7a2e3e: 1 - 610130f3030867e827cb09eb1bf50401b0d9f413b2ca872b57a8d2fae4: 1 + +# Special wallet ["over", "decorate", "flock", "badge", "beauty", "stamp", "chest", "owner", "excess", "omit", "bid", "raccoon", "spin", "reduce", "rival"] +# for STAKE_POOLS_JOIN_05. +- 6199a7c32aaa55a628d936b539f01d5415318dec8bcb5e59ec71af695b: 10000000000 +- 60386c7a86d8844f4085a50241556043c9842d72c315c897a42a8a0510: 10000000000 diff --git a/lib/shelley/test/integration/Main.hs b/lib/shelley/test/integration/Main.hs index 91ce902b9b4..a75baac4455 100644 --- a/lib/shelley/test/integration/Main.hs +++ b/lib/shelley/test/integration/Main.hs @@ -13,6 +13,8 @@ module Main where import Prelude +import Cardano.Address.Derivation + ( XPrv, xprvFromBytes, xpubFromBytes ) import Cardano.BM.Data.Severity ( Severity (..) ) import Cardano.BM.Data.Tracer @@ -23,6 +25,8 @@ import Cardano.CLI ( Port (..), parseLoggingSeverity, withLogging ) import Cardano.Launcher ( ProcessHasExited (..) ) +import Cardano.Slotting.Slot + ( SlotNo (..) ) import Cardano.Startup ( withUtf8Encoding ) import Cardano.Wallet.Api.Server @@ -31,10 +35,14 @@ import Cardano.Wallet.Api.Types ( ApiByronWallet, ApiWallet, WalletStyle (..) ) import Cardano.Wallet.Logging ( BracketLog (..), bracketTracer, trMessageText ) +import Cardano.Wallet.Network + ( NetworkLayer (..) ) import Cardano.Wallet.Network.Ports ( unsafePortNumber ) import Cardano.Wallet.Primitive.AddressDerivation - ( NetworkDiscriminant (..) ) + ( Depth (..), NetworkDiscriminant (..), paymentAddress, publicKey ) +import Cardano.Wallet.Primitive.AddressDerivation.Shelley + ( ShelleyKey (..) ) import Cardano.Wallet.Primitive.CoinSelection ( CoinSelection (..) ) import Cardano.Wallet.Primitive.Fee @@ -59,15 +67,19 @@ import Cardano.Wallet.Shelley , tracerSeverities ) import Cardano.Wallet.Shelley.Compatibility - ( Shelley ) + ( Shelley, initialFundsPseudoTxIn, toStakeKeyRegCert ) import Cardano.Wallet.Shelley.Faucet ( initFaucet ) import Cardano.Wallet.Shelley.Launch ( ClusterLog, withCluster, withSystemTempDir, withTempDir ) +import Cardano.Wallet.Shelley.Network + ( withNetworkLayer ) import Cardano.Wallet.Shelley.Transaction - ( _minimumFee ) + ( TxPayload (..), mkTx, _minimumFee ) import Cardano.Wallet.Transaction ( Certificate (..) ) +import Cardano.Wallet.Unsafe + ( unsafeFromHex, unsafeRunExceptT ) import Control.Concurrent.Async ( race ) import Control.Concurrent.MVar @@ -77,7 +89,9 @@ import Control.Exception import Control.Monad ( forM_, void ) import Control.Tracer - ( Tracer (..), contramap, traceWith ) + ( Tracer (..), contramap, nullTracer, traceWith ) +import Data.Maybe + ( fromJust ) import Data.Proxy ( Proxy (..) ) import Data.Text @@ -209,19 +223,21 @@ specWithServer (tr, tracers) = aroundAll withContext . after tearDown let tr' = contramap MsgCluster tr withSystemTempDir tr' "test" $ \dir -> withCluster tr' minSev 3 dir $ \socketPath block0 (gp, vData) -> - withTempDir tr' dir "wallets" $ \db -> - serveWallet @(IO Shelley) - (SomeNetworkDiscriminant $ Proxy @'Mainnet) - tracers - (SyncTolerance 10) - (Just db) - "127.0.0.1" - ListenOnRandomPort - Nothing - socketPath - block0 - (gp, vData) - (onStart gp) + withTempDir tr' dir "wallets" $ \db -> do + withNetworkLayer nullTracer gp socketPath vData $ \nl -> do + preregisterStakingKeysForTests nl + serveWallet @(IO Shelley) + (SomeNetworkDiscriminant $ Proxy @'Mainnet) + tracers + (SyncTolerance 10) + (Just db) + "127.0.0.1" + ListenOnRandomPort + Nothing + socketPath + block0 + (gp, vData) + (onStart gp) -- | teardown after each test (currently only deleting all wallets) tearDown :: Context t -> IO () @@ -324,3 +340,40 @@ minSeverityFromEnv def var = lookupEnv var >>= \case Nothing -> pure def Just "" -> pure def Just arg -> either die pure (parseLoggingSeverity arg) + +-- | Pre-register a staking key for the STAKE_POOLS_JOIN_05 test. +preregisterStakingKeysForTests :: NetworkLayer IO t b -> IO () +preregisterStakingKeysForTests nl = do + let payload = TxPayload + [toStakeKeyRegCert rewardPub] + (const mempty) + (Fee 9999999900) + let keystore = const (Just (xprv, mempty)) + let txIn = initialFundsPseudoTxIn addr + + let dummyOut = TxOut addr (Coin 0) + + let Right (_, tx) = mkTx + @ShelleyKey + payload + keystore + (SlotNo 5000) + [(txIn, dummyOut)] + [] + unsafeRunExceptT $ postTx nl tx + where + + addr :: Address + addr = paymentAddress @'Mainnet (publicKey xprv) + + -- The wallet's reward key + Just rewardPub = xpubFromBytes $ unsafeFromHex + "949fc9e6b7e1e12e933ac35de5a565c9264b0ac5b631b4f5a21548bc6d65616f30\ + \42af27ce48e0fce0f88696b6ed3476f8c3412cce2f984931fb7658dee1872e" + + xprv :: ShelleyKey 'AddressK XPrv + xprv = ShelleyKey $ fromJust $ xprvFromBytes $ unsafeFromHex + "90b23d7d7d2d77e943bf81b89af4f4b263049b4c2c7f52b9ae\ + \2093bff8ff8c4e845d4583dcbf226613bc1b823811fe682483\ + \c71bf0de92dc7f8f05bacdaba79994f3d3f3cc1793d8afe804\ + \53ab06a875d21ed1adcfad913617796c8662d375fc" diff --git a/nix/.stack.nix/cardano-wallet-shelley.nix b/nix/.stack.nix/cardano-wallet-shelley.nix index d5c1e7821f1..dc76ffdfc14 100644 --- a/nix/.stack.nix/cardano-wallet-shelley.nix +++ b/nix/.stack.nix/cardano-wallet-shelley.nix @@ -140,6 +140,8 @@ (hsPkgs."async" or (errorHandler.buildDepError "async")) (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring")) (hsPkgs."cardano-wallet-cli" or (errorHandler.buildDepError "cardano-wallet-cli")) + (hsPkgs."cardano-addresses" or (errorHandler.buildDepError "cardano-addresses")) + (hsPkgs."cardano-slotting" or (errorHandler.buildDepError "cardano-slotting")) (hsPkgs."cardano-wallet-core" or (errorHandler.buildDepError "cardano-wallet-core")) (hsPkgs."cardano-wallet-core-integration" or (errorHandler.buildDepError "cardano-wallet-core-integration")) (hsPkgs."cardano-wallet-launcher" or (errorHandler.buildDepError "cardano-wallet-launcher"))