@algorandfoundation/algorand-typescript-testing 1.0.0-alpha.2

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 (48) hide show
  1. package/abi-metadata.d.ts +16 -0
  2. package/constants.d.ts +21 -0
  3. package/context-helpers/internal-context.d.ts +26 -0
  4. package/decode-logs.d.ts +8 -0
  5. package/errors.d.ts +5 -0
  6. package/impl/account.d.ts +31 -0
  7. package/impl/acct-params.d.ts +5 -0
  8. package/impl/app-params.d.ts +3 -0
  9. package/impl/application.d.ts +24 -0
  10. package/impl/asset-holding.d.ts +2 -0
  11. package/impl/asset-params.d.ts +3 -0
  12. package/impl/asset.d.ts +23 -0
  13. package/impl/crypto.d.ts +12 -0
  14. package/impl/global.d.ts +18 -0
  15. package/impl/gtxn.d.ts +2 -0
  16. package/impl/index.d.ts +11 -0
  17. package/impl/inner-transactions.d.ts +51 -0
  18. package/impl/itxn.d.ts +8 -0
  19. package/impl/pure.d.ts +32 -0
  20. package/impl/scratch.d.ts +2 -0
  21. package/impl/transactions.d.ts +139 -0
  22. package/impl/txn.d.ts +3 -0
  23. package/index.d.ts +1 -0
  24. package/index.mjs +3687 -0
  25. package/index.mjs.map +1 -0
  26. package/package.json +41 -0
  27. package/runtime-helpers-B6YRp95T.js +460 -0
  28. package/runtime-helpers-B6YRp95T.js.map +1 -0
  29. package/runtime-helpers.d.ts +9 -0
  30. package/runtime-helpers.mjs +4 -0
  31. package/runtime-helpers.mjs.map +1 -0
  32. package/subcontexts/contract-context.d.ts +10 -0
  33. package/subcontexts/ledger-context.d.ts +27 -0
  34. package/subcontexts/transaction-context.d.ts +57 -0
  35. package/test-execution-context.d.ts +45 -0
  36. package/test-transformer/errors.d.ts +3 -0
  37. package/test-transformer/helpers.d.ts +2 -0
  38. package/test-transformer/index.d.ts +6 -0
  39. package/test-transformer/node-factory.d.ts +10 -0
  40. package/test-transformer/supported-binary-op-string.d.ts +3 -0
  41. package/test-transformer/visitors.d.ts +11 -0
  42. package/test-transformer.mjs +297 -0
  43. package/test-transformer.mjs.map +1 -0
  44. package/typescript-helpers.d.ts +9 -0
  45. package/util.d.ts +26 -0
  46. package/value-generators/avm.d.ts +23 -0
  47. package/value-generators/index.d.ts +6 -0
  48. package/value-generators/txn.d.ts +10 -0
@@ -0,0 +1,57 @@
1
+ import { bytes, internal, uint64 } from '@algorandfoundation/algorand-typescript';
2
+ import { DecodedLogs, LogDecoding } from '../decode-logs';
3
+ import { AllTransactionFields, ApplicationTransaction, AssetConfigTransaction, AssetFreezeTransaction, AssetTransferTransaction, KeyRegistrationTransaction, PaymentTransaction, Transaction } from '../impl/transactions';
4
+ import { InnerTxn, InnerTxnFields } from '../impl/itxn';
5
+ import { ApplicationInnerTxn, AssetConfigInnerTxn, AssetFreezeInnerTxn, AssetTransferInnerTxn, KeyRegistrationInnerTxn, PaymentInnerTxn } from '../impl/inner-transactions';
6
+ interface ExecutionScope {
7
+ execute: <TReturn>(body: () => TReturn) => TReturn;
8
+ }
9
+ export declare class TransactionContext {
10
+ #private;
11
+ readonly groups: TransactionGroup[];
12
+ createScope(group: Transaction[], activeTransactionIndex?: number): ExecutionScope;
13
+ ensureScope(group: Transaction[], activeTransactionIndex?: number): ExecutionScope;
14
+ get activeGroup(): TransactionGroup;
15
+ get lastGroup(): TransactionGroup;
16
+ get lastActive(): Transaction;
17
+ appendLog(value: internal.primitives.StubBytesCompat): void;
18
+ exportLogs<const T extends [...LogDecoding[]]>(appId: uint64, ...decoding: T): DecodedLogs<T>;
19
+ }
20
+ export declare class TransactionGroup {
21
+ activeTransactionIndex: number;
22
+ latestTimestamp: number;
23
+ transactions: Transaction[];
24
+ itxnGroups: ItxnGroup[];
25
+ constructingItxnGroup: InnerTxnFields[];
26
+ constructor(transactions: Transaction[], activeTransactionIndex?: number);
27
+ get activeTransaction(): Transaction;
28
+ get activeApplicationId(): uint64;
29
+ get constructingItxn(): InnerTxnFields;
30
+ getScratchSlot(index: internal.primitives.StubUint64Compat): bytes | uint64;
31
+ patchActiveTransactionFields(fields: AllTransactionFields): void;
32
+ beginInnerTransactionGroup(): void;
33
+ appendInnerTransactionGroup(): void;
34
+ submitInnerTransactionGroup(): void;
35
+ getItxnGroup(index?: internal.primitives.StubUint64Compat): ItxnGroup;
36
+ getApplicationTransaction(index?: internal.primitives.StubUint64Compat): ApplicationTransaction;
37
+ getAssetConfigTransaction(index?: internal.primitives.StubUint64Compat): AssetConfigTransaction;
38
+ getAssetTransferTransaction(index?: internal.primitives.StubUint64Compat): AssetTransferTransaction;
39
+ getAssetFreezeTransaction(index?: internal.primitives.StubUint64Compat): AssetFreezeTransaction;
40
+ getKeyRegistrationTransaction(index?: internal.primitives.StubUint64Compat): KeyRegistrationTransaction;
41
+ getPaymentTransaction(index?: internal.primitives.StubUint64Compat): PaymentTransaction;
42
+ getTransaction(index?: internal.primitives.StubUint64Compat): Transaction;
43
+ private getTransactionImpl;
44
+ }
45
+ export declare class ItxnGroup {
46
+ itxns: InnerTxn[];
47
+ constructor(itxns: InnerTxn[]);
48
+ getApplicationInnerTxn(index?: internal.primitives.StubUint64Compat): ApplicationInnerTxn;
49
+ getAssetConfigInnerTxn(index?: internal.primitives.StubUint64Compat): AssetConfigInnerTxn;
50
+ getAssetTransferInnerTxn(index?: internal.primitives.StubUint64Compat): AssetTransferInnerTxn;
51
+ getAssetFreezeInnerTxn(index?: internal.primitives.StubUint64Compat): AssetFreezeInnerTxn;
52
+ getKeyRegistrationInnerTxn(index?: internal.primitives.StubUint64Compat): KeyRegistrationInnerTxn;
53
+ getPaymentInnerTxn(index?: internal.primitives.StubUint64Compat): PaymentInnerTxn;
54
+ getInnerTxn(index?: internal.primitives.StubUint64Compat): InnerTxn;
55
+ private getInnerTxnImpl;
56
+ }
57
+ export {};
@@ -0,0 +1,45 @@
1
+ import { Account, Application, Asset, bytes, internal, uint64 } from '@algorandfoundation/algorand-typescript';
2
+ import { DecodedLogs, LogDecoding } from './decode-logs';
3
+ import * as ops from './impl';
4
+ import { ContractContext } from './subcontexts/contract-context';
5
+ import { LedgerContext } from './subcontexts/ledger-context';
6
+ import { TransactionContext } from './subcontexts/transaction-context';
7
+ import { ValueGenerator } from './value-generators';
8
+ import { submitGroup as itxnSubmitGroup, payment as itxnPayment, keyRegistration as itxnKeyRegistration, assetConfig as itxnAssetConfig, assetTransfer as itxnAssetTransfer, assetFreeze as itxnAssetFreeze, applicationCall as itxnApplicationCall } from './impl/inner-transactions';
9
+ export declare class TestExecutionContext implements internal.ExecutionContext {
10
+ #private;
11
+ constructor();
12
+ account(address?: bytes): Account;
13
+ application(id?: uint64): Application;
14
+ asset(id?: uint64): Asset;
15
+ log(value: bytes): void;
16
+ exportLogs<const T extends [...LogDecoding[]]>(appId: uint64, ...decoding: T): DecodedLogs<T>;
17
+ get op(): typeof ops;
18
+ get contract(): ContractContext;
19
+ get ledger(): LedgerContext;
20
+ get txn(): TransactionContext;
21
+ get any(): ValueGenerator;
22
+ get defaultSender(): Account;
23
+ get abiMetadata(): {
24
+ captureMethodConfig: <T extends import("@algorandfoundation/algorand-typescript").Contract>(contract: T, methodName: string, config?: import("@algorandfoundation/algorand-typescript/arc4").AbiMethodConfig<T> | import("@algorandfoundation/algorand-typescript/arc4").BareMethodConfig) => void;
25
+ };
26
+ get gtxn(): {
27
+ Transaction: (index: uint64) => import("./impl/transactions").Transaction;
28
+ PaymentTxn: (index: uint64) => import("./impl/transactions").PaymentTransaction;
29
+ KeyRegistrationTxn: (index: uint64) => import("./impl/transactions").KeyRegistrationTransaction;
30
+ AssetConfigTxn: (index: uint64) => import("./impl/transactions").AssetConfigTransaction;
31
+ AssetTransferTxn: (index: uint64) => import("./impl/transactions").AssetTransferTransaction;
32
+ AssetFreezeTxn: (index: uint64) => import("./impl/transactions").AssetFreezeTransaction;
33
+ ApplicationTxn: (index: uint64) => import("./impl/transactions").ApplicationTransaction;
34
+ };
35
+ get itxn(): {
36
+ submitGroup: typeof itxnSubmitGroup;
37
+ payment: typeof itxnPayment;
38
+ keyRegistration: typeof itxnKeyRegistration;
39
+ assetConfig: typeof itxnAssetConfig;
40
+ assetTransfer: typeof itxnAssetTransfer;
41
+ assetFreeze: typeof itxnAssetFreeze;
42
+ applicationCall: typeof itxnApplicationCall;
43
+ };
44
+ reset(): void;
45
+ }
@@ -0,0 +1,3 @@
1
+ export declare class TransformerError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,2 @@
1
+ import ts from 'typescript';
2
+ export declare const getPropertyNameAsString: (name: ts.PropertyName) => ts.Identifier | ts.StringLiteral | ts.NoSubstitutionTemplateLiteral;
@@ -0,0 +1,6 @@
1
+ import type ts from 'typescript';
2
+ export interface TransformerConfig {
3
+ includeExt: string[];
4
+ testingPackageName: string;
5
+ }
6
+ export declare const puyaTsTransformer: ts.TransformerFactory<ts.SourceFile> & ((config: Partial<TransformerConfig>) => ts.TransformerFactory<ts.SourceFile>);
@@ -0,0 +1,10 @@
1
+ import { FunctionPType } from '@algorandfoundation/puya-ts';
2
+ import ts from 'typescript';
3
+ export declare const nodeFactory: {
4
+ importHelpers(testingPackageName: string): ts.ImportDeclaration;
5
+ switchableValue(x: ts.Expression): ts.CallExpression;
6
+ binaryOp(left: ts.Expression, right: ts.Expression, op: string): ts.CallExpression;
7
+ prefixUnaryOp(operand: ts.Expression, op: string): ts.CallExpression;
8
+ attachMetaData(classIdentifier: ts.Identifier, method: ts.MethodDeclaration, functionType: FunctionPType): ts.ExpressionStatement;
9
+ captureGenericTypeInfo(x: ts.Expression, type: string): ts.CallExpression;
10
+ };
@@ -0,0 +1,3 @@
1
+ import type { BinaryOperator, PrefixUnaryOperator } from 'typescript';
2
+ export declare function supportedBinaryOpString(x: BinaryOperator): string | undefined;
3
+ export declare function supportedPrefixUnaryOpString(x: PrefixUnaryOperator): string | undefined;
@@ -0,0 +1,11 @@
1
+ import ts from 'typescript';
2
+ import { TransformerConfig } from './index';
3
+ export declare class SourceFileVisitor {
4
+ private context;
5
+ private sourceFile;
6
+ private config;
7
+ private helper;
8
+ constructor(context: ts.TransformationContext, sourceFile: ts.SourceFile, program: ts.Program, config: TransformerConfig);
9
+ result(): ts.SourceFile;
10
+ private visit;
11
+ }
@@ -0,0 +1,297 @@
1
+ import { TypeResolver, anyPType, SourceLocation, ContractClassPType, FunctionPType, typeRegistry, registerPTypes } from '@algorandfoundation/puya-ts';
2
+ import ts from 'typescript';
3
+
4
+ class TransformerError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ }
8
+ }
9
+
10
+ const getPropertyNameAsString = (name) => {
11
+ if (ts.isStringLiteralLike(name)) {
12
+ return name;
13
+ }
14
+ if (ts.isIdentifier(name)) {
15
+ return ts.factory.createStringLiteral(name.text);
16
+ }
17
+ throw new TransformerError(`Node ${name.kind} cannot be converted to a static string`);
18
+ };
19
+
20
+ const factory$1 = ts.factory;
21
+ const nodeFactory = {
22
+ importHelpers(testingPackageName) {
23
+ return factory$1.createImportDeclaration(undefined, factory$1.createImportClause(false, undefined, factory$1.createNamespaceImport(factory$1.createIdentifier('runtimeHelpers'))), factory$1.createStringLiteral(`${testingPackageName}/runtime-helpers`), undefined);
24
+ },
25
+ switchableValue(x) {
26
+ return factory$1.createCallExpression(factory$1.createPropertyAccessExpression(factory$1.createIdentifier('runtimeHelpers'), factory$1.createIdentifier('switchableValue')), undefined, [x]);
27
+ },
28
+ binaryOp(left, right, op) {
29
+ return factory$1.createCallExpression(factory$1.createPropertyAccessExpression(factory$1.createIdentifier('runtimeHelpers'), factory$1.createIdentifier('binaryOp')), undefined, [left, right, factory$1.createStringLiteral(op)]);
30
+ },
31
+ prefixUnaryOp(operand, op) {
32
+ return factory$1.createCallExpression(factory$1.createPropertyAccessExpression(factory$1.createIdentifier('runtimeHelpers'), factory$1.createIdentifier('unaryOp')), undefined, [operand, factory$1.createStringLiteral(op)]);
33
+ },
34
+ attachMetaData(classIdentifier, method, functionType) {
35
+ const methodName = getPropertyNameAsString(method.name);
36
+ const metadata = factory$1.createObjectLiteralExpression([
37
+ factory$1.createPropertyAssignment('methodName', methodName),
38
+ factory$1.createPropertyAssignment('methodSelector', methodName),
39
+ factory$1.createPropertyAssignment('argTypes', factory$1.createArrayLiteralExpression(functionType.parameters.map((p) => factory$1.createStringLiteral(p[1].fullName)))),
40
+ factory$1.createPropertyAssignment('returnType', factory$1.createStringLiteral(functionType.returnType.fullName)),
41
+ ]);
42
+ return factory$1.createExpressionStatement(factory$1.createCallExpression(factory$1.createPropertyAccessExpression(factory$1.createIdentifier('runtimeHelpers'), factory$1.createIdentifier('attachAbiMetadata')), undefined, [classIdentifier, methodName, metadata]));
43
+ },
44
+ captureGenericTypeInfo(x, type) {
45
+ return factory$1.createCallExpression(factory$1.createPropertyAccessExpression(factory$1.createIdentifier('runtimeHelpers'), factory$1.createIdentifier('captureGenericTypeInfo')), undefined, [x, factory$1.createStringLiteral(type)]);
46
+ },
47
+ };
48
+
49
+ function supportedBinaryOpString(x) {
50
+ switch (x) {
51
+ case ts.SyntaxKind.MinusToken:
52
+ return '-';
53
+ case ts.SyntaxKind.PlusToken:
54
+ return '+';
55
+ case ts.SyntaxKind.EqualsEqualsEqualsToken:
56
+ return '===';
57
+ case ts.SyntaxKind.ExclamationEqualsEqualsToken:
58
+ return '!==';
59
+ case ts.SyntaxKind.GreaterThanToken:
60
+ return '>';
61
+ case ts.SyntaxKind.GreaterThanEqualsToken:
62
+ return '>=';
63
+ case ts.SyntaxKind.GreaterThanGreaterThanToken:
64
+ return '>>';
65
+ case ts.SyntaxKind.LessThanToken:
66
+ return '<';
67
+ case ts.SyntaxKind.LessThanEqualsToken:
68
+ return '<=';
69
+ case ts.SyntaxKind.LessThanLessThanToken:
70
+ return '<<';
71
+ case ts.SyntaxKind.AsteriskToken:
72
+ return '*';
73
+ case ts.SyntaxKind.AsteriskAsteriskToken:
74
+ return '**';
75
+ case ts.SyntaxKind.SlashToken:
76
+ return '/';
77
+ case ts.SyntaxKind.PercentToken:
78
+ return '%';
79
+ case ts.SyntaxKind.AmpersandToken:
80
+ return '&';
81
+ case ts.SyntaxKind.BarToken:
82
+ return '|';
83
+ case ts.SyntaxKind.CaretToken:
84
+ return '^';
85
+ case ts.SyntaxKind.AmpersandAmpersandEqualsToken:
86
+ case ts.SyntaxKind.AmpersandAmpersandToken:
87
+ case ts.SyntaxKind.AmpersandEqualsToken:
88
+ case ts.SyntaxKind.AsteriskAsteriskEqualsToken:
89
+ case ts.SyntaxKind.AsteriskEqualsToken:
90
+ case ts.SyntaxKind.BarBarEqualsToken:
91
+ case ts.SyntaxKind.BarBarToken:
92
+ case ts.SyntaxKind.BarEqualsToken:
93
+ case ts.SyntaxKind.CaretEqualsToken:
94
+ case ts.SyntaxKind.CommaToken:
95
+ case ts.SyntaxKind.EqualsEqualsToken:
96
+ case ts.SyntaxKind.EqualsToken:
97
+ case ts.SyntaxKind.ExclamationEqualsToken:
98
+ case ts.SyntaxKind.InKeyword:
99
+ case ts.SyntaxKind.InstanceOfKeyword:
100
+ case ts.SyntaxKind.PercentEqualsToken:
101
+ case ts.SyntaxKind.PlusEqualsToken:
102
+ case ts.SyntaxKind.QuestionQuestionEqualsToken:
103
+ case ts.SyntaxKind.MinusEqualsToken:
104
+ case ts.SyntaxKind.SlashEqualsToken:
105
+ case ts.SyntaxKind.QuestionQuestionToken:
106
+ case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
107
+ case ts.SyntaxKind.LessThanLessThanEqualsToken:
108
+ case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
109
+ case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
110
+ return undefined;
111
+ }
112
+ }
113
+ function supportedPrefixUnaryOpString(x) {
114
+ switch (x) {
115
+ case ts.SyntaxKind.TildeToken:
116
+ return '~';
117
+ default:
118
+ return undefined;
119
+ }
120
+ }
121
+
122
+ const { factory } = ts;
123
+ class SourceFileVisitor {
124
+ context;
125
+ sourceFile;
126
+ config;
127
+ helper;
128
+ constructor(context, sourceFile, program, config) {
129
+ this.context = context;
130
+ this.sourceFile = sourceFile;
131
+ this.config = config;
132
+ const typeResolver = new TypeResolver(program.getTypeChecker(), program.getCurrentDirectory());
133
+ this.helper = {
134
+ additionalStatements: [],
135
+ resolveType(node) {
136
+ try {
137
+ return typeResolver.resolve(node, this.sourceLocation(node));
138
+ }
139
+ catch {
140
+ return anyPType;
141
+ }
142
+ },
143
+ sourceLocation(node) {
144
+ return SourceLocation.fromNode(sourceFile, node, program.getCurrentDirectory());
145
+ },
146
+ };
147
+ }
148
+ result() {
149
+ const updatedSourceFile = ts.visitNode(this.sourceFile, this.visit);
150
+ return factory.updateSourceFile(updatedSourceFile, [
151
+ nodeFactory.importHelpers(this.config.testingPackageName),
152
+ ...updatedSourceFile.statements,
153
+ ...this.helper.additionalStatements,
154
+ ]);
155
+ }
156
+ visit = (node) => {
157
+ if (ts.isFunctionLike(node)) {
158
+ return new FunctionLikeDecVisitor(this.context, node).result();
159
+ }
160
+ if (ts.isClassDeclaration(node)) {
161
+ return new ClassVisitor(this.context, this.helper, node).result();
162
+ }
163
+ return ts.visitEachChild(node, this.visit, this.context);
164
+ };
165
+ }
166
+ class FunctionOrMethodVisitor {
167
+ context;
168
+ constructor(context) {
169
+ this.context = context;
170
+ }
171
+ visit = (node) => {
172
+ return ts.visitEachChild(this.updateNode(node), this.visit, this.context);
173
+ };
174
+ updateNode(node) {
175
+ if (ts.isSwitchStatement(node)) {
176
+ return factory.updateSwitchStatement(node, nodeFactory.switchableValue(node.expression), node.caseBlock);
177
+ }
178
+ if (ts.isCaseClause(node)) {
179
+ return factory.updateCaseClause(node, nodeFactory.switchableValue(node.expression), node.statements);
180
+ }
181
+ if (ts.isBinaryExpression(node)) {
182
+ const tokenText = supportedBinaryOpString(node.operatorToken.kind);
183
+ if (tokenText) {
184
+ return nodeFactory.binaryOp(node.left, node.right, tokenText);
185
+ }
186
+ }
187
+ if (ts.isPrefixUnaryExpression(node)) {
188
+ const tokenText = supportedPrefixUnaryOpString(node.operator);
189
+ if (tokenText) {
190
+ return nodeFactory.prefixUnaryOp(node.operand, tokenText);
191
+ }
192
+ }
193
+ return node;
194
+ }
195
+ }
196
+ class FunctionLikeDecVisitor extends FunctionOrMethodVisitor {
197
+ funcNode;
198
+ constructor(context, funcNode) {
199
+ super(context);
200
+ this.funcNode = funcNode;
201
+ }
202
+ result() {
203
+ return ts.visitNode(this.funcNode, this.visit);
204
+ }
205
+ }
206
+ class MethodDecVisitor extends FunctionOrMethodVisitor {
207
+ methodNode;
208
+ constructor(context, methodNode) {
209
+ super(context);
210
+ this.methodNode = methodNode;
211
+ }
212
+ result() {
213
+ return ts.visitNode(this.methodNode, this.visit);
214
+ }
215
+ }
216
+ class ClassVisitor {
217
+ context;
218
+ helper;
219
+ classDec;
220
+ isArc4;
221
+ constructor(context, helper, classDec) {
222
+ this.context = context;
223
+ this.helper = helper;
224
+ this.classDec = classDec;
225
+ const classType = helper.resolveType(classDec);
226
+ this.isArc4 = classType instanceof ContractClassPType && classType.isARC4;
227
+ }
228
+ result() {
229
+ return this.visit(this.classDec);
230
+ }
231
+ visit = (node) => {
232
+ if (ts.isMethodDeclaration(node)) {
233
+ if (this.classDec.name && this.isArc4) {
234
+ const methodType = this.helper.resolveType(node);
235
+ if (methodType instanceof FunctionPType) {
236
+ this.helper.additionalStatements.push(nodeFactory.attachMetaData(this.classDec.name, node, methodType));
237
+ }
238
+ }
239
+ return new MethodDecVisitor(this.context, node).result();
240
+ }
241
+ if (ts.isCallExpression(node)) {
242
+ let type = this.helper.resolveType(node);
243
+ // `voted = LocalState<uint64>()` is resolved to FunctionPType with returnType LocalState<uint64>
244
+ if (type instanceof FunctionPType)
245
+ type = type.returnType;
246
+ if (typeRegistry.isGeneric(type)) {
247
+ const typeName = type.name;
248
+ return nodeFactory.captureGenericTypeInfo(ts.visitEachChild(node, this.visit, this.context), typeName);
249
+ }
250
+ }
251
+ return ts.visitEachChild(node, this.visit, this.context);
252
+ };
253
+ }
254
+
255
+ const defaultTransformerConfig = {
256
+ includeExt: ['.algo.ts', '.spec.ts'],
257
+ testingPackageName: '@algorandfoundation/algorand-typescript-testing',
258
+ };
259
+ // const programTransformer = {
260
+ // type: 'program',
261
+ // factory(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {
262
+ // registerPTypes(typeRegistry)
263
+ // return (context) => {
264
+ // return (sourceFile) => {
265
+ // if (!includes.some((i) => sourceFile.fileName.endsWith(i))) return sourceFile
266
+ // return new SourceFileVisitor(context, sourceFile, program).result()
267
+ // }
268
+ // }
269
+ // },
270
+ // }
271
+ const createProgramFactory = (config) => {
272
+ function programFactory(program) {
273
+ registerPTypes(typeRegistry);
274
+ return (context) => {
275
+ return (sourceFile) => {
276
+ if (!config.includeExt.some((i) => sourceFile.fileName.endsWith(i)))
277
+ return sourceFile;
278
+ return new SourceFileVisitor(context, sourceFile, program, config).result();
279
+ };
280
+ };
281
+ }
282
+ return programFactory;
283
+ };
284
+ function programTransformer(config) {
285
+ return {
286
+ type: 'program',
287
+ factory: createProgramFactory({ ...defaultTransformerConfig, ...config }),
288
+ };
289
+ }
290
+ programTransformer.type = 'program';
291
+ programTransformer.factory = createProgramFactory(defaultTransformerConfig);
292
+ // Typescript.d.ts typings require a TransformerFactory however rollup plugin supports a program transformer
293
+ // https://github.com/rollup/plugins/blob/master/packages/typescript/src/customTransformers.ts
294
+ const puyaTsTransformer = programTransformer;
295
+
296
+ export { puyaTsTransformer };
297
+ //# sourceMappingURL=test-transformer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-transformer.mjs","sources":["../src/test-transformer/errors.ts","../src/test-transformer/helpers.ts","../src/test-transformer/node-factory.ts","../src/test-transformer/supported-binary-op-string.ts","../src/test-transformer/visitors.ts","../src/test-transformer/index.ts"],"sourcesContent":["export class TransformerError extends Error {\n constructor(message: string) {\n super(message)\n }\n}\n","import ts from 'typescript'\nimport { TransformerError } from './errors'\n\nexport const getPropertyNameAsString = (name: ts.PropertyName): ts.Identifier | ts.StringLiteral | ts.NoSubstitutionTemplateLiteral => {\n if (ts.isStringLiteralLike(name)) {\n return name\n }\n if (ts.isIdentifier(name)) {\n return ts.factory.createStringLiteral(name.text)\n }\n throw new TransformerError(`Node ${name.kind} cannot be converted to a static string`)\n}\n","import { FunctionPType } from '@algorandfoundation/puya-ts'\nimport ts from 'typescript'\nimport type { DeliberateAny } from '../typescript-helpers'\nimport { getPropertyNameAsString } from './helpers'\n\nconst factory = ts.factory\nexport const nodeFactory = {\n importHelpers(testingPackageName: string) {\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier('runtimeHelpers'))),\n factory.createStringLiteral(`${testingPackageName}/runtime-helpers`),\n undefined,\n )\n },\n\n switchableValue(x: ts.Expression) {\n return factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier('runtimeHelpers'), factory.createIdentifier('switchableValue')),\n undefined,\n [x],\n )\n },\n binaryOp(left: ts.Expression, right: ts.Expression, op: string) {\n return factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier('runtimeHelpers'), factory.createIdentifier('binaryOp')),\n undefined,\n [left, right, factory.createStringLiteral(op)],\n )\n },\n\n prefixUnaryOp(operand: ts.Expression, op: string) {\n return factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier('runtimeHelpers'), factory.createIdentifier('unaryOp')),\n undefined,\n [operand, factory.createStringLiteral(op)],\n )\n },\n\n attachMetaData(classIdentifier: ts.Identifier, method: ts.MethodDeclaration, functionType: FunctionPType) {\n const methodName = getPropertyNameAsString(method.name)\n const metadata = factory.createObjectLiteralExpression([\n factory.createPropertyAssignment('methodName', methodName),\n factory.createPropertyAssignment('methodSelector', methodName),\n factory.createPropertyAssignment(\n 'argTypes',\n factory.createArrayLiteralExpression(functionType.parameters.map((p) => factory.createStringLiteral(p[1].fullName))),\n ),\n factory.createPropertyAssignment('returnType', factory.createStringLiteral(functionType.returnType.fullName)),\n ])\n return factory.createExpressionStatement(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier('runtimeHelpers'), factory.createIdentifier('attachAbiMetadata')),\n undefined,\n [classIdentifier, methodName, metadata],\n ),\n )\n },\n\n captureGenericTypeInfo(x: ts.Expression, type: string) {\n return factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('runtimeHelpers'),\n factory.createIdentifier('captureGenericTypeInfo'),\n ),\n undefined,\n [x, factory.createStringLiteral(type)],\n )\n },\n} satisfies Record<string, (...args: DeliberateAny[]) => ts.Node>\n","import type { BinaryOperator, PrefixUnaryOperator } from 'typescript'\nimport ts from 'typescript'\n\nexport function supportedBinaryOpString(x: BinaryOperator): string | undefined {\n switch (x) {\n case ts.SyntaxKind.MinusToken:\n return '-'\n case ts.SyntaxKind.PlusToken:\n return '+'\n case ts.SyntaxKind.EqualsEqualsEqualsToken:\n return '==='\n case ts.SyntaxKind.ExclamationEqualsEqualsToken:\n return '!=='\n case ts.SyntaxKind.GreaterThanToken:\n return '>'\n case ts.SyntaxKind.GreaterThanEqualsToken:\n return '>='\n case ts.SyntaxKind.GreaterThanGreaterThanToken:\n return '>>'\n case ts.SyntaxKind.LessThanToken:\n return '<'\n case ts.SyntaxKind.LessThanEqualsToken:\n return '<='\n case ts.SyntaxKind.LessThanLessThanToken:\n return '<<'\n case ts.SyntaxKind.AsteriskToken:\n return '*'\n case ts.SyntaxKind.AsteriskAsteriskToken:\n return '**'\n case ts.SyntaxKind.SlashToken:\n return '/'\n case ts.SyntaxKind.PercentToken:\n return '%'\n case ts.SyntaxKind.AmpersandToken:\n return '&'\n case ts.SyntaxKind.BarToken:\n return '|'\n case ts.SyntaxKind.CaretToken:\n return '^'\n case ts.SyntaxKind.AmpersandAmpersandEqualsToken:\n case ts.SyntaxKind.AmpersandAmpersandToken:\n case ts.SyntaxKind.AmpersandEqualsToken:\n case ts.SyntaxKind.AsteriskAsteriskEqualsToken:\n case ts.SyntaxKind.AsteriskEqualsToken:\n case ts.SyntaxKind.BarBarEqualsToken:\n case ts.SyntaxKind.BarBarToken:\n case ts.SyntaxKind.BarEqualsToken:\n case ts.SyntaxKind.CaretEqualsToken:\n case ts.SyntaxKind.CommaToken:\n case ts.SyntaxKind.EqualsEqualsToken:\n case ts.SyntaxKind.EqualsToken:\n case ts.SyntaxKind.ExclamationEqualsToken:\n case ts.SyntaxKind.InKeyword:\n case ts.SyntaxKind.InstanceOfKeyword:\n case ts.SyntaxKind.PercentEqualsToken:\n case ts.SyntaxKind.PlusEqualsToken:\n case ts.SyntaxKind.QuestionQuestionEqualsToken:\n case ts.SyntaxKind.MinusEqualsToken:\n case ts.SyntaxKind.SlashEqualsToken:\n case ts.SyntaxKind.QuestionQuestionToken:\n case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:\n case ts.SyntaxKind.LessThanLessThanEqualsToken:\n case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:\n case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:\n return undefined\n }\n}\n\nexport function supportedPrefixUnaryOpString(x: PrefixUnaryOperator): string | undefined {\n switch (x) {\n case ts.SyntaxKind.TildeToken:\n return '~'\n default:\n return undefined\n }\n}\n","import { anyPType, ContractClassPType, FunctionPType, PType, SourceLocation, typeRegistry, TypeResolver } from '@algorandfoundation/puya-ts'\nimport ts from 'typescript'\nimport { TransformerConfig } from './index'\nimport { nodeFactory } from './node-factory'\nimport { supportedBinaryOpString, supportedPrefixUnaryOpString } from './supported-binary-op-string'\n\nconst { factory } = ts\n\ntype VisitorHelper = {\n additionalStatements: ts.Statement[]\n resolveType(node: ts.Node): PType\n sourceLocation(node: ts.Node): SourceLocation\n}\n\nexport class SourceFileVisitor {\n private helper: VisitorHelper\n constructor(\n private context: ts.TransformationContext,\n private sourceFile: ts.SourceFile,\n program: ts.Program,\n private config: TransformerConfig,\n ) {\n const typeResolver = new TypeResolver(program.getTypeChecker(), program.getCurrentDirectory())\n\n this.helper = {\n additionalStatements: [],\n resolveType(node: ts.Node): PType {\n try {\n return typeResolver.resolve(node, this.sourceLocation(node))\n } catch {\n return anyPType\n }\n },\n sourceLocation(node: ts.Node): SourceLocation {\n return SourceLocation.fromNode(sourceFile, node, program.getCurrentDirectory())\n },\n }\n }\n\n public result(): ts.SourceFile {\n const updatedSourceFile = ts.visitNode(this.sourceFile, this.visit) as ts.SourceFile\n\n return factory.updateSourceFile(updatedSourceFile, [\n nodeFactory.importHelpers(this.config.testingPackageName),\n ...updatedSourceFile.statements,\n ...this.helper.additionalStatements,\n ])\n }\n\n private visit = (node: ts.Node): ts.Node => {\n if (ts.isFunctionLike(node)) {\n return new FunctionLikeDecVisitor(this.context, node).result()\n }\n if (ts.isClassDeclaration(node)) {\n return new ClassVisitor(this.context, this.helper, node).result()\n }\n\n return ts.visitEachChild(node, this.visit, this.context)\n }\n}\n\nclass FunctionOrMethodVisitor {\n constructor(protected context: ts.TransformationContext) {}\n protected visit = (node: ts.Node): ts.Node => {\n return ts.visitEachChild(this.updateNode(node), this.visit, this.context)\n }\n\n protected updateNode(node: ts.Node): ts.Node {\n if (ts.isSwitchStatement(node)) {\n return factory.updateSwitchStatement(node, nodeFactory.switchableValue(node.expression), node.caseBlock)\n }\n\n if (ts.isCaseClause(node)) {\n return factory.updateCaseClause(node, nodeFactory.switchableValue(node.expression), node.statements)\n }\n\n if (ts.isBinaryExpression(node)) {\n const tokenText = supportedBinaryOpString(node.operatorToken.kind)\n if (tokenText) {\n return nodeFactory.binaryOp(node.left, node.right, tokenText)\n }\n }\n if (ts.isPrefixUnaryExpression(node)) {\n const tokenText = supportedPrefixUnaryOpString(node.operator)\n if (tokenText) {\n return nodeFactory.prefixUnaryOp(node.operand, tokenText)\n }\n }\n return node\n }\n}\n\nclass FunctionLikeDecVisitor extends FunctionOrMethodVisitor {\n constructor(\n context: ts.TransformationContext,\n private funcNode: ts.SignatureDeclaration,\n ) {\n super(context)\n }\n\n public result(): ts.SignatureDeclaration {\n return ts.visitNode(this.funcNode, this.visit) as ts.SignatureDeclaration\n }\n}\nclass MethodDecVisitor extends FunctionOrMethodVisitor {\n constructor(\n context: ts.TransformationContext,\n private methodNode: ts.MethodDeclaration,\n ) {\n super(context)\n }\n\n public result(): ts.MethodDeclaration {\n return ts.visitNode(this.methodNode, this.visit) as ts.MethodDeclaration\n }\n}\n\nclass ClassVisitor {\n private isArc4: boolean\n constructor(\n private context: ts.TransformationContext,\n private helper: VisitorHelper,\n private classDec: ts.ClassDeclaration,\n ) {\n const classType = helper.resolveType(classDec)\n this.isArc4 = classType instanceof ContractClassPType && classType.isARC4\n }\n\n public result(): ts.ClassDeclaration {\n return this.visit(this.classDec) as ts.ClassDeclaration\n }\n\n private visit = (node: ts.Node): ts.Node => {\n if (ts.isMethodDeclaration(node)) {\n if (this.classDec.name && this.isArc4) {\n const methodType = this.helper.resolveType(node)\n if (methodType instanceof FunctionPType) {\n this.helper.additionalStatements.push(nodeFactory.attachMetaData(this.classDec.name, node, methodType))\n }\n }\n\n return new MethodDecVisitor(this.context, node).result()\n }\n\n if (ts.isCallExpression(node)) {\n let type = this.helper.resolveType(node)\n\n // `voted = LocalState<uint64>()` is resolved to FunctionPType with returnType LocalState<uint64>\n if (type instanceof FunctionPType) type = type.returnType\n\n if (typeRegistry.isGeneric(type)) {\n const typeName = type.name\n return nodeFactory.captureGenericTypeInfo(ts.visitEachChild(node, this.visit, this.context), typeName)\n }\n }\n return ts.visitEachChild(node, this.visit, this.context)\n }\n}\n","import { registerPTypes, typeRegistry } from '@algorandfoundation/puya-ts'\nimport type ts from 'typescript'\nimport type { DeliberateAny } from '../typescript-helpers'\nimport { SourceFileVisitor } from './visitors'\n\nexport interface TransformerConfig {\n includeExt: string[]\n testingPackageName: string\n}\nconst defaultTransformerConfig: TransformerConfig = {\n includeExt: ['.algo.ts', '.spec.ts'],\n testingPackageName: '@algorandfoundation/algorand-typescript-testing',\n}\n\n// const programTransformer = {\n// type: 'program',\n// factory(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n// registerPTypes(typeRegistry)\n// return (context) => {\n// return (sourceFile) => {\n// if (!includes.some((i) => sourceFile.fileName.endsWith(i))) return sourceFile\n// return new SourceFileVisitor(context, sourceFile, program).result()\n// }\n// }\n// },\n// }\nconst createProgramFactory = (config: TransformerConfig) => {\n function programFactory(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n registerPTypes(typeRegistry)\n return (context) => {\n return (sourceFile) => {\n if (!config.includeExt.some((i) => sourceFile.fileName.endsWith(i))) return sourceFile\n return new SourceFileVisitor(context, sourceFile, program, config).result()\n }\n }\n }\n return programFactory\n}\n\nfunction programTransformer(config: Partial<TransformerConfig>) {\n return {\n type: 'program',\n factory: createProgramFactory({ ...defaultTransformerConfig, ...config }),\n }\n}\nprogramTransformer.type = 'program'\nprogramTransformer.factory = createProgramFactory(defaultTransformerConfig)\n\n// Typescript.d.ts typings require a TransformerFactory however rollup plugin supports a program transformer\n// https://github.com/rollup/plugins/blob/master/packages/typescript/src/customTransformers.ts\nexport const puyaTsTransformer: ts.TransformerFactory<ts.SourceFile> &\n ((config: Partial<TransformerConfig>) => ts.TransformerFactory<ts.SourceFile>) = programTransformer as DeliberateAny\n"],"names":["factory"],"mappings":";;;AAAM,MAAO,gBAAiB,SAAQ,KAAK,CAAA;AACzC,IAAA,WAAA,CAAY,OAAe,EAAA;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;KACf;AACF;;ACDM,MAAM,uBAAuB,GAAG,CAAC,IAAqB,KAAyE;AACpI,IAAA,IAAI,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE;AAChC,QAAA,OAAO,IAAI,CAAA;KACZ;AACD,IAAA,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;QACzB,OAAO,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KACjD;IACD,MAAM,IAAI,gBAAgB,CAAC,CAAA,KAAA,EAAQ,IAAI,CAAC,IAAI,CAAyC,uCAAA,CAAA,CAAC,CAAA;AACxF,C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,CAAC,CAAA;AAE3E;AACA;AACO,MAAM,iBAAiB,GACqD;;;;"}
@@ -0,0 +1,9 @@
1
+ export type DeliberateAny = any;
2
+ export type AnyFunction = (...args: DeliberateAny[]) => DeliberateAny;
3
+ export type Mutable<T> = {
4
+ -readonly [P in keyof T]: T[P];
5
+ };
6
+ export type KeyIsFunction<TKey extends keyof TObj, TObj> = TKey extends DeliberateAny ? TObj[TKey] extends AnyFunction ? TKey : never : never;
7
+ export type KeyIsNotFunction<TKey extends keyof TObj, TObj> = TKey extends DeliberateAny ? TObj[TKey] extends AnyFunction ? never : TKey : never;
8
+ export type ObjectKeys<T> = KeyIsNotFunction<keyof T, T>;
9
+ export type FunctionKeys<T> = KeyIsFunction<keyof T, T>;
package/util.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { internal, bytes } from '@algorandfoundation/algorand-typescript';
2
+ import { DeliberateAny } from './typescript-helpers';
3
+ export declare const nameOfType: (x: unknown) => string;
4
+ export declare function iterBigInt(start: bigint, end: bigint): Generator<bigint>;
5
+ export declare const asBigInt: (v: internal.primitives.StubUint64Compat) => bigint;
6
+ export declare const asNumber: (v: internal.primitives.StubUint64Compat) => number;
7
+ export declare function extractGenericTypeArgs(t: string): string[];
8
+ export declare const asUint64Cls: (val: internal.primitives.StubUint64Compat) => internal.primitives.Uint64Cls;
9
+ export declare const asBigUintCls: (val: internal.primitives.StubBigUintCompat) => internal.primitives.BigUintCls;
10
+ export declare const asBytesCls: (val: internal.primitives.StubBytesCompat) => internal.primitives.BytesCls;
11
+ export declare const asUint64: (val: internal.primitives.StubUint64Compat) => import("@algorandfoundation/algorand-typescript").uint64;
12
+ export declare const asBigUint: (val: internal.primitives.StubBigUintCompat) => import("@algorandfoundation/algorand-typescript").biguint;
13
+ export declare const asBytes: (val: internal.primitives.StubBytesCompat) => bytes;
14
+ export declare const toBytes: (val: unknown) => bytes;
15
+ export declare const asMaybeUint64Cls: (val: DeliberateAny) => internal.primitives.Uint64Cls | undefined;
16
+ export declare const asMaybeBigUintCls: (val: DeliberateAny) => internal.primitives.BigUintCls | undefined;
17
+ export declare const asMaybeBytesCls: (val: DeliberateAny) => internal.primitives.BytesCls | undefined;
18
+ export declare const binaryStringToBytes: (s: string) => internal.primitives.BytesCls;
19
+ export declare const getRandomNumber: (min: number, max: number) => number;
20
+ export declare const getRandomBigInt: (min: number | bigint, max: number | bigint) => bigint;
21
+ export declare const getRandomBytes: (length: number) => internal.primitives.BytesCls;
22
+ type LazyInstance<T> = () => T;
23
+ export declare const Lazy: <T>(factory: () => T) => LazyInstance<T>;
24
+ export declare const getObjectReference: (obj: DeliberateAny) => bigint;
25
+ export declare const combineIntoMaxBytePages: (pages: bytes[]) => bytes[];
26
+ export {};
@@ -0,0 +1,23 @@
1
+ import { Account, Application, Asset, bytes, internal, uint64 } from '@algorandfoundation/algorand-typescript';
2
+ import { AccountData } from '../impl/account';
3
+ import { ApplicationData } from '../impl/application';
4
+ import { AssetData } from '../impl/asset';
5
+ type AccountContextData = Partial<AccountData['account']> & {
6
+ address?: internal.primitives.StubBytesCompat;
7
+ optedAssetBalances?: Map<internal.primitives.StubUint64Compat, internal.primitives.StubUint64Compat>;
8
+ optedApplications?: Application[];
9
+ };
10
+ type AssetContextData = Partial<AssetData> & {
11
+ assetId?: internal.primitives.StubUint64Compat;
12
+ };
13
+ type ApplicationContextData = Partial<ApplicationData['application']> & {
14
+ applicationId?: internal.primitives.StubUint64Compat;
15
+ };
16
+ export declare class AvmValueGenerator {
17
+ uint64(minValue?: number | bigint, maxValue?: number | bigint): uint64;
18
+ bytes(length?: number): bytes;
19
+ account(input?: AccountContextData): Account;
20
+ asset(input?: AssetContextData): Asset;
21
+ application(input?: ApplicationContextData): Application;
22
+ }
23
+ export {};
@@ -0,0 +1,6 @@
1
+ import { AvmValueGenerator } from './avm';
2
+ import { TxnValueGenerator } from './txn';
3
+ export declare class ValueGenerator extends AvmValueGenerator {
4
+ txn: TxnValueGenerator;
5
+ constructor();
6
+ }
@@ -0,0 +1,10 @@
1
+ import { gtxn } from '@algorandfoundation/algorand-typescript';
2
+ import { ApplicationTransaction, ApplicationTransactionFields, AssetConfigTransaction, AssetFreezeTransaction, AssetTransferTransaction, KeyRegistrationTransaction, PaymentTransaction, TxnFields } from '../impl/transactions';
3
+ export declare class TxnValueGenerator {
4
+ applicationCall(fields?: ApplicationTransactionFields): ApplicationTransaction;
5
+ payment(fields?: TxnFields<gtxn.PaymentTxn>): PaymentTransaction;
6
+ keyRegistration(fields?: TxnFields<gtxn.KeyRegistrationTxn>): KeyRegistrationTransaction;
7
+ assetConfig(fields?: TxnFields<gtxn.AssetConfigTxn>): AssetConfigTransaction;
8
+ assetTransfer(fields?: TxnFields<gtxn.AssetTransferTxn>): AssetTransferTransaction;
9
+ assetFreeze(fields?: TxnFields<gtxn.AssetFreezeTxn>): AssetFreezeTransaction;
10
+ }