Skip to content

Commit

Permalink
Merge pull request #2182 from demergent-labs/arg_data_raw_prop_test
Browse files Browse the repository at this point in the history
Arg data raw prop test
  • Loading branch information
lastmjs authored Nov 14, 2024
2 parents 82bda55 + 72461fc commit 787a6ae
Show file tree
Hide file tree
Showing 26 changed files with 3,231 additions and 72 deletions.
172 changes: 143 additions & 29 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"type": "module",
"bin": {
"azle": "./src/build/index.ts"
"azle": "./src/build/index.ts",
"tsc": "./node_modules/.bin/tsc"
},
"main": "./src/lib/stable/index.ts",
"repository": {
Expand Down Expand Up @@ -71,7 +72,8 @@
"husky": "7.0.4",
"jest": "^29.7.0",
"lint-staged": "12.3.7",
"prettier": "^3.0.3"
"prettier": "^3.0.3",
"ts-jest": "^29.1.4"
},
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
Expand Down
20 changes: 16 additions & 4 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dns.setDefaultResultOrder('ipv4first');

import { ActorSubclass, HttpAgent } from '@dfinity/agent';
import { describe, expect, test } from '@jest/globals';
import * as fc from 'fast-check';
import { join } from 'path';

import { getCanisterId } from '../dfx';
Expand Down Expand Up @@ -105,10 +106,21 @@ export function it(
it.only = test.only;
it.skip = test.skip;

export const defaultPropTestParams = {
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
endOnFailure: process.env.AZLE_PROPTEST_SHRINK === 'true' ? false : true
};
export function defaultPropTestParams<T = unknown>(): fc.Parameters<T> {
const baseParams = {
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
endOnFailure: process.env.AZLE_PROPTEST_SHRINK === 'true' ? false : true
};

const seed =
process.env.AZLE_PROPTEST_SEED !== undefined
? Number(process.env.AZLE_PROPTEST_SEED)
: undefined;

const path = process.env.AZLE_PROPTEST_PATH;

return seed !== undefined ? { ...baseParams, seed, path } : baseParams;
}

export async function getCanisterActor<T>(
canisterName: string
Expand Down
12 changes: 6 additions & 6 deletions test/property/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export async function runPropTests(
? Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1)
: 1;

const seed = process.env.AZLE_PROPTEST_SEED
? Number(process.env.AZLE_PROPTEST_SEED)
: undefined;
const seed =
process.env.AZLE_PROPTEST_SEED !== undefined
? Number(process.env.AZLE_PROPTEST_SEED)
: undefined;

const path = process.env.AZLE_PROPTEST_PATH;

const executionParams = seed
? { ...defaultParams, seed, path }
: defaultParams;
const executionParams =
seed !== undefined ? { ...defaultParams, seed, path } : defaultParams;

try {
for (let i = 0; i < numRuns; i++) {
Expand Down
5 changes: 5 additions & 0 deletions tests/property/ic_api/arg_data_raw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.azle
.dfx
dfx_generated
node_modules
src
12 changes: 12 additions & 0 deletions tests/property/ic_api/arg_data_raw/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"canisters": {
"canister": {
"type": "azle",
"main": "src/index.ts",
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
}
}
}
}
12 changes: 12 additions & 0 deletions tests/property/ic_api/arg_data_raw/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading

0 comments on commit 787a6ae

Please sign in to comment.