Skip to content

Commit f26bf1f

Browse files
committed
move queryTableCount to Validate.hs + removed code + hlint
1 parent 80125ea commit f26bf1f

File tree

6 files changed

+21
-31
lines changed

6 files changed

+21
-31
lines changed

cardano-chain-gen/src/Cardano/Mock/Query.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ queryStakeAddressHashRaw = do
9393
pure $ stakeAddress ^. Db.StakeAddressHashRaw
9494
pure $ toShort . Base16.encode . unValue <$> res
9595

96-
-- queryTableCount ::
97-
-- (MonadIO m, PersistEntity table, PersistEntityBackend table ~ SqlBackend)
98-
-- => (SqlExpr (Entity table) -> SqlQuery ())
99-
-- -> m Word
100-
-- queryTableCount _ = do
101-
-- res <- selectOne $ do
102-
-- _ <- from (table @table) -- using TypeApplications to generalize the table
103-
-- pure countRows
104-
-- pure $ maybe 0 unValue res
105-
10696
queryStakeAddressCount :: MonadIO io => ReaderT SqlBackend io Word
10797
queryStakeAddressCount = do
10898
res <- selectOne $ do

cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module Test.Cardano.Db.Mock.Config (
4242
withCustomConfigAndLogs,
4343
withFullConfig',
4444
replaceConfigFile,
45-
expectFailSilent,
4645
) where
4746

4847
import Cardano.Api (NetworkMagic (..))
@@ -67,7 +66,7 @@ import Control.Concurrent.STM.TMVar (
6766
tryPutTMVar,
6867
tryReadTMVar,
6968
)
70-
import Control.Exception (SomeException, bracket, catch)
69+
import Control.Exception (SomeException, bracket)
7170
import Control.Monad (void)
7271
import Control.Monad.Extra (eitherM)
7372
import Control.Monad.Logger (NoLoggingT, runNoLoggingT)
@@ -85,8 +84,6 @@ import Ouroboros.Consensus.Shelley.Node (ShelleyLeaderCredentials)
8584
import System.Directory (createDirectoryIfMissing, removePathForcibly)
8685
import System.FilePath.Posix (takeDirectory, (</>))
8786
import System.IO.Silently (hSilence)
88-
import Test.Tasty (TestTree)
89-
import Test.Tasty.HUnit (Assertion, assertFailure, testCase)
9087

9188
data Config = Config
9289
{ topLevelConfig :: TopLevelConfig CardanoBlock
@@ -519,10 +516,3 @@ replaceConfigFile newFilename dbSync@DBSyncEnv {..} = do
519516
configDir = mkConfigDir . takeDirectory . unConfigFile . enpConfigFile $ dbSyncParams
520517
newParams =
521518
dbSyncParams {enpConfigFile = ConfigFile $ configDir </> newFilename}
522-
523-
expectFailSilent :: String -> Assertion -> TestTree
524-
expectFailSilent name action = testCase name $ do
525-
result <- catch (Right <$> action) (\(_ :: SomeException) -> pure $ Left ())
526-
case result of
527-
Left _ -> pure () -- Test failed as expected, do nothing
528-
Right _ -> assertFailure "Expected test to fail but it succeeded"

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Data.Text (Text)
1111
import Test.Tasty (TestTree, testGroup)
1212
import Test.Tasty.HUnit (Assertion, testCase)
1313

14-
import Test.Cardano.Db.Mock.Config (expectFailSilent)
1514
import qualified Test.Cardano.Db.Mock.Unit.Babbage.CommandLineArg.ConfigFile as ConfigFile
1615
import qualified Test.Cardano.Db.Mock.Unit.Babbage.CommandLineArg.EpochDisabled as EpochDisabled
1716
import qualified Test.Cardano.Db.Mock.Unit.Babbage.CommandLineArg.ForceIndex as ForceIndex
@@ -25,6 +24,7 @@ import qualified Test.Cardano.Db.Mock.Unit.Babbage.Rollback as BabRollback
2524
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Simple as BabSimple
2625
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Stake as BabStake
2726
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Tx as BabTx
27+
import Test.Cardano.Db.Mock.Validate (expectFailSilent)
2828

2929
unitTests :: IOManager -> [(Text, Text)] -> TestTree
3030
unitTests iom knownMigrations =

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module Test.Cardano.Db.Mock.Unit.Conway (unitTests) where
22

33
import Cardano.Mock.ChainSync.Server (IOManager ())
44
import Cardano.Prelude
5-
import Test.Cardano.Db.Mock.Config (expectFailSilent)
65
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ConfigFile as ConfigFile
76
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.EpochDisabled as EpochDisabled
87
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ForceIndex as ForceIndex
@@ -17,6 +16,7 @@ import qualified Test.Cardano.Db.Mock.Unit.Conway.Simple as Simple
1716
import qualified Test.Cardano.Db.Mock.Unit.Conway.Stake as Stake
1817
import qualified Test.Cardano.Db.Mock.Unit.Conway.Tx as Tx
1918
import qualified Test.Cardano.Db.Mock.Unit.Conway.Whitelist as Whitelist
19+
import Test.Cardano.Db.Mock.Validate (expectFailSilent)
2020
import Test.Tasty (TestTree (), testGroup)
2121
import Test.Tasty.HUnit (Assertion (), testCase)
2222
import Prelude (String ())

cardano-chain-gen/test/Test/Cardano/Db/Mock/Validate.hs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Test.Cardano.Db.Mock.Validate (
1717
assertRewardRestCount,
1818
assertBlockNoBackoff,
1919
assertBlockNoBackoffTimes,
20+
expectFailSilent,
2021
assertEqQuery,
2122
assertEqBackoff,
2223
assertBackoff,
@@ -39,7 +40,8 @@ module Test.Cardano.Db.Mock.Validate (
3940
assertPoolCounters,
4041
poolCountersQuery,
4142
checkStillRuns,
42-
) where
43+
)
44+
where
4345

4446
import Cardano.Db
4547
import qualified Cardano.Db as DB
@@ -85,7 +87,8 @@ import Database.PostgreSQL.Simple (SqlError (..))
8587
import Ouroboros.Consensus.Cardano.Block
8688
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
8789
import Test.Cardano.Db.Mock.Config
88-
import Test.Tasty.HUnit (assertEqual, assertFailure)
90+
import Test.Tasty (TestTree)
91+
import Test.Tasty.HUnit (Assertion, assertEqual, assertFailure, testCase)
8992

9093
{- HLINT ignore "Reduce duplication" -}
9194

@@ -124,6 +127,13 @@ assertBlockNoBackoffTimes :: [Int] -> DBSyncEnv -> Int -> IO ()
124127
assertBlockNoBackoffTimes times env blockNo =
125128
assertEqBackoff env DB.queryBlockHeight (Just $ fromIntegral blockNo) times "Unexpected BlockNo"
126129

130+
expectFailSilent :: String -> Assertion -> TestTree
131+
expectFailSilent name action = testCase name $ do
132+
result <- catch (Right <$> action) (\(_ :: SomeException) -> pure $ Left ())
133+
case result of
134+
Left _ -> pure () -- Test failed as expected, do nothing
135+
Right _ -> assertFailure "Expected test to fail but it succeeded"
136+
127137
-- checking that unspent count matches from tx_in to tx_out
128138
assertUnspentTx :: DBSyncEnv -> IO ()
129139
assertUnspentTx syncEnv = do
@@ -207,7 +217,7 @@ assertAddrValues env ix expected sta = do
207217
q = queryAddressOutputs address
208218
assertEqBackoff env q expected defaultDelays "Unexpected Balance"
209219

210-
assertRight :: Show err => Either err a -> IO a
220+
assertRight :: (Show err) => Either err a -> IO a
211221
assertRight ei =
212222
case ei of
213223
Right a -> pure a
@@ -234,7 +244,7 @@ assertCertCounts env expected =
234244
pure (registr - 5, deregistr, deleg - 5, withdrawal)
235245

236246
assertRewardCounts ::
237-
EraCrypto era ~ StandardCrypto =>
247+
(EraCrypto era ~ StandardCrypto) =>
238248
DBSyncEnv ->
239249
LedgerState (ShelleyBlock p era) ->
240250
Bool ->
@@ -468,11 +478,11 @@ poolCountersQuery = do
468478
<$> (select . from $ \(_a :: SqlExpr (Entity PoolRelay)) -> pure countRows)
469479
pure (poolHash, poolMetadataRef, poolUpdate, poolOwner, poolRetire, poolRelay)
470480

471-
addPoolCounters :: Num a => (a, a, a, a, a, a) -> (a, a, a, a, a, a) -> (a, a, a, a, a, a)
481+
addPoolCounters :: (Num a) => (a, a, a, a, a, a) -> (a, a, a, a, a, a) -> (a, a, a, a, a, a)
472482
addPoolCounters (a, b, c, d, e, f) (a', b', c', d', e', f') = (a + a', b + b', c + c', d + d', e + e', f + f')
473483

474484
assertPoolLayerCounters ::
475-
EraCrypto era ~ StandardCrypto =>
485+
(EraCrypto era ~ StandardCrypto) =>
476486
DBSyncEnv ->
477487
(Word64, Word64) ->
478488
[(PoolIndex, (Either DBFail Bool, Bool, Bool))] ->

cardano-db-sync/src/Cardano/DbSync/Config/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import qualified Data.Aeson as Aeson
6868
import Data.Aeson.Types (Parser, typeMismatch)
6969
import Data.ByteString.Short (ShortByteString (), fromShort, toShort)
7070
import Data.Default.Class (Default (..))
71-
import qualified Data.Text as T
71+
import qualified Data.Text as Text
7272
import Ouroboros.Consensus.Cardano.CanHardFork (TriggerHardFork (..))
7373

7474
newtype LogFileDir = LogFileDir
@@ -607,7 +607,7 @@ enableDisableToBool = \case
607607

608608
parseValidateHash :: Text -> Parser ShortByteString
609609
parseValidateHash txt =
610-
if "\\x" `T.isPrefixOf` txt
610+
if "\\x" `Text.isPrefixOf` txt
611611
then fail $ "Invalid Hash: starts with \\x please adjust it: " <> show txt
612612
else pure $ toShort $ encodeUtf8 txt
613613

0 commit comments

Comments
 (0)