|
9 | 9 | module LinearVesting.Test where |
10 | 10 |
|
11 | 11 | import PlutusTx |
12 | | -import PlutusTx.Prelude |
| 12 | +import PlutusTx.Prelude hiding ((<>)) |
13 | 13 |
|
14 | 14 | import LinearVesting.Validator (VestingDatum (..), VestingRedeemer (..), validatorCode) |
15 | | -import PlutusLedgerApi.Data.V3 |
| 15 | +import PlutusLedgerApi.Data.V3 qualified as PV3D |
| 16 | +import PlutusLedgerApi.Test.ScriptContextBuilder.Builder |
| 17 | + ( buildScriptContext |
| 18 | + , withAddress |
| 19 | + , withInlineDatum |
| 20 | + , withOutRef |
| 21 | + , withSigner |
| 22 | + , withSpendingScript |
| 23 | + , withValidRange |
| 24 | + ) |
16 | 25 | import PlutusLedgerApi.V1.Data.Value (assetClass) |
17 | | -import PlutusTx.Data.AssocMap qualified as Map |
18 | | -import PlutusTx.Data.List qualified as List |
| 26 | +import PlutusLedgerApi.V3 qualified as PV3 |
| 27 | +import Prelude ((<>)) |
19 | 28 |
|
20 | 29 | validatorCodeFullyApplied :: CompiledCode BuiltinUnit |
21 | 30 | validatorCodeFullyApplied = |
22 | 31 | validatorCode `unsafeApplyCode` liftCodeDef (toBuiltinData testScriptContext) |
23 | 32 |
|
24 | | -testScriptContext :: ScriptContext |
| 33 | +testScriptContext :: PV3.ScriptContext |
25 | 34 | testScriptContext = |
26 | | - ScriptContext |
27 | | - { scriptContextTxInfo = txInfo |
28 | | - , scriptContextRedeemer |
29 | | - , scriptContextScriptInfo |
30 | | - } |
| 35 | + buildScriptContext |
| 36 | + ( withValidRange |
| 37 | + ( PV3.Interval |
| 38 | + (PV3.LowerBound (PV3.Finite 110) True) |
| 39 | + (PV3.UpperBound (PV3.Finite 1100) True) |
| 40 | + ) |
| 41 | + <> withSigner testBeneficiaryPKH |
| 42 | + <> withSpendingScript |
| 43 | + (toBuiltinData FullUnlock) |
| 44 | + ( withOutRef (PV3.TxOutRef txOutRefId txOutRefIdx) |
| 45 | + <> withAddress (PV3.Address (PV3.ScriptCredential scriptHash) Nothing) |
| 46 | + <> withInlineDatum (toBuiltinData testVestingDatum) |
| 47 | + ) |
| 48 | + ) |
31 | 49 | where |
32 | | - txInfo = |
33 | | - TxInfo |
34 | | - { txInfoInputs = mempty |
35 | | - , txInfoReferenceInputs = mempty |
36 | | - , txInfoOutputs = mempty |
37 | | - , txInfoTxCerts = mempty |
38 | | - , txInfoRedeemers = Map.empty |
39 | | - , txInfoVotes = Map.empty |
40 | | - , txInfoProposalProcedures = mempty |
41 | | - , txInfoCurrentTreasuryAmount = Nothing |
42 | | - , txInfoTreasuryDonation = Nothing |
43 | | - , txInfoFee = 0 |
44 | | - , txInfoMint = emptyMintValue |
45 | | - , txInfoWdrl = Map.empty |
46 | | - , txInfoValidRange = |
47 | | - Interval |
48 | | - (LowerBound (Finite 110) True) |
49 | | - (UpperBound (Finite 1100) True) |
50 | | - , txInfoSignatories = List.singleton testBeneficiaryPKH |
51 | | - , txInfoData = Map.empty |
52 | | - , txInfoId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145" |
53 | | - } |
54 | | - |
55 | | - scriptContextRedeemer :: Redeemer |
56 | | - scriptContextRedeemer = Redeemer (toBuiltinData FullUnlock) |
57 | | - |
58 | | - scriptContextScriptInfo :: ScriptInfo |
59 | | - scriptContextScriptInfo = |
60 | | - SpendingScript (TxOutRef txOutRefId txOutRefIdx) (Just datum) |
61 | | - where |
62 | | - txOutRefId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145" |
63 | | - txOutRefIdx = 0 |
64 | | - datum :: Datum |
65 | | - datum = Datum (toBuiltinData testVestingDatum) |
| 50 | + txOutRefId :: PV3.TxId |
| 51 | + txOutRefId = "058fdca70be67c74151cea3846be7f73342d92c0090b62c1052e6790ad83f145" |
| 52 | + txOutRefIdx :: Integer |
| 53 | + txOutRefIdx = 0 |
| 54 | + scriptHash :: PV3.ScriptHash |
| 55 | + scriptHash = PV3.ScriptHash "deadbeef" |
66 | 56 |
|
67 | 57 | testVestingDatum :: VestingDatum |
68 | 58 | testVestingDatum = |
69 | 59 | VestingDatum |
70 | | - { beneficiary = Address (PubKeyCredential testBeneficiaryPKH) Nothing |
71 | | - , vestingAsset = assetClass (CurrencySymbol "$") (TokenName "test-asset") |
| 60 | + { beneficiary = PV3D.Address (PV3D.PubKeyCredential testBeneficiaryPKH) Nothing |
| 61 | + , vestingAsset = assetClass (PV3D.CurrencySymbol "$") (PV3D.TokenName "test-asset") |
72 | 62 | , totalVestingQty = 1000 |
73 | 63 | , vestingPeriodStart = 0 |
74 | 64 | , vestingPeriodEnd = 100 |
75 | 65 | , firstUnlockPossibleAfter = 10 |
76 | 66 | , totalInstallments = 10 |
77 | 67 | } |
78 | 68 |
|
79 | | -testBeneficiaryPKH :: PubKeyHash |
80 | | -testBeneficiaryPKH = PubKeyHash "" |
| 69 | +testBeneficiaryPKH :: PV3.PubKeyHash |
| 70 | +testBeneficiaryPKH = PV3.PubKeyHash "" |
0 commit comments