Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that an empty wallet can't join a stake pool (no_utxos_available) #4376

Merged
merged 7 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,19 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment
)

externalSelectedUtxo <- extractExternallySelectedUTxO ptx
let utxoSelection =
UTxOSelection.fromIndexPair
(internalUtxoAvailable, externalSelectedUtxo)

when (UTxOSelection.availableSize utxoSelection == 0) $
throwE ErrBalanceTxUnableToCreateInput

let mSel = selectAssets
pp
utxoAssumptions
(F.toList $ partialTx ^. bodyTxL . outputsTxBodyL)
redeemers
(UTxOSelection.fromIndexPair
(internalUtxoAvailable, externalSelectedUtxo))
utxoSelection
balance0
(Convert.toWalletCoin minfee0)
randomSeed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ expectErrorMessage
-> m ()
expectErrorMessage want = either expectation wantedErrorButSuccess . snd
where
expectation msg = fmt msg `shouldContain` want
expectation exception = fmt exception `shouldContain` want
fmt = \case
DecodeFailure res msg -> msg ++ "\n" ++ BL8.unpack res
ClientError val -> BL8.unpack $ Aeson.encode val
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import Test.Integration.Framework.DSL
, emptyWallet
, eventually
, eventuallyUsingDelay
, expectErrorInfo
, expectErrorMessage
, expectField
, expectListField
Expand Down Expand Up @@ -534,6 +535,16 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
expectResponseCode HTTP.status404 r
expectErrorMessage (errMsg404NoSuchPool (toText retiredPoolId)) r

it "STAKE_POOLS_JOIN_EMPTY - Empty wallet cannot join a pool" $ \ctx ->
runResourceT $ do
w <- emptyWallet ctx
pool : _ <- map (view #id) <$> notRetiringPools ctx
r <- joinStakePool @n ctx (SpecificPool pool) (w, fixturePassphrase)
verify r
[ expectResponseCode HTTP.status403
, expectErrorInfo (`shouldBe` NoUtxosAvailable)
]

it "STAKE_POOLS_QUIT_02 - Passphrase must be correct to quit" $ \ctx -> runResourceT $ do
w <- fixtureWallet ctx
pool : _ <- map (view #id) <$> notRetiringPools ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ import Test.Integration.Framework.DSL
, emptyRandomWallet
, emptyWallet
, eventually
, expectErrorInfo
, expectErrorMessage
, expectField
, expectListField
Expand Down Expand Up @@ -917,18 +918,18 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
NotEnoughMoney {} -> True
_someOtherError -> False

it "TRANS_NEW_CREATE_04d - Not enough money emptyWallet" $ \ctx -> runResourceT $ do
it "TRANS_NEW_CREATE_04d - No UTxOs available" $ \ctx -> runResourceT $ do
wa <- emptyWallet ctx
wb <- emptyWallet ctx

payload <- liftIO $ mkTxPayload ctx wb (minUTxOValue (_mainEra ctx)) 1

rTx <- request @(ApiConstructTransaction n) ctx
request @(ApiConstructTransaction n) ctx
(Link.createUnsignedTransaction @'Shelley wa) Default payload
verify rTx [expectResponseCode HTTP.status403]
decodeErrorInfo rTx `shouldSatisfy` \case
NotEnoughMoney {} -> True
_someOtherError -> False
>>= flip verify
[ expectResponseCode HTTP.status403
, expectErrorInfo (`shouldBe` NoUtxosAvailable)
]

it "TRANS_NEW_CREATE_04e- Multiple Output Tx to single wallet" $ \ctx -> runResourceT $ do
wa <- fixtureWallet ctx
Expand Down Expand Up @@ -2368,12 +2369,12 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
\ctx -> runResourceT $ do
wa <- emptyWallet ctx
let balancePayload = Json PlutusScenario.pingPong_1
rTx <- request @ApiSerialisedTransaction ctx
(Link.balanceTransaction @'Shelley wa) Default balancePayload
verify rTx [expectResponseCode HTTP.status403]
decodeErrorInfo rTx `shouldSatisfy` \case
NotEnoughMoney {} -> True
_someOtherError -> False
request @ApiSerialisedTransaction
ctx (Link.balanceTransaction @'Shelley wa) Default balancePayload
>>= flip verify
[ expectResponseCode HTTP.status403
, expectErrorInfo (`shouldBe` NoUtxosAvailable)
]

it "TRANS_NEW_BALANCE_02b - Cannot balance when I cannot afford fee" $
\ctx -> runResourceT $ do
Expand Down
1 change: 1 addition & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ CHaP: haskell-nix: nixpkgs-recent: nodePkgs: haskell-nix.cabalProject' [
pkgconfig
nixpkgs-recent.python3Packages.openapi-spec-validator
(ruby_3_1.withPackages (ps: [ ps.rake ps.thor ]))
rubyPackages_3_1.rubocop
sqlite-interactive
curlFull
jq
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ One can run specific tests using by providing `SPEC` or `SPEC_OPTS` arguments to
```
- run only `non-e2e` tests on downloaded binaries and don't wait for node to be synced
```ruby
$ rake run_on[preprod,bins,no-sync] SPEC_OPTS="-t ~e2e"
$ rake run_on[preprod,no-sync] SPEC_OPTS="-t ~e2e"
```
- run only tests matching specific string
```ruby
$ rake run_on[preprod] SPEC_OPTS="-e 'CardanoWallet::Shelley::Wallets'"
```
- run only specific test identified by line of test code against node and wallet from the `$PATH` (skips downloading from Hydra)
- run only specific test identified by line of test code against node and wallet from the `$PATH` (skips downloading from CI)
```ruby
$ TESTS_E2E_BINDIR="" rake run_on[preprod] SPEC=spec/shelley_spec.rb:9
```
Expand Down
18 changes: 11 additions & 7 deletions test/e2e/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -367,30 +367,34 @@ end
##
# Setup utility task getting node and wallet binaries, configs and decoding fixtures
# so it is ready to start
task :setup, [:env, :branch, :skip_configs] do |_task, args|
task :setup, [:env, :branch, :skip_bins, :skip_configs] do |_task, args|
log '>> Getting latest binaries and configs and decoding fixtures...'
env = args[:env]
branch = args[:branch] || 'master'
skip_configs = args[:skip_configs] || nil

if BINS == ''
if args[:skip_bins]
log '>> Skipping getting latest binaries. Will test wallet and node from $PATH.'
else
Rake::Task[:get_latest_bins].invoke(branch)
end
Rake::Task[:get_latest_configs].invoke(env) unless skip_configs

if args[:skip_configs]
log '>> Skipping getting latest configs.'
else
Rake::Task[:get_latest_configs].invoke(env)
end

Rake::Task[:secrets_decode].invoke
end

task :run_on, [:env, :sync_strategy, :skip_configs, :branch] do |_task, args|
task :run_on, [:env, :sync_strategy, :skip_bins, :skip_configs, :branch] do |_task, args|
log '>> Setting up env and running tests...'
log "TESTS_E2E_STATEDIR=#{STATE}"
env = args[:env]
skip_configs = args[:skip_configs]
sync_strategy = args[:sync_strategy] || :sync
branch = args[:branch] || nil

Rake::Task[:setup].invoke(env, branch, skip_configs)
Rake::Task[:setup].invoke(env, branch, args[:skip_bins], args[:skip_configs])
Rake::Task[:display_versions].invoke
Rake::Task[:start_node_and_wallet].invoke(env)

Expand Down
10 changes: 0 additions & 10 deletions test/e2e/spec/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2880,16 +2880,6 @@ def script_hash
expect(fees.to_s).to include 'no_utxos_available'
end

it 'I could join Stake Pool - if I had enough to cover fee' do
id = create_shelley_wallet
pools = SHELLEY.stake_pools
pool_id = pools.list({ stake: 1000 })[0]['id']

join = pools.join(pool_id, id, PASS)
expect(join).to be_correct_and_respond 403
expect(join.to_s).to include 'no_utxos_available'
end

it 'Can list stake pools only when stake is provided' do
pools = SHELLEY.stake_pools
l = pools.list({ stake: 1000 })
Expand Down
Loading