Skip to content

Commit

Permalink
Merge #916
Browse files Browse the repository at this point in the history
916: Byron migration integration tests r=KtorZ a=jonathanknowles

# Issue Number

#778 
#779 

# Overview

This PR adds integration tests to verify that:

- [x] Calculating the migration cost of an empty wallet (with [`getByronWalletMigrateInfo`](cardano-foundation/cardano-wallet#778)) returns a value of `0`.
- [x] Migrating an empty wallet (with the [`migrateByronWallet`](cardano-foundation/cardano-wallet#779) endpoint) should not generate any transactions.
- [x] The actual cost incurred by a migration (with the [`migrateByronWallet`](cardano-foundation/cardano-wallet#779) endpoint) **exactly** matches the cost returned by the [`getByronWalletMigrateInfo`](cardano-foundation/cardano-wallet#778) endpoint.

# 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: Jonathan Knowles <[email protected]>
Co-authored-by: KtorZ <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2019
2 parents 1d71a78 + 7ca629f commit c8e7454
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/core/test/unit/Cardano/Wallet/Primitive/CoinSelectionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import Cardano.Wallet.Primitive.Types
, TxOut (..)
, UTxO (..)
)
import Control.Monad.IO.Class
( liftIO )
import Control.Monad.Trans.Except
( ExceptT, runExceptT )
import Data.List.NonEmpty
Expand Down Expand Up @@ -75,6 +73,7 @@ import qualified Data.ByteString as BS
import qualified Data.List as L
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import qualified Test.QuickCheck.Monadic as QC

spec :: Spec
spec = do
Expand All @@ -85,6 +84,10 @@ spec = do
(checkCoverageWith lowerConfidence prop_shuffleNotDeterministic)
it "sort (shuffled xs) == sort xs"
(checkCoverageWith lowerConfidence prop_shufflePreserveElements)
it "UTxO toList order deterministic" $
checkCoverageWith
lowerConfidence
prop_utxoToListOrderDeterministic
where
lowerConfidence :: Confidence
lowerConfidence = Confidence (10^(6 :: Integer)) 0.75
Expand All @@ -96,25 +99,35 @@ spec = do
prop_shuffleCanShuffle
:: NonEmptyList Int
-> Property
prop_shuffleCanShuffle (NonEmpty xs) = monadicIO $ liftIO $ do
prop_shuffleCanShuffle (NonEmpty xs) = monadicIO $ QC.run $ do
xs' <- shuffle xs
return $ cover 90 (xs /= xs') "shuffled" ()

prop_shuffleNotDeterministic
:: NonEmptyList Int
-> Property
prop_shuffleNotDeterministic (NonEmpty xs) = monadicIO $ liftIO $ do
prop_shuffleNotDeterministic (NonEmpty xs) = monadicIO $ QC.run $ do
xs1 <- shuffle xs
xs2 <- shuffle xs
return $ cover 90 (xs1 /= xs2) "not deterministic" ()

prop_shufflePreserveElements
:: [Int]
-> Property
prop_shufflePreserveElements xs = monadicIO $ liftIO $ do
prop_shufflePreserveElements xs = monadicIO $ QC.run $ do
xs' <- shuffle xs
return $ cover 90 (not $ null xs) "non-empty" (L.sort xs == L.sort xs')

prop_utxoToListOrderDeterministic
:: UTxO
-> Property
prop_utxoToListOrderDeterministic u = monadicIO $ QC.run $ do
let list0 = Map.toList $ getUTxO u
list1 <- shuffle list0
return $
cover 90 (list0 /= list1) "shuffled" $
list0 == Map.toList (Map.fromList list1)

{-------------------------------------------------------------------------------
Coin Selection - Unit Tests
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit c8e7454

Please sign in to comment.