@helios-lang/effect 0.1.1 → 0.1.3
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.
- package/dist/Ledger/Address.js +156 -0
- package/dist/Ledger/Address.js.map +1 -0
- package/dist/Ledger/AssetClass.js +74 -0
- package/dist/Ledger/AssetClass.js.map +1 -0
- package/dist/Ledger/Assets.js +122 -0
- package/dist/Ledger/Assets.js.map +1 -0
- package/dist/Ledger/Credential.js +17 -0
- package/dist/Ledger/Credential.js.map +1 -0
- package/dist/Ledger/DatumHash.js +21 -0
- package/dist/Ledger/DatumHash.js.map +1 -0
- package/dist/Ledger/MintingPolicy.js +45 -0
- package/dist/Ledger/MintingPolicy.js.map +1 -0
- package/dist/Ledger/PubKeyHash.js +21 -0
- package/dist/Ledger/PubKeyHash.js.map +1 -0
- package/dist/Ledger/TxId.js +15 -0
- package/dist/Ledger/TxId.js.map +1 -0
- package/dist/Ledger/TxInput.js +51 -0
- package/dist/Ledger/TxInput.js.map +1 -0
- package/dist/Ledger/TxOutput.js +118 -0
- package/dist/Ledger/TxOutput.js.map +1 -0
- package/dist/Ledger/TxOutputDatum.js +41 -0
- package/dist/Ledger/TxOutputDatum.js.map +1 -0
- package/dist/Ledger/TxOutputId.js +39 -0
- package/dist/Ledger/TxOutputId.js.map +1 -0
- package/dist/Ledger/ValidatorHash.js +21 -0
- package/dist/Ledger/ValidatorHash.js.map +1 -0
- package/dist/Ledger/index.js +14 -0
- package/dist/Ledger/index.js.map +1 -0
- package/dist/Uplc/Data.js +229 -21
- package/dist/Uplc/Data.js.map +1 -1
- package/dist/Uplc/index.js +0 -1
- package/dist/Uplc/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +14 -10
- package/src/Ledger/Address.ts +252 -0
- package/src/Ledger/AssetClass.ts +96 -0
- package/src/Ledger/Assets.ts +164 -0
- package/src/Ledger/Credential.ts +29 -0
- package/src/Ledger/DatumHash.ts +36 -0
- package/src/Ledger/MintingPolicy.ts +57 -0
- package/src/Ledger/PubKeyHash.ts +36 -0
- package/src/Ledger/TxId.ts +31 -0
- package/src/Ledger/TxInput.test.ts +21 -0
- package/src/Ledger/TxInput.ts +66 -0
- package/src/Ledger/TxOutput.ts +165 -0
- package/src/Ledger/TxOutputDatum.ts +64 -0
- package/src/Ledger/TxOutputId.ts +63 -0
- package/src/Ledger/ValidatorHash.ts +36 -0
- package/src/Ledger/index.ts +13 -0
- package/src/Uplc/Data.test.ts +321 -0
- package/src/Uplc/Data.ts +445 -47
- package/src/Uplc/index.ts +0 -1
- package/src/index.ts +1 -1
- package/src/Address.ts +0 -20
- package/src/Uplc/DataSchema.test.ts +0 -207
- package/src/Uplc/DataSchema.ts +0 -181
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import * as Data from "./Data.js"
|
|
4
|
+
|
|
5
|
+
describe("Uplc.DataSchema.BigInt", () => {
|
|
6
|
+
it("succeeds for {int: 0n}", () => {
|
|
7
|
+
expect(Schema.decodeSync(Data.BigInt)({ int: 0n })).toBe(0n)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it("fails for {int: '0'}", () => {
|
|
11
|
+
expect(() => Schema.decodeUnknownSync(Data.BigInt)({ int: "0" })).toThrow()
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe("Uplc.DataSchema.Int", () => {
|
|
16
|
+
it("succeeds for {int: 0n}", () => {
|
|
17
|
+
expect(Schema.decodeSync(Data.Int)({ int: 0n })).toBe(0)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("fails for {int: '0'}", () => {
|
|
21
|
+
expect(() => Schema.decodeUnknownSync(Data.Int)({ int: "0" })).toThrow()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe("Uplc.DataSchema.String", () => {
|
|
26
|
+
it("succeeds for {bytes: ''}", () => {
|
|
27
|
+
expect(Schema.decodeSync(Data.String)(Data.makeByteArrayData(""))).toBe("")
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("fails for {bytes: 'ff'}", () => {
|
|
31
|
+
expect(() =>
|
|
32
|
+
Schema.decodeSync(Data.String)(Data.makeByteArrayData("ff"))
|
|
33
|
+
).toThrow()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it("succeeds for {bytes: '48656C6C6F20576F726C64'}", () => {
|
|
37
|
+
expect(
|
|
38
|
+
Schema.decodeSync(Data.String)(
|
|
39
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64")
|
|
40
|
+
)
|
|
41
|
+
).toBe("Hello World")
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe("Uplc.DataSchema.Array", () => {
|
|
46
|
+
it("succeeds for empty ListData", () => {
|
|
47
|
+
expect(Schema.decodeSync(Data.Array(Data.String))({ list: [] })).toEqual([])
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it("succeeds for ListData containg single 'Hello World' string", () => {
|
|
51
|
+
expect(
|
|
52
|
+
Schema.decodeSync(Data.Array(Data.String))({
|
|
53
|
+
list: [Data.makeByteArrayData("48656C6C6F20576F726C64")]
|
|
54
|
+
})
|
|
55
|
+
).toEqual(["Hello World"])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it("fails if ListData items are heterogenous", () => {
|
|
59
|
+
expect(() =>
|
|
60
|
+
Schema.decodeSync(Data.Array(Data.String))({
|
|
61
|
+
list: [
|
|
62
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
63
|
+
Data.makeIntData(0)
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
).toThrow()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe("Uplc.DataSchema.Struct", () => {
|
|
71
|
+
it("succeeds for empty ListData for empty Struct", () => {
|
|
72
|
+
expect(Schema.decodeSync(Data.Struct({}))({ list: [] })).toEqual({})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("fails for empty ListData if one field is defined", () => {
|
|
76
|
+
expect(() =>
|
|
77
|
+
Schema.decodeSync(Data.Struct({ foo: Data.String }))({
|
|
78
|
+
list: []
|
|
79
|
+
})
|
|
80
|
+
).toThrow()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("succeeds for ListData with single entry if one field is defined", () => {
|
|
84
|
+
expect(
|
|
85
|
+
Schema.decodeSync(Data.Struct({ foo: Data.String }))({
|
|
86
|
+
list: [Data.makeByteArrayData("48656C6C6F20576F726C64")]
|
|
87
|
+
})
|
|
88
|
+
).toEqual({ foo: "Hello World" })
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("fails for ListData with wrong entry in first place with one field is defined", () => {
|
|
92
|
+
expect(() =>
|
|
93
|
+
Schema.decodeSync(Data.Struct({ foo: Data.String }))({
|
|
94
|
+
list: [{ int: 0n }]
|
|
95
|
+
})
|
|
96
|
+
).toThrow()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it("succeeds for ListData with spurious entries at end with one field is defined", () => {
|
|
100
|
+
expect(
|
|
101
|
+
Schema.decodeSync(Data.Struct({ foo: Data.String }))({
|
|
102
|
+
list: [
|
|
103
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
104
|
+
Data.makeIntData(0)
|
|
105
|
+
]
|
|
106
|
+
})
|
|
107
|
+
).toEqual({ foo: "Hello World" })
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it("succeeds for ListData with two entries with two fields", () => {
|
|
111
|
+
expect(
|
|
112
|
+
Schema.decodeSync(Data.Struct({ foo: Data.String, bar: Data.Int }))({
|
|
113
|
+
list: [
|
|
114
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
115
|
+
Data.makeIntData(0n)
|
|
116
|
+
]
|
|
117
|
+
})
|
|
118
|
+
).toEqual({ foo: "Hello World", bar: 0 })
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("fails for ListData with two entries in wrong order with two fields", () => {
|
|
122
|
+
expect(() =>
|
|
123
|
+
Schema.decodeSync(Data.Struct({ bar: Data.Int, foo: Data.String }))({
|
|
124
|
+
list: [
|
|
125
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
126
|
+
Data.makeIntData(0n)
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
).toThrow()
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
describe("Uplc.DataSchema.EnumVariant", () => {
|
|
134
|
+
it("succeeds for empty ConstrData for empty EnumVariant", () => {
|
|
135
|
+
expect(
|
|
136
|
+
Schema.decodeSync(Data.EnumVariant(0, {}))({
|
|
137
|
+
constructor: 0,
|
|
138
|
+
fields: []
|
|
139
|
+
})
|
|
140
|
+
).toEqual({})
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it("fields for ConstrData with wrong tag", () => {
|
|
144
|
+
expect(() =>
|
|
145
|
+
Schema.decodeSync(Data.EnumVariant(0, {}))({
|
|
146
|
+
constructor: 1,
|
|
147
|
+
fields: []
|
|
148
|
+
})
|
|
149
|
+
).toThrow()
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it("fails for empty ConstrData if one field is defined", () => {
|
|
153
|
+
expect(() =>
|
|
154
|
+
Schema.decodeSync(Data.EnumVariant(0, { foo: Data.String }))({
|
|
155
|
+
constructor: 0,
|
|
156
|
+
fields: []
|
|
157
|
+
})
|
|
158
|
+
).toThrow()
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it("succeeds for ConstrData with single entry if one field is defined", () => {
|
|
162
|
+
expect(
|
|
163
|
+
Schema.decodeSync(Data.EnumVariant(0, { foo: Data.String }))({
|
|
164
|
+
constructor: 0,
|
|
165
|
+
fields: [Data.makeByteArrayData("48656C6C6F20576F726C64")]
|
|
166
|
+
})
|
|
167
|
+
).toEqual({ foo: "Hello World" })
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it("fails for ConstrData with wrong entry in first place with one field is defined", () => {
|
|
171
|
+
expect(() =>
|
|
172
|
+
Schema.decodeSync(Data.EnumVariant(0, { foo: Data.String }))({
|
|
173
|
+
constructor: 0,
|
|
174
|
+
fields: [{ int: 0n }]
|
|
175
|
+
})
|
|
176
|
+
).toThrow()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it("succeeds for EnumVariant with spurious entries at end with one field is defined", () => {
|
|
180
|
+
expect(
|
|
181
|
+
Schema.decodeSync(Data.EnumVariant(0, { foo: Data.String }))({
|
|
182
|
+
constructor: 0,
|
|
183
|
+
fields: [
|
|
184
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
185
|
+
Data.makeIntData(0n)
|
|
186
|
+
]
|
|
187
|
+
})
|
|
188
|
+
).toEqual({ foo: "Hello World" })
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it("succeeds for EnumVariant with two entries with two fields", () => {
|
|
192
|
+
expect(
|
|
193
|
+
Schema.decodeSync(
|
|
194
|
+
Data.EnumVariant(0, {
|
|
195
|
+
foo: Data.String,
|
|
196
|
+
bar: Data.Int
|
|
197
|
+
})
|
|
198
|
+
)({
|
|
199
|
+
constructor: 0,
|
|
200
|
+
fields: [
|
|
201
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
202
|
+
Data.makeIntData(0n)
|
|
203
|
+
]
|
|
204
|
+
})
|
|
205
|
+
).toEqual({ foo: "Hello World", bar: 0 })
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it("fails for EnumVariant with two entries in wrong order with two fields", () => {
|
|
209
|
+
expect(() =>
|
|
210
|
+
Schema.decodeSync(
|
|
211
|
+
Data.EnumVariant(0, {
|
|
212
|
+
bar: Data.Int,
|
|
213
|
+
foo: Data.String
|
|
214
|
+
})
|
|
215
|
+
)({
|
|
216
|
+
constructor: 0,
|
|
217
|
+
fields: [
|
|
218
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
219
|
+
Data.makeIntData(0n)
|
|
220
|
+
]
|
|
221
|
+
})
|
|
222
|
+
).toThrow()
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
describe("Uplc.DataSchema.Enum", () => {
|
|
227
|
+
it("succeeds for empty ConstrData for empty EnumVariant", () => {
|
|
228
|
+
expect(
|
|
229
|
+
Schema.decodeSync(Data.Enum({ foo: {} }))({
|
|
230
|
+
constructor: 0,
|
|
231
|
+
fields: []
|
|
232
|
+
})
|
|
233
|
+
).toEqual({ _tag: "foo" })
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it("fields for ConstrData with wrong tag", () => {
|
|
237
|
+
expect(() =>
|
|
238
|
+
Schema.decodeSync(Data.Enum({ foo: {} }))({
|
|
239
|
+
constructor: 1,
|
|
240
|
+
fields: []
|
|
241
|
+
})
|
|
242
|
+
).toThrow()
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it("fails for empty ConstrData if one field is defined", () => {
|
|
246
|
+
expect(() =>
|
|
247
|
+
Schema.decodeSync(Data.Enum({ foo: { bar: Data.String } }))({
|
|
248
|
+
constructor: 0,
|
|
249
|
+
fields: []
|
|
250
|
+
})
|
|
251
|
+
).toThrow()
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it("succeeds for ConstrData with single entry if one field is defined", () => {
|
|
255
|
+
expect(
|
|
256
|
+
Schema.decodeSync(Data.Enum({ foo: { bar: Data.String } }))({
|
|
257
|
+
constructor: 0,
|
|
258
|
+
fields: [Data.makeByteArrayData("48656C6C6F20576F726C64")]
|
|
259
|
+
})
|
|
260
|
+
).toEqual({ _tag: "foo", bar: "Hello World" })
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it("fails for ConstrData with wrong entry in first place with one field is defined", () => {
|
|
264
|
+
expect(() =>
|
|
265
|
+
Schema.decodeSync(Data.Enum({ foo: { bar: Data.String } }))({
|
|
266
|
+
constructor: 0,
|
|
267
|
+
fields: [{ int: 0n }]
|
|
268
|
+
})
|
|
269
|
+
).toThrow()
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it("succeeds for Enum with spurious entries at end with one field is defined", () => {
|
|
273
|
+
expect(
|
|
274
|
+
Schema.decodeSync(Data.Enum({ foo: { bar: Data.String } }))({
|
|
275
|
+
constructor: 0,
|
|
276
|
+
fields: [
|
|
277
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
278
|
+
Data.makeIntData(0n)
|
|
279
|
+
]
|
|
280
|
+
})
|
|
281
|
+
).toEqual({ _tag: "foo", bar: "Hello World" })
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
it("succeeds for Enum with two entries with two fields", () => {
|
|
285
|
+
expect(
|
|
286
|
+
Schema.decodeSync(
|
|
287
|
+
Data.Enum({
|
|
288
|
+
foo: {
|
|
289
|
+
a: Data.String,
|
|
290
|
+
b: Data.Int
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
)({
|
|
294
|
+
constructor: 0,
|
|
295
|
+
fields: [
|
|
296
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
297
|
+
Data.makeIntData(0n)
|
|
298
|
+
]
|
|
299
|
+
})
|
|
300
|
+
).toEqual({ _tag: "foo", a: "Hello World", b: 0 })
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
it("fails for Enum with two entries in wrong order with two fields", () => {
|
|
304
|
+
expect(() =>
|
|
305
|
+
Schema.decodeSync(
|
|
306
|
+
Data.Enum({
|
|
307
|
+
foo: {
|
|
308
|
+
a: Data.Int,
|
|
309
|
+
b: Data.String
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
)({
|
|
313
|
+
constructor: 0,
|
|
314
|
+
fields: [
|
|
315
|
+
Data.makeByteArrayData("48656C6C6F20576F726C64"),
|
|
316
|
+
Data.makeIntData(0n)
|
|
317
|
+
]
|
|
318
|
+
})
|
|
319
|
+
).toThrow()
|
|
320
|
+
})
|
|
321
|
+
})
|