Skip to content

Commit

Permalink
Merge pull request #1970 from demergent-labs/trap_property_tests
Browse files Browse the repository at this point in the history
Trap property tests
  • Loading branch information
lastmjs authored Aug 7, 2024
2 parents e8a2e20 + c203da4 commit 236be73
Show file tree
Hide file tree
Showing 17 changed files with 6,475 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ jobs:
"tests/end_to_end/http_server/tfjs",
"tests/end_to_end/http_server/web_assembly",
"tests/property/ic_api/caller",
"tests/property/ic_api/id"
"tests/property/ic_api/id",
"tests/property/ic_api/trap"
]
END
)
Expand Down
22 changes: 22 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as dns from 'node:dns';
dns.setDefaultResultOrder('ipv4first');

import { ActorSubclass } from '@dfinity/agent';
import { describe, expect, test } from '@jest/globals';
import { join } from 'path';

import { getCanisterId } from '../dfx';
import { execSyncPretty } from '../src/compiler/utils/exec_sync_pretty';
export { expect } from '@jest/globals';

Expand Down Expand Up @@ -115,3 +117,23 @@ function processEnvVars(): {
shouldRunBenchmarks
};
}

export const defaultPropTestParams = {
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
endOnFailure: process.env.AZLE_PROPTEST_SHRINK === 'true' ? false : true
};

export async function getCanisterActor<T>(
canisterName: string
): Promise<ActorSubclass<T>> {
const { createActor } = await import(
join(process.cwd(), 'test', 'dfx_generated', canisterName)
);
const actor = createActor(getCanisterId(canisterName), {
agentOptions: {
host: 'http://127.0.0.1:8000'
}
});

return actor;
}
2 changes: 2 additions & 0 deletions tests/property/ic_api/caller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
Expand Down
14 changes: 5 additions & 9 deletions tests/property/ic_api/caller/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { Principal } from '@dfinity/principal';
import { createAuthenticatedAgent, getCanisterId, whoami } from 'azle/dfx';
import { expect, it, please, Test } from 'azle/test';
import { defaultPropTestParams, expect, it, please, Test } from 'azle/test';
import { execSync } from 'child_process';
import fc from 'fast-check';

Expand Down Expand Up @@ -97,11 +97,9 @@ export function getTests(): Test {
);
}
),
{
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1)
}
defaultPropTestParams
);
}, 1_000_000);
});

it('should return the caller principal for query and update', async () => {
await fc.assert(
Expand Down Expand Up @@ -131,10 +129,8 @@ export function getTests(): Test {
);
}
),
{
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1)
}
defaultPropTestParams
);
}, 1_000_000);
});
};
}
2 changes: 2 additions & 0 deletions tests/property/ic_api/id/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
Expand Down
9 changes: 3 additions & 6 deletions tests/property/ic_api/id/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Principal } from '@dfinity/principal';
import { expect, it, Test } from 'azle/test';
import { defaultPropTestParams, expect, it, Test } from 'azle/test';
import { execSync } from 'child_process';
import fc from 'fast-check';

Expand Down Expand Up @@ -89,11 +89,8 @@ export function getTests(): Test {
);
}
),
{
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
endOnFailure: true
}
defaultPropTestParams
);
}, 1_000_000);
});
};
}
4 changes: 4 additions & 0 deletions tests/property/ic_api/trap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.azle
.dfx
dfx_generated
node_modules
13 changes: 13 additions & 0 deletions tests/property/ic_api/trap/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"canisters": {
"canister": {
"type": "azle",
"main": "src/index.ts",
"candid_gen": "automatic",
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
}
}
}
}
12 changes: 12 additions & 0 deletions tests/property/ic_api/trap/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading

0 comments on commit 236be73

Please sign in to comment.