|
| 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