Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/tg-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ As explained in the [introduction](testing-guide.md), `algorand-typescript-testi
3. **Mockable**: Not implemented, but can be mocked or patched. For example, `op.onlineStake` can be mocked to return specific values or behaviours; otherwise, it raises a `NotImplementedError`. This category covers cases where native or emulated implementation in a unit test context is impractical or overly complex.

For a full list of all public `algorand-typescript` types and their corresponding implementation category, refer to the [Coverage](./coverage.md) section.

## Data Validation

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, `convertBytes(..., { strategy: 'validate' }) method` and `validateEncoding(...)` method.
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.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"vitest": "3.2.4"
},
"dependencies": {
"@algorandfoundation/algorand-typescript": "1.0.0-alpha.87",
"@algorandfoundation/puya-ts": "1.0.0-alpha.87",
"@algorandfoundation/algorand-typescript": "1.0.0-alpha.90",
"@algorandfoundation/puya-ts": "1.0.0-alpha.90",
"elliptic": "^6.6.1",
"js-sha256": "^0.11.0",
"js-sha3": "^0.9.3",
Expand Down
2 changes: 1 addition & 1 deletion src/impl/encoded-types/encoded-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ export function decodeArc4<T>(
export function convertBytes<T extends _ARC4Encoded>(
typeInfoString: string,
bytes: StubBytesCompat,
options: { prefix?: 'none' | 'log'; strategy: 'unsafe-cast' },
options: { prefix?: 'none' | 'log'; strategy: 'unsafe-cast' | 'validate' },
): T {
const typeInfo = JSON.parse(typeInfoString)
return getEncoder<T>(typeInfo)(bytes, typeInfo, options.prefix)
Expand Down
2 changes: 2 additions & 0 deletions src/impl/validate-encoding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @internal */
export function validateEncoding<T>(_value: T) {}
2 changes: 2 additions & 0 deletions src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export { BaseContract, contract } from '../impl/base-contract'
/** @internal */
export { clone } from '../impl/clone'
/** @internal */
export { validateEncoding } from '../impl/validate-encoding'
/** @internal */
export { compile } from '../impl/compiled'
/** @internal */
export { abimethod, baremethod, Contract, readonly } from '../impl/contract'
Expand Down
3 changes: 2 additions & 1 deletion tests/arc4/address.algo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ describe('arc4.Address', () => {

test.each(testData)('fromBytes method', (value) => {
const sdkResult = getABIEncodedValue(asUint8Array(value), abiTypeString, {})
const result = convertBytes<Address>(value, { strategy: 'unsafe-cast' })
// no actual validation in testing lib, just making sure 'validate' strategy value can be passed
const result = convertBytes<Address>(value, { strategy: 'validate' })
expect(result.bytes).toEqual(sdkResult)
})

Expand Down
5 changes: 3 additions & 2 deletions tests/artifacts/arc4-primitive-ops/contract.algo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { biguint, bytes, uint64 } from '@algorandfoundation/algorand-typescript'
import { arc4, BigUint, clone, emit } from '@algorandfoundation/algorand-typescript'
import { arc4, BigUint, clone, emit, validateEncoding } from '@algorandfoundation/algorand-typescript'
import type { Bool, UFixed } from '@algorandfoundation/algorand-typescript/arc4'
import { Byte, Contract, convertBytes, Str, Uint } from '@algorandfoundation/algorand-typescript/arc4'

export class Arc4PrimitiveOpsContract extends Contract {
@arc4.abimethod()
@arc4.abimethod({ validateEncoding: 'unsafe-disabled' })
public verify_uintn_uintn_eq(a: bytes, b: bytes): boolean {
const aBiguint = BigUint(a)
const bBiguint = BigUint(b)
const aUintN = new Uint<64>(aBiguint)
const bUintN = new Uint<64>(bBiguint)
validateEncoding(aUintN)
return aUintN === bUintN
}
@arc4.abimethod()
Expand Down