@algorandfoundation/algorand-typescript-testing 1.0.0-alpha.14 → 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;
@@ -29,7 +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 | string;
32
+ typeInfo: TypeInfo;
33
33
  private value;
34
34
  constructor(typeInfo: TypeInfo | string, v?: CompatForArc4Int<8>);
35
35
  get native(): uint64;
@@ -39,7 +39,7 @@ export declare class ByteImpl extends Byte {
39
39
  static getMaxBitsLength(typeInfo: TypeInfo): BitSize;
40
40
  }
41
41
  export declare class StrImpl extends Str {
42
- typeInfo: TypeInfo | string;
42
+ typeInfo: TypeInfo;
43
43
  private value;
44
44
  constructor(typeInfo: TypeInfo | string, s?: StringCompat);
45
45
  get native(): string;
@@ -48,8 +48,8 @@ export declare class StrImpl extends Str {
48
48
  static fromBytesImpl(value: internal.primitives.StubBytesCompat | Uint8Array, typeInfo: string | TypeInfo, prefix?: 'none' | 'log'): StrImpl;
49
49
  }
50
50
  export declare class BoolImpl extends Bool {
51
- typeInfo: TypeInfo | string;
52
51
  private value;
52
+ typeInfo: TypeInfo;
53
53
  constructor(typeInfo: TypeInfo | string, v?: boolean);
54
54
  get native(): boolean;
55
55
  equals(other: this): boolean;
@@ -179,4 +179,5 @@ export declare const getArc4Encoder: <T>(typeInfo: TypeInfo, encoders?: Record<s
179
179
  export declare const getArc4TypeName: (typeInfo: TypeInfo) => string | undefined;
180
180
  export declare function decodeArc4Impl<T>(sourceTypeInfoString: string, bytes: internal.primitives.StubBytesCompat): T;
181
181
  export declare function encodeArc4Impl<T>(_targetTypeInfoString: string, source: T): bytes;
182
+ export declare const getArc4Encoded: (value: DeliberateAny) => ARC4Encoded;
182
183
  export {};
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-C5d5vNab.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;