Skip to content

Commit

Permalink
Enable "certificate" tests in Conway
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Feb 19, 2024
1 parent 937dda9 commit d6a69e4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,7 @@ selectCoins ctx@ApiLayer {..} argGenChange (ApiT walletId) body = do
let txCtx = defaultTransactionCtx
{ txWithdrawal = withdrawal
, txMetadata = getApiT <$> body ^. #metadata
, txDeposit = Just $ W.getStakeKeyDeposit pp
}

(tx, walletState) <-
Expand Down Expand Up @@ -4017,6 +4018,7 @@ joinStakePool
SpecificPool pool -> pure pool
poolStatus <- liftIO (getPoolStatus poolId)
pools <- liftIO knownPools
pp <- liftIO $ NW.currentProtocolParameters netLayer
withWorkerCtx ctx walletId liftE liftE $ \wrk -> do
let tr = wrk ^. logger
db = wrk ^. typed @(DBLayer IO s)
Expand All @@ -4036,11 +4038,11 @@ joinStakePool
ti
db
currentEpochSlotting
(W.stakeKeyDeposit pp)
pools
poolId
poolStatus

pp <- liftIO $ NW.currentProtocolParameters netLayer
mkApiTransaction ti wrk #pendingSince
MkApiTransactionParams
{ txId = builtTx ^. #txId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_JOIN_01rewards - \
\Can join a pool, earn rewards and collect them"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
src <- fixtureWallet ctx
dest <- emptyWallet ctx
let deposit = depositAmt ctx
Expand Down Expand Up @@ -399,27 +398,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
(`shouldBe` walletRewards)
]

-- Listing stake keys shows
request @(ApiStakeKeys n) ctx (Link.listStakeKeys src) Default Empty
>>= flip
verify
[ expectField (#_foreign) (`shouldBe` [])
, expectField
(#_ours)
( \case
[acc] -> do
(acc ^. #_stake) .> ApiAmount 0
acc
^. (#_delegation . #active . #status)
`shouldBe` Delegating
acc
^. (#_delegation . #active . #target)
`shouldBe` (Just (ApiT pool))
_ -> expectationFailure "wrong number of accounts in \"ours\""
)
, expectField (#_none . #_stake) (.> ApiAmount 0)
]

-- there's currently no withdrawals in the wallet
rw1 <-
request @[ApiTransaction n]
Expand Down Expand Up @@ -597,7 +575,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_JOIN_02 - \
\Cannot join already joined stake pool"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWallet ctx
pool : _ <- map (view #id) <$> notRetiringPools ctx

Expand Down Expand Up @@ -636,7 +613,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do

it "STAKE_POOLS_JOIN_EMPTY - Empty wallet cannot join a pool" $ \ctx ->
runResourceT $ do
noConway ctx "certificate"
w <- emptyWallet ctx
pool : _ <- map (view #id) <$> notRetiringPools ctx
r <- joinStakePool @n ctx (SpecificPool pool) (w, fixturePassphrase)
Expand All @@ -647,7 +623,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
]

it "STAKE_POOLS_QUIT_02 - Passphrase must be correct to quit" $ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWallet ctx
pool : _ <- map (view #id) <$> notRetiringPools ctx

Expand Down Expand Up @@ -702,7 +677,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
]

it "STAKE_POOLS_JOIN_01 - Can rejoin another stakepool" $ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWallet ctx

-- make sure we are at the beginning of new epoch
Expand Down Expand Up @@ -759,7 +733,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
[expectField #delegation (`shouldBe` delegating (ApiT pool2) [])]

it "STAKE_POOLS_JOIN_04 - Rewards accumulate" $ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWallet ctx
pool : _ <- map (view #id) <$> notRetiringPools ctx

Expand Down Expand Up @@ -794,7 +767,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_JOIN_05 - \
\Can join when stake key already exists"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
preregKeyWallet <- liftIO $ preregKeyWalletMnemonic (_faucet ctx)

let payload =
Expand Down Expand Up @@ -824,7 +796,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do

describe "STAKE_POOLS_JOIN_UNSIGNED_01" $ do
it "Can join a pool that's not retiring" $ \ctx -> runResourceT $ do
noConway ctx "certificate"
nonRetiredPools <- eventually "One of the pools should retire." $ do
response <- listPools ctx arbitraryStake

Expand Down Expand Up @@ -881,7 +852,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
describe "STAKE_POOLS_JOIN_UNSIGNED_02"
$ it "Can join a pool that's retiring"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
nonRetiredPools <- eventually "One of the pools should retire." $ do
response <- listPools ctx arbitraryStake

Expand Down Expand Up @@ -981,7 +951,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_QUIT_UNSIGNED_01 - \
\Join/quit when already joined a pool"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWallet ctx

pool1 : pool2 : _ <- map (view #id) <$> notRetiringPools ctx
Expand Down Expand Up @@ -1061,7 +1030,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_JOIN_01x - \
\I can join if I have just the right amount"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWalletWith @n ctx [costOfJoining ctx + depositAmt ctx]
pool : _ <-
map (view #id . getApiT) . snd
Expand All @@ -1081,7 +1049,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_JOIN_01x - \
\I cannot join if I have not enough fee to cover"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
w <- fixtureWalletWith @n ctx [costOfJoining ctx + depositAmt ctx - 1]
pool : _ <-
map (view #id . getApiT) . snd
Expand All @@ -1101,7 +1068,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_QUIT_01xx - \
\I can quit if I have enough to cover fee"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
-- change needed to satisfy minUTxOValue
let initBalance =
[ costOfJoining ctx
Expand Down Expand Up @@ -1211,7 +1177,6 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
"STAKE_POOLS_QUIT_01x - \
\I cannot quit if I have not enough to cover fees"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
let initBalance = [costOfJoining ctx + depositAmt ctx]
w <- fixtureWalletWith @n ctx initBalance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,6 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
foldM_ runStep txid steps

it "TRANS_NEW_JOIN_01a - Can join stakepool, rejoin another and quit" $ \ctx -> runResourceT $ do
noConway ctx "certificate"
let initialAmt = 10 * minUTxOValue (_mainEra ctx)
src <- fixtureWalletWith @n ctx [initialAmt]
dest <- emptyWallet ctx
Expand Down Expand Up @@ -3373,7 +3372,6 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

it "TRANS_NEW_JOIN_02 - Can join stakepool in case I have many UTxOs on 1 address"
$ \ctx -> runResourceT $ do
noConway ctx "certificate"
let amt = minUTxOValue (_mainEra ctx)
src <- emptyWallet ctx
wa <- fixtureWallet ctx
Expand Down
2 changes: 2 additions & 0 deletions lib/wallet/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,8 @@ delegationFee db@DBLayer{..} netLayer changeAddressGen = do
feePercentiles <- transactionFee
db protocolParams timeTranslation changeAddressGen
defaultTransactionCtx
{ txDeposit = Just $ toWallet $ Write.stakeKeyDeposit protocolParams
}
-- It would seem that we should add a delegation action
-- to the partial tx we construct, this was not done
-- previously, and the difference should be negligible.
Expand Down
7 changes: 6 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import Cardano.Wallet.Transaction
, Withdrawal (..)
, defaultTransactionCtx
, txDelegationAction
, txDeposit
, txValidityInterval
, txWithdrawal
)
Expand Down Expand Up @@ -210,11 +211,12 @@ joinStakePool
-> TimeInterpreter (ExceptT PastHorizonException IO)
-> DBLayer IO s
-> CurrentEpochSlotting
-> Coin
-> Set PoolId
-> PoolId
-> PoolLifeCycleStatus
-> IO TransactionCtx
joinStakePool tr ti db currentEpochSlotting pools poolId poolStatus = do
joinStakePool tr ti db currentEpochSlotting deposit pools poolId poolStatus = do
action <- joinStakePoolDelegationAction
tr
db
Expand All @@ -227,6 +229,7 @@ joinStakePool tr ti db currentEpochSlotting pools poolId poolStatus = do
{ txWithdrawal = NoWithdrawal
, txValidityInterval = (Nothing, ttl)
, txDelegationAction = Just action
, txDeposit = Just deposit
}

guardJoin
Expand Down Expand Up @@ -276,12 +279,14 @@ quitStakePool netLayer db timeInterpreter = do
withdrawal <- WithdrawalSelf rewardAccount derivationPath
<$> getCachedRewardAccountBalance netLayer rewardAccount
currentEpochSlotting <- getCurrentEpochSlotting netLayer
pp <- currentProtocolParameters netLayer
action <- quitStakePoolDelegationAction db currentEpochSlotting withdrawal
ttl <- transactionExpirySlot timeInterpreter Nothing
pure defaultTransactionCtx
{ txWithdrawal = withdrawal
, txValidityInterval = (Nothing, ttl)
, txDelegationAction = Just action
, txDeposit = Just $ W.stakeKeyDeposit pp
}

guardQuit :: WalletDelegation -> Withdrawal -> Coin -> Either ErrCannotQuit ()
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ mkTransaction era networkId keyF stakeCreds addrResolver ctx cs = do
Just action ->
let stakeXPub = toXPub $ fst stakeCreds
in certificateFromDelegationAction era (Left stakeXPub)
Nothing action
(view #txDeposit ctx) action
let wdrls = mkWithdrawals networkId wdrl
unsigned <-
mkUnsignedTx
Expand Down

0 comments on commit d6a69e4

Please sign in to comment.