Skip to content

Commit 861f844

Browse files
refac(test-utils): pre-defined accounts (#143)
Introduce pre-defined accounts, alice to grace.
1 parent a768e6f commit 861f844

File tree

7 files changed

+292
-618
lines changed

7 files changed

+292
-618
lines changed

pallets/permission0/tests/fixed.rs

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ use test_utils::*;
55
fn fixed_fails_without_balance() {
66
new_test_ext().execute_with(|| {
77
zero_min_burn();
8-
let agent_0 = 0;
9-
register_empty_agent(agent_0);
108

11-
let agent_1 = 1;
12-
register_empty_agent(agent_1);
9+
let agent_0 = account!(id = 0, agent = "alice");
10+
let agent_1 = account!(id = 1, agent = "bob");
1311

1412
assert_err!(
1513
delegate_stream_permission(
@@ -30,13 +28,9 @@ fn fixed_fails_without_balance() {
3028
fn fixed_creates() {
3129
new_test_ext().execute_with(|| {
3230
zero_min_burn();
33-
let agent_0 = 0;
34-
register_empty_agent(agent_0);
3531

36-
let agent_1 = 1;
37-
register_empty_agent(agent_1);
38-
39-
add_balance(agent_0, as_tors(10) + 1);
32+
let agent_0 = account!(id = 0, agent = "alice", bal = as_tors(10) + 1);
33+
let agent_1 = account!(id = 1, agent = "bob");
4034

4135
let permission_id = assert_ok!(delegate_stream_permission(
4236
agent_0,
@@ -58,13 +52,9 @@ fn fixed_creates() {
5852
fn fixed_reserves() {
5953
new_test_ext().execute_with(|| {
6054
zero_min_burn();
61-
let agent_0 = 0;
62-
register_empty_agent(agent_0);
63-
64-
let agent_1 = 1;
65-
register_empty_agent(agent_1);
6655

67-
add_balance(agent_0, as_tors(10) + 1);
56+
let agent_0 = account!(id = 0, agent = "alice", bal = as_tors(10) + 1);
57+
let agent_1 = account!(id = 1, agent = "bob");
6858

6959
let permission_id = assert_ok!(delegate_stream_permission(
7060
agent_0,
@@ -88,16 +78,10 @@ fn fixed_reserves() {
8878
fn fixed_manual_executes() {
8979
new_test_ext().execute_with(|| {
9080
zero_min_burn();
91-
let agent_0 = 0;
92-
register_empty_agent(agent_0);
93-
94-
let agent_1 = 1;
95-
register_empty_agent(agent_1);
96-
97-
let agent_2 = 2;
98-
register_empty_agent(agent_2);
9981

100-
add_balance(agent_0, as_tors(10) + 1);
82+
let agent_0 = account!(id = 0, agent = "alice", bal = as_tors(10) + 1);
83+
let agent_1 = account!(id = 1, agent = "bob");
84+
let agent_2 = account!(id = 2, agent = "charlie");
10185

10286
let permission_id = assert_ok!(delegate_stream_permission(
10387
agent_0,
@@ -133,16 +117,10 @@ fn fixed_manual_executes() {
133117
fn fixed_manual_executes_only_once() {
134118
new_test_ext().execute_with(|| {
135119
zero_min_burn();
136-
let agent_0 = 0;
137-
register_empty_agent(agent_0);
138120

139-
let agent_1 = 1;
140-
register_empty_agent(agent_1);
141-
142-
let agent_2 = 2;
143-
register_empty_agent(agent_2);
144-
145-
add_balance(agent_0, as_tors(10) + 1);
121+
let agent_0 = account!(id = 0, agent = "alice", bal = as_tors(10) + 1);
122+
let agent_1 = account!(id = 1, agent = "bob");
123+
let agent_2 = account!(id = 2, agent = "charlie");
146124

147125
let permission_id = assert_ok!(delegate_stream_permission(
148126
agent_0,
@@ -182,16 +160,10 @@ fn fixed_manual_executes_only_once() {
182160
fn fixed_at_block_executes() {
183161
new_test_ext().execute_with(|| {
184162
zero_min_burn();
185-
let agent_0 = 0;
186-
register_empty_agent(agent_0);
187-
188-
let agent_1 = 1;
189-
register_empty_agent(agent_1);
190-
191-
let agent_2 = 2;
192-
register_empty_agent(agent_2);
193163

194-
add_balance(agent_0, as_tors(10) + 1);
164+
let agent_0 = account!(id = 0, agent = "alice", bal = as_tors(10) + 1);
165+
let agent_1 = account!(id = 1, agent = "bob");
166+
let agent_2 = account!(id = 2, agent = "charlie");
195167

196168
let _ = assert_ok!(delegate_stream_permission(
197169
agent_0,

pallets/permission0/tests/lifetime.rs

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ use test_utils::*;
66
fn manual_cant_execute_when_expires() {
77
new_test_ext().execute_with(|| {
88
zero_min_burn();
9-
let agent_0 = 0;
10-
register_empty_agent(agent_0);
119

12-
let agent_1 = 1;
13-
register_empty_agent(agent_1);
14-
15-
let agent_2 = 2;
16-
register_empty_agent(agent_2);
17-
18-
add_balance(agent_0, as_tors(10) + 1);
10+
let agent_0 = alice();
11+
let agent_1 = bob();
12+
let agent_2 = charlie();
1913

2014
let permission_id = assert_ok!(delegate_stream_permission(
2115
agent_0,
@@ -40,16 +34,10 @@ fn manual_cant_execute_when_expires() {
4034
fn irrevocable() {
4135
new_test_ext().execute_with(|| {
4236
zero_min_burn();
43-
let agent_0 = 0;
44-
register_empty_agent(agent_0);
45-
46-
let agent_1 = 1;
47-
register_empty_agent(agent_1);
4837

49-
let agent_2 = 2;
50-
register_empty_agent(agent_2);
51-
52-
add_balance(agent_0, as_tors(10) + 1);
38+
let agent_0 = alice();
39+
let agent_1 = bob();
40+
let agent_2 = charlie();
5341

5442
let permission_id = assert_ok!(delegate_stream_permission(
5543
agent_0,
@@ -85,19 +73,11 @@ fn irrevocable() {
8573
fn revocable_by_delegator() {
8674
new_test_ext().execute_with(|| {
8775
zero_min_burn();
88-
let agent_0 = 0;
89-
register_empty_agent(agent_0);
90-
91-
let agent_1 = 1;
92-
register_empty_agent(agent_1);
9376

94-
let agent_2 = 2;
95-
register_empty_agent(agent_2);
96-
97-
let agent_3 = 3;
98-
register_empty_agent(agent_3);
99-
100-
add_balance(agent_0, as_tors(10) + 1);
77+
let agent_0 = alice();
78+
let agent_1 = bob();
79+
let agent_2 = charlie();
80+
let agent_3 = dave();
10181

10282
let permission_id = assert_ok!(delegate_stream_permission(
10383
agent_0,
@@ -143,16 +123,10 @@ fn revocable_by_delegator() {
143123
fn revocable_after_block() {
144124
new_test_ext().execute_with(|| {
145125
zero_min_burn();
146-
let agent_0 = 0;
147-
register_empty_agent(agent_0);
148-
149-
let agent_1 = 1;
150-
register_empty_agent(agent_1);
151126

152-
let agent_2 = 2;
153-
register_empty_agent(agent_2);
154-
155-
add_balance(agent_0, as_tors(10) + 1);
127+
let agent_0 = alice();
128+
let agent_1 = bob();
129+
let agent_2 = charlie();
156130

157131
let permission_id = assert_ok!(delegate_stream_permission(
158132
agent_0,
@@ -184,13 +158,9 @@ fn revocable_after_block() {
184158
fn revocable_by_arbiters() {
185159
new_test_ext().execute_with(|| {
186160
zero_min_burn();
187-
let agent_0 = 0;
188-
register_empty_agent(agent_0);
189-
190-
let agent_1 = 1;
191-
register_empty_agent(agent_1);
192161

193-
add_balance(agent_0, as_tors(10) + 1);
162+
let agent_0 = alice();
163+
let agent_1 = bob();
194164

195165
let delegate_invalid = |accounts: &[AccountId], required_votes| {
196166
delegate_stream_permission(

0 commit comments

Comments
 (0)