-
Notifications
You must be signed in to change notification settings - Fork 30
/
demo.sh
executable file
·80 lines (58 loc) · 2.67 KB
/
demo.sh
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
#!/bin/sh
# The roles here are:
# Both Alice and Bob have their own wallet
# Charlie is a custodian of Alice (but Alice is the owner of her own wallet).
set -e
trap 'dfx stop' EXIT
npm install
dfx start --background --clean
dfx identity new id_alice || true
dfx identity new id_bob || true
dfx identity new id_charlie || true
dfx --identity id_alice canister create --no-wallet alice --with-cycles=5000000000000
dfx --identity id_bob canister create --no-wallet bob --with-cycles=2000000000000
dfx --identity default canister create --no-wallet wallet --with-cycles=3000000000000
alice_wallet="$(dfx canister id alice)"
bob_wallet="$(dfx canister id bob)"
default_wallet="$(dfx canister id wallet)"
dfx build
dfx --identity id_alice canister install alice
dfx --identity id_bob canister install bob
dfx --identity default canister install wallet
dfx --identity id_alice identity set-wallet "$alice_wallet"
dfx --identity id_bob identity set-wallet "$bob_wallet"
dfx --identity default identity set-wallet "$default_wallet"
echo
echo '== Initial cycle balances for Alice and Bob.'
echo
echo "Alice = $(dfx --identity id_alice canister call alice wallet_balance)"
echo "Bob = $(dfx --identity id_bob canister call bob wallet_balance)"
echo
echo '== Create a new canister with Alice as controller using 1000000000001 cycles.'
echo
CREATE_RES=$(dfx --identity id_alice canister call alice wallet_create_canister "(record { cycles = 1000000000001; settings = record {null; null; null;}; })")
echo "New canister id = $(echo "${CREATE_RES}" | tr '\n' ' ' | cut -d'"' -f 2)"
echo
echo '== Transfer 1000000000000 cycles from Alice to Bob.'
echo
eval dfx --identity id_alice canister call alice wallet_send "'(record { canister = principal \"$(dfx canister id bob)\"; amount = 1000000000000 })'"
echo
echo '== Final cycle balances for Alice and Bob.'
echo
echo "Alice = $(dfx --identity id_alice canister call alice wallet_balance)"
echo "Bob = $(dfx --identity id_bob canister call bob wallet_balance)"
echo
echo '== Setting custodian of Alices wallet to Charlie'
echo
dfx --identity id_alice canister call alice authorize "(principal \"$(dfx --identity id_charlie identity get-principal)\")"
echo
echo '== Upgrading...'
echo
dfx --identity id_alice canister install alice --mode=upgrade
echo
echo '== Using Charlie to send cycles...'
echo
eval dfx --identity id_charlie canister call alice wallet_send "'(record { canister = principal \"$(dfx canister id bob)\"; amount = 1000000000000 })'"
echo "Alice = $(dfx --identity id_alice canister call alice wallet_balance)"
echo "Alice^ = $(dfx --identity id_charlie canister call alice wallet_balance)"
echo "Bob = $(dfx --identity id_bob canister call bob wallet_balance)"