@meshsdk/common 1.5.30 → 1.6.0-alpha.20
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/package.json +3 -9
- package/src/constants/cost-models.ts +30 -0
- package/src/constants/index.ts +86 -0
- package/src/constants/language-views.ts +19 -0
- package/src/constants/protocol-parameters.ts +34 -0
- package/src/constants/supported-wallets.ts +12 -0
- package/src/data/index.ts +5 -0
- package/src/data/json/aliases.ts +218 -0
- package/src/data/json/constructors.ts +56 -0
- package/src/data/json/credentials.ts +77 -0
- package/src/data/json/index.ts +33 -0
- package/src/data/json/primitives.ts +154 -0
- package/src/data/mesh/aliases.ts +85 -0
- package/src/data/mesh/constructors.ts +68 -0
- package/src/data/mesh/credentials.ts +77 -0
- package/src/data/mesh/index.ts +4 -0
- package/src/data/mesh/primitives.ts +37 -0
- package/src/data/parser.ts +36 -0
- package/src/data/time.ts +92 -0
- package/src/data/value.ts +70 -0
- package/src/index.ts +7 -0
- package/src/interfaces/evaluator.ts +5 -0
- package/src/interfaces/fetcher.ts +31 -0
- package/src/interfaces/index.ts +7 -0
- package/src/interfaces/initiator.ts +9 -0
- package/src/interfaces/listener.ts +3 -0
- package/src/interfaces/serializer.ts +53 -0
- package/src/interfaces/signer.ts +12 -0
- package/src/interfaces/submitter.ts +3 -0
- package/src/types/account-info.ts +7 -0
- package/src/types/action.ts +15 -0
- package/src/types/asset-extended.ts +9 -0
- package/src/types/asset-metadata.ts +102 -0
- package/src/types/asset.ts +23 -0
- package/src/types/block-info.ts +17 -0
- package/src/types/data-signature.ts +4 -0
- package/src/types/data.ts +10 -0
- package/src/types/deserialized/deserialized-address.ts +6 -0
- package/src/types/deserialized/deserialized-script.ts +4 -0
- package/src/types/deserialized/index.ts +2 -0
- package/src/types/era.ts +1 -0
- package/src/types/index.ts +24 -0
- package/src/types/message.ts +4 -0
- package/src/types/mint.ts +12 -0
- package/src/types/native-script.ts +18 -0
- package/src/types/network.ts +7 -0
- package/src/types/plutus-script.ts +8 -0
- package/src/types/pool-params.ts +41 -0
- package/src/types/protocol.ts +22 -0
- package/src/types/recipient.ts +15 -0
- package/src/types/relay.ts +42 -0
- package/src/types/token.ts +3 -0
- package/src/types/transaction-builder/data.ts +31 -0
- package/src/types/transaction-builder/index.ts +73 -0
- package/src/types/transaction-builder/mint.ts +11 -0
- package/src/types/transaction-builder/output.ts +12 -0
- package/src/types/transaction-builder/script.ts +27 -0
- package/src/types/transaction-builder/txin.ts +46 -0
- package/src/types/transaction-builder/withdrawal.ts +207 -0
- package/src/types/transaction-info.ts +11 -0
- package/src/types/utxo.ts +16 -0
- package/src/types/wallet.ts +6 -0
- package/src/utils/asset-fingerprint.ts +11 -0
- package/src/utils/bigNum.ts +61 -0
- package/src/utils/index.ts +2 -0
- package/test/data/json/aliases.test.ts +135 -0
- package/test/data/json/constructors.test.ts +38 -0
- package/test/data/json/credentials.test.ts +84 -0
- package/test/data/json/primitives.test.ts +133 -0
- package/test/data/mesh/aliases.test.ts +45 -0
- package/test/data/mesh/common.ts +14 -0
- package/test/data/mesh/constructors.test.ts +53 -0
- package/test/data/mesh/credentials.test.ts +74 -0
- package/test/data/mesh/primitives.test.ts +41 -0
- package/test/data/value.test.ts +108 -0
- package/tsconfig.json +5 -0
- package/dist/index.d.mts +0 -1176
- package/dist/index.d.ts +0 -1176
- package/dist/index.js +0 -1
- package/dist/index.mjs +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Asset } from "../asset";
|
|
2
|
+
import { DatumSource, Redeemer } from "./data";
|
|
3
|
+
import { ScriptSource, SimpleScriptSourceInfo } from "./script";
|
|
4
|
+
|
|
5
|
+
export type RefTxIn = { txHash: string; txIndex: number };
|
|
6
|
+
|
|
7
|
+
export type TxInParameter = {
|
|
8
|
+
txHash: string;
|
|
9
|
+
txIndex: number;
|
|
10
|
+
amount?: Asset[];
|
|
11
|
+
address?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type TxIn = PubKeyTxIn | SimpleScriptTxIn | ScriptTxIn;
|
|
15
|
+
|
|
16
|
+
export type PubKeyTxIn = { type: "PubKey"; txIn: TxInParameter };
|
|
17
|
+
|
|
18
|
+
export type SimpleScriptTxIn = {
|
|
19
|
+
type: "SimpleScript";
|
|
20
|
+
txIn: TxInParameter;
|
|
21
|
+
simpleScriptTxIn: SimpleScriptTxInParameter;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type SimpleScriptTxInParameter = {
|
|
25
|
+
scriptSource?:
|
|
26
|
+
| {
|
|
27
|
+
type: "Provided";
|
|
28
|
+
script: string;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
type: "Inline";
|
|
32
|
+
txInInfo: SimpleScriptSourceInfo;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ScriptTxInParameter = {
|
|
37
|
+
scriptSource?: ScriptSource;
|
|
38
|
+
datumSource?: DatumSource;
|
|
39
|
+
redeemer?: Redeemer;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ScriptTxIn = {
|
|
43
|
+
type: "Script";
|
|
44
|
+
txIn: TxInParameter;
|
|
45
|
+
scriptTxIn: ScriptTxInParameter;
|
|
46
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { PoolParams, poolParamsToObj } from "..";
|
|
2
|
+
import { Redeemer } from "./data";
|
|
3
|
+
import { ScriptSource } from "./script";
|
|
4
|
+
|
|
5
|
+
export type Certificate =
|
|
6
|
+
| { type: "RegisterPool"; poolParams: PoolParams }
|
|
7
|
+
| { type: "RegisterStake"; stakeKeyHash: string }
|
|
8
|
+
| { type: "DelegateStake"; stakeKeyHash: string; poolId: string }
|
|
9
|
+
| { type: "DeregisterStake"; stakeKeyHash: string }
|
|
10
|
+
| { type: "RetirePool"; poolId: string; epoch: number }
|
|
11
|
+
| { type: "VoteDelegation"; stakeKeyHash: string; drep: DRep }
|
|
12
|
+
| {
|
|
13
|
+
type: "StakeAndVoteDelegation";
|
|
14
|
+
stakeKeyHash: string;
|
|
15
|
+
poolKeyHash: string;
|
|
16
|
+
drep: DRep;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
type: "StakeRegistrationAndDelegation";
|
|
20
|
+
stakeKeyHash: string;
|
|
21
|
+
poolKeyHash: string;
|
|
22
|
+
coin: number;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
type: "VoteRegistrationAndDelegation";
|
|
26
|
+
stakeKeyHash: string;
|
|
27
|
+
drep: DRep;
|
|
28
|
+
coin: number;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
type: "StakeVoteRegistrationAndDelegation";
|
|
32
|
+
stakeKeyHash: string;
|
|
33
|
+
poolKeyHash: string;
|
|
34
|
+
drep: DRep;
|
|
35
|
+
coin: number;
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
type: "CommitteeHotAuth";
|
|
39
|
+
committeeColdKeyHash: string;
|
|
40
|
+
committeeHotKeyHash: string;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
type: "CommitteeColdResign";
|
|
44
|
+
committeeColdKeyHash: string;
|
|
45
|
+
anchor?: Anchor;
|
|
46
|
+
}
|
|
47
|
+
| {
|
|
48
|
+
type: "DRepRegistration";
|
|
49
|
+
votingKeyHash: string;
|
|
50
|
+
coin: number;
|
|
51
|
+
anchor?: Anchor;
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
type: "DRepDeregistration";
|
|
55
|
+
votingKeyHash: string;
|
|
56
|
+
coin: number;
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
type: "DRepUpdate";
|
|
60
|
+
votingKeyHash: string;
|
|
61
|
+
anchor: Anchor;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type DRep =
|
|
65
|
+
| { keyHash: string }
|
|
66
|
+
| { scriptHash: string }
|
|
67
|
+
| {
|
|
68
|
+
alwaysAbstain: {};
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
alwaysNoConfidence: {};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type Anchor = {
|
|
75
|
+
anchorUrl: string;
|
|
76
|
+
anchorDataHash: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type Withdrawal =
|
|
80
|
+
| {
|
|
81
|
+
pubKeyWithdrawal: {
|
|
82
|
+
address: string;
|
|
83
|
+
coin: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
| {
|
|
87
|
+
plutusScriptWithdrawal: {
|
|
88
|
+
address: string;
|
|
89
|
+
coin: string;
|
|
90
|
+
scriptSource?: ScriptSource;
|
|
91
|
+
redeemer?: Redeemer;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const certificateToObj = (certificate: Certificate): object => {
|
|
96
|
+
switch (certificate.type) {
|
|
97
|
+
case "RegisterPool":
|
|
98
|
+
return {
|
|
99
|
+
registerPool: {
|
|
100
|
+
poolParams: poolParamsToObj(certificate.poolParams),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
case "RegisterStake":
|
|
104
|
+
return {
|
|
105
|
+
registerStake: {
|
|
106
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
case "DelegateStake":
|
|
110
|
+
return {
|
|
111
|
+
delegateStake: {
|
|
112
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
113
|
+
poolId: certificate.poolId,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
case "DeregisterStake":
|
|
117
|
+
return {
|
|
118
|
+
deregisterStake: {
|
|
119
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
case "RetirePool":
|
|
123
|
+
return {
|
|
124
|
+
retirePool: {
|
|
125
|
+
poolId: certificate.poolId,
|
|
126
|
+
epoch: certificate.epoch,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
case "VoteDelegation":
|
|
130
|
+
return {
|
|
131
|
+
voteDelegation: {
|
|
132
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
133
|
+
drep: certificate.drep,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
case "StakeAndVoteDelegation":
|
|
137
|
+
return {
|
|
138
|
+
stakeAndVoteDelegation: {
|
|
139
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
140
|
+
poolKeyHash: certificate.poolKeyHash,
|
|
141
|
+
drep: certificate.drep,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
case "StakeRegistrationAndDelegation":
|
|
145
|
+
return {
|
|
146
|
+
stakeRegistrationAndDelegation: {
|
|
147
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
148
|
+
poolKeyHash: certificate.poolKeyHash,
|
|
149
|
+
coin: certificate.coin,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
case "VoteRegistrationAndDelegation":
|
|
153
|
+
return {
|
|
154
|
+
voteRegistrationAndDelegation: {
|
|
155
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
156
|
+
drep: certificate.drep,
|
|
157
|
+
coin: certificate.coin,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
case "StakeVoteRegistrationAndDelegation":
|
|
161
|
+
return {
|
|
162
|
+
stakeVoteRegistrationAndDelegation: {
|
|
163
|
+
stakeKeyHash: certificate.stakeKeyHash,
|
|
164
|
+
poolKeyHash: certificate.poolKeyHash,
|
|
165
|
+
drep: certificate.drep,
|
|
166
|
+
coin: certificate.coin,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
case "CommitteeHotAuth":
|
|
170
|
+
return {
|
|
171
|
+
committeeHotAuth: {
|
|
172
|
+
committeeColdKeyHash: certificate.committeeColdKeyHash,
|
|
173
|
+
committeeHotKeyHash: certificate.committeeHotKeyHash,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
case "CommitteeColdResign":
|
|
177
|
+
return {
|
|
178
|
+
committeeColdResign: {
|
|
179
|
+
committeeColdKeyHash: certificate.committeeColdKeyHash,
|
|
180
|
+
anchor: certificate.anchor ?? null,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
case "DRepRegistration":
|
|
185
|
+
return {
|
|
186
|
+
dRepRegistration: {
|
|
187
|
+
votingKeyHash: certificate.votingKeyHash,
|
|
188
|
+
coin: certificate.coin,
|
|
189
|
+
anchor: certificate.anchor ?? null,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
case "DRepDeregistration":
|
|
193
|
+
return {
|
|
194
|
+
dRepDeregistration: {
|
|
195
|
+
votingKeyHash: certificate.votingKeyHash,
|
|
196
|
+
coin: certificate.coin,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
case "DRepUpdate":
|
|
200
|
+
return {
|
|
201
|
+
dRepUpdate: {
|
|
202
|
+
votingKeyHash: certificate.votingKeyHash,
|
|
203
|
+
anchor: certificate.anchor,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Asset } from "./asset";
|
|
2
|
+
|
|
3
|
+
export type UTxO = {
|
|
4
|
+
input: {
|
|
5
|
+
outputIndex: number;
|
|
6
|
+
txHash: string;
|
|
7
|
+
};
|
|
8
|
+
output: {
|
|
9
|
+
address: string;
|
|
10
|
+
amount: Asset[];
|
|
11
|
+
dataHash?: string;
|
|
12
|
+
plutusData?: string;
|
|
13
|
+
scriptRef?: string;
|
|
14
|
+
scriptHash?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import CIP14 from "@emurgo/cip14-js";
|
|
2
|
+
|
|
3
|
+
import { toBytes } from "../data";
|
|
4
|
+
|
|
5
|
+
export const AssetFingerprint = CIP14;
|
|
6
|
+
|
|
7
|
+
export const resolveFingerprint = (policyId: string, assetName: string) => {
|
|
8
|
+
return (AssetFingerprint as any).default
|
|
9
|
+
.fromParts(toBytes(policyId), toBytes(assetName))
|
|
10
|
+
.fingerprint();
|
|
11
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export class BigNum {
|
|
2
|
+
value: bigint;
|
|
3
|
+
|
|
4
|
+
constructor(value: number | string) {
|
|
5
|
+
this.value = BigInt(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Operators
|
|
9
|
+
|
|
10
|
+
divFloor(other: BigNum): BigNum {
|
|
11
|
+
this.value = this.value / other.value;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
checkedMul(other: BigNum): BigNum {
|
|
16
|
+
this.value *= other.value;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
checkedAdd(other: BigNum): BigNum {
|
|
21
|
+
this.value += other.value;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
checkedSub(other: BigNum): BigNum {
|
|
26
|
+
this.value -= other.value;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clampedSub(other: BigNum): BigNum {
|
|
31
|
+
const result = this.value - other.value;
|
|
32
|
+
this.value = result < 0n ? 0n : result;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Comparators
|
|
37
|
+
|
|
38
|
+
lessThan(other: BigNum): boolean {
|
|
39
|
+
return this.value < other.value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
compare(other: BigNum): -1 | 0 | 1 {
|
|
43
|
+
if (this.value === other.value) {
|
|
44
|
+
return 0;
|
|
45
|
+
} else if (this.value < other.value) {
|
|
46
|
+
return -1;
|
|
47
|
+
} else {
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static new = (value: number | string): BigNum => {
|
|
53
|
+
return new BigNum(value);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Override
|
|
57
|
+
|
|
58
|
+
toString(): string {
|
|
59
|
+
return this.value.toString();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assetClass,
|
|
3
|
+
assetName,
|
|
4
|
+
assocMap,
|
|
5
|
+
byteString,
|
|
6
|
+
conStr0,
|
|
7
|
+
currencySymbol,
|
|
8
|
+
integer,
|
|
9
|
+
outputReference,
|
|
10
|
+
policyId,
|
|
11
|
+
posixTime,
|
|
12
|
+
pubKeyHash,
|
|
13
|
+
scriptHash,
|
|
14
|
+
tokenName,
|
|
15
|
+
tuple,
|
|
16
|
+
txOutRef,
|
|
17
|
+
} from "../../../src";
|
|
18
|
+
|
|
19
|
+
const testHash = "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc81700";
|
|
20
|
+
const testTxHash =
|
|
21
|
+
"a0bd47e8938e7c41d4c1d7c22033892319d28f86fdace791d45c51946553791b";
|
|
22
|
+
|
|
23
|
+
describe("Plutus byte hash types", () => {
|
|
24
|
+
describe("hashByteString", () => {
|
|
25
|
+
test("hashByteString - valid", () => {
|
|
26
|
+
const result = byteString(testHash);
|
|
27
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify({ bytes: testHash }));
|
|
28
|
+
});
|
|
29
|
+
test("hashByteString - invalid string", () => {
|
|
30
|
+
expect(() => byteString("invalid string")).toThrow();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe("scriptHash", () => {
|
|
34
|
+
test("scriptHash", () => {
|
|
35
|
+
const result = scriptHash(testHash);
|
|
36
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(byteString(testHash)));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe("pubKeyHash", () => {
|
|
40
|
+
test("pubKeyHash", () => {
|
|
41
|
+
const result = pubKeyHash(testHash);
|
|
42
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(byteString(testHash)));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("Plutus data type", () => {
|
|
48
|
+
describe("policyId", () => {
|
|
49
|
+
test("policyId", () => {
|
|
50
|
+
const result = policyId(testHash);
|
|
51
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(byteString(testHash)));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("currencySymbol", () => {
|
|
55
|
+
test("currencySymbol", () => {
|
|
56
|
+
const result = currencySymbol(testHash);
|
|
57
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(byteString(testHash)));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("assetName", () => {
|
|
61
|
+
test("assetName", () => {
|
|
62
|
+
const result = assetName("abcd");
|
|
63
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(byteString("abcd")));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe("tokenName", () => {
|
|
67
|
+
test("tokenName", () => {
|
|
68
|
+
const result = tokenName("abcd");
|
|
69
|
+
expect(JSON.stringify(result)).toBe(JSON.stringify(byteString("abcd")));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe("assetClass", () => {
|
|
73
|
+
test("assetClass", () => {
|
|
74
|
+
const result = assetClass(testHash, "abcd");
|
|
75
|
+
expect(JSON.stringify(result)).toBe(
|
|
76
|
+
JSON.stringify(conStr0([currencySymbol(testHash), tokenName("abcd")])),
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("outputReference", () => {
|
|
81
|
+
test("outputReference", () => {
|
|
82
|
+
const result = outputReference(testTxHash, 1);
|
|
83
|
+
expect(JSON.stringify(result)).toBe(
|
|
84
|
+
JSON.stringify(
|
|
85
|
+
conStr0([conStr0([byteString(testTxHash)]), integer(1)]),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
test("outputReference - invalid length", () => {
|
|
90
|
+
expect(() => outputReference(testHash, 1)).toThrow;
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe("txOutRef", () => {
|
|
94
|
+
test("txOutRef", () => {
|
|
95
|
+
const result = txOutRef(testTxHash, 1);
|
|
96
|
+
expect(JSON.stringify(result)).toBe(
|
|
97
|
+
JSON.stringify(
|
|
98
|
+
conStr0([conStr0([byteString(testTxHash)]), integer(1)]),
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe("posixTime", () => {
|
|
104
|
+
test("posixTime", () => {
|
|
105
|
+
const result = posixTime(123456789000000);
|
|
106
|
+
expect(JSON.stringify(result)).toBe(
|
|
107
|
+
JSON.stringify(integer(123456789000000)),
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe("dict", () => {
|
|
112
|
+
test("dict", () => {
|
|
113
|
+
const result = assocMap([
|
|
114
|
+
["key1", "value1"],
|
|
115
|
+
["key2", "value2"],
|
|
116
|
+
]);
|
|
117
|
+
expect(JSON.stringify(result)).toBe(
|
|
118
|
+
JSON.stringify(
|
|
119
|
+
assocMap([
|
|
120
|
+
["key1", "value1"],
|
|
121
|
+
["key2", "value2"],
|
|
122
|
+
]),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe("tuple", () => {
|
|
128
|
+
test("tuple", () => {
|
|
129
|
+
const result = tuple({ bytes: "1234" }, { bytes: "abcd" });
|
|
130
|
+
expect(JSON.stringify(result)).toBe(
|
|
131
|
+
JSON.stringify({ list: [{ bytes: "1234" }, { bytes: "abcd" }] }),
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { conStr, conStr0, conStr1, conStr2 } from "../../../src";
|
|
2
|
+
|
|
3
|
+
const testByteString = { bytes: "abcd" };
|
|
4
|
+
|
|
5
|
+
describe("Plutus data type", () => {
|
|
6
|
+
describe("constructor", () => {
|
|
7
|
+
test("conStr", () => {
|
|
8
|
+
const result = conStr(0, [testByteString]);
|
|
9
|
+
expect(JSON.stringify(result)).toBe(
|
|
10
|
+
JSON.stringify({ constructor: 0, fields: [testByteString] }),
|
|
11
|
+
);
|
|
12
|
+
});
|
|
13
|
+
test("conStr0", () => {
|
|
14
|
+
const result = conStr0([testByteString]);
|
|
15
|
+
expect(JSON.stringify(result)).toBe(
|
|
16
|
+
JSON.stringify({ constructor: 0, fields: [testByteString] }),
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
test("conStr1", () => {
|
|
20
|
+
const result = conStr1([testByteString]);
|
|
21
|
+
expect(JSON.stringify(result)).toBe(
|
|
22
|
+
JSON.stringify({ constructor: 1, fields: [testByteString] }),
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
test("conStr2", () => {
|
|
26
|
+
const result = conStr2([testByteString]);
|
|
27
|
+
expect(JSON.stringify(result)).toBe(
|
|
28
|
+
JSON.stringify({ constructor: 2, fields: [testByteString] }),
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("Input validation", () => {
|
|
34
|
+
test("Non array fields", () => {
|
|
35
|
+
expect(() => conStr(0, testByteString)).toThrow();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
conStr0,
|
|
3
|
+
conStr1,
|
|
4
|
+
maybeStakingHash,
|
|
5
|
+
pubKeyAddress,
|
|
6
|
+
pubKeyHash,
|
|
7
|
+
scriptAddress,
|
|
8
|
+
scriptHash,
|
|
9
|
+
} from "../../../src";
|
|
10
|
+
|
|
11
|
+
const testKeyHash1 = "1e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0";
|
|
12
|
+
const testKeyHash2 = "d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac0";
|
|
13
|
+
|
|
14
|
+
describe("Plutus data type", () => {
|
|
15
|
+
describe("maybeStakingHash", () => {
|
|
16
|
+
test("maybeStakingHash - no staking hash", () => {
|
|
17
|
+
const result = maybeStakingHash("");
|
|
18
|
+
expect(JSON.stringify(result)).toBe(
|
|
19
|
+
JSON.stringify({ constructor: 1, fields: [] }),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
test("maybeStakingHash - pub key staking hash", () => {
|
|
23
|
+
const result = maybeStakingHash(testKeyHash1);
|
|
24
|
+
expect(JSON.stringify(result)).toBe(
|
|
25
|
+
JSON.stringify(
|
|
26
|
+
conStr0([conStr0([conStr0([pubKeyHash(testKeyHash1)])])]),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
test("maybeStakingHash - script staking hash", () => {
|
|
31
|
+
const result = maybeStakingHash(testKeyHash1, true);
|
|
32
|
+
expect(JSON.stringify(result)).toBe(
|
|
33
|
+
JSON.stringify(
|
|
34
|
+
conStr0([conStr0([conStr1([scriptHash(testKeyHash1)])])]),
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe("pubKeyAddress", () => {
|
|
40
|
+
test("pubKeyAddress", () => {
|
|
41
|
+
const result = pubKeyAddress(testKeyHash1);
|
|
42
|
+
expect(JSON.stringify(result)).toBe(
|
|
43
|
+
JSON.stringify(
|
|
44
|
+
conStr0([conStr0([pubKeyHash(testKeyHash1)]), maybeStakingHash("")]),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
test("pubKeyAddress - full base address", () => {
|
|
49
|
+
const result = pubKeyAddress(testKeyHash1, testKeyHash2);
|
|
50
|
+
expect(JSON.stringify(result)).toBe(
|
|
51
|
+
JSON.stringify(
|
|
52
|
+
conStr0([
|
|
53
|
+
conStr0([pubKeyHash(testKeyHash1)]),
|
|
54
|
+
maybeStakingHash(testKeyHash2),
|
|
55
|
+
]),
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("scriptAddress", () => {
|
|
61
|
+
test("scriptAddress", () => {
|
|
62
|
+
const result = scriptAddress(testKeyHash1, testKeyHash2);
|
|
63
|
+
expect(JSON.stringify(result)).toBe(
|
|
64
|
+
JSON.stringify(
|
|
65
|
+
conStr0([
|
|
66
|
+
conStr1([pubKeyHash(testKeyHash1)]),
|
|
67
|
+
maybeStakingHash(testKeyHash2),
|
|
68
|
+
]),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
test("scriptAddress - full base address", () => {
|
|
73
|
+
const result = scriptAddress(testKeyHash1, testKeyHash2);
|
|
74
|
+
expect(JSON.stringify(result)).toBe(
|
|
75
|
+
JSON.stringify(
|
|
76
|
+
conStr0([
|
|
77
|
+
conStr1([pubKeyHash(testKeyHash1)]),
|
|
78
|
+
maybeStakingHash(testKeyHash2),
|
|
79
|
+
]),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|