Skip to content

Commit

Permalink
Merge pull request #4646 from IntersectMBO/td/fix-empty-withdrawals-p…
Browse files Browse the repository at this point in the history
…red-failure

Don't return `ZeroTreasuryWithdrawals` failure during bootstrap
  • Loading branch information
lehins authored Sep 25, 2024
2 parents c051be1 + 9f66649 commit ed804de
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
6 changes: 4 additions & 2 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Gov.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
import Cardano.Ledger.Shelley.PParams (pvCanFollow)
import Cardano.Ledger.TxIn (TxId (..))
import Control.DeepSeq (NFData)
import Control.Monad (unless)
import Control.Monad.Trans.Reader (asks)
import Control.State.Transition.Extended (
STS (..),
Expand Down Expand Up @@ -467,8 +468,9 @@ govTransition = do
-- Policy check
runTest $ checkPolicy @era constitutionPolicy proposalPolicy

-- The sum of all withdrawals must be positive
F.fold wdrls /= mempty ?! ZeroTreasuryWithdrawals pProcGovAction
unless (HF.bootstrapPhase (pp ^. ppProtocolVersionL)) $
-- The sum of all withdrawals must be positive
F.fold wdrls /= mempty ?! ZeroTreasuryWithdrawals pProcGovAction
UpdateCommittee _mPrevGovActionId membersToRemove membersToAdd _qrm -> do
checkConflictingUpdate
checkExpirationEpoch
Expand Down
68 changes: 33 additions & 35 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/GovSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ spec = do
proposalsWithVotingSpec
votingSpec
policySpec
withdrawalsSpec
predicateFailuresSpec
unknownCostModelsSpec

Expand All @@ -70,6 +69,7 @@ relevantDuringBootstrapSpec ::
) =>
SpecWith (ImpTestState era)
relevantDuringBootstrapSpec = do
withdrawalsSpec
hardForkSpec
pparamUpdateSpec
proposalsSpec
Expand Down Expand Up @@ -1154,55 +1154,53 @@ withdrawalsSpec ::
withdrawalsSpec =
describe "Withdrawals" $ do
it "Fails with invalid network ID in withdrawal addresses" $ do
rewardAccount <- registerRewardAccount
rewardCredential <- KeyHashObj <$> freshKeyHash
let badRewardAccount =
RewardAccount
{ raNetwork = Mainnet -- Our network is Testnet
, raCredential = rewardCredential
}
propDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppGovActionDepositL
submitFailingProposal
ProposalProcedure
{ pProcReturnAddr = rewardAccount
, pProcGovAction =
TreasuryWithdrawals
(Map.singleton badRewardAccount $ Coin 100_000_000)
SNothing
, pProcDeposit = propDeposit
, pProcAnchor = def
}
[ injectFailure $
TreasuryWithdrawalsNetworkIdMismatch
(Set.singleton badRewardAccount)
Testnet
]
wdrls = TreasuryWithdrawals (Map.singleton badRewardAccount $ Coin 100_000_000) SNothing
idMismatch = TreasuryWithdrawalsNetworkIdMismatch (Set.singleton badRewardAccount) Testnet
expectPredFailures [idMismatch] [idMismatch] wdrls

it "Fails for empty withdrawals" $ do
rwdAccount1 <- freshKeyHash >>= getRewardAccountFor . KeyHashObj
rwdAccount2 <- freshKeyHash >>= getRewardAccountFor . KeyHashObj
let wdrl = TreasuryWithdrawals Map.empty SNothing
in submitFailingGovAction
wdrl
[injectFailure $ ZeroTreasuryWithdrawals wdrl]
let wdrls = TreasuryWithdrawals Map.empty SNothing
in expectPredFailures [ZeroTreasuryWithdrawals wdrls] [] wdrls

let wdrl = TreasuryWithdrawals [(rwdAccount1, zero)] SNothing
in submitFailingGovAction
wdrl
[injectFailure $ ZeroTreasuryWithdrawals wdrl]
let wdrls = TreasuryWithdrawals [(rwdAccount1, zero)] SNothing
in expectPredFailures [ZeroTreasuryWithdrawals wdrls] [] wdrls

let wdrl = TreasuryWithdrawals [(rwdAccount1, zero), (rwdAccount2, zero)] SNothing
in submitFailingGovAction
wdrl
[injectFailure $ ZeroTreasuryWithdrawals wdrl]
let wdrls = TreasuryWithdrawals [(rwdAccount1, zero), (rwdAccount2, zero)] SNothing
in expectPredFailures [ZeroTreasuryWithdrawals wdrls] [] wdrls

rwdAccountRegistered <- registerRewardAccount
let wdrl = TreasuryWithdrawals [(rwdAccountRegistered, zero)] SNothing
in submitFailingGovAction
wdrl
[injectFailure $ ZeroTreasuryWithdrawals wdrl]
let wdrls = TreasuryWithdrawals [(rwdAccountRegistered, zero)] SNothing
in expectPredFailures [ZeroTreasuryWithdrawals wdrls] [] wdrls

void $ submitTreasuryWithdrawals [(rwdAccount1, zero), (rwdAccount2, Coin 100000)]
curProtVer <- getProtVer
let wdrls = [(rwdAccount1, zero), (rwdAccount2, Coin 100000)]
ga = TreasuryWithdrawals (Map.fromList wdrls) SNothing
in if HF.bootstrapPhase curProtVer
then do
expectPredFailures [] [] ga
else void $ submitTreasuryWithdrawals wdrls
where
expectPredFailures ::
[ConwayGovPredFailure era] -> [ConwayGovPredFailure era] -> GovAction era -> ImpTestM era ()
expectPredFailures predFailures bootstrapPredFailures wdrl = do
curProtVer <- getProtVer
propP <- proposalWithRewardAccount wdrl
submitFailingProposal
propP
( injectFailure
<$> ( if HF.bootstrapPhase curProtVer
then DisallowedProposalDuringBootstrap propP NE.:| bootstrapPredFailures
else NE.fromList predFailures
)
)

proposalWithRewardAccount ::
forall era.
Expand Down

0 comments on commit ed804de

Please sign in to comment.