Skip to content

Commit

Permalink
Merge pull request #1909 from demergent-labs/test_stabilization
Browse files Browse the repository at this point in the history
Test stabilization
  • Loading branch information
lastmjs authored Jul 17, 2024
2 parents 1efffe4 + bed003a commit 6253314
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 185 deletions.
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"deep-is": "^0.1.4",
"esbuild": "^0.23.0",
"esbuild-plugin-tsc": "^0.4.0",
"ethers": "^6.11.1",
"ethers": "6.11.1",
"fs-extra": "^11.2.0",
"glob": "^10.3.15",
"hash-of-directory": "^1.0.1",
Expand Down
42 changes: 7 additions & 35 deletions property_tests/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ export type Test<> = {
test?: () => Promise<AzleResult>;
};

// TODO get rid of this union once the jest migration is complete
export type AzleResult =
| Partial<{
Ok: { isSuccessful: boolean; message?: string };
Err: string;
}>
| Partial<{ Ok: boolean; Err: string }>;
export type AzleResult = Partial<{
Ok: { isSuccessful: boolean; message?: string };
Err: string;
}>;

// TODO should this just return a boolean?
// TODO then the function calling can decide to throw or not
Expand Down Expand Up @@ -74,20 +71,10 @@ export async function runTests(
}
}

// TODO replace this with the below commented out code once jest migration is complete
const message =
typeof result.Ok === 'object' && result.Ok !== null
? result.Ok.message
: undefined;
const successful =
typeof result.Ok === 'boolean'
? result.Ok
: result.Ok.isSuccessful;

if (successful !== true) {
if (result.Ok.isSuccessful !== true) {
console.info('\x1b[31m', `test: ${test.name} failed`);
if (message !== undefined) {
console.info('\x1b[31m', `${message}`);
if (result.Ok.message !== undefined) {
console.info('\x1b[31m', `${result.Ok.message}`);
}
console.info('\x1b[0m');

Expand All @@ -98,21 +85,6 @@ export async function runTests(
}
}

// TODO bring this back once jest migration is complete
// if (result.Ok.isSuccessful !== true) {
// console.info('\x1b[31m', `test: ${test.name} failed`);
// if (result.Ok.message !== undefined) {
// console.info('\x1b[31m', `${result.Ok.message}`);
// }
// console.info('\x1b[0m');

// if (exitProcess) {
// process.exit(1);
// } else {
// return false;
// }
// }

console.info('\x1b[32m', `test: ${test.name} passed`);
console.info('\x1b[0m');
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion property_tests/tests/service/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const AllServicesQueryMethodArb = QueryMethodArb(
const CanisterConfigArb = fc
.array(AllServicesQueryMethodArb, {
...defaultArrayConstraints,
maxLength: 45
maxLength: 30 // If the number of generated services is too large we will run out of space in the wasm custom section.
})
.map((queryMethods): CanisterConfig => {
return { queryMethods };
Expand Down
16 changes: 5 additions & 11 deletions property_tests/tests/stable_b_tree_map/test/contains_key.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor } from 'azle/property_tests';
import { getActor } from 'azle/property_tests';
import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb';
import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb';
import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb';
import { AzleResult, Test } from 'azle/property_tests/test';
import { AzleResult, Test, testEquality } from 'azle/property_tests/test';
import fc from 'fast-check';

export function ContainsKeyTestArb(
Expand Down Expand Up @@ -60,9 +60,7 @@ function generateTests(
keySampleAgentArgumentValue
);

return {
Ok: deepEqual(result, true)
};
return testEquality(result, true);
}
}
],
Expand All @@ -76,9 +74,7 @@ function generateTests(
keySampleAgentArgumentValue
);

return {
Ok: deepEqual(result, true)
};
return testEquality(result, true);
}
}
],
Expand All @@ -92,9 +88,7 @@ function generateTests(
keySampleAgentArgumentValue
);

return {
Ok: deepEqual(result, false)
};
return testEquality(result, false);
}
}
]
Expand Down
20 changes: 9 additions & 11 deletions property_tests/tests/stable_b_tree_map/test/get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor } from 'azle/property_tests';
import { getActor } from 'azle/property_tests';
import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb';
import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb';
import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb';
import { AzleResult, Test } from 'azle/property_tests/test';
import { AzleResult, Test, testEquality } from 'azle/property_tests/test';
import fc from 'fast-check';

export function GetTestArb(
Expand Down Expand Up @@ -70,9 +70,9 @@ function generateTests(
keySampleAgentArgumentValue
);

return {
Ok: deepEqual(result, [valueSampleAgentArgumentValue])
};
return testEquality(result, [
valueSampleAgentArgumentValue
]);
}
}
],
Expand All @@ -86,9 +86,9 @@ function generateTests(
keySampleAgentArgumentValue
);

return {
Ok: deepEqual(result, [valueSampleAgentArgumentValue])
};
return testEquality(result, [
valueSampleAgentArgumentValue
]);
}
}
],
Expand All @@ -102,9 +102,7 @@ function generateTests(
keySampleAgentArgumentValue
);

return {
Ok: deepEqual(result, [])
};
return testEquality(result, []);
}
}
]
Expand Down
8 changes: 3 additions & 5 deletions property_tests/tests/stable_b_tree_map/test/insert.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor } from 'azle/property_tests';
import { getActor } from 'azle/property_tests';
import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb';
import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb';
import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb';
import { AzleResult, Test } from 'azle/property_tests/test';
import { AzleResult, Test, testEquality } from 'azle/property_tests/test';
import fc from 'fast-check';

export function InsertTestArb(
Expand Down Expand Up @@ -72,9 +72,7 @@ function generateTests(
valueSampleAgentArgumentValue
);

return {
Ok: deepEqual(result, [])
};
return testEquality(result, []);
}
}
]
Expand Down
16 changes: 5 additions & 11 deletions property_tests/tests/stable_b_tree_map/test/is_empty.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor } from 'azle/property_tests';
import { getActor } from 'azle/property_tests';
import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb';
import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb';
import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb';
import { AzleResult, Test } from 'azle/property_tests/test';
import { AzleResult, Test, testEquality } from 'azle/property_tests/test';
import fc from 'fast-check';

export function IsEmptyTestArb(
Expand Down Expand Up @@ -48,9 +48,7 @@ function generateTests(functionName: string): Test[][] {

const result = await actor[functionName]();

return {
Ok: deepEqual(result, true)
};
return testEquality(result, true);
}
}
],
Expand All @@ -62,9 +60,7 @@ function generateTests(functionName: string): Test[][] {

const result = await actor[functionName]();

return {
Ok: deepEqual(result, false)
};
return testEquality(result, false);
}
}
],
Expand All @@ -76,9 +72,7 @@ function generateTests(functionName: string): Test[][] {

const result = await actor[functionName]();

return {
Ok: deepEqual(result, true)
};
return testEquality(result, true);
}
}
]
Expand Down
36 changes: 15 additions & 21 deletions property_tests/tests/stable_b_tree_map/test/items.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor } from 'azle/property_tests';
import { getActor } from 'azle/property_tests';
import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb';
import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb';
import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb';
import { AzleResult, Test } from 'azle/property_tests/test';
import { AzleResult, Test, testEquality } from 'azle/property_tests/test';
import fc from 'fast-check';

export function ItemsTestArb(
Expand Down Expand Up @@ -58,14 +58,12 @@ function generateTests(

const result = await actor[functionName]();

return {
Ok: deepEqual(result, [
[
keySampleAgentArgumentValue,
valueSampleAgentArgumentValue
]
])
};
return testEquality(result, [
[
keySampleAgentArgumentValue,
valueSampleAgentArgumentValue
]
]);
}
}
],
Expand All @@ -77,14 +75,12 @@ function generateTests(

const result = await actor[functionName]();

return {
Ok: deepEqual(result, [
[
keySampleAgentArgumentValue,
valueSampleAgentArgumentValue
]
])
};
return testEquality(result, [
[
keySampleAgentArgumentValue,
valueSampleAgentArgumentValue
]
]);
}
}
],
Expand All @@ -96,9 +92,7 @@ function generateTests(

const result = await actor[functionName]();

return {
Ok: deepEqual(result, [])
};
return testEquality(result, []);
}
}
]
Expand Down
Loading

0 comments on commit 6253314

Please sign in to comment.