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

Canister Version Prop Tests #2143

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ jobs:
id: set-exclude-dirs
run: |
RELEASE_TESTS="${{ format('
tests/end_to_end/candid_rpc/class_syntax/new/
tests/end_to_end/http_server/new/
tests/end_to_end/candid_rpc/class_syntax/new
tests/end_to_end/http_server/new
') }}"

UNSTABLE_TESTS="${{ format('
examples/basic_bitcoin
examples/bitcoin_psbt
examples/ckbtc
tests/end_to_end/candid_rpc/class_syntax/multi_deploy
tests/end_to_end/http_server/ethers_base
tests/end_to_end/http_server/http_outcall_fetch
tests/end_to_end/http_server/ic_evm_rpc
tests/end_to_end/http_server/multi_deploy
tests/property/candid_rpc/class_api/stable_b_tree_map
tests/property/candid_rpc/functional_api/stable_b_tree_map
tests/property/ic_api/performance_counter
Expand Down
13 changes: 13 additions & 0 deletions scripts/hash_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createHash } from 'crypto';
import { readFile } from 'fs/promises';

async function getFileHash(path: string): Promise<string> {
const fileData = await readFile(path);
let h = createHash('sha256');
h.update(fileData);
const result = h.digest('hex');
console.log(result);
return result;
}

getFileHash(process.argv[2]);
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { createHash } from 'crypto';
import { FileReadResult, open } from 'fs/promises';

export async function hashFile(path: string): Promise<Buffer> {
return await hashFileByParts(path, 0);
}

async function hashFileByParts(
export async function hashFileByParts(
path: string,
position: number,
position: number = 0,
previousHash?: Buffer
): Promise<Buffer> {
const { buffer, bytesRead } = await getBytesToHash(path, position);
Expand Down Expand Up @@ -43,7 +39,7 @@ async function getBytesToHash(
}

function hashChunkWith(data: Buffer, previousHash?: Buffer): Buffer {
const h = createHash('sha256');
let h = createHash('sha256');
h.update(data);
if (previousHash !== undefined) {
h.update(previousHash);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { hashFile } from '.';
import { hashFileByParts } from '.';

async function main(): Promise<void> {
const args = process.argv.slice(2);
const filePath = args[0];
const fileHash = await hashFile(filePath);
const fileHash = await hashFileByParts(filePath);
console.info(fileHash.toString('hex'));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { open, stat } from 'fs/promises';

import { hashFile } from '../../../../../../scripts/hash_file';
import { hashFileByParts } from '../../../../../../scripts/hash_file_by_parts';
import { Dest, Src } from '.';
import { bytesToHumanReadable } from './bytes_to_human_readable';
import { UploaderActor } from './uploader_actor';
Expand Down Expand Up @@ -80,7 +80,7 @@ async function shouldBeUploaded(
destPath: string,
actor: UploaderActor
): Promise<boolean> {
const localHash = (await hashFile(srcPath)).toString('hex');
const localHash = (await hashFileByParts(srcPath)).toString('hex');
const canisterHashOption = await actor._azle_get_file_hash(destPath);
if (canisterHashOption.length === 0) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.azle
.dfx
dfx_generated
node_modules
12 changes: 12 additions & 0 deletions tests/end_to_end/candid_rpc/class_syntax/multi_deploy/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"canisters": {
"multi_deploy": {
"type": "azle",
"main": "src/index.ts",
"declarations": {
"output": "test/dfx_generated/multi_deploy",
"node_compatibility": true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading