Skip to content

Commit 1302148

Browse files
committed
add asset class tests
1 parent a869d25 commit 1302148

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

bot-plutus-interface.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ test-suite bot-plutus-interface-test
177177
ghc-options: -fplugin-opt PlutusTx.Plugin:defer-errors
178178
other-modules:
179179
Spec.BotPlutusInterface.Balance
180+
Spec.BotPlutusInterface.CoinSelection
180181
Spec.BotPlutusInterface.Collateral
181182
Spec.BotPlutusInterface.Config
182183
Spec.BotPlutusInterface.Contract

src/BotPlutusInterface/CoinSelection.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
22
{-# LANGUAGE RankNTypes #-}
33

4-
module BotPlutusInterface.CoinSelection (valueToVec, valuesToVecs, selectTxIns) where
4+
module BotPlutusInterface.CoinSelection (valueToVec, valuesToVecs, selectTxIns, uniqueAssetClasses) where
55

66
import Control.Lens (foldOf, folded, ix, over, to, uncons, (^..), (^?), _Just)
77
import Control.Monad.Freer (Eff, Member)

test/Spec.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Main (main) where
22

33
import Spec.BotPlutusInterface.Balance qualified
4+
import Spec.BotPlutusInterface.CoinSelection qualified
45
import Spec.BotPlutusInterface.Collateral qualified
56
import Spec.BotPlutusInterface.Contract qualified
67
import Spec.BotPlutusInterface.ContractStats qualified
@@ -25,6 +26,7 @@ tests =
2526
[ Spec.BotPlutusInterface.Contract.tests
2627
, Spec.BotPlutusInterface.UtxoParser.tests
2728
, Spec.BotPlutusInterface.Balance.tests
29+
, Spec.BotPlutusInterface.CoinSelection.tests
2830
, Spec.BotPlutusInterface.Server.tests
2931
, Spec.BotPlutusInterface.ContractStats.tests
3032
, Spec.BotPlutusInterface.TxStatusChange.tests
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Spec.BotPlutusInterface.CoinSelection (tests) where
2+
3+
import BotPlutusInterface.CoinSelection (uniqueAssetClasses)
4+
import Control.Lens (folded, (^..), to)
5+
import Data.Set (Set)
6+
import Data.Set qualified as Set
7+
import Ledger qualified
8+
import Ledger.Ada qualified as Ada
9+
import Ledger.Address (Address, PaymentPubKeyHash (PaymentPubKeyHash))
10+
import Ledger.Address qualified as Address
11+
import Ledger.CardanoWallet qualified as Wallet
12+
import Ledger.Crypto (PubKeyHash)
13+
import Ledger.Tx (Tx (..), TxIn (..), TxInType (..), TxOut (..), TxOutRef (..))
14+
import Ledger.Value qualified as Value
15+
import Test.Tasty (TestTree, testGroup)
16+
import Test.Tasty.HUnit (Assertion, assertFailure, testCase, (@?=))
17+
import Prelude
18+
19+
20+
tests :: TestTree
21+
tests =
22+
testGroup
23+
"BotPlutusInterface.CoinSelection"
24+
[ testCase "validAssetClasses" validAssetClasses
25+
]
26+
27+
28+
pkh1, pkh2 :: PubKeyHash
29+
pkh1 = Address.unPaymentPubKeyHash . Wallet.paymentPubKeyHash $ Wallet.knownMockWallet 1
30+
pkh2 = Address.unPaymentPubKeyHash . Wallet.paymentPubKeyHash $ Wallet.knownMockWallet 2
31+
32+
addr1, addr2 :: Address
33+
addr1 = Ledger.pubKeyHashAddress (PaymentPubKeyHash pkh1) Nothing
34+
addr2 = Ledger.pubKeyHashAddress (PaymentPubKeyHash pkh2) Nothing
35+
36+
txOutRef1, txOutRef2, txOutRef3, txOutRef4 :: TxOutRef
37+
txOutRef1 = TxOutRef "384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51" 0
38+
txOutRef2 = TxOutRef "52a003b3f4956433429631afe4002f82a924a5a7a891db7ae1f6434797a57dff" 1
39+
txOutRef3 = TxOutRef "d8a5630a9d7e913f9d186c95e5138a239a4e79ece3414ac894dbf37280944de3" 0
40+
txOutRef4 = TxOutRef "d8a5630a9d7e913f9d186c95e5138a239a4e79ece3414ac894dbf37280944de3" 2
41+
txOutRef5 = TxOutRef "34d491e0596b3a04be6e3442ebf115b33900f26e5e415e5151f820778ba576ed" 0
42+
43+
utxo1, utxo2, utxo3, utxo4 :: (TxOutRef, TxOut)
44+
utxo1 = (txOutRef1, TxOut addr1 (Ada.lovelaceValueOf 1_100_000) Nothing)
45+
utxo2 = (txOutRef2, TxOut addr1 (Ada.lovelaceValueOf 1_000_000) Nothing)
46+
utxo3 = (txOutRef3, TxOut addr1 (Ada.lovelaceValueOf 900_000) Nothing)
47+
utxo4 = (txOutRef4, TxOut addr1 (Ada.lovelaceValueOf 800_000 <> Value.singleton "11223344" "Token1" 500) Nothing)
48+
utxo5 = (txOutRef4, TxOut addr1 (Ada.lovelaceValueOf 800_000 <> Value.singleton "44332211" "Token2" 500) Nothing)
49+
50+
51+
validAssetClasses :: Assertion
52+
validAssetClasses = (uniqueAssetClasses $ map (txOutValue . snd) [utxo1,utxo2,utxo3,utxo4,utxo5]) @?= Set.fromList
53+
[Value.assetClass Ada.adaSymbol Ada.adaToken, Value.assetClass "44332211" "Token2", Value.assetClass "11223344" "Token1"]

0 commit comments

Comments
 (0)