/
actor-class-mgmt.mo
126 lines (109 loc) · 3.34 KB
/
actor-class-mgmt.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import Prim "mo:⛔";
import Cycles = "cycles/cycles";
import Cs "actor-class-mgmt/C";
actor a {
type Change_origin = {
#from_user : {
user_id : Principal;
};
#from_canister : {
canister_id : Principal;
canister_version : ?Nat64;
};
};
type Change_details = {
#creation : { controllers : [Principal] };
#code_uninstall;
#code_deployment : {
mode : { #install; #reinstall; #upgrade};
// module_hash : Blob; // introduces non-determinism when codegen improves
};
#controllers_change : {
controllers : [Principal];
};
};
type Change = {
// timestamp_nanos : Nat64; // just omit this
canister_version : Nat64;
origin : Change_origin;
details : Change_details;
};
let ic00 = actor "aaaaa-aa" :
actor {
create_canister : {
settings : ? {
controllers : ?[Principal];
compute_allocation: ?Nat;
memory_allocation: ?Nat;
freezing_threshold: ?Nat;
}
} -> async { canister_id : Principal };
canister_info : {
canister_id : Principal;
num_requested_changes : ?Nat64;
} -> async {
total_num_changes : Nat64;
recent_changes : [Change];
// module_hash : ?Blob;
controllers : [Principal];
};
};
let default_settings = { settings = null };
// same as default but explicit
let settings = { settings = ? {
controllers = null;
compute_allocation = null;
freezing_threshold = null;
memory_allocation = null;
};
};
public func go () : async () {
// To get lots of cycles in both drun and ic-ref-run
if (Cycles.balance() == 0)
await Cycles.provisional_top_up_actor(a, 100_000_000_000_000);
do {
Cycles.add<system>(2_000_000_000_000);
let c0 = await
Cs.C (0, ?(Prim.principalOfActor a));
assert ({args = 0; upgrades = 0} == (await c0.observe()));
Cycles.add<system>(2_000_000_000_000);
let c1 = await
(system Cs.C)(#new default_settings)(1, null);
assert ({args = 1; upgrades = 0} == (await c1.observe()));
assert (c1 != c0);
Cycles.add<system>(2_000_000_000_000);
let c2 = await
(system Cs.C)(#new settings)(2, null);
assert ({args = 2; upgrades = 0} == (await c2.observe()));
assert (c2 != c1);
Cycles.add<system>(2_000_000_000_000);
let {canister_id = p} = await
ic00.create_canister default_settings;
// no need to add cycles
let c3 = await
(system Cs.C)(#install p)(3, null);
assert ({args = 3; upgrades = 0} == (await c3.observe()));
assert (Prim.principalOfActor c3 == p);
assert (c3 != c2);
// no need to add cycles
let c4 = await
(system Cs.C)(#upgrade c3)(4, null);
assert ({args = 4; upgrades = 1} == (await c4.observe()));
assert (c4 == c3);
// no need to add cycles
let c5 = await
(system Cs.C)(#reinstall c4)(5, null);
assert ({args = 5; upgrades = 0} == (await c5.observe()));
assert (c5 == c4);
let info = await ic00.canister_info {
canister_id = p;
num_requested_changes = ?4
};
Prim.debugPrint (debug_show info);
};
};
}
//CALL ingress go "DIDL\x00\x00"
//SKIP run
//SKIP run-ir
//SKIP run-low