Skip to content

Commit d67e33f

Browse files
committed
feat: allow mock results to be setup for compileArc4 and abiCall
1 parent e5857c4 commit d67e33f

29 files changed

+1667
-298
lines changed

docs/code/index/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
## Classes
1010

11+
- [ApplicationSpy](classes/ApplicationSpy.md)
1112
- [AssertError](classes/AssertError.md)
1213
- [AvmError](classes/AvmError.md)
1314
- [CodeError](classes/CodeError.md)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
[**@algorandfoundation/algorand-typescript-testing**](../../README.md)
2+
3+
***
4+
5+
[@algorandfoundation/algorand-typescript-testing](../../README.md) / [index](../README.md) / ApplicationSpy
6+
7+
# Class: ApplicationSpy\<TContract\>
8+
9+
Defined in: [src/application-spy.ts:15](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/application-spy.ts#L15)
10+
11+
## Type Parameters
12+
13+
### TContract
14+
15+
`TContract` *extends* `Contract`
16+
17+
## Constructors
18+
19+
### Constructor
20+
21+
> **new ApplicationSpy**\<`TContract`\>(`contract`): `ApplicationSpy`\<`TContract`\>
22+
23+
Defined in: [src/application-spy.ts:26](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/application-spy.ts#L26)
24+
25+
#### Parameters
26+
27+
##### contract
28+
29+
`TContract` | `ConstructorFor`\<`TContract`\>
30+
31+
#### Returns
32+
33+
`ApplicationSpy`\<`TContract`\>
34+
35+
## Properties
36+
37+
### contract
38+
39+
> **contract**: `TContract` \| `ConstructorFor`\<`TContract`\>
40+
41+
Defined in: [src/application-spy.ts:19](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/application-spy.ts#L19)
42+
43+
## Accessors
44+
45+
### abiCallHooks
46+
47+
#### Get Signature
48+
49+
> **get** **abiCallHooks**(): `BytesMap`\<(`innerTxnContext`) => `void`[]\>
50+
51+
Defined in: [src/application-spy.ts:22](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/application-spy.ts#L22)
52+
53+
##### Returns
54+
55+
`BytesMap`\<(`innerTxnContext`) => `void`[]\>
56+
57+
## Methods
58+
59+
### onAbiCall()
60+
61+
> **onAbiCall**\<`TContract`, `TMethod`\>(`methodSignature`, `callback`): `void`
62+
63+
Defined in: [src/application-spy.ts:49](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/application-spy.ts#L49)
64+
65+
Registers a callback for a specific method signature.
66+
67+
#### Type Parameters
68+
69+
##### TContract
70+
71+
`TContract` *extends* `Contract`
72+
73+
The type of the contract being spied on.
74+
75+
##### TMethod
76+
77+
`TMethod` *extends* `"bareCreate"` \| `InstanceMethod`\<`TContract`\>
78+
79+
The type of the method being spied on.
80+
81+
#### Parameters
82+
83+
##### methodSignature
84+
85+
`TMethod`
86+
87+
The method signature to spy on.
88+
89+
##### callback
90+
91+
(`itxnContext`) => `void`
92+
93+
The callback function to execute when the method is called.
94+
95+
#### Returns
96+
97+
`void`

docs/code/index/classes/TestExecutionContext.md

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Class: TestExecutionContext
88

9-
Defined in: [src/test-execution-context.ts:20](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L20)
9+
Defined in: [src/test-execution-context.ts:26](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L26)
1010

1111
The `TestExecutionContext` class provides a context for executing tests in an Algorand environment.
1212
It manages various contexts such as contract, ledger, and transaction contexts, and provides utilities
@@ -18,7 +18,7 @@ for generating values, managing accounts, and handling logic signatures.
1818

1919
> **new TestExecutionContext**(`defaultSenderAddress`?): `TestExecutionContext`
2020
21-
Defined in: [src/test-execution-context.ts:36](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L36)
21+
Defined in: [src/test-execution-context.ts:43](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L43)
2222

2323
Creates an instance of `TestExecutionContext`.
2424

@@ -42,7 +42,7 @@ The default sender address.
4242

4343
> **get** **activeLogicSigArgs**(): `bytes`[]
4444
45-
Defined in: [src/test-execution-context.ts:117](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L117)
45+
Defined in: [src/test-execution-context.ts:124](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L124)
4646

4747
Returns the active logic signature arguments.
4848

@@ -58,7 +58,7 @@ Returns the active logic signature arguments.
5858

5959
> **get** **any**(): [`ValueGenerator`](../../value-generators/classes/ValueGenerator.md)
6060
61-
Defined in: [src/test-execution-context.ts:90](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L90)
61+
Defined in: [src/test-execution-context.ts:97](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L97)
6262

6363
Returns the value generator.
6464

@@ -74,7 +74,7 @@ Returns the value generator.
7474

7575
> **get** **contract**(): [`ContractContext`](../../subcontexts/contract-context/classes/ContractContext.md)
7676
77-
Defined in: [src/test-execution-context.ts:63](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L63)
77+
Defined in: [src/test-execution-context.ts:70](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L70)
7878

7979
Returns the contract context.
8080

@@ -90,7 +90,7 @@ Returns the contract context.
9090

9191
> **get** **defaultSender**(): `Account`
9292
93-
Defined in: [src/test-execution-context.ts:99](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L99)
93+
Defined in: [src/test-execution-context.ts:106](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L106)
9494

9595
Returns the default sender account.
9696

@@ -102,7 +102,7 @@ Returns the default sender account.
102102

103103
> **set** **defaultSender**(`val`): `void`
104104
105-
Defined in: [src/test-execution-context.ts:108](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L108)
105+
Defined in: [src/test-execution-context.ts:115](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L115)
106106

107107
Sets the default sender account.
108108

@@ -126,7 +126,7 @@ The default sender account.
126126

127127
> **get** **ledger**(): [`LedgerContext`](../../subcontexts/ledger-context/classes/LedgerContext.md)
128128
129-
Defined in: [src/test-execution-context.ts:72](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L72)
129+
Defined in: [src/test-execution-context.ts:79](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L79)
130130

131131
Returns the ledger context.
132132

@@ -142,7 +142,7 @@ Returns the ledger context.
142142

143143
> **get** **templateVars**(): `Record`\<`string`, `any`\>
144144
145-
Defined in: [src/test-execution-context.ts:126](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L126)
145+
Defined in: [src/test-execution-context.ts:133](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L133)
146146

147147
Returns the template variables.
148148

@@ -158,7 +158,7 @@ Returns the template variables.
158158

159159
> **get** **txn**(): [`TransactionContext`](../../subcontexts/transaction-context/classes/TransactionContext.md)
160160
161-
Defined in: [src/test-execution-context.ts:81](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L81)
161+
Defined in: [src/test-execution-context.ts:88](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L88)
162162

163163
Returns the transaction context.
164164

@@ -168,11 +168,35 @@ Returns the transaction context.
168168

169169
## Methods
170170

171+
### addApplicationSpy()
172+
173+
> **addApplicationSpy**\<`TContract`\>(`spy`): `void`
174+
175+
Defined in: [src/test-execution-context.ts:204](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L204)
176+
177+
#### Type Parameters
178+
179+
##### TContract
180+
181+
`TContract` *extends* `Contract`
182+
183+
#### Parameters
184+
185+
##### spy
186+
187+
[`ApplicationSpy`](ApplicationSpy.md)\<`TContract`\>
188+
189+
#### Returns
190+
191+
`void`
192+
193+
***
194+
171195
### executeLogicSig()
172196

173197
> **executeLogicSig**(`logicSig`, ...`args`): `boolean` \| `uint64`
174198
175-
Defined in: [src/test-execution-context.ts:137](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L137)
199+
Defined in: [src/test-execution-context.ts:144](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L144)
176200

177201
Executes a logic signature with the given arguments.
178202

@@ -200,7 +224,7 @@ The arguments for the logic signature.
200224

201225
> **exportLogs**\<`T`\>(`appId`, ...`decoding`): `DecodedLogs`\<`T`\>
202226
203-
Defined in: [src/test-execution-context.ts:54](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L54)
227+
Defined in: [src/test-execution-context.ts:61](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L61)
204228

205229
Exports logs for a given application ID and decoding.
206230

@@ -230,11 +254,11 @@ The log decoding.
230254

231255
***
232256

233-
### getCompiledApp()
257+
### getCompiledAppEntry()
234258

235-
> **getCompiledApp**(`contract`): `undefined` \| \[`ConstructorFor`\<`BaseContract`\>, `uint64`\]
259+
> **getCompiledAppEntry**(`contract`): `undefined` \| \{ `key`: `ConstructorFor`\<`BaseContract`\>; `value`: `uint64`; \}
236260
237-
Defined in: [src/test-execution-context.ts:163](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L163)
261+
Defined in: [src/test-execution-context.ts:170](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L170)
238262

239263
Gets a compiled application by contract.
240264

@@ -248,15 +272,15 @@ The contract class.
248272

249273
#### Returns
250274

251-
`undefined` \| \[`ConstructorFor`\<`BaseContract`\>, `uint64`\]
275+
`undefined` \| \{ `key`: `ConstructorFor`\<`BaseContract`\>; `value`: `uint64`; \}
252276

253277
***
254278

255-
### getCompiledLogicSig()
279+
### getCompiledLogicSigEntry()
256280

257-
> **getCompiledLogicSig**(`logicsig`): `undefined` \| \[`ConstructorFor`\<`LogicSig`\>, `Account`\]
281+
> **getCompiledLogicSigEntry**(`logicsig`): `undefined` \| \{ `key`: `ConstructorFor`\<`LogicSig`\>; `value`: `Account`; \}
258282
259-
Defined in: [src/test-execution-context.ts:188](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L188)
283+
Defined in: [src/test-execution-context.ts:221](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L221)
260284

261285
Gets a compiled logic signature.
262286

@@ -270,15 +294,51 @@ The logic signature class.
270294

271295
#### Returns
272296

273-
`undefined` \| \[`ConstructorFor`\<`LogicSig`\>, `Account`\]
297+
`undefined` \| \{ `key`: `ConstructorFor`\<`LogicSig`\>; `value`: `Account`; \}
298+
299+
***
300+
301+
### getOnAbiCall()
302+
303+
> **getOnAbiCall**\<`TContract`\>(`methodSignature`, `contract`?): `object`
304+
305+
Defined in: [src/test-execution-context.ts:190](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L190)
306+
307+
#### Type Parameters
308+
309+
##### TContract
310+
311+
`TContract` *extends* `Contract`
312+
313+
#### Parameters
314+
315+
##### methodSignature
316+
317+
`StubBytesCompat` | `KeyIsFunction`\<keyof `TContract`, `TContract`\> | `InstanceMethod`\<`TContract`\>
318+
319+
##### contract?
320+
321+
`TContract` | `ConstructorFor`\<`TContract`\>
322+
323+
#### Returns
324+
325+
`object`
326+
327+
##### key
328+
329+
> **key**: `bytes` = `selector`
330+
331+
##### value
332+
333+
> **value**: `undefined` \| (`innerTxnContext`) => `void`[]
274334
275335
***
276336

277337
### reset()
278338

279339
> **reset**(): `void`
280340
281-
Defined in: [src/test-execution-context.ts:211](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L211)
341+
Defined in: [src/test-execution-context.ts:244](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L244)
282342

283343
Reinitializes the execution context, clearing all state variables and resetting internal components.
284344
Invoked between test cases to ensure isolation.
@@ -293,7 +353,7 @@ Invoked between test cases to ensure isolation.
293353

294354
> **setCompiledApp**(`c`, `appId`): `void`
295355
296-
Defined in: [src/test-execution-context.ts:173](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L173)
356+
Defined in: [src/test-execution-context.ts:180](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L180)
297357

298358
Sets a compiled application.
299359

@@ -321,7 +381,7 @@ The application ID.
321381

322382
> **setCompiledLogicSig**(`c`, `account`): `void`
323383
324-
Defined in: [src/test-execution-context.ts:198](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L198)
384+
Defined in: [src/test-execution-context.ts:231](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L231)
325385

326386
Sets a compiled logic signature.
327387

@@ -349,7 +409,7 @@ The account associated with the logic signature.
349409

350410
> **setTemplateVar**(`name`, `value`, `prefix`?): `void`
351411
352-
Defined in: [src/test-execution-context.ts:153](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L153)
412+
Defined in: [src/test-execution-context.ts:160](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-execution-context.ts#L160)
353413

354414
Sets a template variable.
355415

0 commit comments

Comments
 (0)