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 migrateByronWallet migrates funds correctly. #950

Merged
merged 16 commits into from
Nov 6, 2019

Conversation

jonathanknowles
Copy link
Member

@jonathanknowles jonathanknowles commented Nov 4, 2019

Issue Number

#779

Overview

This PR tests that after a successful call to migrateByronWallet:

  • all funds are debited from the source wallet, leaving a balance of 0.
  • all funds are eventually credited to the target wallet, minus the fee.
  • the resultant fee is the same as the fee predicted by getByronWalletMigrateInfo.

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/byron-migrate-tests branch from 0ad8987 to 40cafc2 Compare November 4, 2019 06:36
@jonathanknowles jonathanknowles self-assigned this Nov 4, 2019
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/byron-migrate-tests branch 5 times, most recently from d40fafe to c89328f Compare November 5, 2019 08:37
@jonathanknowles jonathanknowles changed the title WIP: Add tests to demonstrate that migrateByronWallet actually migrates funds. Test that migrateByronWallet depletes all funds from a source wallet. Nov 5, 2019
verify r0
[ expectResponseCode @IO HTTP.status200
, expectFieldSatisfy balanceAvailable (> 0)
]
Copy link
Member

Choose a reason for hiding this comment

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

This check is superfluous, that is what fixture*Wallet* gives you already. The function only returns when funds are available.

Copy link
Member Author

@jonathanknowles jonathanknowles Nov 5, 2019

Choose a reason for hiding this comment

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

This check is superfluous, that is what fixture*Wallet* gives you already. The function only returns when funds are available.

Fair enough. I added this as a sanity check (and to make the assumptions more explicit), but we can remove it if we're confident that the fixtureByronWallet will only ever return a wallet with non-zero funds.

Copy link
Member

Choose a reason for hiding this comment

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

We are :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed!

(Json [aesonQQ|{"passphrase": #{sourceWalletPass}}|])
verify r1
[ expectResponseCode @IO HTTP.status202
, expectFieldSatisfy id (not . null)
Copy link
Member

Choose a reason for hiding this comment

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

In the end, I think we can even be stronger in the assertion here. We expect exactly one transaction.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the end, I think we can even be stronger in the assertion here. We expect exactly one transaction.

How can we be certain that there is exactly one transaction? Surely this depends on the UTxO distribution of the Byron fixture wallet? If the Byron fixture wallet has a complicated UTxO, that could easily result in more than one transaction being returned by migrateByronWallet.

If it is the case that the Byron fixture wallet has a very simple UTxO that causes only one transaction to be generated, surely that's an implementation detail that this test should not be concerned with?

Copy link
Member

Choose a reason for hiding this comment

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

Fixture wallets always have the exact same distributions (fixed by the genesis configuration) :

10 UTxOs of 10M Ada (or 1M, not sure anymore).

Also, if you use fixtureWalletWith you can chose yourself what that distribution should be (the function takes a list of coins if I recall correctly).

Copy link
Contributor

@piotr-iohk piotr-iohk Nov 5, 2019

Choose a reason for hiding this comment

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

Fixture wallets always have the exact same distributions

There is also this wallet in genesis -> https://github.com/input-output-hk/cardano-wallet/blob/master/lib/jormungandr/test/data/jormungandr/genesis.yaml#L68-L88.

I have added this some time ago to have some variation... but I think that the utxo distribution is the same for it (i.e. 10 UTxOs), only the number of transaction is different on this particular one. (Initially it has 1 tx, whereas others have 10txs). If it is problematic or confusing then maybe it should be changed.

Copy link
Member Author

@jonathanknowles jonathanknowles Nov 5, 2019

Choose a reason for hiding this comment

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

I think we should be cautious about making tests that depend on obscure details of mock data, unless those details are exposed as shared, top-level, reusable constants.

While it may the case that migrating the default faucet wallet just creates a single transaction, I don't see any advantage of making our test depend on that fact. I would argue that it's enough to ascertain that we have at least one transaction.

That is, unless we define the default faucet UTxO as a reusable constant, and then make the number of expected transactions a function of that constant, but I suspect that's overkill.

Copy link
Member

Choose a reason for hiding this comment

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

While it may the case that migrating the default faucet wallet just creates a single transaction, I don't see any advantage of making our test depend on that fact. I would argue that it's enough to ascertain that we have at least one transaction.

I'll introduce a fixtureByronWalletWith very much like its current dual for fixtureWallet.
With this, we'll be able to make it obvious what the UTxO size is without having to rely on a implicit knowledge on the testing setup AND, more importantly, we'll able to test a scenario where the migration actually requires more than one transaction (by creating a big UTxO, very much we do for testing the limit of the fee policy).

Copy link
Contributor

@piotr-iohk piotr-iohk Nov 5, 2019

Choose a reason for hiding this comment

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

Yes, it is one of the faucet wallets. As far as I remember I just removed those first several funds which just creates one inital tx with 10 utxos for this single wallet (as all those addresses belong to the same wallet)... others have 10 txs with 1 utxo each (per fixture wallet)...

Copy link
Member

Choose a reason for hiding this comment

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

Ah! It'd have been better not to use a faucet wallet for this, but to define the mnemonic separately :|

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 we should be cautious about making tests that depend on details of mock data

In this particular case one aspect is that we know what to expect with our fixture wallet mock (10 txs with 10 utxos)... unless someone silently breaks this expectation (like me with introducing this variation in genesis... which I think know is not really valuable, unless we really want to test this particular case... which we currently don't).

For that reason it is maybe safer (and clearer from the test reader perspective later on) to use fixtureWalletWith where we can define utxo distribution and even the number of transactions if needed.

Copy link
Member

Choose a reason for hiding this comment

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

For that reason it is maybe safer (and clearer from the test reader perspective later on)

💯

@@ -188,7 +189,53 @@ spec = do
getFromResponse amount r0
actualFee `shouldBe` predictedFee
Copy link
Member

Choose a reason for hiding this comment

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

I'd instead look for the following assertion:

        -- Wait for the funds to have arrived onto the new wallet
        eventually $ do
            rNew <- request @ApiWallet ctx (getWalletEp newW) Default Empty
            verify rNew
                [ expectFieldEqual balanceAvailable (faucetAmt - fee)
                , expectFieldEqual balanceTotal (faucetAmt - fee)
                ]

Which is stronger as it shows that the estimated fee were correct and that funds have arrived on the target wallet.

Copy link
Member Author

Choose a reason for hiding this comment

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

@KtorZ That stronger test is available in PR #960.

@KtorZ KtorZ force-pushed the jonathanknowles/byron-migrate-tests branch from 43cf03f to e67d034 Compare November 5, 2019 23:24
@KtorZ
Copy link
Member

KtorZ commented Nov 5, 2019

  • Revised integration scenarios to avoid partial pattern-match on request results
  • Remove "fixtureByronWalletWith" and instead, use a top-level constant "fixturePassphrase"
  • Bumped Jörmungandr installation to current Jörmungandr's master
  • Adjusted Binary module for Jörmungandr to work with the recent version (more config params added, and also an extra 64 bytes in the stake delegation object which is probably some sort of authentication payload)
  • Cleaned-up redundant tests in Jörmungandr Binary spec already covered by the binary encode/decode roundtrip
  • Re-generated arbitrary genesis blocks from Jörmungandr latest master to make sure we are "rountripping" relevant formats.

cc @Anviking

@KtorZ
Copy link
Member

KtorZ commented Nov 5, 2019

bors r+

iohk-bors bot added a commit that referenced this pull request Nov 5, 2019
950: Test that `migrateByronWallet` depletes all funds from a source wallet. r=KtorZ a=jonathanknowles

# Issue Number

#779 

# Overview

This PR tests that after a successful call to `migrateByronWallet`, all funds are debited from the source wallet, leaving a balance of `0`.

# Further work

A further PR will test that funds are appropriately credited to the target wallet.

Co-authored-by: Jonathan Knowles <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
@KtorZ KtorZ force-pushed the jonathanknowles/byron-migrate-tests branch from e67d034 to b681a25 Compare November 5, 2019 23:30
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 5, 2019

Canceled

@KtorZ
Copy link
Member

KtorZ commented Nov 5, 2019

bors r+

iohk-bors bot added a commit that referenced this pull request Nov 5, 2019
950: Test that `migrateByronWallet` depletes all funds from a source wallet. r=KtorZ a=jonathanknowles

# Issue Number

#779 

# Overview

This PR tests that after a successful call to `migrateByronWallet`, all funds are debited from the source wallet, leaving a balance of `0`.

# Further work

A further PR will test that funds are appropriately credited to the target wallet.

Co-authored-by: Jonathan Knowles <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
Co-authored-by: KtorZ <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 6, 2019

Build failed

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/byron-migrate-tests branch from b681a25 to 5c07f79 Compare November 6, 2019 01:32
@jonathanknowles jonathanknowles changed the title Test that migrateByronWallet depletes all funds from a source wallet. Test that migrateByronWallet migrates funds correctly. Nov 6, 2019
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/byron-migrate-tests branch from bd1b894 to c2d29c6 Compare November 6, 2019 01:57
@rvl
Copy link
Contributor

rvl commented Nov 6, 2019

Last bors failure was due to #931 (ExitFailure 66).

@jonathanknowles
Copy link
Member Author

bors r+

iohk-bors bot added a commit that referenced this pull request Nov 6, 2019
950: Test that `migrateByronWallet` migrates funds correctly. r=jonathanknowles a=jonathanknowles

# Issue Number

#779 

# Overview

This PR tests that after a successful call to `migrateByronWallet`:

- [x] all funds are debited from the source wallet, leaving a balance of `0`.
- [x] all funds are eventually credited to the target wallet, minus the fee.
- [x] the resultant fee is the same as the fee predicted by `getByronWalletMigrateInfo`.

Co-authored-by: Jonathan Knowles <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
Co-authored-by: KtorZ <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 6, 2019

Build succeeded

@iohk-bors iohk-bors bot merged commit 9252ed0 into master Nov 6, 2019
@jonathanknowles jonathanknowles deleted the jonathanknowles/byron-migrate-tests branch November 6, 2019 03:42
@KtorZ KtorZ added this to the Byron Wallet Support milestone Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants