Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into migrate-vite
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 5, 2024
2 parents 3254f9a + 81d7d81 commit 9d904ae
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 76 deletions.
33 changes: 17 additions & 16 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
strategy:
fail-fast: false
env:
DFX_VERSION: 0.20.0
IC_REPL_VERSION: 0.7.4
MOC_VERSION: 0.12.0
DFX_VERSION: 0.22.0
IC_REPL_VERSION: 0.7.5
MOPS_VERSION: 0.2.0
steps:
- name: Setup Rust
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -48,34 +48,35 @@ jobs:
npm i -g ic-mops
dfx cache install
cd $(dfx cache show)
wget https://github.com/dfinity/motoko/releases/download/$MOC_VERSION/motoko-Linux-x86_64-$MOC_VERSION.tar.gz
tar zxvf motoko-Linux-x86_64-$MOC_VERSION.tar.gz
wget https://github.com/chenyan2002/mops-cli/releases/download/$MOPS_VERSION/mops-cli-linux64
cp ./mops-cli-linux64 /usr/local/bin/mops-cli
chmod a+x /usr/local/bin/mops-cli
- name: Start dfx
run: |
dfx start --background
- name: Checkout base branch
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'breaking_changes')
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
- name: Deploy main branch
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'breaking_changes')
run: |
dfx deploy backend
# - name: Checkout base branch
# if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'breaking_changes')
# uses: actions/checkout@v4
# with:
# ref: ${{ github.base_ref }}
# - name: Deploy main branch
# if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'breaking_changes')
# run: |
# dfx deploy backend
- uses: actions/checkout@v4
- name: Deploy current branch
run: dfx deploy backend
- name: CanisterPool test
run: |
(for f in service/pool/tests/*.test.sh; do
echo "==== Run test $f ===="
ic-repl "$f" || exit
ic-repl -v "$f" || exit
done)
- name: Actor class test
run: |
cd ./service/pool/tests/actor_class
dfx canister create --all
dfx build
ic-repl ./test.sh
ic-repl -v ./test.sh
- name: Stop dfx
run: dfx stop
9 changes: 5 additions & 4 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- 18
- 20
env:
DFX_VERSION: 0.20.0
DFX_VERSION: 0.22.0
SKIP_WASM: true
MOC_VERSION: 0.12.0
MOPS_VERSION: 0.2.0
steps:
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node }}
Expand All @@ -41,8 +41,9 @@ jobs:
npm i -g ic-mops
dfx cache install
cd $(dfx cache show)
wget https://github.com/dfinity/motoko/releases/download/$MOC_VERSION/motoko-Linux-x86_64-$MOC_VERSION.tar.gz
tar zxvf motoko-Linux-x86_64-$MOC_VERSION.tar.gz
wget https://github.com/chenyan2002/mops-cli/releases/download/$MOPS_VERSION/mops-cli-linux64
cp ./mops-cli-linux64 /usr/local/bin/mops-cli
chmod a+x /usr/local/bin/mops-cli
- name: Start dfx
run: |
dfx start --background
Expand Down
21 changes: 8 additions & 13 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,28 @@
]
},
"backend": {
"type": "custom",
"dependencies": ["wasm-utils"],
"specified_id": "mwrha-maaaa-aaaab-qabqq-cai",
"main": "service/pool/Main.mo",
"type": "motoko",
"build": ["mops-cli build service/pool/Main.mo"],
"candid": "target/pool/pool.did",
"wasm": "target/pool/pool.wasm",
"optimize": "cycles"
},
"saved": {
"type": "custom",
"specified_id": "vhtho-raaaa-aaaab-qadoq-cai",
"main": "service/saved/Saved.mo",
"type": "motoko",
"build": ["mops-cli build service/saved/Saved.mo"],
"candid": "target/Saved/Saved.did",
"wasm": "target/Saved/Saved.wasm",
"optimize": "cycles"
},
"react_app": {
"dependencies": ["backend", "saved"],
"specified_id": "m7sm4-2iaaa-aaaab-qabra-cai",
"frontend": {
"entrypoint": "public/index.html"
},
"source": ["build"],
"type": "assets"
}
},
"defaults": {
"build": {
"output": "build",
"packtool": "mops sources"
}
},
"output_env_file": ".env"
}
1 change: 0 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"prestart": "dfx start --background; [ -f .dfx/local/canister_ids.json ] || dfx deploy",
"predeploy": "npm run prestart",
"prepare": "husky",
"postinstall": "mops install",
"dev": "vite"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion script/deploy_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function build_frontend(name) {
function deploy_frontend(dist) {
let expired = ite(exist(frontend_info), is_expired(frontend_info, frontend_init?.canister_time_to_live), true);
let info = ite(exist(frontend_info), opt frontend_info, null);
if expired {
if expired { // TODO: check it is also not transferred
"Frontend caniter expired, fetching a new one...";
let new_info = call Frontend.deployCanister(info, null);
} else {
Expand Down
34 changes: 24 additions & 10 deletions script/deploy_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ function install(wasm, args, cycles) {

function start_testnet() {
"creating a new testnet...";
let wasm = file("./pool.wasm");
let wasm = file("../target/pool/pool.wasm");
let backend_init = opt record {
cycles_per_canister = 105_000_000_000;
max_num_canisters = 2;
max_num_canisters = 9;
nonce_time_to_live = 300_000_000_000;
canister_time_to_live = 1200_000_000_000;
max_family_tree_size = 5;
no_uninstall = opt false;
};
let frontend_init = opt record {
cycles_per_canister = 105_000_000_000;
max_num_canisters = 2;
max_num_canisters = 9;
nonce_time_to_live = 300_000_000_000;
canister_time_to_live = 1200_000_000_000;
max_family_tree_size = 5;
Expand All @@ -56,19 +56,33 @@ function start_testnet() {

function populate_asset_canister(Frontend, n) {
let asset = file("./chunked_map.wasm");
let deploy_arg = opt record { arg = encode (); wasm_module = asset; bypass_wasm_transform = opt true };
while gt(n, 0) {
let info = call Frontend.deployCanister(null, opt record { arg = encode (); wasm_module = asset; });
assert info[1] == variant { install };
stringify("deploying asset canister ", n, " with id ", info[0].id);
let n = sub(n, 1);
if lt(n, 5) {
let info = call Frontend.deployCanister(null, deploy_arg);
stringify("deploying asset canister ", n, " with id ", stringify(info));
let n = sub(n, 1);
} else {
let info = par_call [Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg)];
stringify("deploying asset canister ", n, " with id ", stringify(info));
let n = sub(n, 5);
};
};
call Frontend.releaseAllCanisters();
};
function populate_backend(Backend, n) {
let nonce = record { timestamp = 0; nonce = 0 };
let origin = record { origin = "admin"; tags = vec {} };
while gt(n, 0) {
let info = call Backend.getCanisterId(record { timestamp = 0; nonce = 0 }, record { origin = "admin"; tags = vec {} });
stringify("init backend canister ", n, " with id ", info.id);
let n = sub(n, 1);
if lt(n, 5) {
let info = call Backend.getCanisterId(nonce, origin);
stringify("init backend canister ", n, " with id ", stringify(info));
let n = sub(n, 1);
} else {
let info = par_call [Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin)];
stringify("init backend canister ", n, " with id ", stringify(info));
let n = sub(n, 5);
};
};
call Backend.releaseAllCanisters();
};
Expand Down
39 changes: 27 additions & 12 deletions script/update_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,59 @@ let testnet_env = env_name("testnet");

function populate_asset_canister(Frontend, n) {
let asset = file("./chunked_map.wasm");
let deploy_arg = opt record { arg = encode (); wasm_module = asset; bypass_wasm_transform = opt true };
while gt(n, 0) {
let info = call Frontend.deployCanister(null, opt record { arg = encode (); wasm_module = asset; });
stringify("deploying asset canister ", n, " with id ", info[0].id);
let n = sub(n, 1);
if lt(n, 5) {
let info = call Frontend.deployCanister(null, deploy_arg);
stringify("deploying asset canister ", n, " with id ", stringify(info));
let n = sub(n, 1);
} else {
let info = par_call [Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg), Frontend.deployCanister(null, deploy_arg)];
stringify("deploying asset canister ", n, " with id ", stringify(info));
let n = sub(n, 5);
};
};
call Frontend.releaseAllCanisters();
};
function populate_backend(Backend, n) {
let nonce = record { timestamp = 0; nonce = 0 };
let origin = record { origin = "admin"; tags = vec {} };
while gt(n, 0) {
let info = call Backend.getCanisterId(record { timestamp = 0; nonce = 0 }, record { origin = "admin"; tags = vec {} });
stringify("init backend canister ", n, " with id ", info.id);
let n = sub(n, 1);
if lt(n, 5) {
let info = call Backend.getCanisterId(nonce, origin);
stringify("init backend canister ", n, " with id ", stringify(info));
let n = sub(n, 1);
} else {
let info = par_call [Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin), Backend.getCanisterId(nonce, origin)];
stringify("init backend canister ", n, " with id ", stringify(info));
let n = sub(n, 5);
};
};
call Backend.releaseAllCanisters();
};

load testnet_env;
let backend_init = opt record {
cycles_per_canister = 550_000_000_000;
max_num_canisters = 50;
max_num_canisters = 1000;
nonce_time_to_live = 300_000_000_000;
canister_time_to_live = 2700_000_000_000;
max_family_tree_size = 5;
no_uninstall = opt false;
};
let frontend_init = opt record {
cycles_per_canister = 550_000_000_000;
max_num_canisters = 50;
max_num_canisters = 1000;
nonce_time_to_live = 300_000_000_000;
canister_time_to_live = 2700_000_000_000;
max_family_tree_size = 5;
no_uninstall = opt true;
};
let wasm = file("../target/pool/pool.wasm");
//install(Backend, wasm, backend_init, variant { upgrade });
//install(Frontend, wasm, frontend_init, variant { upgrade });
//call Frontend.releaseAllCanisters();
install(Backend, wasm, backend_init, variant { upgrade });
install(Frontend, wasm, frontend_init, variant { upgrade });
call Frontend.releaseAllCanisters();
populate_asset_canister(Frontend, frontend_init?.max_num_canisters);
//call Backend.releaseAllCanisters();
call Backend.releaseAllCanisters();
populate_backend(Backend, backend_init?.max_num_canisters);
export(testnet_env, Backend, Frontend, backend_init, frontend_init);
9 changes: 5 additions & 4 deletions service/pool/IC.mo
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ module {
taken_at_timestamp : Nat64;
};
public type http_header = { value : Text; name : Text };
public type transform_function = shared query {
context : Blob;
response : http_request_result;
} -> async http_request_result;
public type http_request_args = {
url : Text;
method : { #get; #head; #post };
max_response_bytes : ?Nat64;
body : ?Blob;
transform : ?{
function : shared query {
context : Blob;
response : http_request_result;
} -> async http_request_result;
function : transform_function;
context : Blob;
};
headers : [http_header];
Expand Down
Loading

0 comments on commit 9d904ae

Please sign in to comment.