Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property tests blob #1407

Merged
merged 4 commits into from
Oct 20, 2023
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
14 changes: 12 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
"examples/tuple_types",
"examples/update",
"examples/vanilla_js",
"property_tests/tests/blob",
"property_tests/tests/int",
"property_tests/tests/int8",
"property_tests/tests/int16",
Expand All @@ -139,7 +140,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 @@ -211,7 +213,15 @@ jobs:
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: npm test
run: AZLE_NUM_PROPTEST_RUNS=10 npm test
- 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=100 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: AZLE_NUM_PROPTEST_RUNS=100 npm test

check-basic-integration-tests-success:
needs: basic-integration-tests
Expand Down
6 changes: 6 additions & 0 deletions property_tests/arbitraries/candid/constructed/blob_arb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fc from 'fast-check';

export const BlobArb = fc.tuple(
fc.uint8Array(),
fc.oneof(fc.constant('blob'), fc.constant('Vec(nat8)'))
);
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
8 changes: 6 additions & 2 deletions property_tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import fc from 'fast-check';
import { TestSample, createCanisterArb } from './arbitraries/canister_arb';
import { writeFileSync } from 'fs';
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import { runTests } from '../test';

export function runPropTests(testArb: fc.Arbitrary<TestSample>) {
fc.assert(
fc.asyncProperty(createCanisterArb(testArb), async (canister) => {
if (!existsSync('src')) {
mkdirSync('src');
}

writeFileSync('src/index.ts', canister.sourceCode);

execSync(`dfx canister uninstall-code canister || true`, {
Expand All @@ -26,7 +30,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/blob/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