Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 7, 2023
1 parent 5d1196d commit 1874172
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
20 changes: 10 additions & 10 deletions service/pool/tests/actor_class/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let deleter = file(".dfx/local/canisters/Deleter/Deleter.wasm");
let S = install(wasm, null, opt 100_000_000_000_000);

let nonce = record { timestamp = 1 : int; nonce = 1 : nat };
let c1 = call S.getCanisterId(nonce);
let c1 = call S.getCanisterId(nonce, "test");
let args = record { arg = blob ""; wasm_module = parent; mode = variant { install }; canister_id = c1.id };
call S.installCode(c1, args, false, false);
call S.installCode(c1, args, record { profiling = false; is_whitelisted = false; origin = "test" });

let c1 = c1.id;

Expand Down Expand Up @@ -48,26 +48,26 @@ let init = opt record {
let S = install(wasm, init, opt 100_000_000_000_000);

let nonce = record { timestamp = 1 : int; nonce = 1 : nat };
let c1 = call S.getCanisterId(nonce);
let c1 = call S.getCanisterId(nonce, "test");
let args = record { arg = blob ""; wasm_module = parent; mode = variant { install }; canister_id = c1.id };
call S.installCode(c1, args, false, false);
call S.installCode(c1, args, record { profiling = false; is_whitelisted = false; origin = "test" });
let c1 = c1.id;

fail call c1.makeChild(0);
call S.getCanisterId(nonce);
call S.getCanisterId(nonce);
call S.getCanisterId(nonce, "test");
call S.getCanisterId(nonce, "test");

// Security check
let S = install(wasm, null, opt 100_000_000_000_000);

let nonce = record { timestamp = 1 : int; nonce = 1 : nat };
let c1 = call S.getCanisterId(nonce);
let c1 = call S.getCanisterId(nonce, "test");
let args = record { arg = blob ""; wasm_module = parent; mode = variant { install }; canister_id = c1.id };
call S.installCode(c1, args, false, false);
call S.installCode(c1, args, record { profiling = false; is_whitelisted = false; origin = "test" });

let c2 = call S.getCanisterId(nonce);
let c2 = call S.getCanisterId(nonce, "test");
let args = record { arg = blob ""; wasm_module = deleter; mode = variant { install }; canister_id = c2.id };
call S.installCode(c2, args, false, false);
call S.installCode(c2, args, record { profiling = false; is_whitelisted = false; origin = "test" });

let c1 = c1.id;
let c2 = c2.id;
Expand Down
22 changes: 11 additions & 11 deletions service/pool/tests/canisterPool.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let init = opt record {
let S = install(wasm, init, null);
let nonce = record { timestamp = 1 : int; nonce = 1 : nat };
let CID = call S.getCanisterId(nonce);
call S.installCode(CID, record { arg = blob ""; wasm_module = empty_wasm; mode = variant { install }; canister_id = CID.id }, false, false);
call S.installCode(CID, record { arg = blob ""; wasm_module = empty_wasm; mode = variant { install }; canister_id = CID.id }, record { profiling = false; is_whitelisted = false; origin = "test" });
metadata(CID.id, "module_hash");

// Immediately expire
Expand All @@ -27,13 +27,13 @@ let init = opt record {
};
let S = install(wasm, init, null);

let c1 = call S.getCanisterId(nonce);
let c1 = call S.getCanisterId(nonce, "test");
c1;
let c2 = call S.getCanisterId(nonce);
let c2 = call S.getCanisterId(nonce, "test");
c2;
let c3 = call S.getCanisterId(nonce);
let c3 = call S.getCanisterId(nonce, "test");
c3;
let c4 = call S.getCanisterId(nonce);
let c4 = call S.getCanisterId(nonce, "test");
c4;
assert c1.id != c2.id;
assert c1.id == c3.id;
Expand All @@ -48,14 +48,14 @@ let init = opt record {
max_family_tree_size = 5 : nat;
};
reinstall(S, wasm, init);
let c3 = call S.getCanisterId(nonce);
let c3 = call S.getCanisterId(nonce, "test");
c3;
let c4 = call S.getCanisterId(nonce);
let c4 = call S.getCanisterId(nonce, "test");
c4;
fail call S.getCanisterId(nonce);
fail call S.getCanisterId(nonce, "test");
assert _ ~= "No available canister id";
call S.removeCode(c4);
call S.getCanisterId(nonce);
call S.getCanisterId(nonce, "test");
assert _.id == c4.id;
assert _.timestamp != c4.timestamp;

Expand All @@ -68,15 +68,15 @@ let init = opt record {
max_family_tree_size = 5 : nat;
};
let S = install(wasm, init, opt 100_000_000_000);
fail call S.getCanisterId(nonce);
fail call S.getCanisterId(nonce, "test");
assert _ ~= "105_000_000_000 cycles";
call ic.provisional_top_up_canister(
record {
canister_id = S;
amount = 100_000_000_000_000;
},
);
call S.getCanisterId(nonce);
call S.getCanisterId(nonce, "test");

// Enough time has passed that the timer has removed the canister code
fail metadata(CID.id, "module_hash");
Expand Down
8 changes: 4 additions & 4 deletions service/pool/tests/nonce.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ let init = opt record {
};
let S = install(wasm, init, null);

call S.getCanisterId(record { timestamp = 4780472194_000_000_000; nonce = 1 });
fail call S.getCanisterId(record { timestamp = 4780472194_000_000_000; nonce = 1 });
call S.getCanisterId(record { timestamp = 4780472194_000_000_000; nonce = 1 }, "test");
fail call S.getCanisterId(record { timestamp = 4780472194_000_000_000; nonce = 1 }, "test");
assert _ ~= "Nonce already used";
call S.getCanisterId(record { timestamp = 4780472194_000_000_001; nonce = 1 });
call S.getCanisterId(record { timestamp = 4780472194_000_000_001; nonce = 1 }, "test");

identity bob;
fail call S.getCanisterId(record { timestamp = 4780472194_000_000_002; nonce = 1 });
fail call S.getCanisterId(record { timestamp = 4780472194_000_000_002; nonce = 1 }, "test");
assert _ ~= "Proof of work check failed";
18 changes: 11 additions & 7 deletions service/pool/tests/upgrade.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ let init = opt record {
let S = install(wasm, init, null);

let nonce = record { timestamp = 1 : int; nonce = 1 : nat };
let c1 = call S.getCanisterId(nonce);
let c1 = call S.getCanisterId(nonce, "test");
c1;
let c2 = call S.getCanisterId(nonce);
let c2 = call S.getCanisterId(nonce, "test");
c2;

upgrade(S, wasm, init);
let c3 = call S.getCanisterId(nonce);
let c3 = call S.getCanisterId(nonce, "test");
c3;
let c4 = call S.getCanisterId(nonce);
let c4 = call S.getCanisterId(nonce, "test");
c4;
assert c1.id != c2.id;
assert c1.id == c3.id;
Expand All @@ -35,12 +35,16 @@ let init = opt record {
canister_time_to_live = 3600_000_000_000 : nat;
max_family_tree_size = 5 : nat;
};
let stats = call S.getStats();
upgrade(S, wasm, init);
let c5 = call S.getCanisterId(nonce);
// stats are preserved after upgrade
call S.getStats();
assert _ == stats;
let c5 = call S.getCanisterId(nonce, "test");
c5;
assert c5.id != c1.id;
assert c5.id != c2.id;
fail call S.getCanisterId(nonce);
fail call S.getCanisterId(nonce, "test");
assert _ ~= "No available canister id";

// Cannot reduce pool
Expand All @@ -54,5 +58,5 @@ let init = opt record {
fail upgrade(S, wasm, init);
assert _ ~= "Cannot reduce canisterPool for upgrade";
// still old canister, new TTL does not apply
fail call S.getCanisterId(nonce);
fail call S.getCanisterId(nonce, "test");
assert _ ~= "No available canister id";

0 comments on commit 1874172

Please sign in to comment.