@algorandfoundation/algorand-typescript-testing 1.0.0-alpha.13 → 1.0.0-alpha.15

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/impl/emit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function emitImpl<T>(typeInfoString: string, event: T | string, ...eventProps: unknown[]): void;
@@ -19,7 +19,7 @@ export declare class UFixedNxMImpl<N extends BitSize, M extends number> extends
19
19
  private value;
20
20
  private bitSize;
21
21
  private precision;
22
- private typeInfo;
22
+ typeInfo: TypeInfo;
23
23
  constructor(typeInfo: TypeInfo | string, v: `${number}.${number}`);
24
24
  get native(): UFixedNxM<N, M>["native"];
25
25
  get bytes(): bytes;
@@ -29,6 +29,7 @@ export declare class UFixedNxMImpl<N extends BitSize, M extends number> extends
29
29
  static getArc4TypeName: (t: TypeInfo) => string;
30
30
  }
31
31
  export declare class ByteImpl extends Byte {
32
+ typeInfo: TypeInfo;
32
33
  private value;
33
34
  constructor(typeInfo: TypeInfo | string, v?: CompatForArc4Int<8>);
34
35
  get native(): uint64;
@@ -38,8 +39,9 @@ export declare class ByteImpl extends Byte {
38
39
  static getMaxBitsLength(typeInfo: TypeInfo): BitSize;
39
40
  }
40
41
  export declare class StrImpl extends Str {
42
+ typeInfo: TypeInfo;
41
43
  private value;
42
- constructor(_typeInfo: TypeInfo | string, s?: StringCompat);
44
+ constructor(typeInfo: TypeInfo | string, s?: StringCompat);
43
45
  get native(): string;
44
46
  get bytes(): bytes;
45
47
  equals(other: this): boolean;
@@ -47,7 +49,8 @@ export declare class StrImpl extends Str {
47
49
  }
48
50
  export declare class BoolImpl extends Bool {
49
51
  private value;
50
- constructor(_typeInfo: TypeInfo | string, v?: boolean);
52
+ typeInfo: TypeInfo;
53
+ constructor(typeInfo: TypeInfo | string, v?: boolean);
51
54
  get native(): boolean;
52
55
  equals(other: this): boolean;
53
56
  get bytes(): bytes;
@@ -60,8 +63,8 @@ type StaticArrayGenericArgs = {
60
63
  export declare class StaticArrayImpl<TItem extends ARC4Encoded, TLength extends number> extends StaticArray<TItem, TLength> {
61
64
  private value?;
62
65
  private uint8ArrayValue?;
63
- private typeInfo;
64
66
  private size;
67
+ typeInfo: TypeInfo;
65
68
  genericArgs: StaticArrayGenericArgs;
66
69
  constructor(typeInfo: TypeInfo | string, ...items: TItem[] & {
67
70
  length: TLength;
@@ -73,12 +76,13 @@ export declare class StaticArrayImpl<TItem extends ARC4Encoded, TLength extends
73
76
  get items(): TItem[];
74
77
  setItem(index: number, value: TItem): void;
75
78
  copy(): StaticArrayImpl<TItem, TLength>;
79
+ get native(): TItem[];
76
80
  static fromBytesImpl(value: internal.primitives.StubBytesCompat | Uint8Array, typeInfo: string | TypeInfo, prefix?: 'none' | 'log'): StaticArrayImpl<ARC4Encoded, number>;
77
81
  static getMaxBytesLength(typeInfo: TypeInfo): number;
78
82
  static getArc4TypeName: (t: TypeInfo) => string;
79
83
  }
80
84
  export declare class AddressImpl extends Address {
81
- private typeInfo;
85
+ typeInfo: TypeInfo;
82
86
  private value;
83
87
  constructor(typeInfo: TypeInfo | string, value?: Account | string | bytes);
84
88
  get bytes(): bytes;
@@ -96,7 +100,7 @@ type DynamicArrayGenericArgs = {
96
100
  export declare class DynamicArrayImpl<TItem extends ARC4Encoded> extends DynamicArray<TItem> {
97
101
  private value?;
98
102
  private uint8ArrayValue?;
99
- private typeInfo;
103
+ typeInfo: TypeInfo;
100
104
  genericArgs: DynamicArrayGenericArgs;
101
105
  constructor(typeInfo: TypeInfo | string, ...items: TItem[]);
102
106
  get bytes(): bytes;
@@ -105,6 +109,7 @@ export declare class DynamicArrayImpl<TItem extends ARC4Encoded> extends Dynamic
105
109
  get items(): TItem[];
106
110
  setItem(index: number, value: TItem): void;
107
111
  copy(): DynamicArrayImpl<TItem>;
112
+ get native(): TItem[];
108
113
  push(...values: TItem[]): void;
109
114
  pop(): TItem;
110
115
  static fromBytesImpl(value: internal.primitives.StubBytesCompat | Uint8Array, typeInfo: string | TypeInfo, prefix?: 'none' | 'log'): DynamicArrayImpl<ARC4Encoded>;
@@ -114,7 +119,7 @@ export declare class DynamicArrayImpl<TItem extends ARC4Encoded> extends Dynamic
114
119
  export declare class TupleImpl<TTuple extends [ARC4Encoded, ...ARC4Encoded[]]> extends Tuple<TTuple> {
115
120
  private value?;
116
121
  private uint8ArrayValue?;
117
- private typeInfo;
122
+ typeInfo: TypeInfo;
118
123
  genericArgs: TypeInfo[];
119
124
  constructor(typeInfo: TypeInfo | string);
120
125
  get bytes(): bytes;
@@ -132,17 +137,17 @@ declare const StructImpl_base: DeliberateAny;
132
137
  export declare class StructImpl<T extends StructConstraint> extends StructImpl_base {
133
138
  static [x: string]: any;
134
139
  private uint8ArrayValue?;
135
- private typeInfo;
136
140
  genericArgs: Record<string, TypeInfo>;
137
141
  constructor(typeInfo: TypeInfo | string, value?: T);
138
142
  get bytes(): bytes;
139
143
  get items(): T;
144
+ get native(): T;
140
145
  private decodeAsProperties;
141
146
  static fromBytesImpl(value: internal.primitives.StubBytesCompat | Uint8Array, typeInfo: string | TypeInfo, prefix?: 'none' | 'log'): StructImpl<StructConstraint>;
142
147
  static getArc4TypeName: (t: TypeInfo) => string;
143
148
  }
144
149
  export declare class DynamicBytesImpl extends DynamicBytes {
145
- private typeInfo;
150
+ typeInfo: TypeInfo;
146
151
  private value;
147
152
  constructor(typeInfo: TypeInfo | string, value?: bytes | string);
148
153
  get bytes(): bytes;
@@ -156,7 +161,7 @@ export declare class DynamicBytesImpl extends DynamicBytes {
156
161
  }
157
162
  export declare class StaticBytesImpl extends StaticBytes {
158
163
  private value;
159
- private typeInfo;
164
+ typeInfo: TypeInfo;
160
165
  constructor(typeInfo: TypeInfo | string, value?: bytes | string);
161
166
  get bytes(): bytes;
162
167
  equals(other: this): boolean;
@@ -172,4 +177,7 @@ export declare function interpretAsArc4Impl<T extends ARC4Encoded>(typeInfoStrin
172
177
  export declare const arc4Encoders: Record<string, fromBytes<DeliberateAny>>;
173
178
  export declare const getArc4Encoder: <T>(typeInfo: TypeInfo, encoders?: Record<string, fromBytes<DeliberateAny>>) => fromBytes<T>;
174
179
  export declare const getArc4TypeName: (typeInfo: TypeInfo) => string | undefined;
180
+ export declare function decodeArc4Impl<T>(sourceTypeInfoString: string, bytes: internal.primitives.StubBytesCompat): T;
181
+ export declare function encodeArc4Impl<T>(_targetTypeInfoString: string, source: T): bytes;
182
+ export declare const getArc4Encoded: (value: DeliberateAny) => ARC4Encoded;
175
183
  export {};
@@ -122,6 +122,9 @@ export declare class ApplicationTransaction extends TransactionBase implements g
122
122
  get numClearStateProgramPages(): uint64;
123
123
  get numLogs(): uint64;
124
124
  get lastLog(): bytes;
125
+ get apat(): Account[];
126
+ get apas(): Asset[];
127
+ get apfa(): Application[];
125
128
  appArgs(index: internal.primitives.StubUint64Compat): bytes;
126
129
  accounts(index: internal.primitives.StubUint64Compat): Account;
127
130
  assets(index: internal.primitives.StubUint64Compat): Asset;
package/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- import { Bytes, Uint64, Account, internal, Base64, arc4, Ecdsa, op, TransactionType, Asset, Application, BigUint, BaseContract, Contract } from '@algorandfoundation/algorand-typescript';
2
- import { a as asMaybeUint64Cls, l as lazyContext, b as asUint64, c as asBytes, t as toBytes, d as asMaybeBytesCls, e as asBigUint, B as BITS_IN_BYTE, M as MAX_BYTES_SIZE, f as asUint64Cls, g as asBytesCls, h as MAX_UINT8, i as binaryStringToBytes, U as UINT64_SIZE, j as MAX_UINT64, k as asNumber, m as MAX_BOX_SIZE, n as asUint8Array, o as conactUint8Arrays, P as PROGRAM_TAG, L as LOGIC_DATA_PREFIX, p as getObjectReference, q as getApplicationAddress, r as MIN_TXN_FEE, D as DEFAULT_ACCOUNT_MIN_BALANCE, s as DEFAULT_MAX_TXN_LIFE, Z as ZERO_ADDRESS, u as DEFAULT_ASSET_CREATE_MIN_BALANCE, v as DEFAULT_ASSET_OPT_IN_MIN_BALANCE, w as DEFAULT_GLOBAL_GENESIS_HASH, x as combineIntoMaxBytePages, y as MAX_ITEMS_IN_LOG, A as ABI_RETURN_VALUE_LOG_PREFIX, z as getRandomBytes, C as getArc4Encoder, E as AccountCls, F as ApplicationCls, G as AssetCls, H as arc4Encoders, I as AccountMap, J as getGenericTypeInfo, K as getArc4Selector, N as isContractProxy, O as getContractMethodAbiMetadata, Q as copyAbiMetadatas, R as getContractAbiMetadata, S as BytesMap, T as iterBigInt, V as Uint64Map, W as AssetHolding$1, X as asBigInt, Y as TRANSACTION_GROUP_MAX_SIZE, _ as getRandomBigInt, $ as AccountData, a0 as ApplicationData, a1 as AddressImpl, a2 as UintNImpl, a3 as getRandomNumber, a4 as MAX_UINT16, a5 as MAX_UINT32, a6 as MAX_UINT128, a7 as MAX_UINT256, a8 as MAX_UINT512, a9 as DynamicBytesImpl, aa as StrImpl, ab as captureMethodConfig, ac as DEFAULT_TEMPLATE_VAR_PREFIX } from './runtime-helpers-CUc689EZ.js';
3
- import { ec } from 'elliptic';
4
- import { sha256 as sha256$1 } from 'js-sha256';
5
- import { sha3_256 as sha3_256$1, keccak256 as keccak256$1 } from 'js-sha3';
6
- import { sha512_256 as sha512_256$1 } from 'js-sha512';
7
- import nacl from 'tweetnacl';
1
+ import { Bytes, Uint64, Account, internal, Base64, op, arc4, TransactionType, Asset, Application, BigUint, BaseContract, Contract } from '@algorandfoundation/algorand-typescript';
2
+ import { a as asMaybeUint64Cls, l as lazyContext, b as asUint64, c as asBytes, t as toBytes, d as asMaybeBytesCls, e as asBigUint, B as BITS_IN_BYTE, M as MAX_BYTES_SIZE, f as asUint64Cls, g as asBytesCls, h as testInvariant, i as MAX_UINT8, j as binaryStringToBytes, U as UINT64_SIZE, n as notImplementedError, k as MAX_UINT64, m as asNumber, o as MAX_BOX_SIZE, p as asUint8Array, q as conactUint8Arrays, r as getObjectReference, s as getApplicationAddress, u as MIN_TXN_FEE, D as DEFAULT_ACCOUNT_MIN_BALANCE, v as DEFAULT_MAX_TXN_LIFE, Z as ZERO_ADDRESS, w as DEFAULT_ASSET_CREATE_MIN_BALANCE, x as DEFAULT_ASSET_OPT_IN_MIN_BALANCE, y as DEFAULT_GLOBAL_GENESIS_HASH, E as EllipticCurve, z as ecdsaPkDecompress, A as ecdsaPkRecover, C as ecdsaVerify, F as ed25519verify, G as ed25519verifyBare, H as keccak256, I as sha256, J as sha3_256, K as sha512_256, L as vrfVerify, N as combineIntoMaxBytePages, O as MAX_ITEMS_IN_LOG, P as ABI_RETURN_VALUE_LOG_PREFIX, Q as getRandomBytes, R as getArc4Encoder, S as AccountCls, T as ApplicationCls, V as AssetCls, W as arc4Encoders, X as AccountMap, Y as getGenericTypeInfo, _ as getArc4Selector, $ as isContractProxy, a0 as getContractMethodAbiMetadata, a1 as copyAbiMetadatas, a2 as getContractAbiMetadata, a3 as BytesMap, a4 as iterBigInt, a5 as Uint64Map, a6 as AssetHolding$1, a7 as asBigInt, a8 as TRANSACTION_GROUP_MAX_SIZE, a9 as getRandomBigInt, aa as AccountData, ab as ApplicationData, ac as AddressImpl, ad as UintNImpl, ae as getRandomNumber, af as MAX_UINT16, ag as MAX_UINT32, ah as MAX_UINT128, ai as MAX_UINT256, aj as MAX_UINT512, ak as DynamicBytesImpl, al as StrImpl, am as captureMethodConfig, an as DEFAULT_TEMPLATE_VAR_PREFIX } from './runtime-helpers-BtUWpK9t.js';
8
3
  import { randomBytes } from 'crypto';
9
4
  import '@algorandfoundation/algorand-typescript/arc4';
10
5
  import '@algorandfoundation/puya-ts';
6
+ import 'js-sha512';
11
7
  import 'assert';
8
+ import 'elliptic';
9
+ import 'js-sha256';
10
+ import 'js-sha3';
11
+ import 'tweetnacl';
12
12
 
13
13
  const resolveAppIndex = (appIdOrIndex) => {
14
14
  const input = asUint64(appIdOrIndex);
@@ -331,20 +331,6 @@ const AssetHolding = {
331
331
  },
332
332
  };
333
333
 
334
- class NotImplementedError extends Error {
335
- constructor(feature) {
336
- super(`${feature} is not available in test context. Mock using your preferred testing framework.`);
337
- }
338
- }
339
- function notImplementedError(feature) {
340
- throw new NotImplementedError(feature);
341
- }
342
- function testInvariant(condition, message) {
343
- if (!condition) {
344
- throw new internal.errors.InternalError(message);
345
- }
346
- }
347
-
348
334
  const addw = (a, b) => {
349
335
  const uint64A = internal.primitives.Uint64Cls.fromCompat(a);
350
336
  const uint64B = internal.primitives.Uint64Cls.fromCompat(b);
@@ -773,94 +759,6 @@ const Box$1 = {
773
759
  },
774
760
  };
775
761
 
776
- const sha256 = (a) => {
777
- const bytesA = internal.primitives.BytesCls.fromCompat(a);
778
- const hashArray = sha256$1.create().update(bytesA.asUint8Array()).digest();
779
- const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
780
- return hashBytes.asAlgoTs();
781
- };
782
- const sha3_256 = (a) => {
783
- const bytesA = internal.primitives.BytesCls.fromCompat(a);
784
- const hashArray = sha3_256$1.create().update(bytesA.asUint8Array()).digest();
785
- const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
786
- return hashBytes.asAlgoTs();
787
- };
788
- const keccak256 = (a) => {
789
- const bytesA = internal.primitives.BytesCls.fromCompat(a);
790
- const hashArray = keccak256$1.create().update(bytesA.asUint8Array()).digest();
791
- const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
792
- return hashBytes.asAlgoTs();
793
- };
794
- const sha512_256 = (a) => {
795
- const bytesA = internal.primitives.BytesCls.fromCompat(a);
796
- const hashArray = sha512_256$1.create().update(bytesA.asUint8Array()).digest();
797
- const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
798
- return hashBytes.asAlgoTs();
799
- };
800
- const ed25519verifyBare = (a, b, c) => {
801
- const bytesA = internal.primitives.BytesCls.fromCompat(a);
802
- const bytesB = internal.primitives.BytesCls.fromCompat(b);
803
- const bytesC = internal.primitives.BytesCls.fromCompat(c);
804
- return nacl.sign.detached.verify(bytesA.asUint8Array(), bytesB.asUint8Array(), bytesC.asUint8Array());
805
- };
806
- const ed25519verify = (a, b, c) => {
807
- const txn = lazyContext.activeGroup.activeTransaction;
808
- const programBytes = asBytesCls(txn.onCompletion == arc4.OnCompleteAction[arc4.OnCompleteAction.ClearState] ? txn.clearStateProgram : txn.approvalProgram);
809
- const logicSig = conactUint8Arrays(asUint8Array(PROGRAM_TAG), programBytes.asUint8Array());
810
- const logicSigAddress = sha512_256$1.array(logicSig);
811
- const addressBytes = Bytes(logicSigAddress);
812
- const data = LOGIC_DATA_PREFIX.concat(addressBytes).concat(asBytes(a));
813
- return ed25519verifyBare(data, b, c);
814
- };
815
- const ecdsaVerify = (v, a, b, c, d, e) => {
816
- const dataBytes = internal.primitives.BytesCls.fromCompat(a);
817
- const sigRBytes = internal.primitives.BytesCls.fromCompat(b);
818
- const sigSBytes = internal.primitives.BytesCls.fromCompat(c);
819
- const pubkeyXBytes = internal.primitives.BytesCls.fromCompat(d);
820
- const pubkeyYBytes = internal.primitives.BytesCls.fromCompat(e);
821
- const publicKey = internal.primitives.BytesCls.fromCompat(new Uint8Array([0x04]))
822
- .concat(pubkeyXBytes)
823
- .concat(pubkeyYBytes);
824
- const ecdsa = new ec(curveMap[v]);
825
- const keyPair = ecdsa.keyFromPublic(publicKey.asUint8Array());
826
- return keyPair.verify(dataBytes.asUint8Array(), { r: sigRBytes.asUint8Array(), s: sigSBytes.asUint8Array() });
827
- };
828
- const ecdsaPkRecover = (v, a, b, c, d) => {
829
- if (v !== Ecdsa.Secp256k1) {
830
- internal.errors.internalError(`Unsupported ECDSA curve: ${v}`);
831
- }
832
- const dataBytes = internal.primitives.BytesCls.fromCompat(a);
833
- const rBytes = internal.primitives.BytesCls.fromCompat(c);
834
- const sBytes = internal.primitives.BytesCls.fromCompat(d);
835
- const recoveryId = internal.primitives.Uint64Cls.fromCompat(b);
836
- const ecdsa = new ec(curveMap[v]);
837
- const pubKey = ecdsa.recoverPubKey(dataBytes.asUint8Array(), { r: rBytes.asUint8Array(), s: sBytes.asUint8Array() }, recoveryId.asNumber());
838
- const x = pubKey.getX().toArray('be');
839
- const y = pubKey.getY().toArray('be');
840
- return [Bytes(x), Bytes(y)];
841
- };
842
- const ecdsaPkDecompress = (v, a) => {
843
- const bytesA = internal.primitives.BytesCls.fromCompat(a);
844
- const ecdsa = new ec(curveMap[v]);
845
- const keyPair = ecdsa.keyFromPublic(bytesA.asUint8Array());
846
- const pubKey = keyPair.getPublic();
847
- const x = pubKey.getX().toArray('be');
848
- const y = pubKey.getY().toArray('be');
849
- return [Bytes(new Uint8Array(x)), Bytes(new Uint8Array(y))];
850
- };
851
- const vrfVerify = (_s, _a, _b, _c) => {
852
- notImplementedError('vrfVerify');
853
- };
854
- const EllipticCurve = new Proxy({}, {
855
- get: (_target, prop) => {
856
- notImplementedError(`EllipticCurve.${prop.toString()}`);
857
- },
858
- });
859
- const curveMap = {
860
- [Ecdsa.Secp256k1]: 'secp256k1',
861
- [Ecdsa.Secp256r1]: 'p256',
862
- };
863
-
864
762
  class GlobalData {
865
763
  minTxnFee;
866
764
  minBalance;
@@ -2817,6 +2715,15 @@ class ApplicationTransaction extends TransactionBase {
2817
2715
  get lastLog() {
2818
2716
  return this.#appLogs.at(-1) ?? lazyContext.getApplicationData(this.appId.id).appLogs.at(-1) ?? Bytes();
2819
2717
  }
2718
+ get apat() {
2719
+ return this.#accounts;
2720
+ }
2721
+ get apas() {
2722
+ return this.#assets;
2723
+ }
2724
+ get apfa() {
2725
+ return this.#apps;
2726
+ }
2820
2727
  appArgs(index) {
2821
2728
  return toBytes(this.#appArgs[asNumber(index)]);
2822
2729
  }
@@ -4164,7 +4071,7 @@ class Arc4ValueGenerator {
4164
4071
  * */
4165
4072
  address() {
4166
4073
  const source = new AvmValueGenerator().account();
4167
- const result = new AddressImpl({ name: 'StaticArray', genericArgs: { elementType: { name: 'Byte' }, size: { name: '32' } } }, source);
4074
+ const result = new AddressImpl({ name: 'StaticArray', genericArgs: { elementType: { name: 'Byte', genericArgs: [{ name: '8' }] }, size: { name: '32' } } }, source);
4168
4075
  return result;
4169
4076
  }
4170
4077
  /**
@@ -4237,7 +4144,7 @@ class Arc4ValueGenerator {
4237
4144
  * @returns: A new, random dynamic bytes of size `n` bits.
4238
4145
  * */
4239
4146
  dynamicBytes(n) {
4240
- return new DynamicBytesImpl({ name: 'DynamicArray', genericArgs: { elementType: { name: 'Byte' } } }, getRandomBytes(n / BITS_IN_BYTE).asAlgoTs());
4147
+ return new DynamicBytesImpl({ name: 'DynamicBytes', genericArgs: { elementType: { name: 'Byte', genericArgs: [{ name: '8' }] } } }, getRandomBytes(n / BITS_IN_BYTE).asAlgoTs());
4241
4148
  }
4242
4149
  /**
4243
4150
  * Generate a random dynamic string of size `n` bits.