Skip to content

Commit

Permalink
Merge pull request #1446 from demergent-labs/stable_json
Browse files Browse the repository at this point in the history
Stable json
  • Loading branch information
lastmjs authored Nov 8, 2023
2 parents 777b421 + 8b58d21 commit 619f35f
Show file tree
Hide file tree
Showing 214 changed files with 3,877 additions and 617 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
should_run_tests: ${{ steps.should_run_tests.outputs.should_run_tests }} # We only want the next job to run the tests once we have finished deploying to npm and GitHub
example_directories: ${{ steps.example_directories.outputs.example_directories }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# if: contains(github.head_ref, 'release--')
with:
ref: ${{ contains(github.head_ref, 'release--') && github.event.pull_request.head.ref || github.ref }} # This is necessary for this job to be able to commit and push to the origin remote properly
Expand Down Expand Up @@ -124,6 +124,7 @@ jobs:
"examples/robust_imports",
"examples/simple_erc20",
"examples/simple_user_accounts",
"examples/stable_json",
"examples/stable_memory",
"examples/stable_structures",
"examples/timers",
Expand Down Expand Up @@ -192,7 +193,7 @@ jobs:
example_directories: ${{ needs.release-candidate-deploy.outputs.should_run_tests == 'true' && fromJSON(needs.release-candidate-deploy.outputs.example_directories) || fromJSON('["dummy"]') }}
steps:
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
uses: actions/checkout@v2
uses: actions/checkout@v4
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -232,7 +233,11 @@ jobs:
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests && (github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: AZLE_PROPTEST_NUM_RUNS=100 AZLE_PROPTEST_VERBOSE=true npm test
run: AZLE_NUM_PROPTEST_RUNS=100 AZLE_PROPTEST_VERBOSE=true npm test
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests && matrix.example_directories != 'examples/new' }}
shell: bash -l {0}
working-directory: ${{ matrix.example_directories }}
run: $GITHUB_WORKSPACE/node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs

check-basic-integration-tests-success:
needs: basic-integration-tests
Expand Down
106 changes: 47 additions & 59 deletions examples/audio_recorder/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/audio_recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"azle": "0.18.6"
},
"devDependencies": {
"@dfinity/agent": "0.11.1",
"@dfinity/agent": "^0.19.3",
"ts-node": "10.7.0",
"typescript": "4.6.3"
}
Expand Down
7 changes: 5 additions & 2 deletions examples/audio_recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const User = Record({
recordingIds: Vec(Principal),
username: text
});
type User = typeof User;

const Recording = Record({
id: Principal,
Expand All @@ -31,14 +32,16 @@ const Recording = Record({
name: text,
userId: Principal
});
type Recording = typeof Recording;

const AudioRecorderError = Variant({
RecordingDoesNotExist: Principal,
UserDoesNotExist: Principal
});
type AudioRecorderError = typeof AudioRecorderError;

let users = StableBTreeMap(Principal, User, 0);
let recordings = StableBTreeMap(Principal, Recording, 1);
let users = StableBTreeMap<Principal, User>(Principal, User, 0);
let recordings = StableBTreeMap<Principal, Recording>(Principal, Recording, 1);

export default Canister({
createUser: update([text], User, (username) => {
Expand Down
17 changes: 6 additions & 11 deletions examples/audio_recorder/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { ok, Test } from 'azle/test';
import {
Recording,
_SERVICE,
User
} from './dfx_generated/audio_recorder/audio_recorder.did';
import { _SERVICE } from './dfx_generated/audio_recorder/audio_recorder.did';
import { ActorSubclass } from '@dfinity/agent';

// TODO to be more thorough we could test all of the error cases as well

let global_user: User;
let global_recording: Recording;
let global_user: any;
let global_recording: any;

export function get_tests(
audio_recorder_canister: ActorSubclass<_SERVICE>
Expand All @@ -18,9 +14,8 @@ export function get_tests(
{
name: 'create_user',
test: async () => {
const user = await audio_recorder_canister.createUser(
'lastmjs'
);
const user =
await audio_recorder_canister.createUser('lastmjs');

global_user = user;

Expand Down Expand Up @@ -48,7 +43,7 @@ export function get_tests(

const recording = result.Ok;

global_recording = recording;
global_recording = recording as any;

return {
Ok:
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_bitcoin/src/bitcoin_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { blob, ic, match, nat64, Opt, Vec } from 'azle';
import {
BitcoinNetwork,
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_bitcoin/src/bitcoin_plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { blob, int32, nat32, nat64, registerPlugin, Vec } from 'azle';

export type BitcoinAddress = {
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_bitcoin/src/bitcoin_wallet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

//! A demo of a very bare-bones bitcoin "wallet".
//!
//! The wallet here showcases how bitcoin addresses can be be computed
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_bitcoin/src/ecdsa_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { blob, ic, match, Opt, Vec } from 'azle';
import { managementCanister } from 'azle/canisters/management';

Expand Down
2 changes: 2 additions & 0 deletions examples/basic_bitcoin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { blob, $init, match, nat64, $postUpgrade, $update, Vec } from 'azle';
import {
BitcoinNetwork,
Expand Down
2 changes: 2 additions & 0 deletions examples/basic_bitcoin/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { nat64, Record } from 'azle';

export type SendRequest = Record<{
Expand Down
2 changes: 1 addition & 1 deletion examples/bitcoin/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function installBitcoin() {
}

export async function whileRunningBitcoinDaemon(
callback: () => Promise<void> | void
callback: () => Promise<boolean> | void
) {
installBitcoin();
const bitcoinDaemon = await startBitcoinDaemon();
Expand Down
2 changes: 1 addition & 1 deletion examples/ckbtc/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { existsSync, rmSync } from 'fs-extra';
import { getTests } from './tests';

export async function whileRunningBitcoinDaemon(
callback: () => Promise<void> | void
callback: () => Promise<boolean> | void
) {
const bitcoinDaemon = await startBitcoinDaemon();
await callback();
Expand Down
3 changes: 3 additions & 0 deletions examples/ckbtc/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { Identity } from '@dfinity/agent';
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { getCanisterId } from 'azle/test';

// @ts-ignore
import { _SERVICE } from '../wallet/frontend/dfx_generated/wallet_backend/wallet_backend.did';

// @ts-ignore
import { createActor } from '../wallet/frontend/dfx_generated/wallet_backend';

type Config = {
Expand Down
2 changes: 2 additions & 0 deletions examples/ckbtc/wallet/frontend/elements/ck-app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { LitElement, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { AuthClient } from '@dfinity/auth-client';
Expand Down
1 change: 1 addition & 0 deletions examples/complex_init/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCanisterId, runTests } from 'azle/test';
import { createActor as createComplexActor } from '../test/dfx_generated/complex_init';
// @ts-ignore
import { createActor as createRecActor } from '../test/dfx_generated/rec_init';
import { get_rec_tests, get_tests } from './tests';

Expand Down
1 change: 1 addition & 0 deletions examples/complex_init/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { _SERVICE as _COMPLEX_SERVICE } from './dfx_generated/complex_init/complex_init.did';
// @ts-ignore
import { _SERVICE as _REC_SERVICE } from './dfx_generated/rec_init/rec_init.did';

export function get_tests(
Expand Down
Loading

0 comments on commit 619f35f

Please sign in to comment.