fix broken tests; utilizing new PCB APIs

This commit is contained in:
Hongrui Fang 2022-07-21 18:28:12 +08:00
parent 3c482cc348
commit e881f69c99
12 changed files with 150 additions and 204 deletions

View file

@ -30,8 +30,6 @@ import Agora.Proposal.Time (MaxTimeRangeWidth (MaxTimeRangeWidth), ProposalTimin
import Data.Default (Default (..))
import Plutarch.Api.V1 (mintingPolicySymbol, mkMintingPolicy)
import Plutarch.Context (
BaseBuilder,
buildTxInfoUnsafe,
input,
mint,
output,
@ -46,9 +44,6 @@ import Plutarch.Context (
import PlutusLedgerApi.V1 (
CurrencySymbol,
MintingPolicy,
ScriptContext (..),
ScriptPurpose (Minting),
TxInfo,
TxOutRef (TxOutRef),
ValidatorHash,
)
@ -59,7 +54,7 @@ import Sample.Shared (
)
import Sample.Shared qualified as Shared
import Test.Specification (SpecificationTree, testPolicy)
import Test.Util (pubKeyHashes, sortValue)
import Test.Util (CombinableBuilder, mkMinting, pubKeyHashes, sortValue)
data Parameters = Parameters
{ datumThresholdsValid :: Bool
@ -115,8 +110,8 @@ govSymbol = mintingPolicySymbol govPolicy
--------------------------------------------------------------------------------
mintGST :: Parameters -> TxInfo
mintGST ps = buildTxInfoUnsafe builder
mintGST :: forall b. CombinableBuilder b => Parameters -> b
mintGST ps = builder
where
gstAC =
if ps.mintStateTokenWithName
@ -149,7 +144,6 @@ mintGST ps = buildTxInfoUnsafe builder
---
witnessBuilder :: BaseBuilder
witnessBuilder =
if ps.presentWitness
then
@ -166,7 +160,6 @@ mintGST ps = buildTxInfoUnsafe builder
---
govBuilder :: BaseBuilder
govBuilder =
let datum =
if ps.withGovernorDatum
@ -177,8 +170,6 @@ mintGST ps = buildTxInfoUnsafe builder
. withValue governorValue
. datum
--
builder :: BaseBuilder
builder =
mconcat
[ txId "986b756ffb1c9839fc8d0b22a308ac91d5b5d0ebbfa683a47588c8a5cf70b5af"
@ -247,17 +238,10 @@ mintGSTWithNoneEmptyNameParameters =
--------------------------------------------------------------------------------
mkTestCase :: String -> Parameters -> Bool -> SpecificationTree
mkTestCase
name
ps
valid = policyTest
where
txInfo = mintGST ps
policyTest =
testPolicy
valid
name
(governorPolicy governor)
()
(ScriptContext txInfo (Minting govSymbol))
mkTestCase name ps valid =
testPolicy
valid
name
(governorPolicy governor)
()
(mkMinting mintGST ps govSymbol)

View file

@ -24,8 +24,6 @@ import Agora.Utils (validatorHashToTokenName)
import Data.Default (def)
import Plutarch.Api.V1 (PValidator, mkValidator, validatorHash)
import Plutarch.Context (
BaseBuilder,
buildTxInfoUnsafe,
input,
mint,
output,
@ -37,9 +35,6 @@ import Plutarch.Context (
)
import PlutusLedgerApi.V1 (
Data,
ScriptContext (ScriptContext),
ScriptPurpose (Spending),
TxInfo,
TxOutRef (TxOutRef),
ValidatorHash,
Value,
@ -54,7 +49,7 @@ import Sample.Shared (
minAda,
)
import Test.Specification (SpecificationTree, testValidator)
import Test.Util (pubKeyHashes, sortValue, validatorHashes, withOptional)
import Test.Util (CombinableBuilder, mkSpending, pubKeyHashes, sortValue, validatorHashes, withOptional)
--------------------------------------------------------------------------------
@ -131,13 +126,10 @@ governorRef =
"6cce6dfbb697f9e2c4fe9786bb576eb7bd6cbcf7801a4ba13d596006c2d5b957"
1
governorScriptPurpose :: ScriptPurpose
governorScriptPurpose = Spending governorRef
governorRedeemer :: GovernorRedeemer
governorRedeemer = MutateGovernor
mkGovernorBuilder :: GovernorParameters -> BaseBuilder
mkGovernorBuilder :: forall b. CombinableBuilder b => GovernorParameters -> b
mkGovernorBuilder ps =
let gst = Value.assetClassValue govAssetClass 1
value = sortValue $ gst <> minAda
@ -179,7 +171,7 @@ mkGATValue v q =
(validatorHashToTokenName gatOwner)
q
mkMockEffectBuilder :: MockEffectParameters -> BaseBuilder
mkMockEffectBuilder :: forall b. CombinableBuilder b => MockEffectParameters -> b
mkMockEffectBuilder ps =
let mkGATValue' = mkGATValue ps.gatValidity
inputValue = mkGATValue' 1
@ -200,13 +192,12 @@ mkMockEffectBuilder ps =
--------------------------------------------------------------------------------
mutate :: ParameterBundle -> TxInfo
mutate :: forall b. CombinableBuilder b => ParameterBundle -> b
mutate pb =
buildTxInfoUnsafe $
mconcat
[ mkGovernorBuilder pb.governorParameters
, mkMockEffectBuilder pb.mockEffectParameters
]
mconcat
[ mkGovernorBuilder pb.governorParameters
, mkMockEffectBuilder pb.mockEffectParameters
]
--------------------------------------------------------------------------------
@ -218,10 +209,7 @@ mkTestCase name pb (Validity forGov) =
(governorValidator governor)
governorInputDatum
governorRedeemer
( ScriptContext
(mutate pb)
governorScriptPurpose
)
(mkSpending mutate pb governorRef)
--------------------------------------------------------------------------------