fix treasury implementation and tests
This commit is contained in:
parent
cf4d44cc3b
commit
04d6cbefe9
6 changed files with 28 additions and 119 deletions
|
|
@ -18,8 +18,8 @@ module Sample.Treasury (
|
|||
) where
|
||||
|
||||
import Plutarch.Context (
|
||||
MintingBuilder,
|
||||
buildMinting',
|
||||
SpendingBuilder,
|
||||
buildSpending',
|
||||
credential,
|
||||
input,
|
||||
mint,
|
||||
|
|
@ -27,8 +27,8 @@ import Plutarch.Context (
|
|||
script,
|
||||
signedWith,
|
||||
txId,
|
||||
withMinting,
|
||||
withRefTxId,
|
||||
withSpendingOutRefId,
|
||||
withValue,
|
||||
)
|
||||
import PlutusLedgerApi.V1.Address (Address (..))
|
||||
|
|
@ -55,7 +55,7 @@ import Sample.Shared (
|
|||
wrongEffHash,
|
||||
)
|
||||
|
||||
baseCtxBuilder :: MintingBuilder
|
||||
baseCtxBuilder :: SpendingBuilder
|
||||
baseCtxBuilder =
|
||||
let treasury =
|
||||
mconcat
|
||||
|
|
@ -69,7 +69,7 @@ baseCtxBuilder =
|
|||
, mint (Value.singleton gatCs gatTn (-1))
|
||||
, input treasury
|
||||
, output treasury
|
||||
, withMinting gatCs
|
||||
, withSpendingOutRefId "73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049"
|
||||
]
|
||||
|
||||
{- | A `ScriptContext` that should be compatible with treasury
|
||||
|
|
@ -77,7 +77,7 @@ baseCtxBuilder =
|
|||
-}
|
||||
validCtx :: ScriptContext
|
||||
validCtx =
|
||||
let builder :: MintingBuilder
|
||||
let builder :: SpendingBuilder
|
||||
builder =
|
||||
mconcat
|
||||
[ baseCtxBuilder
|
||||
|
|
@ -88,7 +88,7 @@ validCtx =
|
|||
, withRefTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
||||
]
|
||||
]
|
||||
in buildMinting' builder
|
||||
in buildSpending' builder
|
||||
|
||||
treasuryRef :: TxOutRef
|
||||
treasuryRef =
|
||||
|
|
@ -121,7 +121,7 @@ walletIn =
|
|||
|
||||
trCtxGATNameNotAddress :: ScriptContext
|
||||
trCtxGATNameNotAddress =
|
||||
let builder :: MintingBuilder
|
||||
let builder :: SpendingBuilder
|
||||
builder =
|
||||
mconcat
|
||||
[ baseCtxBuilder
|
||||
|
|
@ -132,4 +132,4 @@ trCtxGATNameNotAddress =
|
|||
, withRefTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3"
|
||||
]
|
||||
]
|
||||
in buildMinting' builder
|
||||
in buildSpending' builder
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ Tests need to fail when:
|
|||
module Spec.Treasury (specs) where
|
||||
|
||||
import Agora.Treasury (
|
||||
TreasuryRedeemer (SpendTreasuryGAT),
|
||||
treasuryValidator,
|
||||
)
|
||||
import Agora.Utils (CompiledValidator (CompiledValidator))
|
||||
|
|
@ -34,7 +33,7 @@ import PlutusLedgerApi.V1.Value qualified as Value (singleton)
|
|||
import PlutusLedgerApi.V2 (DCert (DCertDelegRegKey))
|
||||
import PlutusLedgerApi.V2.Contexts (
|
||||
ScriptContext (scriptContextPurpose, scriptContextTxInfo),
|
||||
ScriptPurpose (Certifying, Rewarding, Spending),
|
||||
ScriptPurpose (Certifying, Minting, Rewarding),
|
||||
TxInfo (txInfoInputs, txInfoMint),
|
||||
)
|
||||
import Sample.Shared (deterministicTracingConfing, trCredential)
|
||||
|
|
@ -42,7 +41,6 @@ import Sample.Treasury (
|
|||
gatCs,
|
||||
gatTn,
|
||||
trCtxGATNameNotAddress,
|
||||
treasuryRef,
|
||||
validCtx,
|
||||
walletIn,
|
||||
)
|
||||
|
|
@ -53,7 +51,7 @@ import Test.Specification (
|
|||
validatorSucceedsWith,
|
||||
)
|
||||
|
||||
compiledTreasuryValidator :: CompiledValidator () TreasuryRedeemer
|
||||
compiledTreasuryValidator :: CompiledValidator () ()
|
||||
compiledTreasuryValidator =
|
||||
CompiledValidator $
|
||||
mkValidator deterministicTracingConfing $
|
||||
|
|
@ -69,32 +67,32 @@ specs =
|
|||
"Allows for effect changes"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
validCtx
|
||||
, validatorSucceedsWith
|
||||
"Fails when GAT token name is not script address"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
trCtxGATNameNotAddress
|
||||
]
|
||||
, group
|
||||
"Negative"
|
||||
[ group
|
||||
"Fails with ScriptPurpose not Minting"
|
||||
"Fails with ScriptPurpose not Spending"
|
||||
[ validatorFailsWith
|
||||
"Spending"
|
||||
"Minting"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
validCtx
|
||||
{ scriptContextPurpose = Spending treasuryRef
|
||||
{ scriptContextPurpose = Minting ""
|
||||
}
|
||||
, validatorFailsWith
|
||||
"Rewarding"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
validCtx
|
||||
{ scriptContextPurpose =
|
||||
Rewarding $
|
||||
|
|
@ -104,7 +102,7 @@ specs =
|
|||
"Certifying"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
validCtx
|
||||
{ scriptContextPurpose =
|
||||
Certifying $
|
||||
|
|
@ -116,7 +114,7 @@ specs =
|
|||
"Fails when multiple GATs burned"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
validCtx
|
||||
{ scriptContextTxInfo =
|
||||
validCtx.scriptContextTxInfo
|
||||
|
|
@ -131,7 +129,7 @@ specs =
|
|||
"Fails with wallet as input"
|
||||
compiledTreasuryValidator
|
||||
()
|
||||
SpendTreasuryGAT
|
||||
()
|
||||
( let txInfo = validCtx.scriptContextTxInfo
|
||||
inputs = txInfo.txInfoInputs
|
||||
newInputs =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue