@@ -2,10 +2,9 @@ module Spec.TestContract.AdjustTx (
22 runAdjustTest ,
33) where
44
5- import BotPlutusInterface.Contract (runContract )
65import Control.Lens.Operators ((^.) )
6+ import Data.List.NonEmpty qualified as NonEmpty
77import Data.Text (Text )
8- import Data.Text qualified as Text
98import Data.Void (Void )
109import Ledger (
1110 PaymentPubKeyHash ,
@@ -14,44 +13,36 @@ import Ledger (
1413 getCardanoTxId ,
1514 )
1615import Ledger qualified
17- import Ledger.Ada (adaValueOf )
1816import Ledger.Ada qualified as Ada
19-
20- -- import Ledger.Constraints (mkTx)
2117import Ledger.Constraints qualified as Constraints
2218import Ledger.Constraints.OffChain qualified as OffChain
23- import Ledger.Scripts qualified as Scripts
24- import Ledger.Typed.Scripts (TypedValidator , Validator , ValidatorTypes , mkUntypedMintingPolicy )
25- import Ledger.Typed.Scripts qualified as TypedScripts
26- import Ledger.Value (Value , flattenValue , tokenName )
27- import Ledger.Value qualified
19+ import Ledger.Value (Value )
2820import Plutus.Contract (
2921 Contract ,
30- ContractError (ConstraintResolutionContractError ),
3122 adjustUnbalancedTx ,
3223 awaitTxConfirmed ,
3324 mkTxConstraints ,
34- submitTx ,
35- submitTxConstraintsWith ,
36- submitUnbalancedTx ,
37- utxosAt ,
3825 )
3926import Plutus.Contract qualified as Contract
4027import Plutus.PAB.Effects.Contract.Builtin (EmptySchema )
41- import Plutus.Script.Utils.V1.Scripts qualified as ScriptUtils
42- import Plutus.V1.Ledger.Value qualified as Value
43- import PlutusTx qualified
44- import PlutusTx.Prelude qualified as PP
45- import Test.Plutip.Contract
28+ import Test.Plutip.Contract (
29+ TestWallets ,
30+ assertExecution ,
31+ initAda ,
32+ withContract ,
33+ )
34+ import Test.Plutip.Internal.BotPlutusInterface.Wallet (BpiWallet )
35+ import Test.Plutip.Internal.Types (ClusterEnv )
4636import Test.Plutip.Predicate (
4737 shouldSucceed ,
4838 yieldSatisfies ,
4939 )
40+ import Test.Tasty (TestTree )
5041import Prelude
5142
5243adjustTx :: PaymentPubKeyHash -> Contract () EmptySchema Text [Value ]
5344adjustTx toPkh = do
54- ownPkh <- Contract. ownPaymentPubKeyHash
45+ ownPkh <- Contract. ownFirstPaymentPubKeyHash
5546 let ownAddr = Ledger. pubKeyHashAddress ownPkh Nothing
5647 utxos <- Contract. utxosAt ownAddr
5748 let consts =
@@ -64,19 +55,23 @@ adjustTx toPkh = do
6455 adjustedTx <- adjustUnbalancedTx unbalancedTx
6556 let rawTx = adjustedTx ^. OffChain. tx
6657 vals = map txOutValue $ txOutputs rawTx
67- -- crdTx <- submitUnbalancedTx adjustedTx
6858 balTx <- Contract. balanceTx adjustedTx
6959 crdTx <- Contract. submitBalancedTx balTx
70- _ <- Contract. awaitTxConfirmed (getCardanoTxId crdTx)
60+ _ <- awaitTxConfirmed (getCardanoTxId crdTx)
7161 pure vals
7262
7363adjustTx' :: [PaymentPubKeyHash ] -> Contract () EmptySchema Text [Value ]
7464adjustTx' [] = do
75- pkh <- Contract. ownPaymentPubKeyHash
65+ pkh <- Contract. ownFirstPaymentPubKeyHash
7666 adjustTx pkh
7767adjustTx' (pkh : _) = adjustTx pkh
7868
79- -- The actual test
69+ -- | A type for the output of `assertExecution`.
70+ type PlutipTest = (TestWallets , IO (ClusterEnv , NonEmpty. NonEmpty BpiWallet ) -> TestTree )
71+
72+ -- | Tests whether `adjustUnbalancedTx` actually tops up the
73+ -- UTxO to get to the minimum required ADA.
74+ runAdjustTest :: PlutipTest
8075runAdjustTest =
8176 assertExecution
8277 " Adjust Unbalanced Tx Contract"
0 commit comments