Skip to content

Commit

Permalink
prop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed May 27, 2024
1 parent c6e2bdd commit bd68b4c
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 99 deletions.
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';
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';
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
Expand Up @@ -3,7 +3,7 @@ import { deepEqual, 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, test } from 'azle/test';

import { InspectMessageBehavior } from './test';

Expand Down Expand Up @@ -56,9 +56,7 @@ function generateTest(
};
} catch (error: any) {
if (behavior === 'RETURN') {
return {
Ok: error.message.includes('rejected the message')
};
return test(error.message.includes('rejected the message'));
}

if (behavior === 'THROW') {
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 @@ -14,6 +14,8 @@ import {
import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb';
import fc from 'fast-check';

import { testEquality } from '../../../../../test';

const SimplePreUpgradeArb = PreUpgradeMethodArb({
generateBody: () =>
/*TS*/ `stable.insert(PRE_UPGRADE_HOOK_EXECUTED, true);`,
Expand Down Expand Up @@ -95,7 +97,7 @@ function generateGetPreUpgradeExecutedCanisterMethod(): QueryMethod {
const actor = getActor(__dirname);
const result = await actor.getPreUpgradeExecuted();

return { Ok: deepEqual(result, []) };
return testEquality(result, []);
}
}
],
Expand All @@ -106,7 +108,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

0 comments on commit bd68b4c

Please sign in to comment.