@meshsdk/contract 1.6.0-alpha.21 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/index.cjs +37 -0
  2. package/dist/index.js +28 -1803
  3. package/package.json +30 -14
  4. package/.turbo/turbo-build$colon$docs.log +0 -8
  5. package/.turbo/turbo-build$colon$mesh.log +0 -19
  6. package/dist/index.mjs +0 -1834
  7. package/src/common.ts +0 -186
  8. package/src/coupon-bond-guaranteed/aiken-workspace/readme.md +0 -0
  9. package/src/coupon-bond-guaranteed/offchain.ts +0 -3
  10. package/src/coupon-bond-guaranteed/readme.md +0 -3
  11. package/src/escrow/aiken-workspace/aiken.lock +0 -26
  12. package/src/escrow/aiken-workspace/aiken.toml +0 -19
  13. package/src/escrow/aiken-workspace/lib/escrow/types.ak +0 -21
  14. package/src/escrow/aiken-workspace/lib/escrow/validators/escrow.ak +0 -122
  15. package/src/escrow/aiken-workspace/plutus.json +0 -238
  16. package/src/escrow/aiken-workspace/readme.md +0 -55
  17. package/src/escrow/aiken-workspace/validators/escrow.ak +0 -9
  18. package/src/escrow/aiken-workspace/validators/tests/escrow.ak +0 -462
  19. package/src/escrow/index.ts +0 -1
  20. package/src/escrow/offchain.ts +0 -254
  21. package/src/escrow/readme.md +0 -38
  22. package/src/giftcard/aiken-workspace/aiken.lock +0 -26
  23. package/src/giftcard/aiken-workspace/aiken.toml +0 -19
  24. package/src/giftcard/aiken-workspace/plutus.json +0 -138
  25. package/src/giftcard/aiken-workspace/readme.md +0 -55
  26. package/src/giftcard/aiken-workspace/validators/oneshot.ak +0 -173
  27. package/src/giftcard/index.ts +0 -1
  28. package/src/giftcard/offchain.ts +0 -184
  29. package/src/giftcard/readme.md +0 -36
  30. package/src/hello-world/aiken-workspace/README.md +0 -19
  31. package/src/hello-world/aiken-workspace/aiken.lock +0 -15
  32. package/src/hello-world/aiken-workspace/aiken.toml +0 -14
  33. package/src/hello-world/aiken-workspace/contract.md +0 -27
  34. package/src/hello-world/aiken-workspace/plutus.json +0 -69
  35. package/src/hello-world/aiken-workspace/validators/hello_world.ak +0 -24
  36. package/src/hello-world/index.ts +0 -1
  37. package/src/hello-world/offchain.ts +0 -24
  38. package/src/hello-world/readme.md +0 -1
  39. package/src/index.ts +0 -6
  40. package/src/marketplace/aiken-workspace/aiken.lock +0 -26
  41. package/src/marketplace/aiken-workspace/aiken.toml +0 -19
  42. package/src/marketplace/aiken-workspace/lib/marketplace/types.ak +0 -15
  43. package/src/marketplace/aiken-workspace/lib/marketplace/validators/marketplace.ak +0 -52
  44. package/src/marketplace/aiken-workspace/plutus.json +0 -204
  45. package/src/marketplace/aiken-workspace/readme.md +0 -55
  46. package/src/marketplace/aiken-workspace/validators/marketplace.ak +0 -14
  47. package/src/marketplace/aiken-workspace/validators/tests/marketplace.ak +0 -218
  48. package/src/marketplace/index.ts +0 -1
  49. package/src/marketplace/offchain.ts +0 -248
  50. package/src/marketplace/readme.md +0 -45
  51. package/src/payment-splitter/aiken-workspace/aiken.lock +0 -15
  52. package/src/payment-splitter/aiken-workspace/aiken.toml +0 -14
  53. package/src/payment-splitter/aiken-workspace/plutus.json +0 -83
  54. package/src/payment-splitter/aiken-workspace/validators/payment-splitter.ak +0 -329
  55. package/src/payment-splitter/index.ts +0 -1
  56. package/src/payment-splitter/offchain.ts +0 -143
  57. package/src/payment-splitter/readme.md +0 -100
  58. package/src/swap/aiken-workspace/aiken.lock +0 -26
  59. package/src/swap/aiken-workspace/aiken.toml +0 -19
  60. package/src/swap/aiken-workspace/plutus.json +0 -208
  61. package/src/swap/aiken-workspace/readme.md +0 -55
  62. package/src/swap/aiken-workspace/validators/swap.ak +0 -188
  63. package/src/swap/index.ts +0 -1
  64. package/src/swap/offchain.ts +0 -139
  65. package/src/swap/readme.md +0 -35
  66. package/src/vesting/aiken-workspace/README.md +0 -24
  67. package/src/vesting/aiken-workspace/aiken.lock +0 -26
  68. package/src/vesting/aiken-workspace/aiken.toml +0 -19
  69. package/src/vesting/aiken-workspace/lib/vesting/types.ak +0 -8
  70. package/src/vesting/aiken-workspace/lib/vesting/validators/vesting.ak +0 -19
  71. package/src/vesting/aiken-workspace/plutus.json +0 -67
  72. package/src/vesting/aiken-workspace/validators/tests/vesting.ak +0 -108
  73. package/src/vesting/aiken-workspace/validators/vesting.ak +0 -9
  74. package/src/vesting/index.ts +0 -1
  75. package/src/vesting/offchain.ts +0 -117
  76. package/src/vesting/readme.md +0 -36
  77. package/tsconfig.json +0 -5
  78. /package/dist/{index.d.mts → index.d.cts} +0 -0
@@ -1,254 +0,0 @@
1
- import {
2
- ConStr0,
3
- conStr0,
4
- ConStr1,
5
- conStr1,
6
- mConStr1,
7
- mConStr2,
8
- parsePlutusValueToAssets,
9
- PubKeyAddress,
10
- pubKeyAddress,
11
- Value,
12
- value,
13
- } from "@meshsdk/common";
14
- import {
15
- Asset,
16
- deserializeAddress,
17
- deserializeDatum,
18
- mergeAssets,
19
- serializeAddressObj,
20
- serializePlutusScript,
21
- UTxO,
22
- } from "@meshsdk/core";
23
- import { applyParamsToScript } from "@meshsdk/core-csl";
24
-
25
- import { MeshTxInitiator, MeshTxInitiatorInput } from "../common";
26
- import blueprint from "./aiken-workspace/plutus.json";
27
-
28
- export const MeshEscrowBlueprint = blueprint;
29
-
30
- export type InitiationDatum = ConStr0<[PubKeyAddress, Value]>;
31
- export const initiateEscrowDatum = (
32
- walletAddress: string,
33
- amount: Asset[],
34
- ): InitiationDatum => {
35
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress(walletAddress);
36
- return conStr0([
37
- pubKeyAddress(pubKeyHash, stakeCredentialHash),
38
- value(amount),
39
- ]);
40
- };
41
-
42
- export type ActiveEscrowDatum = ConStr1<
43
- [PubKeyAddress, Value, PubKeyAddress, Value]
44
- >;
45
- export const activeEscrowDatum = (
46
- initiationDatum: InitiationDatum,
47
- walletAddress: string,
48
- amount: Asset[],
49
- ): ActiveEscrowDatum => {
50
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress(walletAddress);
51
- const [initiator, initiatorAmount] = initiationDatum.fields;
52
- return conStr1([
53
- initiator,
54
- initiatorAmount,
55
- pubKeyAddress(pubKeyHash, stakeCredentialHash),
56
- value(amount),
57
- ]);
58
- };
59
-
60
- export type RecipientDepositRedeemer = ConStr0<[PubKeyAddress, Value]>;
61
- export const recipientDepositRedeemer = (
62
- recipient: string,
63
- depositAmount: Asset[],
64
- ) => initiateEscrowDatum(recipient, depositAmount);
65
-
66
- export class MeshEscrowContract extends MeshTxInitiator {
67
- scriptCbor = applyParamsToScript(blueprint.validators[0]!.compiledCode, []);
68
-
69
- constructor(inputs: MeshTxInitiatorInput) {
70
- super(inputs);
71
- }
72
-
73
- initiateEscrow = async (escrowAmount: Asset[]): Promise<string> => {
74
- const { utxos, walletAddress } = await this.getWalletInfoForTx();
75
- const { address: scriptAddr } = serializePlutusScript(
76
- { code: this.scriptCbor, version: "V2" },
77
- undefined,
78
- this.networkId,
79
- );
80
-
81
- await this.mesh
82
- .txOut(scriptAddr, escrowAmount)
83
- .txOutInlineDatumValue(
84
- initiateEscrowDatum(walletAddress, escrowAmount),
85
- "JSON",
86
- )
87
- .changeAddress(walletAddress)
88
- .selectUtxosFrom(utxos)
89
- .complete();
90
- return this.mesh.txHex;
91
- };
92
-
93
- cancelEscrow = async (escrowUtxo: UTxO): Promise<string> => {
94
- const { utxos, walletAddress, collateral } =
95
- await this.getWalletInfoForTx();
96
- const { address: scriptAddr } = serializePlutusScript(
97
- { code: this.scriptCbor, version: "V2" },
98
- undefined,
99
- this.networkId,
100
- );
101
-
102
- const inputDatum = deserializeDatum<InitiationDatum | ActiveEscrowDatum>(
103
- escrowUtxo.output.plutusData!,
104
- );
105
-
106
- if (inputDatum.constructor === 1) {
107
- const [
108
- initiatorAddressObj,
109
- initiatorAmount,
110
- recipientAddressObj,
111
- recipientAmount,
112
- ] = inputDatum.fields;
113
-
114
- const initiatorAddress = serializeAddressObj(initiatorAddressObj);
115
- const recipientAddress = serializeAddressObj(recipientAddressObj!);
116
- const initiatorToReceive = parsePlutusValueToAssets(initiatorAmount);
117
- const recipientToReceive = parsePlutusValueToAssets(recipientAmount!);
118
- this.mesh
119
- .txOut(initiatorAddress, initiatorToReceive)
120
- .txOut(recipientAddress, recipientToReceive);
121
- }
122
-
123
- await this.mesh
124
- .spendingPlutusScriptV2()
125
- .txIn(
126
- escrowUtxo.input.txHash,
127
- escrowUtxo.input.outputIndex,
128
- escrowUtxo.output.amount,
129
- scriptAddr,
130
- )
131
- .spendingReferenceTxInInlineDatumPresent()
132
- .spendingReferenceTxInRedeemerValue(mConStr1([]))
133
- .txInScript(this.scriptCbor)
134
- .requiredSignerHash(deserializeAddress(walletAddress).pubKeyHash)
135
- .changeAddress(walletAddress)
136
- .txInCollateral(
137
- collateral.input.txHash,
138
- collateral.input.outputIndex,
139
- collateral.output.amount,
140
- collateral.output.address,
141
- )
142
- .selectUtxosFrom(utxos)
143
- .complete();
144
- return this.mesh.txHex;
145
- };
146
-
147
- recipientDeposit = async (
148
- escrowUtxo: UTxO,
149
- depositAmount: Asset[],
150
- ): Promise<string> => {
151
- const { utxos, walletAddress, collateral } =
152
- await this.getWalletInfoForTx();
153
- const { address: scriptAddr } = serializePlutusScript(
154
- { code: this.scriptCbor, version: "V2" },
155
- undefined,
156
- this.networkId,
157
- );
158
- const inputDatum = deserializeDatum<InitiationDatum>(
159
- escrowUtxo.output.plutusData!,
160
- );
161
- const outputDatum = activeEscrowDatum(
162
- inputDatum,
163
- walletAddress,
164
- depositAmount,
165
- );
166
-
167
- const inputAssets = parsePlutusValueToAssets(inputDatum.fields[1]);
168
- const escrowAmount = mergeAssets([...depositAmount, ...inputAssets]);
169
-
170
- await this.mesh
171
- .spendingPlutusScriptV2()
172
- .txIn(
173
- escrowUtxo.input.txHash,
174
- escrowUtxo.input.outputIndex,
175
- escrowUtxo.output.amount,
176
- scriptAddr,
177
- )
178
- .spendingReferenceTxInInlineDatumPresent()
179
- .txInRedeemerValue(
180
- recipientDepositRedeemer(walletAddress, depositAmount),
181
- "JSON",
182
- {
183
- mem: 7_000_000,
184
- steps: 3_000_000_000,
185
- },
186
- )
187
- .txInScript(this.scriptCbor)
188
- .txOut(scriptAddr, escrowAmount)
189
- .txOutInlineDatumValue(outputDatum, "JSON")
190
- .changeAddress(walletAddress)
191
- .txInCollateral(
192
- collateral.input.txHash,
193
- collateral.input.outputIndex,
194
- collateral.output.amount,
195
- collateral.output.address,
196
- )
197
- .selectUtxosFrom(utxos)
198
- .complete();
199
- return this.mesh.txHex;
200
- };
201
-
202
- completeEscrow = async (escrowUtxo: UTxO): Promise<string> => {
203
- const { utxos, walletAddress, collateral } =
204
- await this.getWalletInfoForTx();
205
- const { address: scriptAddr } = serializePlutusScript(
206
- { code: this.scriptCbor, version: "V2" },
207
- undefined,
208
- this.networkId,
209
- );
210
- const inputDatum = deserializeDatum<ActiveEscrowDatum>(
211
- escrowUtxo.output.plutusData!,
212
- );
213
- const [
214
- initiatorAddressObj,
215
- initiatorAmount,
216
- recipientAddressObj,
217
- recipientAmount,
218
- ] = inputDatum.fields;
219
- const initiatorAddress = serializeAddressObj(initiatorAddressObj);
220
- const recipientAddress = serializeAddressObj(recipientAddressObj);
221
- const initiatorToReceive = parsePlutusValueToAssets(recipientAmount);
222
- const recipientToReceive = parsePlutusValueToAssets(initiatorAmount);
223
-
224
- await this.mesh
225
- .spendingPlutusScriptV2()
226
- .txIn(
227
- escrowUtxo.input.txHash,
228
- escrowUtxo.input.outputIndex,
229
- escrowUtxo.output.amount,
230
- scriptAddr,
231
- )
232
- .spendingReferenceTxInInlineDatumPresent()
233
- .spendingReferenceTxInRedeemerValue(mConStr2([]))
234
- .txInScript(this.scriptCbor)
235
- .txOut(initiatorAddress, initiatorToReceive)
236
- .txOut(recipientAddress, recipientToReceive)
237
- .requiredSignerHash(deserializeAddress(recipientAddress).pubKeyHash)
238
- .requiredSignerHash(deserializeAddress(initiatorAddress).pubKeyHash)
239
- .changeAddress(walletAddress)
240
- .txInCollateral(
241
- collateral.input.txHash,
242
- collateral.input.outputIndex,
243
- collateral.output.amount,
244
- collateral.output.address,
245
- )
246
- .selectUtxosFrom(utxos)
247
- .complete();
248
- return this.mesh.txHex;
249
- };
250
-
251
- getUtxoByTxHash = async (txHash: string): Promise<UTxO | undefined> => {
252
- return await this._getUtxoByTxHash(this.scriptCbor, txHash);
253
- };
254
- }
@@ -1,38 +0,0 @@
1
- # Escrow contract
2
-
3
- Escrow contract facilitates the secure exchange of assets between two parties by acting as a trusted intermediary that holds the assets until the conditions of the agreement are met.
4
-
5
- [Demo](https://meshjs.dev/smart-contracts/escrow)
6
-
7
- The escrow smart contract allows two parties to exchange assets securely. The contract holds the assets until both parties agree and sign off on the transaction.
8
-
9
- There are 4 actions available to interact with this smart contract:
10
-
11
- - initiate escrow and deposit assets
12
- - deposit assets
13
- - complete escrow
14
- - cancel escrow
15
-
16
- To initialize the escrow, we need to initialize a provider, MeshTxBuilder and MeshEscrowContract.
17
-
18
- ```
19
- import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
20
- import { MeshEscrowContract } from '@meshsdk/contracts';
21
- import { useWallet } from '@meshsdk/react';
22
-
23
- const { connected, wallet } = useWallet();
24
-
25
- const blockchainProvider = new BlockfrostProvider(APIKEY);
26
-
27
- const meshTxBuilder = new MeshTxBuilder({
28
- fetcher: blockchainProvider,
29
- submitter: blockchainProvider,
30
- });
31
-
32
- const contract = new MeshEscrowContract({
33
- mesh: meshTxBuilder,
34
- fetcher: blockchainProvider,
35
- wallet: wallet,
36
- networkId: 0,
37
- });
38
- ```
@@ -1,26 +0,0 @@
1
- # This file was generated by Aiken
2
- # You typically do not need to edit this file
3
-
4
- [[requirements]]
5
- name = "aiken-lang/stdlib"
6
- version = "1.9.0"
7
- source = "github"
8
-
9
- [[requirements]]
10
- name = "sidan-lab/aiken-utils"
11
- version = "0.1.6-beta"
12
- source = "github"
13
-
14
- [[packages]]
15
- name = "aiken-lang/stdlib"
16
- version = "1.9.0"
17
- requirements = []
18
- source = "github"
19
-
20
- [[packages]]
21
- name = "sidan-lab/aiken-utils"
22
- version = "0.1.6-beta"
23
- requirements = []
24
- source = "github"
25
-
26
- [etags]
@@ -1,19 +0,0 @@
1
- name = "meshjs/giftcard"
2
- version = "0.0.0"
3
- license = "Apache-2.0"
4
- description = "Aiken contracts for project 'meshjs/giftcard'"
5
-
6
- [repository]
7
- user = "meshjs"
8
- project = "giftcard"
9
- platform = "github"
10
-
11
- [[dependencies]]
12
- name = "aiken-lang/stdlib"
13
- version = "1.9.0"
14
- source = "github"
15
-
16
- [[dependencies]]
17
- name = "sidan-lab/aiken-utils"
18
- version = "0.1.6-beta"
19
- source = "github"
@@ -1,138 +0,0 @@
1
- {
2
- "preamble": {
3
- "title": "meshjs/giftcard",
4
- "description": "Aiken contracts for project 'meshjs/giftcard'",
5
- "version": "0.0.0",
6
- "plutusVersion": "v2",
7
- "compiler": {
8
- "name": "Aiken",
9
- "version": "v1.0.29-alpha+unknown"
10
- },
11
- "license": "Apache-2.0"
12
- },
13
- "validators": [
14
- {
15
- "title": "oneshot.gift_card",
16
- "redeemer": {
17
- "title": "rdmr",
18
- "schema": {
19
- "$ref": "#/definitions/oneshot~1Action"
20
- }
21
- },
22
- "parameters": [
23
- {
24
- "title": "token_name",
25
- "schema": {
26
- "$ref": "#/definitions/ByteArray"
27
- }
28
- },
29
- {
30
- "title": "utxo_ref",
31
- "schema": {
32
- "$ref": "#/definitions/aiken~1transaction~1OutputReference"
33
- }
34
- }
35
- ],
36
- "compiledCode": "5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",
37
- "hash": "0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"
38
- },
39
- {
40
- "title": "oneshot.redeem",
41
- "datum": {
42
- "title": "_d",
43
- "schema": {
44
- "$ref": "#/definitions/Data"
45
- }
46
- },
47
- "redeemer": {
48
- "title": "_r",
49
- "schema": {
50
- "$ref": "#/definitions/Data"
51
- }
52
- },
53
- "parameters": [
54
- {
55
- "title": "token_name",
56
- "schema": {
57
- "$ref": "#/definitions/ByteArray"
58
- }
59
- },
60
- {
61
- "title": "policy_id",
62
- "schema": {
63
- "$ref": "#/definitions/ByteArray"
64
- }
65
- }
66
- ],
67
- "compiledCode": "5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",
68
- "hash": "39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"
69
- }
70
- ],
71
- "definitions": {
72
- "ByteArray": {
73
- "dataType": "bytes"
74
- },
75
- "Data": {
76
- "title": "Data",
77
- "description": "Any Plutus data."
78
- },
79
- "Int": {
80
- "dataType": "integer"
81
- },
82
- "aiken/transaction/OutputReference": {
83
- "title": "OutputReference",
84
- "description": "An `OutputReference` is a unique reference to an output on-chain. The `output_index`\n corresponds to the position in the output list of the transaction (identified by its id)\n that produced that output",
85
- "anyOf": [
86
- {
87
- "title": "OutputReference",
88
- "dataType": "constructor",
89
- "index": 0,
90
- "fields": [
91
- {
92
- "title": "transaction_id",
93
- "$ref": "#/definitions/aiken~1transaction~1TransactionId"
94
- },
95
- {
96
- "title": "output_index",
97
- "$ref": "#/definitions/Int"
98
- }
99
- ]
100
- }
101
- ]
102
- },
103
- "aiken/transaction/TransactionId": {
104
- "title": "TransactionId",
105
- "description": "A unique transaction identifier, as the hash of a transaction body. Note that the transaction id\n isn't a direct hash of the `Transaction` as visible on-chain. Rather, they correspond to hash\n digests of transaction body as they are serialized on the network.",
106
- "anyOf": [
107
- {
108
- "title": "TransactionId",
109
- "dataType": "constructor",
110
- "index": 0,
111
- "fields": [
112
- {
113
- "title": "hash",
114
- "$ref": "#/definitions/ByteArray"
115
- }
116
- ]
117
- }
118
- ]
119
- },
120
- "oneshot/Action": {
121
- "title": "Action",
122
- "anyOf": [
123
- {
124
- "title": "Mint",
125
- "dataType": "constructor",
126
- "index": 0,
127
- "fields": []
128
- },
129
- {
130
- "title": "Burn",
131
- "dataType": "constructor",
132
- "index": 1,
133
- "fields": []
134
- }
135
- ]
136
- }
137
- }
138
- }
@@ -1,55 +0,0 @@
1
- # giftcard
2
-
3
- Write validators in the `validators` folder, and supporting functions in the `lib` folder using `.ak` as a file extension.
4
-
5
- For example, as `validators/always_true.ak`
6
-
7
- ```gleam
8
- validator {
9
- fn spend(_datum: Data, _redeemer: Data, _context: Data) -> Bool {
10
- True
11
- }
12
- }
13
- ```
14
-
15
- ## Building
16
-
17
- ```sh
18
- aiken build
19
- ```
20
-
21
- ## Testing
22
-
23
- You can write tests in any module using the `test` keyword. For example:
24
-
25
- ```gleam
26
- test foo() {
27
- 1 + 1 == 2
28
- }
29
- ```
30
-
31
- To run all tests, simply do:
32
-
33
- ```sh
34
- aiken check
35
- ```
36
-
37
- To run only tests matching the string `foo`, do:
38
-
39
- ```sh
40
- aiken check -m foo
41
- ```
42
-
43
- ## Documentation
44
-
45
- If you're writing a library, you might want to generate an HTML documentation for it.
46
-
47
- Use:
48
-
49
- ```sh
50
- aiken docs
51
- ```
52
-
53
- ## Resources
54
-
55
- Find more on the [Aiken's user manual](https://aiken-lang.org).
@@ -1,173 +0,0 @@
1
- use aiken/dict
2
- use aiken/list
3
- use aiken/transaction.{
4
- Input, OutputReference, ScriptContext, Transaction, placeholder,
5
- } as tx
6
- use aiken/transaction/value.{from_asset, to_minted_value, zero}
7
- use sidan_placeholder/address.{mock_pub_key_address}
8
- use sidan_placeholder/builder.{complete, mint, new_tx_tester, tx_in}
9
- use sidan_placeholder/key_hex.{mock_policy_id}
10
- use sidan_placeholder/output_reference.{mock_tx_hash, mock_utxo_ref}
11
-
12
- validator(token_name: ByteArray, policy_id: ByteArray) {
13
- fn redeem(_d: Data, _r: Data, ctx: ScriptContext) -> Bool {
14
- let ScriptContext { transaction, .. } = ctx
15
- let Transaction { mint, .. } = transaction
16
- expect [Pair(asset_name, amount)] =
17
- mint
18
- |> value.from_minted_value
19
- |> value.tokens(policy_id)
20
- |> dict.to_pairs()
21
- amount == -1 && asset_name == token_name
22
- }
23
- }
24
-
25
- type Action {
26
- Mint
27
- Burn
28
- }
29
-
30
- validator(token_name: ByteArray, utxo_ref: OutputReference) {
31
- fn gift_card(rdmr: Action, ctx: ScriptContext) -> Bool {
32
- let ScriptContext { transaction, purpose } = ctx
33
- expect tx.Mint(policy_id) = purpose
34
- let Transaction { inputs, mint, .. } = transaction
35
- expect [Pair(asset_name, amount)] =
36
- mint
37
- |> value.from_minted_value
38
- |> value.tokens(policy_id)
39
- |> dict.to_pairs()
40
- when rdmr is {
41
- Mint -> {
42
- expect Some(_input) =
43
- list.find(inputs, fn(input) { input.output_reference == utxo_ref })
44
- amount == 1 && asset_name == token_name
45
- }
46
- Burn -> amount == -1 && asset_name == token_name
47
- }
48
- }
49
- }
50
-
51
- type TestCase {
52
- is_mint_info_correct: Bool,
53
- is_token_name_correct: Bool,
54
- }
55
-
56
- fn get_mint_test_tx(test_case: TestCase) -> Transaction {
57
- let TestCase { is_mint_info_correct, is_token_name_correct } = test_case
58
-
59
- let token_name =
60
- if is_token_name_correct {
61
- "hello world"
62
- } else {
63
- "goodbye"
64
- }
65
-
66
- new_tx_tester()
67
- |> tx_in(True, mock_tx_hash(0), 0, zero(), mock_pub_key_address(0, None))
68
- |> mint(is_mint_info_correct, mock_policy_id(0), token_name, 1)
69
- |> mint(!is_mint_info_correct, mock_policy_id(0), token_name, 2)
70
- |> complete()
71
- }
72
-
73
- test success_mint() {
74
- let test_gift_card_name = "hello world"
75
- let utxo = mock_utxo_ref(0, 0)
76
- let test_case =
77
- TestCase { is_mint_info_correct: True, is_token_name_correct: True }
78
- let tx = get_mint_test_tx(test_case)
79
- let ctx =
80
- ScriptContext { transaction: tx, purpose: tx.Mint(mock_policy_id(0)) }
81
- gift_card(test_gift_card_name, utxo, Mint, ctx)
82
- }
83
-
84
- test fail_mint_with_more_than_1_mint() {
85
- let test_gift_card_name = "hello world"
86
- let utxo = mock_utxo_ref(0, 0)
87
- let test_case =
88
- TestCase { is_mint_info_correct: False, is_token_name_correct: True }
89
- let tx = get_mint_test_tx(test_case)
90
- let ctx =
91
- ScriptContext { transaction: tx, purpose: tx.Mint(mock_policy_id(0)) }
92
- !gift_card(test_gift_card_name, utxo, Mint, ctx)
93
- }
94
-
95
- test fail_mint_without_param_name_minted() {
96
- let test_gift_card_name = "hello world"
97
- let utxo = mock_utxo_ref(0, 0)
98
- let test_case =
99
- TestCase { is_mint_info_correct: True, is_token_name_correct: False }
100
- let tx = get_mint_test_tx(test_case)
101
- let ctx =
102
- ScriptContext { transaction: tx, purpose: tx.Mint(mock_policy_id(0)) }
103
- !gift_card(test_gift_card_name, utxo, Mint, ctx)
104
- }
105
-
106
- fn get_redeem_test_tx(test_case: TestCase) -> Transaction {
107
- let TestCase { is_mint_info_correct, is_token_name_correct } = test_case
108
-
109
- let token_name =
110
- if is_token_name_correct {
111
- "hello world"
112
- } else {
113
- "goodbye"
114
- }
115
-
116
- let mint =
117
- if is_mint_info_correct {
118
- from_asset(mock_policy_id(0), token_name, -1)
119
- } else {
120
- from_asset(mock_policy_id(0), token_name, -2)
121
- }
122
- |> to_minted_value
123
-
124
- Transaction { ..placeholder(), mint: mint }
125
- }
126
-
127
- test success_redeem() {
128
- let test_gift_card_name = "hello world"
129
- let utxo = mock_utxo_ref(0, 0)
130
- let test_case =
131
- TestCase { is_token_name_correct: True, is_mint_info_correct: True }
132
- let tx = get_redeem_test_tx(test_case)
133
- let ctx =
134
- ScriptContext { transaction: tx, purpose: tx.Mint(mock_policy_id(0)) }
135
- redeem(test_gift_card_name, mock_policy_id(0), "", "", ctx) && gift_card(
136
- test_gift_card_name,
137
- utxo,
138
- Burn,
139
- ctx,
140
- )
141
- }
142
-
143
- test fail_redeem_without_correct_name() {
144
- let test_gift_card_name = "hello world"
145
- let utxo = mock_utxo_ref(0, 0)
146
- let test_case =
147
- TestCase { is_token_name_correct: False, is_mint_info_correct: True }
148
- let tx = get_redeem_test_tx(test_case)
149
- let ctx =
150
- ScriptContext { transaction: tx, purpose: tx.Mint(mock_policy_id(0)) }
151
- !(redeem(test_gift_card_name, mock_policy_id(0), "", "", ctx) && gift_card(
152
- test_gift_card_name,
153
- utxo,
154
- Burn,
155
- ctx,
156
- ))
157
- }
158
-
159
- test fail_redeem_without_correct_mint_info() {
160
- let test_gift_card_name = "hello world"
161
- let utxo = mock_utxo_ref(0, 0)
162
- let test_case =
163
- TestCase { is_token_name_correct: True, is_mint_info_correct: False }
164
- let tx = get_redeem_test_tx(test_case)
165
- let ctx =
166
- ScriptContext { transaction: tx, purpose: tx.Mint(mock_policy_id(0)) }
167
- !(redeem(test_gift_card_name, mock_policy_id(0), "", "", ctx) && gift_card(
168
- test_gift_card_name,
169
- utxo,
170
- Burn,
171
- ctx,
172
- ))
173
- }