Skip to content

Commit

Permalink
Merge branch 'main' into audit_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs authored Sep 1, 2024
2 parents 8d716cf + 3fc5ba5 commit 17b741f
Show file tree
Hide file tree
Showing 45 changed files with 14,498 additions and 19,310 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
"examples/bitcoin_psbt",
"examples/ckbtc",
"examples/hello_world",
"examples/hello_world_candid_rpc",
"examples/hello_world_http_server",
"tests/property/candid_rpc/class_api/blob",
"tests/property/candid_rpc/class_api/bool",
"tests/property/candid_rpc/class_api/canister_methods/http_request",
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/superheroes",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/threshold_ecdsa",
"tests/end_to_end/candid_rpc/class_syntax/motoko_examples/whoami",
"tests/end_to_end/candid_rpc/class_syntax/new_candid_rpc",
"tests/end_to_end/candid_rpc/class_syntax/new",
"tests/end_to_end/candid_rpc/class_syntax/notify_raw",
"tests/end_to_end/candid_rpc/class_syntax/null_example",
"tests/end_to_end/candid_rpc/class_syntax/optional_types",
Expand Down
1 change: 1 addition & 0 deletions examples/hello_world/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.azle
.dfx
dfx_generated
node_modules
23 changes: 1 addition & 22 deletions examples/hello_world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ To create and deploy a simple sample application called `hello_world`:

```bash
# create a new default project called hello_world
npx azle new hello_world --http-server
npx azle new hello_world
cd hello_world
```

Expand All @@ -82,24 +82,3 @@ In a separate terminal in the `hello_world` directory:
# deploy your canister
dfx deploy
```

If you would like your canister to autoreload on file changes:

```bash
AZLE_AUTORELOAD=true dfx deploy
```

View your frontend in a web browser at `http://[canisterId].localhost:8000`.

To obtain your application's [canisterId]:

```bash
dfx canister id backend
```

Communicate with your canister using any HTTP client library, for example using `curl`:

```bash
curl http://[canisterId].localhost:8000/db
curl -X POST -H "Content-Type: application/json" -d "{ \"hello\": \"world\" }" http://[canisterId].localhost:8000/db/update
```
11 changes: 5 additions & 6 deletions examples/hello_world/dfx.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"canisters": {
"backend": {
"hello_world": {
"type": "azle",
"main": "src/backend/index.ts",
"custom": {
"experimental": true,
"assets": [["src/frontend/dist", "dist"]],
"build_assets": "npm run build"
"main": "src/index.ts",
"declarations": {
"output": "test/dfx_generated/hello_world",
"node_compatibility": true
}
}
}
Expand Down
9,169 changes: 1,000 additions & 8,169 deletions examples/hello_world/package-lock.json

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions examples/hello_world/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
{
"scripts": {
"build": "cd src/frontend && VITE_CANISTER_ORIGIN=http://$(dfx canister id backend).localhost:8000 vite build",
"pretest": "tsx test/pretest.ts",
"test": "jest"
},
"dependencies": {
"azle": "0.23.0",
"express": "^4.18.2",
"lit": "^3.1.2"
"azle": "0.23.0"
},
"devDependencies": {
"@types/express": "^4.17.21",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"tsx": "^4.15.7",
"typescript": "^5.2.2",
"vite": "^5.0.12"
"typescript": "^5.2.2"
}
}
File renamed without changes.
8 changes: 6 additions & 2 deletions examples/hello_world/test/pretest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { execSync } from 'child_process';

function pretest(): void {
execSync(`dfx canister uninstall-code backend || true`, {
execSync(`dfx canister uninstall-code hello_world || true`, {
stdio: 'inherit'
});

execSync(`dfx deploy`, {
execSync(`dfx deploy hello_world`, {
stdio: 'inherit'
});

execSync(`dfx generate hello_world`, {
stdio: 'inherit'
});
}
Expand Down
9 changes: 7 additions & 2 deletions examples/hello_world/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { createActor } from './dfx_generated/hello_world';
import { getTests } from './tests';

const canisterId = getCanisterId('backend');
const helloWorldCanister = createActor(getCanisterId('hello_world'), {
agentOptions: {
host: 'http://127.0.0.1:8000'
}
});

runTests(getTests(canisterId));
runTests(getTests(helloWorldCanister));
33 changes: 17 additions & 16 deletions examples/hello_world/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { ActorSubclass } from '@dfinity/agent';
import { expect, it, Test } from 'azle/test';

export function getTests(canisterId: string): Test {
const origin = `http://${canisterId}.localhost:8000`;
// @ts-ignore this path may not exist when these tests are imported into other test projects
import { _SERVICE } from './dfx_generated/hello_world/hello_world.did';

export function getTests(helloWorldCanister: ActorSubclass<_SERVICE>): Test {
return () => {
it('gets a simple hello world database', async () => {
const response = await fetch(`${origin}/db`);
const responseJson = await response.json();
it('gets original message', async () => {
const result = await helloWorldCanister.getMessage();

expect(responseJson).toEqual({ hello: '' });
expect(result).toBe('Hello world!');
});

it('updates a simple hello world database', async () => {
const response = await fetch(`${origin}/db/update`, {
method: 'POST',
headers: [['Content-Type', 'application/json']],
body: JSON.stringify({
hello: 'world'
})
});
const responseJson = await response.json();
it('sets a new message', async () => {
const result =
await helloWorldCanister.setMessage('Goodbye world!');

expect(responseJson).toEqual({ hello: 'world' });
expect(result).toBeUndefined();
});

it('gets persisted new message', async () => {
const result = await helloWorldCanister.getMessage();

expect(result).toBe('Goodbye world!');
});
};
}
4 changes: 1 addition & 3 deletions examples/hello_world/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"outDir": "HACK_BECAUSE_OF_ALLOW_JS",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true
"outDir": "HACK_BECAUSE_OF_ALLOW_JS"
}
}
12 changes: 0 additions & 12 deletions examples/hello_world_candid_rpc/dfx.json

This file was deleted.

Loading

0 comments on commit 17b741f

Please sign in to comment.