-
Notifications
You must be signed in to change notification settings - Fork 339
/
account.test.sh
84 lines (75 loc) · 2 KB
/
account.test.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
81
82
83
#!ic-repl
load "prelude.sh";
import fake = "2vxsx-fae" as "../.dfx/local/canisters/basic_dao/basic_dao.did";
let wasm = file("../.dfx/local/canisters/basic_dao/basic_dao.wasm");
// Setup initial account
identity alice;
let args = encode fake.__init_args(
record {
accounts = vec { record { owner = alice; tokens = record { amount_e8s = 1_000_000_000_000 } } };
proposals = vec {};
system_params = record {
transfer_fee = record { amount_e8s = 10_000 };
proposal_vote_threshold = record { amount_e8s = 1_000_000_000 };
proposal_submission_deposit = record { amount_e8s = 10_000 };
};
}
);
let DAO = install(wasm, args, null);
call DAO.account_balance();
assert _.amount_e8s == (1_000_000_000_000 : nat);
// destination address needs to exist
identity bob;
call DAO.account_balance();
assert _.amount_e8s == (0 : nat);
call DAO.transfer(
record {
to = alice;
amount = record {
amount_e8s = 500_000_000_000;
};
}
);
assert _.err == "Caller needs an account to transfer funds";
// transfer from alice to bob
identity alice;
call DAO.transfer(
record {
to = bob;
amount = record {
amount_e8s = 500_000_000_000;
};
},
);
call DAO.account_balance();
assert _.amount_e8s == (499_999_990_000 : nat);
identity bob;
call DAO.account_balance();
assert _.amount_e8s == (500_000_000_000 : nat);
// not enough funds considering transfer fee
call DAO.transfer(
record {
to = alice;
amount = record {
amount_e8s = 500_000_000_000;
};
}
);
assert _.err ~= "Caller's account has insufficient funds to transfer";
// transfer to self
call DAO.transfer(
record {
to = bob;
amount = record {
amount_e8s = 10;
};
}
);
call DAO.account_balance();
assert _.amount_e8s == (499_999_990_000 : nat);
// upgrade preserves states
identity alice;
upgrade(DAO, wasm, args);
let accounts = call DAO.list_accounts();
assert accounts[0].tokens.amount_e8s == (499_999_990_000 : nat);
assert accounts[1].tokens.amount_e8s == (499_999_990_000 : nat);