|
1 | | -module Spec.TestContract.MintAndPay (mintAndPayTokens) where |
| 1 | +module Spec.TestContract.MintAndPay (zeroAdaOutTestContract) where |
2 | 2 |
|
3 | | -import Control.Monad (void) |
4 | | -import Data.List.NonEmpty qualified as NonEmpty |
5 | | -import Data.Map qualified as Map |
6 | 3 | import Data.Text (Text) |
7 | 4 | import Ledger ( |
8 | | - Address, |
9 | | - CardanoTx, |
10 | | - ChainIndexTxOut, |
11 | 5 | CurrencySymbol, |
12 | | - PaymentPubKeyHash (PaymentPubKeyHash), |
13 | | - ScriptContext (scriptContextTxInfo), |
14 | | - TxId, |
15 | | - TxInfo (txInfoMint), |
16 | | - TxOutRef, |
| 6 | + PaymentPubKeyHash, |
| 7 | + ScriptContext, |
17 | 8 | getCardanoTxId, |
18 | | - scriptHashAddress, |
19 | 9 | ) |
20 | | -import Ledger.Ada (adaValueOf) |
21 | 10 | import Ledger.Constraints qualified as Constraints |
22 | 11 | import Ledger.Scripts qualified as Scripts |
23 | | -import Ledger.Typed.Scripts (TypedValidator, Validator, ValidatorTypes, mkUntypedMintingPolicy) |
| 12 | +import Ledger.Typed.Scripts (mkUntypedMintingPolicy) |
24 | 13 | import Ledger.Typed.Scripts qualified as TypedScripts |
25 | | -import Ledger.Value (flattenValue, tokenName) |
26 | | -import Plutus.Contract (Contract, mkTxConstraints, adjustUnbalancedTx, submitTxConfirmed) |
27 | | --- import Plutus.Contract qualified as Contract |
| 14 | +import Ledger.Value (tokenName) |
| 15 | +import Plutus.Contract (Contract, adjustUnbalancedTx, awaitTxConfirmed, mkTxConstraints, submitTxConfirmed, submitTxConstraintsWith) |
| 16 | + |
| 17 | +import Data.Void (Void) |
28 | 18 | import Plutus.PAB.Effects.Contract.Builtin (EmptySchema) |
29 | 19 | import Plutus.Script.Utils.V1.Scripts qualified as ScriptUtils |
30 | 20 | import Plutus.V1.Ledger.Value qualified as Value |
31 | 21 | import PlutusTx qualified |
32 | 22 | import PlutusTx.Prelude qualified as PP |
33 | 23 | import Prelude |
34 | | -import Data.Void (Void) |
35 | 24 |
|
| 25 | +{- This test contract checks that outputs with 0 Ada are hadled properly. |
| 26 | + BPI does adjustment of ouptupt even w/o explicit `adjustUnbalancedTx`, |
| 27 | + so this test contract checks bot cases - with implicit and explicit adjustment. |
| 28 | +-} |
| 29 | +zeroAdaOutTestContract :: PaymentPubKeyHash -> Contract () EmptySchema Text () |
| 30 | +zeroAdaOutTestContract pkh = |
| 31 | + mintAndPayWithAdjustment 0 pkh |
| 32 | + >> mintAndPayNoAdjustment 0 pkh |
| 33 | + >> mintAndPayWithAdjustment 7 pkh |
| 34 | + >> mintAndPayNoAdjustment 7 pkh |
| 35 | + |
| 36 | +mintAndPayWithAdjustment :: Integer -> PaymentPubKeyHash -> Contract () EmptySchema Text () |
| 37 | +mintAndPayWithAdjustment tokensAmt pkh = do |
| 38 | + let token = Value.singleton currencySymbol (tokenName "ff") tokensAmt |
| 39 | + txc1 = |
| 40 | + Constraints.mustMintValueWithRedeemer Scripts.unitRedeemer token |
| 41 | + <> Constraints.mustPayToPubKey pkh token |
| 42 | + lookups1 = Constraints.plutusV1MintingPolicy mintingPolicy |
| 43 | + |
| 44 | + utx <- mkTxConstraints @Void lookups1 txc1 |
| 45 | + tx <- adjustUnbalancedTx utx |
| 46 | + submitTxConfirmed tx |
36 | 47 |
|
37 | | -mintAndPayTokens :: PaymentPubKeyHash -> Contract () EmptySchema Text () |
38 | | -mintAndPayTokens pkh = do |
39 | | - let token = Value.singleton currencySymbol (tokenName "ff") 10 |
40 | | - txc1 = Constraints.mustMintValueWithRedeemer Scripts.unitRedeemer token |
41 | | - <> Constraints.mustPayToPubKey pkh token |
42 | | - lookups1 = Constraints.plutusV1MintingPolicy mintingPolicy |
| 48 | +mintAndPayNoAdjustment :: Integer -> PaymentPubKeyHash -> Contract () EmptySchema Text () |
| 49 | +mintAndPayNoAdjustment tokensAmt pkh = do |
| 50 | + let token = Value.singleton currencySymbol (tokenName "ff") tokensAmt |
| 51 | + txc1 = |
| 52 | + Constraints.mustMintValueWithRedeemer Scripts.unitRedeemer token |
| 53 | + <> Constraints.mustPayToPubKey pkh token |
| 54 | + lookups1 = Constraints.plutusV1MintingPolicy mintingPolicy |
43 | 55 |
|
44 | | - utx <- mkTxConstraints @Void lookups1 txc1 |
45 | | - tx <- adjustUnbalancedTx utx |
46 | | - submitTxConfirmed tx |
| 56 | + tx <- submitTxConstraintsWith @Void lookups1 txc1 |
| 57 | + awaitTxConfirmed (getCardanoTxId tx) |
47 | 58 |
|
48 | 59 | -- minting policy |
49 | 60 | {-# INLINEABLE mkPolicy #-} |
50 | 61 | mkPolicy :: () -> ScriptContext -> Bool |
51 | 62 | mkPolicy _ _ = |
52 | 63 | PP.traceIfFalse "Mint only check" check |
53 | 64 | where |
54 | | - -- info = scriptContextTxInfo ctx |
55 | 65 | check = PP.length someWork PP.== 10 |
56 | 66 | someWork = PP.sort [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] :: [Integer] |
57 | 67 |
|
|
0 commit comments