From 145a1943a926f8f9633d1da54af0fa6c40347267 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Tue, 4 Oct 2022 02:04:14 +0000 Subject: [PATCH] Remove the so-called "pointless" tests from `Api.TypesSpec`. It's not clear what value these tests provide. Of course, they do allow us to artificially increase our coverage from the point of view of the code coverage checker. But it's not clear why we should want to do this. Moreover, artificially increasing the coverage score in this way may hide real gaps in test coverage: because of these "pointless" tests, our code coverage report currently can't tell us which types are really exercised by our test suite, and which are not. Additionally, the set of types tested here is incomplete: many newer types were never added to the list. If we really need to have this kind of test, then instead of maintaining these test definitions manually (a process that is error prone, requires a lot of boilerplate, and increases review overhead), it would be better to generate them automatically: then we can automatically cover all types used in the API, rather than just an subset. However, if our goal is to reach 100% coverage of all API record field accessors, perhaps it would be better to focus our efforts on writing meaningful tests that actually stimulate the API. --- .../test/unit/Cardano/Wallet/Api/TypesSpec.hs | 487 ------------------ 1 file changed, 487 deletions(-) diff --git a/lib/wallet/test/unit/Cardano/Wallet/Api/TypesSpec.hs b/lib/wallet/test/unit/Cardano/Wallet/Api/TypesSpec.hs index 2577dca2b42..9e3cd5f5c00 100644 --- a/lib/wallet/test/unit/Cardano/Wallet/Api/TypesSpec.hs +++ b/lib/wallet/test/unit/Cardano/Wallet/Api/TypesSpec.hs @@ -457,7 +457,6 @@ import Test.QuickCheck , suchThat , vector , vectorOf - , (.&&.) , (===) ) import Test.QuickCheck.Arbitrary.Generic @@ -901,492 +900,6 @@ spec = parallel $ do parseUrlPiece "patate" `shouldBe` (Left @Text @(ApiT AddressState) msg) - parallel $ describe "pointless tests to trigger coverage for record accessors" $ do - it "ApiEpochInfo" $ property $ \x -> - let - x' = ApiEpochInfo - { epochNumber = epochNumber (x :: ApiEpochInfo) - , epochStartTime = epochStartTime (x :: ApiEpochInfo) - } - in - x' === x .&&. show x' === show x - it "ApiSelectCoinsData" $ property $ \x -> - let - x' = ApiSelectCoinsPayments - { payments = payments (x :: ApiSelectCoinsPayments ('Testnet 0)) - , withdrawal = withdrawal (x :: ApiSelectCoinsPayments ('Testnet 0)) - , metadata = metadata (x :: ApiSelectCoinsPayments ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiCoinSelection" $ property $ \x -> - let - x' = ApiCoinSelection - { inputs = inputs - (x :: ApiCoinSelection ('Testnet 0)) - , outputs = outputs - (x :: ApiCoinSelection ('Testnet 0)) - , change = change - (x :: ApiCoinSelection ('Testnet 0)) - , collateral = collateral - (x :: ApiCoinSelection ('Testnet 0)) - , withdrawals = withdrawals - (x :: ApiCoinSelection ('Testnet 0)) - , certificates = certificates - (x :: ApiCoinSelection ('Testnet 0)) - , depositsTaken = depositsTaken - (x :: ApiCoinSelection ('Testnet 0)) - , depositsReturned = depositsReturned - (x :: ApiCoinSelection ('Testnet 0)) - , metadata = metadata - (x :: ApiCoinSelection ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiCoinSelectionChange" $ property $ \x -> - let - x' = ApiCoinSelectionChange - { address = address - (x :: ApiCoinSelectionChange ('Testnet 0)) - , amount = amount - (x :: ApiCoinSelectionChange ('Testnet 0)) - , assets = assets - (x :: ApiCoinSelectionChange ('Testnet 0)) - , derivationPath = derivationPath - (x :: ApiCoinSelectionChange ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiCoinSelectionCollateral" $ property $ \x -> - let - x' = ApiCoinSelectionCollateral - { id = id - (x :: ApiCoinSelectionCollateral ('Testnet 0)) - , index = index - (x :: ApiCoinSelectionCollateral ('Testnet 0)) - , address = address - (x :: ApiCoinSelectionCollateral ('Testnet 0)) - , amount = amount - (x :: ApiCoinSelectionCollateral ('Testnet 0)) - , derivationPath = derivationPath - (x :: ApiCoinSelectionCollateral ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiCoinSelectionOutput" $ property $ \x -> - let - x' = ApiCoinSelectionOutput - { address = address - (x :: ApiCoinSelectionOutput ('Testnet 0)) - , amount = amount - (x :: ApiCoinSelectionOutput ('Testnet 0)) - , assets = assets - (x :: ApiCoinSelectionOutput ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiWallet" $ property $ \x -> - let - x' = ApiWallet - { id = id (x :: ApiWallet) - , addressPoolGap = addressPoolGap (x :: ApiWallet) - , balance = balance (x :: ApiWallet) - , assets = assets (x :: ApiWallet) - , delegation = delegation (x :: ApiWallet) - , name = name (x :: ApiWallet) - , passphrase = passphrase (x :: ApiWallet) - , state = state (x :: ApiWallet) - , tip = tip (x :: ApiWallet) - } - in - x' === x .&&. show x' === show x - it "ApiByronWallet" $ property $ \x -> - let - x' = ApiByronWallet - { id = id (x :: ApiByronWallet) - , balance = balance (x :: ApiByronWallet) - , assets = assets (x :: ApiByronWallet) - , name = name (x :: ApiByronWallet) - , passphrase = passphrase (x :: ApiByronWallet) - , state = state (x :: ApiByronWallet) - , tip = tip (x :: ApiByronWallet) - , discovery = discovery (x :: ApiByronWallet) - } - in - x' === x .&&. show x' === show x - it "ApiWalletMigrationBalance" $ property $ \x -> - let - x' = ApiWalletMigrationBalance - { ada = ada - (x :: ApiWalletMigrationBalance) - , assets = assets - (x :: ApiWalletMigrationBalance) - } - in - x' === x .&&. show x' === show x - it "ApiWalletMigrationPlan" $ property $ \x -> - let - x' = ApiWalletMigrationPlan - { selections = selections - (x :: ApiWalletMigrationPlan ('Testnet 0)) - , totalFee = totalFee - (x :: ApiWalletMigrationPlan ('Testnet 0)) - , balanceLeftover = balanceLeftover - (x :: ApiWalletMigrationPlan ('Testnet 0)) - , balanceSelected = balanceSelected - (x :: ApiWalletMigrationPlan ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiWalletMigrationPlanPostData" $ property $ \x -> - let - x' = ApiWalletMigrationPlanPostData - { addresses = addresses - (x :: ApiWalletMigrationPlanPostData ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiWalletMigrationPostData lenient" $ property $ \x -> - let - x' = ApiWalletMigrationPostData - { passphrase = passphrase - (x :: ApiWalletMigrationPostData ('Testnet 0) "lenient") - , addresses = addresses - (x :: ApiWalletMigrationPostData ('Testnet 0) "lenient") - } - in - x' === x .&&. show x' === show x - it "ApiWalletMigrationPostData raw" $ property $ \x -> - let - x' = ApiWalletMigrationPostData - { passphrase = passphrase - (x :: ApiWalletMigrationPostData ('Testnet 0) "user") - , addresses = addresses - (x :: ApiWalletMigrationPostData ('Testnet 0) "user") - } - in - x' === x .&&. show x' === show x - it "ApiWalletPassphrase" $ property $ \x -> - let - x' = ApiWalletPassphrase - { passphrase = - passphrase (x :: ApiWalletPassphrase) - } - in - x' === x .&&. show x' === show x - it "ApiFee" $ property $ \x -> - let - x' = ApiFee - { estimatedMin = estimatedMin (x :: ApiFee) - , estimatedMax = estimatedMax (x :: ApiFee) - , minimumCoins = minimumCoins (x :: ApiFee) - , deposit = deposit (x :: ApiFee) - } - in - x' === x .&&. show x' === show x - it "ApiTxId" $ property $ \x -> - let - x' = ApiTxId - { id = id (x :: ApiTxId) - } - in - x' === x .&&. show x' === show x - it "WalletPostData" $ property $ \x -> - let - x' = WalletPostData - { addressPoolGap = addressPoolGap (x :: WalletPostData) - , mnemonicSentence = mnemonicSentence (x :: WalletPostData) - , mnemonicSecondFactor = mnemonicSecondFactor (x :: WalletPostData) - , name = name (x :: WalletPostData) - , passphrase = passphrase (x :: WalletPostData) - } - in - x' === x .&&. show x' === show x - it "WalletPutData" $ property $ \x -> - let - x' = WalletPutData - { name = name (x :: WalletPutData) - } - in - x' === x .&&. show x' === show x - it "SettingsPutData" $ property $ \x -> - let - x' = SettingsPutData - { settings = settings (x :: SettingsPutData) - } - in - x' === x .&&. show x' === show x - it "WalletPutPassphraseData" $ property $ \case - WalletPutPassphraseData (Left x) -> - let - x' = WalletPutPassphraseOldPassphraseData - { oldPassphrase = oldPassphrase - (x :: WalletPutPassphraseOldPassphraseData) - , newPassphrase = newPassphrase - (x :: WalletPutPassphraseOldPassphraseData) - } - in - x' === x .&&. show x' === show x - WalletPutPassphraseData (Right x) -> - let - x' = Api.WalletPutPassphraseMnemonicData - { mnemonicSentence = mnemonicSentence - (x :: WalletPutPassphraseMnemonicData) - , mnemonicSecondFactor = mnemonicSecondFactor - (x :: WalletPutPassphraseMnemonicData) - , newPassphrase = newPassphrase - (x :: WalletPutPassphraseMnemonicData) - } - in - x' === x .&&. show x' === show x - it "ByronWalletPutPassphraseData" $ property $ \x -> - let - x' = ByronWalletPutPassphraseData - { oldPassphrase = oldPassphrase (x :: ByronWalletPutPassphraseData) - , newPassphrase = newPassphrase (x :: ByronWalletPutPassphraseData) - } - in - x' === x .&&. show x' === show x - it "ApiSignTransactionPostData" $ property $ \x -> - let - x' = ApiSignTransactionPostData - { transaction = transaction (x :: ApiSignTransactionPostData) - , passphrase = passphrase (x :: ApiSignTransactionPostData) - , encoding = encoding (x :: ApiSignTransactionPostData) - } - in - x' === x .&&. show x' === show x - it "PostTransactionOldData" $ property $ \x -> - let - x' = PostTransactionOldData - { payments = payments (x :: PostTransactionOldData ('Testnet 0)) - , passphrase = passphrase (x :: PostTransactionOldData ('Testnet 0)) - , withdrawal = withdrawal (x :: PostTransactionOldData ('Testnet 0)) - , metadata = metadata (x :: PostTransactionOldData ('Testnet 0)) - , timeToLive = timeToLive (x :: PostTransactionOldData ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "PostTransactionFeeOldData" $ property $ \x -> - let - x' = PostTransactionFeeOldData - { payments = payments (x :: PostTransactionFeeOldData ('Testnet 0)) - , withdrawal = withdrawal (x :: PostTransactionFeeOldData ('Testnet 0)) - , metadata = metadata (x :: PostTransactionFeeOldData ('Testnet 0)) - , timeToLive = timeToLive (x :: PostTransactionFeeOldData ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiBalanceTransactionPostData" $ property $ \x -> - let - x' = ApiBalanceTransactionPostData - { transaction = transaction (x :: ApiBalanceTransactionPostData ('Testnet 0)) - , inputs = inputs (x :: ApiBalanceTransactionPostData ('Testnet 0)) - , redeemers = redeemers (x :: ApiBalanceTransactionPostData ('Testnet 0)) - , encoding = encoding (x :: ApiBalanceTransactionPostData ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiTransaction" $ property $ \x -> - let - x' = ApiTransaction - { id = id - (x :: ApiTransaction ('Testnet 0)) - , amount = amount - (x :: ApiTransaction ('Testnet 0)) - , fee = fee - (x :: ApiTransaction ('Testnet 0)) - , depositTaken = depositTaken - (x :: ApiTransaction ('Testnet 0)) - , depositReturned = depositReturned - (x :: ApiTransaction ('Testnet 0)) - , insertedAt = insertedAt - (x :: ApiTransaction ('Testnet 0)) - , pendingSince = pendingSince - (x :: ApiTransaction ('Testnet 0)) - , expiresAt = expiresAt - (x :: ApiTransaction ('Testnet 0)) - , depth = depth - (x :: ApiTransaction ('Testnet 0)) - , direction = direction - (x :: ApiTransaction ('Testnet 0)) - , inputs = inputs - (x :: ApiTransaction ('Testnet 0)) - , outputs = outputs - (x :: ApiTransaction ('Testnet 0)) - , collateral = collateral - (x :: ApiTransaction ('Testnet 0)) - , collateralOutputs = collateralOutputs - (x :: ApiTransaction ('Testnet 0)) - , status = status - (x :: ApiTransaction ('Testnet 0)) - , withdrawals = withdrawals - (x :: ApiTransaction ('Testnet 0)) - , metadata = metadata - (x :: ApiTransaction ('Testnet 0)) - , scriptValidity = scriptValidity - (x :: ApiTransaction ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiConstructTransactionData" $ property $ \x -> - let - x' = ApiConstructTransactionData - { payments = payments - (x :: ApiConstructTransactionData ('Testnet 0)) - , withdrawal = withdrawal - (x :: ApiConstructTransactionData ('Testnet 0)) - , metadata = metadata - (x :: ApiConstructTransactionData ('Testnet 0)) - , mintBurn = mintBurn - (x :: ApiConstructTransactionData ('Testnet 0)) - , delegations = delegations - (x :: ApiConstructTransactionData ('Testnet 0)) - , validityInterval = validityInterval - (x :: ApiConstructTransactionData ('Testnet 0)) - , encoding = encoding - (x :: ApiConstructTransactionData ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiDecodedTransaction" $ property $ \x -> - let - x' = ApiDecodedTransaction - { id = id - (x :: ApiDecodedTransaction ('Testnet 0)) - , fee = fee - (x :: ApiDecodedTransaction ('Testnet 0)) - , inputs = inputs - (x :: ApiDecodedTransaction ('Testnet 0)) - , outputs = outputs - (x :: ApiDecodedTransaction ('Testnet 0)) - , collateral = collateral - (x :: ApiDecodedTransaction ('Testnet 0)) - , collateralOutputs = collateralOutputs - (x :: ApiDecodedTransaction ('Testnet 0)) - , withdrawals = withdrawals - (x :: ApiDecodedTransaction ('Testnet 0)) - , metadata = metadata - (x :: ApiDecodedTransaction ('Testnet 0)) - , mint = mint - (x :: ApiDecodedTransaction ('Testnet 0)) - , burn = burn - (x :: ApiDecodedTransaction ('Testnet 0)) - , certificates = certificates - (x :: ApiDecodedTransaction ('Testnet 0)) - , depositsTaken = depositsTaken - (x :: ApiDecodedTransaction ('Testnet 0)) - , depositsReturned = depositsReturned - (x :: ApiDecodedTransaction ('Testnet 0)) - , scriptValidity = scriptValidity - (x :: ApiDecodedTransaction ('Testnet 0)) - , validityInterval = validityInterval - (x :: ApiDecodedTransaction ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "ApiPutAddressesData" $ property $ \x -> - let - x' = ApiPutAddressesData - { addresses = addresses (x :: ApiPutAddressesData ('Testnet 0)) - } - in - x' === x .&&. show x' === show x - it "AddressAmount" $ property $ \x -> - let - x' = AddressAmount - { address = address - (x :: AddressAmount (ApiT Address, Proxy ('Testnet 0))) - , amount = amount - (x :: AddressAmount (ApiT Address, Proxy ('Testnet 0))) - , assets = assets - (x :: AddressAmount (ApiT Address, Proxy ('Testnet 0))) - } - in - x' === x .&&. show x' === show x - it "AddressAmountNoAssets" $ property $ \x -> - let - x' = AddressAmountNoAssets - { address = address - (x :: AddressAmountNoAssets - (ApiT Address, Proxy ('Testnet 0))) - , amount = amount - (x :: AddressAmountNoAssets - (ApiT Address, Proxy ('Testnet 0))) - } - in - x' === x .&&. show x' === show x - it "ApiBlockReference" $ property $ \x -> - let - x' = ApiBlockReference - { absoluteSlotNumber = absoluteSlotNumber (x :: ApiBlockReference) - , slotId = slotId (x :: ApiBlockReference) - , time = time (x :: ApiBlockReference) - , block = block (x :: ApiBlockReference) - } - in - x' === x .&&. show x' === show x - it "ApiSlotReference" $ property $ \x -> - let - x' = ApiSlotReference - { absoluteSlotNumber = absoluteSlotNumber (x :: ApiSlotReference) - , slotId = slotId (x :: ApiSlotReference) - , time = time (x :: ApiSlotReference) - } - in - x' === x .&&. show x' === show x - it "ApiNetworkInformation" $ property $ \x -> - let - x' = ApiNetworkInformation - { syncProgress = syncProgress (x :: ApiNetworkInformation) - , nextEpoch = nextEpoch (x :: ApiNetworkInformation) - , nodeTip = nodeTip (x :: ApiNetworkInformation) - , networkTip = networkTip (x :: ApiNetworkInformation) - , nodeEra = nodeEra (x :: ApiNetworkInformation) - , networkInfo = networkInfo (x :: ApiNetworkInformation) - , walletMode = walletMode (x :: ApiNetworkInformation) - } - in - x' === x .&&. show x' === show x - it "ApiNetworkClock" $ property $ \x -> - let - x' = ApiNetworkClock - { ntpStatus = ntpStatus (x :: ApiNetworkClock) - } - in - x' === x .&&. show x' === show x - it "ApiNetworkParameters" $ property $ \x -> - let x' = ApiNetworkParameters - { genesisBlockHash = genesisBlockHash - (x :: ApiNetworkParameters) - , blockchainStartTime = blockchainStartTime - (x :: ApiNetworkParameters) - , slotLength = slotLength - (x :: ApiNetworkParameters) - , epochLength = epochLength - (x :: ApiNetworkParameters) - , securityParameter = securityParameter - (x :: ApiNetworkParameters) - , activeSlotCoefficient = activeSlotCoefficient - (x :: ApiNetworkParameters) - , decentralizationLevel = decentralizationLevel - (x :: ApiNetworkParameters) - , desiredPoolNumber = desiredPoolNumber - (x :: ApiNetworkParameters) - , maximumTokenBundleSize = maximumTokenBundleSize - (x :: ApiNetworkParameters) - , eras = eras - (x :: ApiNetworkParameters) - , maximumCollateralInputCount = maximumCollateralInputCount - (x :: ApiNetworkParameters) - , minimumCollateralPercentage = minimumCollateralPercentage - (x :: ApiNetworkParameters) - , executionUnitPrices = executionUnitPrices - (x :: ApiNetworkParameters) - } - in - x' === x .&&. show x' === show x - describe "Api Errors" $ do it "Every constructor from ApiErrorCode has a corresponding type in the schema" $ let res = fromJSON @SchemaApiErrorCode specification