Skip to content

Commit 2593723

Browse files
sgillespiekderme
authored andcommitted
test(cardano-chain-gen): Add a treasury donation test
1 parent 5340913 commit 2593723

File tree

12 files changed

+102
-41
lines changed

12 files changed

+102
-41
lines changed

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ consTxBody ::
122122
MultiAsset StandardCrypto ->
123123
[ConwayTxCert StandardConway] ->
124124
Withdrawals StandardCrypto ->
125+
Coin ->
125126
ConwayTxBody StandardConway
126-
consTxBody ins cols ref outs colOut fees minted certs withdrawals =
127+
consTxBody ins cols ref outs colOut fees minted certs withdrawals donation =
127128
ConwayTxBody
128129
{ ctbSpendInputs = ins
129130
, ctbCollateralInputs = cols
@@ -143,15 +144,26 @@ consTxBody ins cols ref outs colOut fees minted certs withdrawals =
143144
, ctbVotingProcedures = Governance.VotingProcedures mempty
144145
, ctbProposalProcedures = mempty
145146
, ctbCurrentTreasuryValue = SNothing
146-
, ctbTreasuryDonation = Coin 0
147+
, ctbTreasuryDonation = donation
147148
}
148149

149150
consCertTxBody ::
150151
Maybe (TxIn StandardCrypto) ->
151152
[ConwayTxCert StandardConway] ->
152153
Withdrawals StandardCrypto ->
153154
ConwayTxBody StandardConway
154-
consCertTxBody ref = consTxBody mempty mempty (toSet ref) mempty SNothing (Coin 0) mempty
155+
consCertTxBody ref certs withdrawals =
156+
consTxBody
157+
mempty
158+
mempty
159+
(toSet ref)
160+
mempty
161+
SNothing
162+
(Coin 0)
163+
mempty
164+
certs
165+
withdrawals
166+
(Coin 0)
155167
where
156168
toSet Nothing = mempty
157169
toSet (Just a) = Set.singleton a
@@ -176,19 +188,22 @@ mkPaymentTx ::
176188
ConwayUTxOIndex ->
177189
Integer ->
178190
Integer ->
191+
Integer ->
179192
ConwayLedgerState ->
180193
Either ForgingError (AlonzoTx StandardConway)
181-
mkPaymentTx inputIndex outputIndex amount = mkPaymentTx' inputIndex outputIndices
194+
mkPaymentTx inputIndex outputIndex amount =
195+
mkPaymentTx' inputIndex outputIndices
182196
where
183197
outputIndices = [(outputIndex, valueFromList (Coin amount) [])]
184198

185199
mkPaymentTx' ::
186200
ConwayUTxOIndex ->
187201
[(ConwayUTxOIndex, MaryValue StandardCrypto)] ->
188202
Integer ->
203+
Integer ->
189204
ConwayLedgerState ->
190205
Either ForgingError (AlonzoTx StandardConway)
191-
mkPaymentTx' inputIndex outputIndices fees state' = do
206+
mkPaymentTx' inputIndex outputIndices fees donation state' = do
192207
(inputPair, _) <- resolveUTxOIndex inputIndex state'
193208
outputs <- mapM mkOutputs outputIndices
194209

@@ -212,6 +227,7 @@ mkPaymentTx' inputIndex outputIndices fees state' = do
212227
SNothing
213228
(Coin fees)
214229
mempty
230+
(Coin donation)
215231
where
216232
mkOutputs (outIx, val) = do
217233
addr <- resolveAddress outIx state'
@@ -252,6 +268,7 @@ mkLockByScriptTx inputIndex txOutTypes amount fees state' = do
252268
SNothing
253269
(Coin fees)
254270
mempty
271+
(Coin 0)
255272

256273
mkUnlockScriptTx ::
257274
[ConwayUTxOIndex] ->
@@ -413,6 +430,7 @@ mkMultiAssetsScriptTx inputIx colInputIx outputIx refInput minted succeeds fees
413430
mempty
414431
mempty -- TODO[sgillespie]: minted?
415432
(Withdrawals mempty)
433+
(Coin 0)
416434
where
417435
mkOuts (outIx, val) = do
418436
addr <- resolveAddress outIx state'
@@ -452,6 +470,7 @@ mkDepositTxPools inputIndex deposit state' = do
452470
mempty
453471
(allPoolStakeCert' state')
454472
(Withdrawals mempty)
473+
(Coin 0)
455474

456475
mkRegisterDRepTx ::
457476
Credential 'DRepRole StandardCrypto ->
@@ -588,6 +607,7 @@ mkDummyTxBody =
588607
mempty
589608
mempty
590609
(Withdrawals mempty)
610+
mempty
591611

592612
mkFullTx ::
593613
Int ->
@@ -769,6 +789,7 @@ consPaymentTxBody ::
769789
StrictMaybe (BabbageTxOut StandardConway) ->
770790
Coin ->
771791
MultiAsset StandardCrypto ->
792+
Coin ->
772793
ConwayTxBody StandardConway
773794
consPaymentTxBody ins cols ref outs colOut fees minted =
774795
consTxBody ins cols ref outs colOut fees minted mempty (Withdrawals mempty)
@@ -853,6 +874,7 @@ mkUnlockScriptTx' inputIndex colInputIndex outputIndex refInput colOut succeeds
853874
(maybeToStrictMaybe colOut)
854875
(Coin fees)
855876
mempty
877+
(Coin 0)
856878

857879
allPoolStakeCert' :: ConwayLedgerState -> [ConwayTxCert StandardConway]
858880
allPoolStakeCert' st = map (mkRegTxCert SNothing) (getCreds st)

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway/Scenarios.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mkDelegateBlocks creds interpreter = forgeBlocksChunked interpreter creds $ \txC
7272
mkPaymentBlocks :: UTxOIndex StandardConway -> [Addr StandardCrypto] -> Interpreter -> IO [CardanoBlock]
7373
mkPaymentBlocks utxoIx addresses interpreter =
7474
forgeBlocksChunked interpreter addresses $ \txAddrs ->
75-
Conway.mkPaymentTx' utxoIx (map mkUTxOAddress txAddrs) 0 . unState
75+
Conway.mkPaymentTx' utxoIx (map mkUTxOAddress txAddrs) 0 0 . unState
7676
where
7777
mkUTxOAddress addr = (UTxOAddress addr, MaryValue (Coin 1) mempty)
7878

@@ -110,7 +110,7 @@ registerDRepAndDelegateVotes' drepId stakeIx ledger = do
110110
regDelegCert =
111111
Conway.mkDelegTxCert (DelegVote $ DRepCredential drepId) stakeCreds
112112

113-
paymentTx <- Conway.mkPaymentTx (UTxOIndex 0) utxoStake 10_000 500 ledger
113+
paymentTx <- Conway.mkPaymentTx (UTxOIndex 0) utxoStake 10_000 500 0 ledger
114114
regTx <- Conway.mkRegisterDRepTx drepId
115115
delegTx <- Conway.mkDCertTx [regDelegCert] (Withdrawals mempty) Nothing
116116

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Cardano.Mock.Query (
1111
queryGovActionCounts,
1212
queryConstitutionAnchor,
1313
queryRewardRests,
14+
queryTreasuryDonations,
1415
) where
1516

1617
import qualified Cardano.Db as Db
@@ -150,3 +151,14 @@ queryRewardRests = do
150151
pure (reward ^. Db.RewardRestType, reward ^. Db.RewardRestAmount)
151152

152153
pure $ map (bimap unValue (Db.unDbLovelace . unValue)) res
154+
155+
queryTreasuryDonations ::
156+
MonadIO io =>
157+
ReaderT SqlBackend io Word64
158+
queryTreasuryDonations = do
159+
res <- selectOne $ do
160+
txs <- from $ table @Db.Tx
161+
pure $ sum_ (txs ^. Db.TxTreasuryDonation)
162+
163+
let total = join (unValue <$> res)
164+
pure $ maybe 0 Db.unDbLovelace total

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
@@ -109,6 +109,7 @@ unitTests iom knownMigrations =
109109
[ test "simple tx" Tx.addSimpleTx
110110
, test "simple tx in Shelley era" Tx.addSimpleTxShelley
111111
, test "simple tx with ledger disabled" Tx.addSimpleTxNoLedger
112+
, test "tx with treasury donation" Tx.addTxTreasuryDonation
112113
, test "consume utxo same block" Tx.consumeSameBlock
113114
, test "tx with metadata" Tx.addTxMetadata
114115
, test "tx with metadata disabled" Tx.addTxMetadataDisabled

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ checkEpochDisabledArg =
2626
-- Add two blocks with transactions
2727
void $
2828
withConwayFindLeaderAndSubmitTx interpreter mockServer $
29-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
29+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
3030
void $
3131
withConwayFindLeaderAndSubmitTx interpreter mockServer $
32-
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000
32+
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000 0
3333
-- Add some more empty blocks
3434
void $ forgeAndSubmitBlocks interpreter mockServer 60
3535

@@ -50,10 +50,10 @@ checkEpochEnabled =
5050
-- Add two blocks with transactions
5151
void $
5252
withConwayFindLeaderAndSubmitTx interpreter mockServer $
53-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
53+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
5454
void $
5555
withConwayFindLeaderAndSubmitTx interpreter mockServer $
56-
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000
56+
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000 0
5757
-- Add some more empty blocks
5858
void $ forgeAndSubmitBlocks interpreter mockServer 60
5959

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ txConsumedColumnCheck ioManager names = do
4545

4646
void $
4747
withConwayFindLeaderAndSubmitTx interpreter mockServer $
48-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500
48+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500 0
4949

5050
assertBlockNoBackoff dbSync 1
5151
assertEqQuery
@@ -79,10 +79,10 @@ basicPrune = do
7979
-- Add blocks with transactions
8080
void $
8181
withConwayFindLeaderAndSubmitTx interpreter mockServer $
82-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
82+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
8383
void $
8484
withConwayFindLeaderAndSubmitTx interpreter mockServer $
85-
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000
85+
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000 0
8686

8787
-- Check tx-out count before pruning
8888
assertBlockNoBackoff dbSync (fullBlockSize blks)
@@ -118,10 +118,10 @@ pruneWithSimpleRollback =
118118
-- Create some payment transactions
119119
void $
120120
withConwayFindLeaderAndSubmitTx interpreter mockServer $
121-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
121+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
122122
void $
123123
withConwayFindLeaderAndSubmitTx interpreter mockServer $
124-
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000
124+
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000 0
125125
assertEqQuery dbSync DB.queryTxOutCount 14 ""
126126

127127
-- Submit some blocks
@@ -196,10 +196,10 @@ pruningShouldKeepSomeTx ioManager names = do
196196
-- blocks so should not be pruned
197197
void $
198198
withConwayFindLeaderAndSubmitTx interpreter mockServer $
199-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
199+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
200200
void $
201201
withConwayFindLeaderAndSubmitTx interpreter mockServer $
202-
Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 10_000
202+
Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 10_000 0
203203
blk2 <- forgeAndSubmitBlocks interpreter mockServer 18
204204
-- Verify the two transactions above weren't pruned
205205
assertBlockNoBackoff dbSync (fromIntegral $ length (blk1 <> blk2) + 2)
@@ -243,12 +243,12 @@ pruneAndRollBackOneBlock =
243243
-- blocks so should not be pruned
244244
void $
245245
withConwayFindLeaderAndSubmitTx interpreter mockServer $
246-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
246+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
247247
-- Create a block to rollback to
248248
blk100 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
249249
state' <- getConwayLedgerState interpreter
250250
-- Add some more blocks
251-
let tx1 = Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 500 state'
251+
let tx1 = Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 500 0 state'
252252
void $ withConwayFindLeaderAndSubmit interpreter mockServer (\_ -> sequence [tx1])
253253
-- Verify the last 2 transactions weren't pruned
254254
assertBlockNoBackoff dbSync 101
@@ -284,12 +284,12 @@ noPruneAndRollBack =
284284
-- Add a block with transactions
285285
void $
286286
withConwayFindLeaderAndSubmitTx interpreter mockServer $
287-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
287+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
288288
-- Create a block to rollback to
289289
blk100 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
290290
-- Add some more blocks
291291
state' <- getConwayLedgerState interpreter
292-
let tx1 = Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 500 state'
292+
let tx1 = Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 500 0 state'
293293
void $ withConwayFindLeaderAndSubmit interpreter mockServer $ \_ -> sequence [tx1]
294294

295295
-- Verify the transactions weren't pruned
@@ -326,9 +326,9 @@ pruneSameBlock =
326326
blk77 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
327327
-- Add a block with transactions
328328
void $ withConwayFindLeaderAndSubmit interpreter mockServer $ \state' -> do
329-
tx0 <- Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 20_000 20_000 state'
329+
tx0 <- Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 20_000 20_000 0 state'
330330
let utxo0 = Prelude.head (Conway.mkUTxOConway tx0)
331-
tx1 <- Conway.mkPaymentTx (UTxOPair utxo0) (UTxOIndex 2) 10_000 500 state'
331+
tx1 <- Conway.mkPaymentTx (UTxOPair utxo0) (UTxOIndex 2) 10_000 500 0 state'
332332
pure [tx0, tx1]
333333
-- Verify the transactions weren't pruned
334334
assertBlockNoBackoff dbSync 78
@@ -365,9 +365,9 @@ noPruneSameBlock =
365365
blk97 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
366366
-- Add a block with transactions
367367
void $ withConwayFindLeaderAndSubmit interpreter mockServer $ \state' -> do
368-
tx0 <- Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 20_000 20_000 state'
368+
tx0 <- Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 20_000 20_000 0 state'
369369
let utxo0 = Prelude.head (Conway.mkUTxOConway tx0)
370-
tx1 <- Conway.mkPaymentTx (UTxOPair utxo0) (UTxOIndex 2) 10_000 500 state'
370+
tx1 <- Conway.mkPaymentTx (UTxOPair utxo0) (UTxOIndex 2) 10_000 500 0 state'
371371
pure [tx0, tx1]
372372
-- Add some more empty blocks
373373
void $ forgeAndSubmitBlocks interpreter mockServer 2

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ forkFixedEpoch =
401401
-- Add a simple Conway tx
402402
void $
403403
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
404-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500
404+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500 0
405405
-- Fill the rest of the epoch
406406
epochs1 <- Api.fillUntilNextEpoch interpreter mockServer
407407

@@ -429,7 +429,7 @@ rollbackFork =
429429
-- Forge a Conway tx
430430
blk <-
431431
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
432-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500
432+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500 0
433433

434434
-- Wait for it to sync
435435
assertBlockNoBackoff dbSync $ 2 + length (epoch0 <> epoch1 <> epoch1')
@@ -490,7 +490,7 @@ forkParam =
490490
-- Add a simple Conway tx
491491
void $
492492
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
493-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500
493+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500 0
494494
-- Wait for it to sync
495495
assertBlockNoBackoff dbSync $ 2 + length (epoch0 <> epoch1)
496496
where

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ simpleRewards =
3232
-- create any rewards
3333
void $
3434
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
35-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 1000 1000
35+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 1000 1000 0
3636
-- Fill up epochs
3737
epochs <- Api.fillEpochs interpreter mockServer 3
3838

@@ -56,7 +56,7 @@ simpleRewards =
5656
-- distributed
5757
void $
5858
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
59-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
59+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
6060
-- Fill more epochs
6161
epochs' <- Api.fillEpochs interpreter mockServer 2
6262
-- Wait for it to sync
@@ -153,7 +153,7 @@ rollbackBoundary =
153153
-- Forge a transaction to distribute rewards
154154
void $
155155
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
156-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
156+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000 0
157157
-- Create a point to rollback to
158158
blks <- Api.forgeAndSubmitBlocks interpreter mockServer 50
159159
-- Fill up the rest of the epoch

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ rollbackChangeTxOrder =
240240

241241
-- Create some transactions
242242
state' <- getConwayLedgerState interpreter
243-
let tx0 = Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500 state'
244-
tx1 = Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 500 state'
245-
tx2 = Conway.mkPaymentTx (UTxOIndex 4) (UTxOIndex 5) 10_000 500 state'
243+
let tx0 = Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500 0 state'
244+
tx1 = Conway.mkPaymentTx (UTxOIndex 2) (UTxOIndex 3) 10_000 500 0 state'
245+
tx2 = Conway.mkPaymentTx (UTxOIndex 4) (UTxOIndex 5) 10_000 500 0 state'
246246
-- Submit them
247247
void $ withConwayFindLeaderAndSubmit interpreter mockServer $ \_ ->
248248
sequence [tx0, tx1]

0 commit comments

Comments
 (0)