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

add vec property tests #1404

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion .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
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
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
Loading