-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conversation
0ad8987
to
40cafc2
Compare
d40fafe
to
c89328f
Compare
migrateByronWallet
actually migrates funds.migrateByronWallet
depletes all funds from a source wallet.
verify r0 | ||
[ expectResponseCode @IO HTTP.status200 | ||
, expectFieldSatisfy balanceAvailable (> 0) | ||
] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are :)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 fund
s 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)...
There was a problem hiding this comment.
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 :|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
43cf03f
to
e67d034
Compare
cc @Anviking |
bors r+ |
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]>
e67d034
to
b681a25
Compare
Canceled |
bors r+ |
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]>
Build failed |
This is consistent with the name of the operation.
…tion. The actual termination condition is that the target value is reached or exceeded. It's not required that the target value is exceeded (contrary to what the original log message implied).
This prefix better reflects the purpose of these tests.
This allows callers to specify a particular name and passphrase.
b681a25
to
5c07f79
Compare
migrateByronWallet
depletes all funds from a source wallet.migrateByronWallet
migrates funds correctly.
Also took the opportunity to clean up a bit binary specs for Jörmungandr and remove superfluous tests (already covered by the arbitrarily generate blocks)
bd1b894
to
c2d29c6
Compare
Last bors failure was due to #931 ( |
bors r+ |
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]>
Build succeeded |
Issue Number
#779
Overview
This PR tests that after a successful call to
migrateByronWallet
:0
.getByronWalletMigrateInfo
.