Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[CBR-366] Adding test for partial getters #3469

Merged

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Aug 24, 2018

Description

Adding test for partial getters

Linked issue

https://iohk.myjetbrains.com/youtrack/issue/CBR-366

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • If my code deals with exceptions, it follows the guidelines.
  • I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.
  • CHANGELOG entry has been added and is linked to the correct PR on GitHub.

Testing checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.

QA Steps

Unit tests:
stack test --ta "-m GetAccountBalance" cardano-sl-wallet-new:wallet-unit-tests
stack test --ta "-m GetAccountAddresses" cardano-sl-wallet-new:wallet-unit-tests
Integration tests:
nix-build release.nix -A tests.walletIntegration

Screenshots (if available)

@paweljakubas paweljakubas requested review from edsko and KtorZ August 24, 2018 00:01
Copy link
Contributor

@edsko edsko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but just to confirm-- did you manage to have an account with a non-zero balance?

@paweljakubas
Copy link
Contributor Author

yes, in the integration test added the following is taken place:

  1. Genesis wallet and random wallet with 5 accounts are created
  2. Balances as obtained by getAccounts and by getAccountBalances are compared (here zero balances)
  3. Money is transferred from genesis wallet to random wallet's accounts
  4. delayThread is adopted to confirm transactions in the blockchain
  5. Point 2 is repeated, this time for accounts with nonzero balances

@edsko
Copy link
Contributor

edsko commented Aug 24, 2018

Money is transferred from genesis wallet to random wallet's accounts

You mean in wallet-new/integration/AccountSpecs.hs right?

@paweljakubas
Copy link
Contributor Author

paweljakubas commented Aug 24, 2018

yes this is the fragment responsible:

let payment amount toAddr = Payment
{ pmtSource = PaymentSource
{ psWalletId = walId genesis
, psAccountIndex = accIndex fromAcct
}
, pmtDestinations = pure PaymentDistribution
{ pdAddress = addrId toAddr
, pdAmount = V1 (Core.mkCoin amount)
}
, pmtGroupingPolicy = Nothing
, pmtSpendingPassword = Nothing
}
amounts <- generate $ shuffle [1..5]
let addrAndAmount = zip (map (\(addr : _) -> addr) $ map accAddresses accs) amounts
forM_ addrAndAmount $ \(addr, amount) ->
postTransaction wc (payment amount addr)

@edsko
Copy link
Contributor

edsko commented Aug 24, 2018

Ok, sounds good. Ideally we'd modify the wallet tests themselves to be able to do something similar, perhaps hook it up to our blockchain infrastructure, but for now, this will do just fine :) Thanks!

@KtorZ KtorZ changed the base branch from develop to develop-new August 24, 2018 07:42
Copy link
Contributor

@KtorZ KtorZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @paweljakubas 👍

randomNewAccount <- forM [1..4] $ \(_i :: Int) ->
generate arbitrary :: IO NewAccount
forM_ randomNewAccount $ \(rAcc :: NewAccount) ->
postAccount wc (walId wallet) rAcc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a side note but this is a good use-case for >>=. The 4 lines above can be expressed as:

forM_ [1..4] $ \_ -> generate arbitrary >>= postAccount wc (walId wallet)

balancesPartialUpdated <-
mapM (\resp -> wrData <$> resp `shouldPrism` _Right) balancesPartialUpdatedResp'

map (AccountBalance . accAmount) accsUpdated `shouldBe` balancesPartialUpdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why 5 accounts and not only one 😄 ?

Left (WalletLayer.GetAccountError (V1 (Kernel.UnknownHdAccount _))) ->
return ()
Left unexpectedErr ->
fail $ "expecting different failure than " <> show unexpectedErr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Right accs -> (map V1.accAddresses $ API.wrData accs)
`shouldBe`
(map (\(Right bal) -> (V1.acaAddresses . API.wrData) bal) partialAddresses)
Left err -> fail (show err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^.^ .. That is maybe overkill / redundant with integration tests in the end. I think we can trust Servant here if our handlers function work as expected 😛

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is patterned after @adinapoli-iohk 's tests, which do the same.

@KtorZ
Copy link
Contributor

KtorZ commented Aug 24, 2018

NOT MERGING THIS YET. Wait for #3462 to get in develop

@KtorZ KtorZ changed the base branch from develop-new to develop August 24, 2018 12:09
@KtorZ KtorZ merged commit 85ebea0 into develop Aug 24, 2018
@KtorZ KtorZ deleted the paweljakubas/CBR-366/add-tests-for-account-partial-getters branch August 24, 2018 12:31
KtorZ added a commit that referenced this pull request Nov 9, 2018
…d-tests-for-account-partial-getters

[CBR-366] Adding test for partial getters
KtorZ added a commit to input-output-hk/cardano-wallet-legacy that referenced this pull request Nov 9, 2018
…hk/paweljakubas/CBR-366/add-tests-for-account-partial-getters

[CBR-366] Adding test for partial getters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants