From b3eaf34e4a9f4359c5af54e4848bd3a04f296c15 Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Fri, 24 Nov 2023 16:50:38 +0100 Subject: [PATCH 1/4] Simplify `balanceTransactionWithDummyChangeState` --- .../Internal/Cardano/Write/Tx/BalanceSpec.hs | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs index bba05c79945..7b3be7cc0c8 100644 --- a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs +++ b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs @@ -119,10 +119,6 @@ import Cardano.Wallet.Address.Keys.WalletKey import Cardano.Wallet.Flavor ( KeyFlavorS (..) ) -import Cardano.Wallet.Primitive.Model - ( Wallet (..) - , unsafeInitWallet - ) import Cardano.Wallet.Primitive.NetworkId ( NetworkDiscriminant (..) , NetworkId (..) @@ -416,13 +412,6 @@ import qualified Cardano.Slotting.Time as Slotting import qualified Cardano.Wallet.Address.Derivation.Byron as Byron import qualified Cardano.Wallet.Address.Derivation.Shelley as Shelley import qualified Cardano.Wallet.Primitive.Ledger.Convert as Convert -import qualified Cardano.Wallet.Primitive.Types as W - ( Block (..) - , BlockHeader (..) - ) -import qualified Cardano.Wallet.Primitive.Types as W.Block - ( header - ) import qualified Cardano.Wallet.Primitive.Types.Address as W ( Address (..) ) @@ -436,7 +425,6 @@ import qualified Cardano.Wallet.Primitive.Types.Credentials as W ) import qualified Cardano.Wallet.Primitive.Types.Hash as W ( Hash (..) - , mockHash ) import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W.TokenBundle import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W @@ -461,9 +449,6 @@ import qualified Data.ByteString.Char8 as B8 import qualified Data.Foldable as F import qualified Data.List.NonEmpty as NE import qualified Data.Map.Strict as Map -import qualified Data.Quantity as W - ( Quantity (..) - ) import qualified Data.Sequence.Strict as StrictSeq import qualified Data.Set as Set import qualified Data.Text as T @@ -2071,8 +2056,7 @@ balanceTransactionWithDummyChangeState utxoAssumptions utxo seed partialTx = dummyTimeTranslation utxoIndex dummyChangeAddrGen - (getState $ unsafeInitWallet utxo (W.Block.header block0) - DummyChangeState { nextUnusedIndex = 0 }) + (DummyChangeState 0) partialTx where utxoIndex = constructUTxOIndex @era $ fromWalletUTxO utxo @@ -2221,18 +2205,6 @@ cardanoToWalletTxOut = -- Test values -------------------------------------------------------------------------------- -block0 :: W.Block -block0 = W.Block - { header = W.BlockHeader - { slotNo = SlotNo 0 - , blockHeight = W.Quantity 0 - , headerHash = W.mockHash $ SlotNo 0 - , parentHeaderHash = Nothing - } - , transactions = [] - , delegations = [] - } - {- HLINT ignore costModelsForTesting "Use underscore" -} costModelsForTesting :: Alonzo.CostModels costModelsForTesting = either (error . show) id $ do From 1d07ae665dbedc6e026bc8d7afac0f38232ee1e6 Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Mon, 27 Nov 2023 14:25:03 +0100 Subject: [PATCH 2/4] Remove dep on wallet delegation types in `BalanceSpec` --- .../Internal/Cardano/Write/Tx/BalanceSpec.hs | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs index 7b3be7cc0c8..04d3d823a2b 100644 --- a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs +++ b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs @@ -67,7 +67,13 @@ import Cardano.Ledger.Language ( Language (..) ) import Cardano.Ledger.Shelley.API - ( StrictMaybe (SJust, SNothing) + ( Credential (KeyHashObj) + , Credential (..) + , DCert (DCertDeleg) + , DelegCert (..) + , Delegation (..) + , KeyHash (..) + , StrictMaybe (SJust, SNothing) , Withdrawals (..) ) import Cardano.Mnemonic @@ -78,9 +84,6 @@ import Cardano.Mnemonic import Cardano.Numeric.Util ( power ) -import Cardano.Pool.Types - ( PoolId (..) - ) import Cardano.Wallet ( defaultChangeAddressGen ) @@ -133,10 +136,6 @@ import Cardano.Wallet.Primitive.Slotting ) import Cardano.Wallet.Shelley.Transaction ( mkByronWitness - , mkDelegationCertificates - ) -import Cardano.Wallet.Transaction - ( DelegationAction (..) ) import Cardano.Wallet.Unsafe ( unsafeFromHex @@ -881,8 +880,6 @@ balanceTransactionGoldenSpec = describe "balance goldens" $ do outs = map (W.TxOut addr . W.TokenBundle.fromCoin) coins dummyHash = W.Hash $ B8.replicate 32 '0' - rootK = - Shelley.unsafeGenerateKeyFromSeed (dummyMnemonic, Nothing) mempty addr = W.Address $ unsafeFromHex "60b1e5e0fb74c86c801f646841e07cdb42df8b82ef3ce4e57cb5412e77" @@ -902,15 +899,14 @@ balanceTransactionGoldenSpec = describe "balance goldens" $ do Nothing CardanoApi.TxScriptValidityNone + stakeKey = KeyHashObj $ KeyHash + "1866df9e2f1a61b522d1ef2518b51574a8205a70eafd257a9ad9949b" + pool = KeyHash + "ec28f33dcbe6d6400a1e5e339bd0647c202020202020202020202020" certs = - CardanoApi.toShelleyCertificate - <$> mkDelegationCertificates delegationAction (Left xpub) - where - poolId = PoolId "\236(\243=\203\230\214@\n\RS^3\155\208d|\ - \\ts\202l\f\249\194\187\230\131\141\198" - - xpub = getRawKey ShelleyKeyS $ publicKey ShelleyKeyS rootK - delegationAction = JoinRegisteringKey poolId + [ DCertDeleg $ RegKey stakeKey + , DCertDeleg $ Delegate $ Delegation stakeKey pool + ] txFee :: CardanoApi.Tx CardanoApi.BabbageEra -> CardanoApi.Lovelace txFee (CardanoApi.Tx (CardanoApi.TxBody content) _) = From f94af04ae01b3ddfe9f16707c688325bfb8d148b Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Mon, 27 Nov 2023 14:30:22 +0100 Subject: [PATCH 3/4] Drop some cardano-api usage in `delegate` definition --- .../unit/Internal/Cardano/Write/Tx/BalanceSpec.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs index 04d3d823a2b..acfced3eb55 100644 --- a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs +++ b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs @@ -55,6 +55,7 @@ import Cardano.Ledger.Api , allInputsTxBodyF , bodyTxL , coinTxOutL + , mkBasicTx , ppCoinsPerUTxOByteL , ppMaxTxSizeL , ppMinFeeAL @@ -889,15 +890,12 @@ balanceTransactionGoldenSpec = describe "balance goldens" $ do ] delegate :: PartialTx BabbageEra - delegate = PartialTx (fromCardanoApiTx $ CardanoApi.Tx body []) mempty [] + delegate = PartialTx (mkBasicTx body) mempty [] where - body = CardanoApi.ShelleyTxBody - CardanoApi.ShelleyBasedEraBabbage - (Ledger.mkBasicTxBody & certsTxBodyL .~ StrictSeq.fromList certs) - [] - CardanoApi.TxBodyNoScriptData - Nothing - CardanoApi.TxScriptValidityNone + body :: TxBody BabbageEra + body = + mkBasicTxBody + & certsTxBodyL .~ StrictSeq.fromList certs stakeKey = KeyHashObj $ KeyHash "1866df9e2f1a61b522d1ef2518b51574a8205a70eafd257a9ad9949b" From 6c6cc9e630138d8e555e16a30840db8ae715205f Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Tue, 28 Nov 2023 10:40:36 +0100 Subject: [PATCH 4/4] fixup: simplify dummy values --- .../unit/Internal/Cardano/Write/Tx/BalanceSpec.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs index acfced3eb55..1a18b8a52de 100644 --- a/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs +++ b/lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs @@ -897,13 +897,13 @@ balanceTransactionGoldenSpec = describe "balance goldens" $ do mkBasicTxBody & certsTxBodyL .~ StrictSeq.fromList certs - stakeKey = KeyHashObj $ KeyHash - "1866df9e2f1a61b522d1ef2518b51574a8205a70eafd257a9ad9949b" - pool = KeyHash - "ec28f33dcbe6d6400a1e5e339bd0647c202020202020202020202020" + dummyStakeKey = KeyHashObj $ KeyHash + "00000000000000000000000000000000000000000000000000000000" + dummyPool = KeyHash + "00000000000000000000000000000000000000000000000000000001" certs = - [ DCertDeleg $ RegKey stakeKey - , DCertDeleg $ Delegate $ Delegation stakeKey pool + [ DCertDeleg $ RegKey dummyStakeKey + , DCertDeleg $ Delegate $ Delegation dummyStakeKey dummyPool ] txFee :: CardanoApi.Tx CardanoApi.BabbageEra -> CardanoApi.Lovelace