Skip to content

Commit ebc7954

Browse files
committed
feat: add support for ABI validation
1 parent d4d9554 commit ebc7954

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

docs/testing-guide/concepts.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ As explained in the [introduction](index.md), `algorand-typescript-testing` _inj
6464
3. **Mockable**: Not implemented, but can be mocked or patched. For example, `op.onlineStake` can be mocked to return specific values or behaviors; otherwise, it raises a `NotImplementedError`. This category covers cases where native or emulated implementation in a unit test context is impractical or overly complex.
6565

6666
For a full list of all public `algorand-typescript` types and their corresponding implementation category, refer to the [Coverage](../coverage.md) section.
67+
68+
## Data Validation
69+
70+
Algorand TypeScript and the puya compiler have functionality to perform validation of transaction inputs via the `--validate-abi-args`, `--validate-abi-return` CLI arguments, `arc4.abimethod({validateEncoding: ...})` decorator, and `validateEncoding(...)` method.
71+
The Algorand TypeScript Testing library does _NOT_ implement this validation behaviour, as you should test invalid inputs using an integrated test against a real Algorand network.

src/impl/validate-encoding.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** @internal */
2+
export function validateEncoding<T>(_value: T) {}

src/internal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export { Box, BoxMap, BoxRef, GlobalState, LocalState } from '../impl/state'
1313
export { TemplateVarImpl as TemplateVar } from '../impl/template-var'
1414
export { Txn } from '../impl/txn'
1515
export { urangeImpl as urange } from '../impl/urange'
16+
export { validateEncoding } from '../impl/validate-encoding'
1617
export { assert, err } from '../util'
1718
export * as arc4 from './arc4'
1819
export * as op from './op'

tests/artifacts/arc4-primitive-ops/contract.algo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { bytes } from '@algorandfoundation/algorand-typescript'
2-
import { arc4, BigUint, emit } from '@algorandfoundation/algorand-typescript'
2+
import { arc4, BigUint, emit, validateEncoding } from '@algorandfoundation/algorand-typescript'
33
import type { Bool, UFixedNxM } from '@algorandfoundation/algorand-typescript/arc4'
44
import { Byte, Contract, interpretAsArc4, Str, UintN } from '@algorandfoundation/algorand-typescript/arc4'
55

66
export class Arc4PrimitiveOpsContract extends Contract {
7-
@arc4.abimethod()
7+
@arc4.abimethod({ validateEncoding: 'unsafe-disabled' })
88
public verify_uintn_uintn_eq(a: bytes, b: bytes): boolean {
99
const aBiguint = BigUint(a)
1010
const bBiguint = BigUint(b)
1111
const aUintN = new UintN<64>(aBiguint)
1212
const bUintN = new UintN<64>(bBiguint)
13+
validateEncoding(aUintN)
1314
return aUintN === bUintN
1415
}
1516
@arc4.abimethod()

0 commit comments

Comments
 (0)