This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add statistics and NoLockedFunds tests to Escrow
Extend Escrow tests, add negative testing Add NoLockedFunds to Escrow tests
- Loading branch information
1 parent
3412d47
commit 284c6f2
Showing
7 changed files
with
135 additions
and
16 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
nix/pkgs/haskell/materialized-darwin/.plan.nix/plutus-use-cases.nix
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
nix/pkgs/haskell/materialized-linux/.plan.nix/plutus-use-cases.nix
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
nix/pkgs/haskell/materialized-windows/.plan.nix/plutus-use-cases.nix
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE MonoLocalBinds #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Spec.Escrow.Endpoints where | ||
|
||
import Data.Text (unpack) | ||
|
||
import Control.Monad (void) | ||
|
||
import Ledger (Datum (..), PaymentPubKeyHash) | ||
import Ledger qualified | ||
import Ledger.Constraints qualified as Constraints | ||
import Ledger.Interval (from) | ||
import Ledger.Tx qualified as Tx | ||
import Ledger.Typed.Scripts (TypedValidator) | ||
import Ledger.Typed.Scripts qualified as Scripts | ||
|
||
import Plutus.Contract | ||
import Plutus.Contract.Typed.Tx qualified as Typed | ||
import PlutusTx qualified | ||
import PlutusTx.Prelude hiding (Applicative (..), Semigroup (..), check, foldMap) | ||
|
||
import Prelude (Semigroup (..)) | ||
|
||
import Plutus.Contracts.Escrow | ||
|
||
type EscrowTestSchema = Endpoint "badrefund-escrow" PaymentPubKeyHash .\/ EscrowSchema | ||
|
||
-- | 'badRefund' with an endpoint. | ||
badRefundEp :: | ||
forall w s. | ||
( HasEndpoint "badrefund-escrow" PaymentPubKeyHash s | ||
) | ||
=> EscrowParams Datum | ||
-> Promise w s EscrowError () | ||
badRefundEp escrow = endpoint @"badrefund-escrow" $ \pk -> badRefund (typedValidator escrow) pk | ||
|
||
-- Submit a transaction attempting to take the refund belonging to the given pk. | ||
badRefund :: | ||
forall w s. | ||
TypedValidator Escrow | ||
-> PaymentPubKeyHash | ||
-> Contract w s EscrowError () | ||
badRefund inst pk = do | ||
unspentOutputs <- utxosAt (Scripts.validatorAddress inst) | ||
current <- currentTime | ||
let flt _ ciTxOut = either id Ledger.datumHash (Tx._ciTxOutDatum ciTxOut) == Ledger.datumHash (Datum (PlutusTx.toBuiltinData pk)) | ||
tx' = Typed.collectFromScriptFilter flt unspentOutputs Refund | ||
<> Constraints.mustValidateIn (from (current - 1)) | ||
utx <- mkTxConstraints ( Constraints.typedValidatorLookups inst | ||
<> Constraints.unspentOutputs unspentOutputs | ||
) tx' | ||
handleError (\err -> logError $ "Caught error: " ++ unpack err) $ | ||
void $ submitUnbalancedTx (Constraints.adjustUnbalancedTx utx) | ||
|