@@ -12,6 +12,7 @@ use primitives::{
12
12
adapter:: KeystoreOptions ,
13
13
channel:: { Channel , Nonce } ,
14
14
config:: TokenInfo ,
15
+ test_util:: { ADVERTISER , CREATOR , FOLLOWER , GUARDIAN , GUARDIAN_2 , LEADER , PUBLISHER } ,
15
16
Address , BigNum , Config , ValidatorId ,
16
17
} ;
17
18
@@ -48,129 +49,41 @@ pub static KEYSTORE_IDENTITY: Lazy<(Address, KeystoreOptions)> = Lazy::new(|| {
48
49
( address, keystore_options ( "keystore.json" , "adexvalidator" ) )
49
50
} ) ;
50
51
51
- pub static GANACHE_KEYSTORES : Lazy < HashMap < String , ( Address , KeystoreOptions ) > > = Lazy :: new ( || {
52
+ pub static KEYSTORES : Lazy < HashMap < Address , KeystoreOptions > > = Lazy :: new ( || {
52
53
vec ! [
53
54
(
54
- "guardian" . to_string( ) ,
55
- (
56
- "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39"
57
- . parse( )
58
- . expect( "Valid Address" ) ,
59
- keystore_options(
60
- "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39_keystore.json" ,
61
- "address0" ,
62
- ) ,
63
- ) ,
64
- ) ,
65
- (
66
- "leader" . to_string( ) ,
67
- (
68
- "0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5"
69
- . parse( )
70
- . expect( "Valid Address" ) ,
71
- keystore_options(
72
- "0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5_keystore.json" ,
73
- "address1" ,
74
- ) ,
75
- ) ,
76
- ) ,
77
- (
78
- "follower" . to_string( ) ,
79
- (
80
- "0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02"
81
- . parse( )
82
- . expect( "Valid Address" ) ,
83
- keystore_options(
84
- "0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02_keystore.json" ,
85
- "address2" ,
86
- ) ,
87
- ) ,
88
- ) ,
89
- (
90
- "creator" . to_string( ) ,
91
- (
92
- "0x0E45891a570Af9e5A962F181C219468A6C9EB4e1"
93
- . parse( )
94
- . expect( "Valid Address" ) ,
95
- keystore_options(
96
- "0x0E45891a570Af9e5A962F181C219468A6C9EB4e1_keystore.json" ,
97
- "address3" ,
98
- ) ,
99
- ) ,
100
- ) ,
101
- (
102
- "advertiser" . to_string( ) ,
103
- (
104
- "0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d"
105
- . parse( )
106
- . expect( "Valid Address" ) ,
107
- keystore_options(
108
- "0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d_keystore.json" ,
109
- "address4" ,
110
- ) ,
111
- ) ,
112
- ) ,
113
- (
114
- "guardian2" . to_string( ) ,
115
- (
116
- "0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8"
117
- . parse( )
118
- . expect( "Valid Address" ) ,
119
- keystore_options(
120
- "0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8_keystore.json" ,
121
- "address5" ,
122
- ) ,
123
- ) ,
55
+ * LEADER ,
56
+ keystore_options( & format!( "{}_keystore.json" , * LEADER ) , "ganache0" ) ,
124
57
) ,
125
- ]
126
- . into_iter ( )
127
- . collect ( )
128
- } ) ;
129
-
130
- /// Addresses generated on local running `ganache` for testing purposes.
131
- /// see the `ganache-cli.sh` script in the repository
132
- pub static GANACHE_ADDRESSES : Lazy < HashMap < String , Address > > = Lazy :: new ( || {
133
- vec ! [
134
58
(
135
- "guardian" . to_string( ) ,
136
- "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39"
137
- . parse( )
138
- . expect( "Valid Address" ) ,
59
+ * FOLLOWER ,
60
+ keystore_options( & format!( "{}_keystore.json" , * FOLLOWER ) , "ganache1" ) ,
139
61
) ,
140
62
(
141
- "leader" . to_string( ) ,
142
- "0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5"
143
- . parse( )
144
- . expect( "Valid Address" ) ,
63
+ * GUARDIAN ,
64
+ keystore_options( & format!( "{}_keystore.json" , * GUARDIAN ) , "ganache2" ) ,
145
65
) ,
146
66
(
147
- "follower" . to_string( ) ,
148
- "0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02"
149
- . parse( )
150
- . expect( "Valid Address" ) ,
67
+ * CREATOR ,
68
+ keystore_options( & format!( "{}_keystore.json" , * CREATOR ) , "ganache3" ) ,
151
69
) ,
152
70
(
153
- "creator" . to_string( ) ,
154
- "0x0E45891a570Af9e5A962F181C219468A6C9EB4e1"
155
- . parse( )
156
- . expect( "Valid Address" ) ,
71
+ * ADVERTISER ,
72
+ keystore_options( & format!( "{}_keystore.json" , * ADVERTISER ) , "ganache4" ) ,
157
73
) ,
158
74
(
159
- "advertiser" . to_string( ) ,
160
- "0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d"
161
- . parse( )
162
- . expect( "Valid Address" ) ,
75
+ * PUBLISHER ,
76
+ keystore_options( & format!( "{}_keystore.json" , * PUBLISHER ) , "ganache5" ) ,
163
77
) ,
164
78
(
165
- "guardian2" . to_string( ) ,
166
- "0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8"
167
- . parse( )
168
- . expect( "Valid Address" ) ,
79
+ * GUARDIAN_2 ,
80
+ keystore_options( & format!( "{}_keystore.json" , * GUARDIAN_2 ) , "ganache6" ) ,
169
81
) ,
170
82
]
171
83
. into_iter ( )
172
84
. collect ( )
173
85
} ) ;
86
+
174
87
/// Local `ganache` is running at:
175
88
pub const GANACHE_URL : & str = "http://localhost:8545" ;
176
89
@@ -193,9 +106,9 @@ fn keystore_options(file_name: &str, password: &str) -> KeystoreOptions {
193
106
194
107
pub fn get_test_channel ( token_address : Address ) -> Channel {
195
108
Channel {
196
- leader : ValidatorId :: from ( & GANACHE_ADDRESSES [ "leader" ] ) ,
197
- follower : ValidatorId :: from ( & GANACHE_ADDRESSES [ "follower" ] ) ,
198
- guardian : GANACHE_ADDRESSES [ "advertiser" ] ,
109
+ leader : ValidatorId :: from ( & LEADER ) ,
110
+ follower : ValidatorId :: from ( & FOLLOWER ) ,
111
+ guardian : * GUARDIAN ,
199
112
token : token_address,
200
113
nonce : Nonce :: from ( 12345_u32 ) ,
201
114
}
@@ -251,7 +164,7 @@ pub async fn sweeper_sweep(
251
164
channel : & Channel ,
252
165
depositor : [ u8 ; 20 ] ,
253
166
) -> web3:: contract:: Result < H256 > {
254
- let from_leader_account = H160 ( * GANACHE_ADDRESSES [ "leader" ] . as_bytes ( ) ) ;
167
+ let from_leader_account = H160 ( * LEADER . as_bytes ( ) ) ;
255
168
256
169
sweeper_contract
257
170
. call (
@@ -281,11 +194,7 @@ pub async fn deploy_sweeper_contract(
281
194
opt. gas_price = Some ( 1 . into ( ) ) ;
282
195
opt. gas = Some ( 6_721_975 . into ( ) ) ;
283
196
} ) )
284
- . execute (
285
- * SWEEPER_BYTECODE ,
286
- ( ) ,
287
- H160 ( GANACHE_ADDRESSES [ "leader" ] . to_bytes ( ) ) ,
288
- )
197
+ . execute ( * SWEEPER_BYTECODE , ( ) , H160 ( LEADER . to_bytes ( ) ) )
289
198
. await ?;
290
199
291
200
let sweeper_address = Address :: from ( sweeper_contract. address ( ) . to_fixed_bytes ( ) ) ;
@@ -304,18 +213,14 @@ pub async fn deploy_outpace_contract(
304
213
opt. gas_price = Some ( 1 . into ( ) ) ;
305
214
opt. gas = Some ( 6_721_975 . into ( ) ) ;
306
215
} ) )
307
- . execute (
308
- * OUTPACE_BYTECODE ,
309
- ( ) ,
310
- H160 ( GANACHE_ADDRESSES [ "leader" ] . to_bytes ( ) ) ,
311
- )
216
+ . execute ( * OUTPACE_BYTECODE , ( ) , H160 ( LEADER . to_bytes ( ) ) )
312
217
. await ?;
313
218
let outpace_address = Address :: from ( outpace_contract. address ( ) . to_fixed_bytes ( ) ) ;
314
219
315
220
Ok ( ( outpace_address, outpace_contract) )
316
221
}
317
222
318
- /// Deploys the Mock Token contract from `GANACHE_ADDRESS['leader']`
223
+ /// Deploys the Mock Token contract from [`LEADER`]
319
224
pub async fn deploy_token_contract (
320
225
web3 : & Web3 < Http > ,
321
226
min_token_units : u64 ,
@@ -327,11 +232,7 @@ pub async fn deploy_token_contract(
327
232
opt. gas_price = Some ( 1 . into ( ) ) ;
328
233
opt. gas = Some ( 6_721_975 . into ( ) ) ;
329
234
} ) )
330
- . execute (
331
- * MOCK_TOKEN_BYTECODE ,
332
- ( ) ,
333
- H160 ( GANACHE_ADDRESSES [ "leader" ] . to_bytes ( ) ) ,
334
- )
235
+ . execute ( * MOCK_TOKEN_BYTECODE , ( ) , H160 ( LEADER . to_bytes ( ) ) )
335
236
. await ?;
336
237
337
238
let token_info = TokenInfo {
0 commit comments