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

Add a function to test for specific tokens and wallets on the final ledger state #333

Open
facundominguez opened this issue Mar 13, 2023 · 0 comments

Comments

@facundominguez
Copy link
Member

In an audit I ended up using a function like the following to test the final ledger state of a trace.

-- | Assert success of a validator where wallets are holding the given
-- amounts of a certain token
assertSuccessWithTokens ::
  (C.IsProp prop, Show a) =>
  C.InitialDistribution ->
  [(C.Wallet, Pl.AssetClass, Integer)] ->
  C.StagedMockChain a ->
  prop
assertSuccessWithTokens dst xs =
  C.testSucceedsFrom'
    ( \_ s -> (`C.testAll` xs) $ \(w, ac, i) ->
        let actual = Value.assetClassValueOf (holdingInState s w) ac
         in testBoolMsg (message w ac i actual) $ actual == i
    )
    dst
  where
    message w ac i actual =
      "Expected wallet "
        <> walletString w
        <> " to hold "
        <> show i
        <> " of token "
        <> show ac
        <> " but found "
        <> show actual
    walletString w = fromMaybe "unknown" (CW.mwPrintAs w)

This function is helpful when using tokens other than ada. With ada is harder to guess the exact amounts since they depend on the fees that have been charged.

To deal with Ada, maybe the above function could be generalized to receive predicates for each token

assertSuccessWithTokens ::
  (C.IsProp prop, Show a) =>
  C.InitialDistribution ->
  [(C.Wallet, Pl.AssetClass, Integer -> Bool)] ->
  C.StagedMockChain a ->
  prop
@facundominguez facundominguez changed the title Add a function to test specific values on the final ledger state Add a function to test for specific tokens and wallets on the final ledger state Mar 13, 2023
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

No branches or pull requests

1 participant