Skip to content

Commit a85b648

Browse files
committed
Add test for ada pots
1 parent c8e4281 commit a85b648

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ unitTests iom knownMigrations =
130130
, test "basic pool stats functionality" Rollback.poolStatBasicTest
131131
, test "pool stat rollback no duplicates" Rollback.poolStatRollbackNoDuplicates
132132
, test "pool stat rollback general" Rollback.poolStatRollbackGeneral
133+
, test "ada pots max supply and rollback" Rollback.adaPots
133134
]
134135
, testGroup
135136
"different configs"

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Test.Cardano.Db.Mock.Unit.Conway.Rollback (
1919
poolStatBasicTest,
2020
poolStatRollbackNoDuplicates,
2121
poolStatRollbackGeneral,
22+
adaPots,
2223
) where
2324

2425
import qualified Cardano.Db as DB
@@ -484,3 +485,33 @@ poolStatRollbackGeneral =
484485
where
485486
args = initCommandLineArgs {claFullMode = False}
486487
testLabel = "conwayPoolStatRollbackGeneral"
488+
489+
adaPots :: IOManager -> [(Text, Text)] -> Assertion
490+
adaPots =
491+
withFullConfigDropDB "config-conway-rewards-rho" testLabel $ \interpreter mockServer dbSync -> do
492+
startDBSync dbSync
493+
blks0 <- fillEpochs interpreter mockServer 3
494+
blks1 <- forgeAndSubmitBlocks interpreter mockServer 70
495+
assertBlockNoBackoff dbSync $ length blks0 + 70
496+
blks2 <- fillEpochs interpreter mockServer 1
497+
assertBlockNoBackoff dbSync $ length blks0 + 70 + length blks2
498+
499+
potsPerEpoch0 <- queryDBSync dbSync DB.queryAdaPotsAll
500+
assertEqual "Ada pots don't match" [(1, 60_000_000), (2, 60_000_000), (3, 60_000_000), (4, 60_000_000)] potsPerEpoch0
501+
502+
-- Rollback to previous point
503+
rollbackTo interpreter mockServer (blockPoint $ last blks1)
504+
void $
505+
withConwayFindLeaderAndSubmitTx interpreter mockServer $ \_ ->
506+
Right $ Conway.mkDonationTx (Coin 500)
507+
assertBlockNoBackoff dbSync $ length blks0 + 70 + 1
508+
509+
potsPerEpoch1 <- queryDBSync dbSync DB.queryAdaPotsAll
510+
assertEqual "Ada pots don't match" [(1, 60_000_000), (2, 60_000_000), (3, 60_000_000)] potsPerEpoch1
511+
512+
blks3 <- fillEpochs interpreter mockServer 1
513+
assertBlockNoBackoff dbSync $ length blks0 + 70 + 1 + length blks3
514+
potsPerEpoch2 <- queryDBSync dbSync DB.queryAdaPotsAll
515+
assertEqual "Ada pots don't match" [(1, 60_000_000), (2, 60_000_000), (3, 60_000_000), (4, 60_000_000)] potsPerEpoch2
516+
where
517+
testLabel = "adaPots"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[5,12,19,39,44,49,54,56,59,77,86,89,91,93,98,100,106,110,121,126,128,130,140,158,161,163,164,166,170,171,176,180,185,186,196,198,213,231,236,237,243,244,248,262,264,274,283,284,286,293,298,299,305,310,316,332,338,340,343,344,346,347,348,357,358,362,363,370,374,386,387,393,396,402,413,415,416,420,429,433,436,441,442,450,455,460,477,478,479,480,485,486,492,493,496,504,505,506,514,521,531,536,557,558,559,560,568,569,576,582,589,603,605,609,613,618,621,623,627,632,634,645,656,660,662,666,673,674,678,679,695,696,699,710,717,718,720,730,732,738,745,752,762,764,769,773,775,780,782,788,791,804,809,814,815,816,818,840,842,845,849,854,857,858,862,864,877,881,888,890,897,901,904,907,950,953,957,960,965,966,970,978,980,994,997,1006,1019,1021,1043,1045,1054,1056,1057,1061,1069,1071,1074,1075,1076,1079,1080,1082,1089,1091,1097,1118,1120,1123,1129,1130,1144,1147,1150,1156,1176,1177,1179,1183,1205,1206,1209,1219,1220,1223,1232,1235,1238,1249,1250,1253,1255,1266,1269,1274,1275,1284,1290,1292,1293,1295,1303,1307,1313,1319,1335,1337,1341,1353,1355,1360,1369,1372,1386,1390,1401,1402,1416,1418,1424,1446,1452,1453,1454,1466,1475,1486,1488,1490,1495,1496,1498,1499,1503,1511,1518,1523,1524,1528,1533,1537,1549,1551,1556,1563,1564,1569,1570,1575,1579,1596,1601,1614,1615,1626,1631,1633,1642,1656,1664,1674,1676,1682,1684,1689,1696,1700,1704,1706,1707,1710,1717,1719,1722,1724,1728,1729,1734,1735,1740,1746,1755,1757,1768,1771,1776,1786,1793,1794,1809,1812,1821,1825,1831,1834,1835,1846,1850,1853,1857,1862,1879,1884,1887,1894,1898,1903,1905,1908,1910,1912,1916,1917,1925,1932,1946,1951,1953,1957,1961,1963,1964,1966,1970,1975,1979,1986,1987,1990,1993,2015,1894,1898,1903,1905,1908,1910,1912,1916,1917,1925,1932,1946,1951,1953,1957,1961,1963,1964,1966,1970,1975,1979,1986,1987,1990,1993,2015]

cardano-db/src/Cardano/Db/Statement/EpochAndProtocol.hs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module Cardano.Db.Statement.EpochAndProtocol where
66

7-
import Cardano.Prelude (Word64)
7+
import Cardano.Prelude (Int64, Proxy (..), Word64)
88
import Data.Functor.Contravariant ((>$<))
99
import qualified Data.Text as Text
1010
import qualified Data.Text.Encoding as TextEnc
@@ -22,7 +22,7 @@ import Cardano.Db.Schema.Types (utcTimeAsTimestampDecoder)
2222
import Cardano.Db.Statement.Function.Core (ResultType (..), runSession, runSessionEntity)
2323
import Cardano.Db.Statement.Function.Insert (insert, insertCheckUnique, insertReplace)
2424
import Cardano.Db.Statement.Function.Query (countAll, replace, selectByFieldFirst)
25-
import Cardano.Db.Statement.Types (Entity (..))
25+
import Cardano.Db.Statement.Types (Entity (..), tableName)
2626
import Cardano.Db.Types (DbLovelace (..), DbM)
2727

2828
--------------------------------------------------------------------------------
@@ -341,6 +341,47 @@ insertPotTransfer :: SEnP.PotTransfer -> DbM Id.PotTransferId
341341
insertPotTransfer potTransfer =
342342
runSession mkDbCallStack $ HsqlSes.statement potTransfer insertPotTransferStmt
343343

344+
--------------------------------------------------------------------------------
345+
-- AdaPots
346+
--------------------------------------------------------------------------------
347+
queryAdaPotsAllStmt :: HsqlStmt.Statement () [(Int64, Int64)]
348+
queryAdaPotsAllStmt =
349+
HsqlStmt.Statement sql encoder decoder True
350+
where
351+
adaPotsTable = tableName (Proxy @SEnP.AdaPots)
352+
353+
sql =
354+
TextEnc.encodeUtf8 $
355+
Text.concat
356+
[ "SELECT "
357+
, " epoch_no, "
358+
, " ( treasury "
359+
, " + reserves "
360+
, " + rewards "
361+
, " + utxo "
362+
, " + deposits_stake "
363+
, " + deposits_drep "
364+
, " + deposits_proposal "
365+
, " + fees "
366+
, " )::bigint "
367+
, "FROM "
368+
, adaPotsTable
369+
, " ORDER BY epoch_no"
370+
]
371+
372+
encoder = mempty
373+
374+
decoder =
375+
HsqlD.rowList $
376+
(,)
377+
<$> HsqlD.column (HsqlD.nonNullable HsqlD.int8) -- epoch_no
378+
<*> HsqlD.column (HsqlD.nonNullable HsqlD.int8) -- computed total
379+
380+
queryAdaPotsAll :: DbM [(Int64, Int64)]
381+
queryAdaPotsAll =
382+
runSession mkDbCallStack $
383+
HsqlSes.statement () queryAdaPotsAllStmt
384+
344385
--------------------------------------------------------------------------------
345386
-- Reserve
346387
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)