Skip to content

Commit

Permalink
Merge pull request #1405 from demergent-labs/multiple_property_test_r…
Browse files Browse the repository at this point in the history
…ounds

Multiple property test rounds
  • Loading branch information
lastmjs authored Oct 20, 2023
2 parents b0ace52 + 0ab41fd commit 8ee906a
Show file tree
Hide file tree
Showing 11 changed files with 1,377 additions and 6 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ jobs:
"property_tests/tests/nat8",
"property_tests/tests/nat16",
"property_tests/tests/nat32",
"property_tests/tests/nat64"
"property_tests/tests/nat64",
"property_tests/tests/vec"
]
END
)
Expand Down Expand Up @@ -208,10 +209,14 @@ jobs:
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: npm link azle
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests && contains(github.head_ref, 'release--') }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: AZLE_NUM_PROPTEST_RUNS=10 npm test
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests && (github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: npm test
run: AZLE_NUM_PROPTEST_RUNS=100 npm test

check-basic-integration-tests-success:
needs: basic-integration-tests
Expand Down
45 changes: 45 additions & 0 deletions property_tests/arbitraries/candid/constructed/vec_arb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fc from 'fast-check';
import { IntArb } from '../primitive/ints/int_arb';
import { Int8Arb } from '../primitive/ints/int8_arb';
import { Int16Arb } from '../primitive/ints/int16_arb';
import { Int32Arb } from '../primitive/ints/int32_arb';
import { Int64Arb } from '../primitive/ints/int64_arb';
import { NatArb } from '../primitive/nats/nat_arb';
import { Nat8Arb } from '../primitive/nats/nat8_arb';
import { Nat16Arb } from '../primitive/nats/nat16_arb';
import { Nat32Arb } from '../primitive/nats/nat32_arb';
import { Nat64Arb } from '../primitive/nats/nat64_arb';

// TODO look into making this recursive
// TODO we want to be able to have vecs of vecs
export const VecArb = fc.oneof(
fc.array(IntArb).map((sample) => createVecArbWrapper(sample, 'Vec(int)')),
fc.array(Int8Arb).map((sample) => createVecArbWrapper(sample, 'Vec(int8)')),
fc
.array(Int16Arb)
.map((sample) => createVecArbWrapper(sample, 'Vec(int16)')),
fc
.array(Int32Arb)
.map((sample) => createVecArbWrapper(sample, 'Vec(int32)')),
fc
.array(Int64Arb)
.map((sample) => createVecArbWrapper(sample, 'Vec(int64)')),
fc.array(NatArb).map((sample) => createVecArbWrapper(sample, 'Vec(nat)')),
fc.array(Nat8Arb).map((sample) => createVecArbWrapper(sample, 'Vec(nat8)')),
fc
.array(Nat16Arb)
.map((sample) => createVecArbWrapper(sample, 'Vec(nat16)')),
fc
.array(Nat32Arb)
.map((sample) => createVecArbWrapper(sample, 'Vec(nat32)')),
fc
.array(Nat64Arb)
.map((sample) => createVecArbWrapper(sample, 'Vec(nat64)'))
);

function createVecArbWrapper(sample: any[], candidType: string) {
return {
vec: sample,
candidType
};
}
1 change: 0 additions & 1 deletion property_tests/arbitraries/canister_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type TestSample = {
paramCandidTypes: string;
returnCandidType: string;
paramNames: string[];
paramSamples: any[];
body: string;
test: any;
};
Expand Down
1 change: 0 additions & 1 deletion property_tests/arbitraries/query_method_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TestSample } from './canister_arb';
export function createQueryMethodArb(testArb: fc.Arbitrary<TestSample>) {
return testArb.map((testSample) => {
const paramNames = testSample.paramNames;
const paramSamples = testSample.paramSamples;
const paramCandidTypes = testSample.paramCandidTypes;
const returnCandidType = testSample.returnCandidType;
const body = testSample.body;
Expand Down
2 changes: 1 addition & 1 deletion property_tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function runPropTests(testArb: fc.Arbitrary<TestSample>) {
return true;
}),
{
numRuns: 1
numRuns: Number(process.env.AZLE_NUM_PROP_TEST_RUNS ?? 1)
}
);
}
16 changes: 16 additions & 0 deletions property_tests/tests/vec/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"canisters": {
"canister": {
"type": "custom",
"main": "src/index.ts",
"candid": "src/index.did",
"build": "npx azle canister",
"wasm": ".azle/canister/canister.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
}
}
}
}
Loading

0 comments on commit 8ee906a

Please sign in to comment.