Skip to content

Commit

Permalink
Merge #1008
Browse files Browse the repository at this point in the history
1008: Additional tests for migrating and calculating migration cost for wallets containing only dust r=piotr-iohk a=piotr-iohk



# Issue Number

#779 
#1007

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [ ] Added additional tests for attempting to migrate and calculate migration cost for dust wallets. Those special wallets added to `genesis.yaml`


# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Piotr Stachyra <[email protected]>
Co-authored-by: Pawel Jakubas <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2019
2 parents 30abf96 + 80c6e34 commit 7054d56
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,39 @@ spec = do
]

it "BYRON_CALCULATE_02 - \
\for empty wallet calculated fee is zero."
\Cannot calculate fee for empty wallet."
$ \ctx -> do
w <- emptyByronWallet ctx
let ep = calculateByronMigrationCostEp w
r <- request @ApiByronWalletMigrationInfo ctx ep Default Empty
verify r
[ expectResponseCode @IO HTTP.status200
, expectFieldEqual amount 0
[ expectResponseCode @IO HTTP.status403
, expectErrorMessage (errMsg403NothingToMigrate $ w ^. walletId)
]

it "BYRON_CALCULATE_02 - \
\Cannot calculate fee for wallet with dust, that cannot be migrated."
$ \ctx -> do
-- NOTE
-- Special mnemonic for which wallet with dust
-- (1 utxo with 10 lovelace)
let mnemonics =
[ "prison", "census", "discover", "give"
, "sound", "behave", "hundred", "cave"
, "someone", "orchard", "just", "wild"
] :: [Text]
let payloadRestore = Json [json| {
"name": "Dust Byron Wallet",
"mnemonic_sentence": #{mnemonics},
"passphrase": #{fixturePassphrase}
} |]
(_, w) <- unsafeRequest @ApiByronWallet ctx
postByronWalletEp payloadRestore
let ep = calculateByronMigrationCostEp w
r <- request @ApiByronWalletMigrationInfo ctx ep Default Empty
verify r
[ expectResponseCode @IO HTTP.status403
, expectErrorMessage (errMsg403NothingToMigrate $ w ^. walletId)
]

it "BYRON_CALCULATE_03 - \
Expand Down Expand Up @@ -344,6 +369,42 @@ spec = do
, expectErrorMessage (errMsg403NothingToMigrate srcId)
]

it "BYRON_MIGRATE_02 - \
\migrating wallet with dust should fail."
$ \ctx -> do
-- NOTE
-- Special mnemonic for which wallet with dust
-- (5 utxos with 60 lovelace in total)
let mnemonics =
[ "suffer", "decorate", "head", "opera"
, "yellow", "debate", "visa", "fire"
, "salute", "hybrid", "stone", "smart"
] :: [Text]
let payloadRestore = Json [json| {
"name": "Dust Byron Wallet",
"mnemonic_sentence": #{mnemonics},
"passphrase": #{fixturePassphrase}
} |]
(_, sourceWallet) <- unsafeRequest @ApiByronWallet ctx
postByronWalletEp payloadRestore
eventually_ $ do
request @ApiByronWallet ctx
(getByronWalletEp sourceWallet)
Default
Empty >>= flip verify
[ expectFieldSatisfy balanceAvailable (> 0)
]

targetWallet <- emptyWallet ctx
let payload = Json [json|{"passphrase": "Secure Passphrase"}|]
let ep = migrateByronWalletEp sourceWallet targetWallet
r <- request @[ApiTransaction n] ctx ep Default payload
let srcId = sourceWallet ^. walletId
verify r
[ expectResponseCode @IO HTTP.status403
, expectErrorMessage (errMsg403NothingToMigrate srcId)
]

it "BYRON_MIGRATE_03 - \
\actual fee for migration is the same as the predicted fee."
$ \ctx -> do
Expand Down
6 changes: 4 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,10 @@ getByronWalletMigrationInfo
-> ApiT WalletId
-- ^ Source wallet (Byron)
-> Handler ApiByronWalletMigrationInfo
getByronWalletMigrationInfo ctx (ApiT wid) =
infoFromSelections <$> getSelections
getByronWalletMigrationInfo ctx (ApiT wid) = do
sels <- getSelections
when (null sels) $ liftHandler $ throwE $ ErrMigratingEmptyWallet wid
return $ infoFromSelections sels
where
infoFromSelections :: [CoinSelection] -> ApiByronWalletMigrationInfo
infoFromSelections =
Expand Down
Binary file modified lib/jormungandr/test/data/jormungandr/block0.bin
Binary file not shown.
26 changes: 26 additions & 0 deletions lib/jormungandr/test/data/jormungandr/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6122,6 +6122,32 @@ initial:
- cert: signedcert1q8qtmpgefmhlwrwlm48kxq43hpkxnvz8fey2jlmce5lea3mxnskfqq264syfguy58qc5aswgkp5hsg8u9ma2ey28dz6nu4xk3v9uu9af4rmltr2l3fcuvvcncxcd8pkujg55zdm9vvkpd7v68fsk700346rkd0cew62txal4zzm082gf22t652dqeyxvxr8gve9kt30fvpg5yjgpwe6ppl
- cert: signedcert1qxzn99jx8a2rw80gp9uea47tmcndv7gm28vy9as6akevy32204aqwq2ulwml0mqq2pyel0gu09g4y9k9443kh973j39aaznahx886yngqwgl2dse22c2n494hxlfzkw8v4rtxuj43unq04u7r848v28axlge63zlr4wpuwq080y3htyxxcx6dujzz84m7tupkhxrpcu0t9x67cq0x6dn8y

# A special Byron Wallet comming from ["suffer", "decorate", "head", "opera", "yellow", "debate", "visa", "fire", "salute", "hybrid", "stone", "smart"]
#
# with with only dust
- legacy_fund:
- address: DdzFFzCqrhsz56VqWWAQpRMcSFYE1WKeuFcVzV9UpovnJghF4YmV7TkMLNh1GCHftUBNEZQ2h3fCKsb25syBYrd1Qob2XkyeS6vgDzQ8
value: 10
- legacy_fund:
- address: DdzFFzCqrhsfE8zNNyc84uMJrR6Ma3ToNYfwwZ4oQVGt8QrG9ZQtKngy3Qe4tzioZSdnwpD9n8RwFC22n61ytMs7NkXhVHrZwPoDjUju
value: 11
- legacy_fund:
- address: DdzFFzCqrht6QNVjDuTwuwzYbubxxEHkRLR717NWYsUeqimhr9WwQQMJS8r4cfoW6Fkdefm53ea5vX5drr55vrTsGcPDKjFgENcXtDC8
value: 12
- legacy_fund:
- address: DdzFFzCqrhspYWP9aDtu4t3LQWyt4h7zWSYgmRbfdvHindyJoSozKq81ZDEAVhzQy7PFCMFBDFyzrszZXvHQCwTwyPLpqgFwadJqn6rN
value: 13
- legacy_fund:
- address: DdzFFzCqrhsktZddiMaLXEBdfpcZaJvUQpaM3KUQgaj4Tg3v2EeVU8HXimv6Ci7C46rYeQJ16sgwxU7t71eEbVpAknSsZDgCrk1ZbLk6
value: 14

# A special Byron Wallet comming from ["prison", "census", "discover", "give", "sound", "behave", "hundred", "cave", "someone", "orchard", "just", "wild"]
#
# with with only dust
- legacy_fund:
- address: DdzFFzCqrhseC4ds1oxM2HDhuBZSJQQdkTqbBRJhsgt544jMChLCcxjqbqqjNKQSXCye8CVGQVcaSTpKZ62Gn8LG47cfErV9oyruvkLx
value: 10

# A special Byron Wallet coming from ["collect", "fold", "file", "clown", "injury", "sun", "brass", "diet", "exist", "spike", "behave", "clip"]
#
# with 500 UTxOs where 100 of them are dust
Expand Down

0 comments on commit 7054d56

Please sign in to comment.