Skip to content

Commit

Permalink
Check that createPlan preserves the total non-ada token balance.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Apr 22, 2021
1 parent 5d3c959 commit 2445551
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import Cardano.Wallet.Primitive.Types.Coin
( Coin (..) )
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle (..) )
import Cardano.Wallet.Primitive.Types.TokenMap
( TokenMap )
import Control.Monad
( replicateM )
import Data.Either
Expand Down Expand Up @@ -162,6 +164,9 @@ prop_createPlan_inner mockConstraints inputs reward =
. verify
(totalInputAda >= totalOutputAda)
"ada is consumed and not created"
. verify
(totalInputTokenBalance == totalOutputTokenBalance)
"balance of non-ada tokens is preserved"
. verify
(totalFee result == totalFeeExpected)
"total fee is correct"
Expand Down Expand Up @@ -200,6 +205,10 @@ prop_createPlan_inner mockConstraints inputs reward =
"total fee expected"
. report (totalFee result)
"total fee actual"
. report totalInputTokenBalance
"total input token balance"
. report totalOutputTokenBalance
"total output token balance"

makeStatistics
= tabulate "Number of transactions required"
Expand Down Expand Up @@ -322,6 +331,14 @@ prop_createPlan_inner mockConstraints inputs reward =
totalOutputAda =
F.foldMap (view #coin . F.fold . view #outputs) (selections result)

totalInputTokenBalance :: TokenMap
totalInputTokenBalance =
F.foldMap (view #tokens . view #inputBalance) (selections result)

totalOutputTokenBalance :: TokenMap
totalOutputTokenBalance =
F.foldMap (view #tokens . F.fold . view #outputs) (selections result)

--------------------------------------------------------------------------------
-- Categorizing multiple UTxO entries
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 2445551

Please sign in to comment.