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

Improve tests just prop tests #1861

Merged
merged 6 commits into from
Jul 9, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crypto-browserify": "^3.12.0",
"deep-is": "^0.1.4",
"esbuild": "^0.19.3",
"esbuild-plugin-tsc": "^0.4.0",
"ethers": "^6.11.1",
Expand All @@ -59,7 +60,6 @@
"@typescript-eslint/eslint-plugin": "^6.13.0",
"@typescript-eslint/parser": "^6.13.0",
"deep-equal": "^2.2.3",
"deep-is": "^0.1.4",
"eslint": "^8.54.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
Expand Down
8 changes: 3 additions & 5 deletions property_tests/tests/blob/test/generate_tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
functionName: string,
Expand Down Expand Up @@ -29,9 +29,7 @@ export function generateTests(
)
);

return {
Ok: deepEqual(result, expectedResult)
};
return testEquality(result, expectedResult);
}
}
]
Expand Down
8 changes: 3 additions & 5 deletions property_tests/tests/bool/test/generate_tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
functionName: string,
Expand All @@ -24,9 +24,7 @@ export function generateTests(

const result = await actor[functionName](...paramValues);

return {
Ok: deepEqual(result, expectedResult)
};
return testEquality(result, expectedResult);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpRequest, HttpResponse } from 'azle/experimental';
import { deepEqual, Named } from 'azle/property_tests';
import { Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { HttpResponseAgentResponseValue } from 'azle/property_tests/arbitraries/http/response_arb';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

import { fletch } from './fletch';

Expand Down Expand Up @@ -42,12 +42,11 @@ export function generateTests(
...expectedResponse,
headers: sortedExpectedHeaders
};
const valuesAreEqual = deepEqual(

return testEquality(
processedResponse,
processedExpectedResponse
);

return { Ok: valuesAreEqual };
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpRequest, HttpResponse } from 'azle/experimental';
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { HttpResponseAgentResponseValue } from 'azle/property_tests/arbitraries/http/response_arb';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

import { fletch } from './fletch';

Expand All @@ -26,9 +26,7 @@ export function generateTests(

const result = await actor['get_state']();

return {
Ok: deepEqual(result, 0)
};
return testEquality(result, 0);
}
},
{
Expand All @@ -54,12 +52,11 @@ export function generateTests(
...expectedResponse,
headers: sortedExpectedHeaders
};
const valuesAreEqual = deepEqual(

return testEquality(
processedResponse,
processedExpectedResponse
);

return { Ok: valuesAreEqual };
}
},
{
Expand All @@ -69,9 +66,7 @@ export function generateTests(

const result = await actor['get_state']();

return {
Ok: deepEqual(result, 1)
};
return testEquality(result, 1);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
_functionName: string,
Expand All @@ -20,13 +20,7 @@ export function generateTests(
const actor = getActor(__dirname);
const result = await actor.getInitValues();

const valuesAreEqual = deepEqual(result, expectedResult);

return valuesAreEqual
? { Ok: true }
: {
Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}`
};
return testEquality(result, expectedResult);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Agent } from '@dfinity/agent';
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

import { InspectMessageBehavior } from './test';

Expand Down Expand Up @@ -48,24 +48,26 @@ function generateTest(
const result = await actor[functionName](...paramValues);

if (behavior === 'ACCEPT') {
return { Ok: deepEqual(result, expectedResult) };
return testEquality(result, expectedResult);
}

return {
Err: 'Expected canister method to throw but it did not'
};
} catch (error: any) {
if (behavior === 'RETURN') {
return {
Ok: error.message.includes('rejected the message')
};
return testEquality(
error.message.includes('rejected the message'),
true
);
}

if (behavior === 'THROW') {
const expectedError = `Method \\"${functionName}\\" not allowed`;
return {
Ok: error.message.includes(expectedError)
};
return testEquality(
error.message.includes(expectedError),
true
);
}

throw error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
_functionName: string,
Expand All @@ -23,19 +23,10 @@ export function generateTests(
const isPostUpgradeCalled =
await actor.isPostUpgradeCalled();

const valuesAreEqual =
deepEqual(initValues, expectedResult) &&
isPostUpgradeCalled === false;

return valuesAreEqual
? { Ok: true }
: {
Err: `\n
Incorrect return value
expected: ${expectedResult}
received: ${initValues}
isPostUpgradeCalled: ${isPostUpgradeCalled}`
};
return testEquality(
[initValues, isPostUpgradeCalled],
[expectedResult, false]
);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
_functionName: string,
Expand All @@ -24,19 +24,10 @@ export function generateTests(
await actor.getPostUpgradeValues();
const isInitCalled = await actor.isInitCalled();

const valuesAreEqual =
deepEqual(postUpgradeValues, expectedResult) &&
isInitCalled === false;

return valuesAreEqual
? { Ok: true }
: {
Err: `\n
Incorrect return value
expected: ${expectedResult}
received: ${postUpgradeValues}
isInitCalled: ${isInitCalled}`
};
return testEquality(
[postUpgradeValues, isInitCalled],
[expectedResult, false]
);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepEqual, getActor, runPropTests } from 'azle/property_tests';
import { getActor, runPropTests } from 'azle/property_tests';
import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb';
import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
Expand All @@ -12,6 +12,7 @@ import {
QueryMethodArb
} from 'azle/property_tests/arbitraries/canister_methods/query_method_arb';
import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb';
import { testEquality } from 'azle/test';
import fc from 'fast-check';

const SimplePreUpgradeArb = PreUpgradeMethodArb({
Expand Down Expand Up @@ -95,7 +96,7 @@ function generateGetPreUpgradeExecutedCanisterMethod(): QueryMethod {
const actor = getActor(__dirname);
const result = await actor.getPreUpgradeExecuted();

return { Ok: deepEqual(result, []) };
return testEquality(result, []);
}
}
],
Expand All @@ -106,7 +107,7 @@ function generateGetPreUpgradeExecutedCanisterMethod(): QueryMethod {
const actor = getActor(__dirname);
const result = await actor.getPreUpgradeExecuted();

return { Ok: deepEqual(result, [true]) };
return testEquality(result, [true]);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
functionName: string,
Expand All @@ -21,13 +21,7 @@ export function generateTests(
test: async () => {
const actor = getActor(__dirname);
const result = await actor[functionName](...paramValues);
const valuesAreEqual = deepEqual(result, expectedResult);

return valuesAreEqual
? { Ok: true }
: {
Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}`
};
return testEquality(result, expectedResult);
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
functionName: string,
Expand All @@ -21,13 +21,8 @@ export function generateTests(
test: async () => {
const actor = getActor(__dirname);
const result = await actor[functionName](...paramValues);
const valuesAreEqual = deepEqual(result, expectedResult);

return valuesAreEqual
? { Ok: true }
: {
Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}`
};
return testEquality(result, expectedResult);
}
}
]
Expand Down
8 changes: 3 additions & 5 deletions property_tests/tests/float32/test/generate_tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
functionName: string,
Expand All @@ -23,9 +23,7 @@ export function generateTests(

const result = await actor[functionName](...paramValues);

return {
Ok: deepEqual(result, expectedResult)
};
return testEquality(result, expectedResult);
}
}
]
Expand Down
8 changes: 3 additions & 5 deletions property_tests/tests/float64/test/generate_tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepEqual, getActor, Named } from 'azle/property_tests';
import { getActor, Named } from 'azle/property_tests';
import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb';
import { Test } from 'azle/test';
import { Test, testEquality } from 'azle/test';

export function generateTests(
functionName: string,
Expand All @@ -27,9 +27,7 @@ export function generateTests(

const result = await actor[functionName](...paramValues);

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