Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7622a70
commit 606f63f
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/BuildConstraintsSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
module Language.Marlowe.Runtime.Transaction.BuildConstraintsSpec | ||
( spec | ||
) where | ||
|
||
import Data.ByteString (ByteString) | ||
import qualified Data.ByteString as BS | ||
import qualified Data.Map as Map | ||
import qualified Data.Set as Set | ||
import qualified Language.Marlowe.Runtime.ChainSync.Api as Chain | ||
import qualified Language.Marlowe.Runtime.Core.Api as Core.Api | ||
import qualified Language.Marlowe.Runtime.Transaction.Api as Transaction.Api | ||
import qualified Language.Marlowe.Runtime.Transaction.BuildConstraints as BuildConstraints | ||
import Language.Marlowe.Runtime.Transaction.Constraints (TxConstraints(..)) | ||
import qualified Language.Marlowe.Runtime.Transaction.Constraints as TxConstraints | ||
import Test.Hspec (Spec, shouldBe) | ||
import qualified Test.Hspec as Hspec | ||
import qualified Test.Hspec.QuickCheck as Hspec.QuickCheck | ||
import qualified Test.QuickCheck as QuickCheck | ||
|
||
byteStringGen :: QuickCheck.Gen ByteString | ||
byteStringGen = BS.pack <$> QuickCheck.arbitrary | ||
|
||
spec :: Spec | ||
spec = Hspec.describe "buildWithdrawConstraints" do | ||
Hspec.QuickCheck.prop "implements Marlowe V1" do | ||
tokenName <- Chain.TokenName <$> byteStringGen | ||
policyId <- Chain.PolicyId <$> byteStringGen | ||
|
||
let assetId :: Chain.AssetId | ||
assetId = Chain.AssetId policyId tokenName | ||
|
||
actual :: Either Transaction.Api.WithdrawError (TxConstraints 'Core.Api.V1) | ||
actual = BuildConstraints.buildWithdrawConstraints Core.Api.MarloweV1 assetId | ||
|
||
expected :: Either Transaction.Api.WithdrawError (TxConstraints 'Core.Api.V1) | ||
expected = Right $ TxConstraints | ||
{ marloweInputConstraints = TxConstraints.MarloweInputConstraintsNone | ||
, payoutInputConstraints = Set.singleton assetId | ||
, roleTokenConstraints = TxConstraints.SpendRoleTokens $ Set.singleton assetId | ||
, payToAddresses = Map.empty | ||
, payToRoles = Map.empty | ||
, marloweOutputConstraints = TxConstraints.MarloweOutputConstraintsNone | ||
, signatureConstraints = Set.empty | ||
, metadataConstraints = Map.empty | ||
} | ||
|
||
pure $ actual `shouldBe` expected |