@@ -35,6 +35,7 @@ def get_required_env_var(name):
35
35
cd_smart_contracts_dir = f"cd { smart_contracts_dir } ; "
36
36
moniker = get_required_env_var ("MONIKER" )
37
37
owner_addr = get_required_env_var ("OWNER_ADDR" )
38
+ user1_addr = get_required_env_var ("USER1ADDR" )
38
39
39
40
40
41
def test_log_line (s ):
@@ -112,7 +113,7 @@ def get_sifchain_addr_balance(sifaddress, denom):
112
113
# balance_fn is a lambda that takes no arguments
113
114
# and returns a result. Runs the function up to
114
115
# max_attempts times, or until the result is equal to target_balance
115
- def wait_for_balance (balance_fn , target_balance , max_attempts = 30 ):
116
+ def wait_for_balance (balance_fn , target_balance , max_attempts = 30 , debug_prefix = "" ):
116
117
attempts = 0
117
118
while True :
118
119
balance = balance_fn ()
@@ -121,17 +122,28 @@ def wait_for_balance(balance_fn, target_balance, max_attempts=30):
121
122
else :
122
123
attempts += 1
123
124
if attempts >= max_attempts :
124
- print_error_message (f"Failed to get target balance of { target_balance } , balance is { balance } " )
125
+ print_error_message (
126
+ f"{ debug_prefix } Failed to get target balance of { target_balance } , balance is { balance } " )
125
127
else :
128
+ if verbose :
129
+ print (
130
+ f"waiting for target balance { debug_prefix } : { target_balance } , current balance is { balance } , attempt { attempts } " )
126
131
time .sleep (1 )
127
132
128
133
129
134
def wait_for_sifchain_balance (user , denom , network_password , target_balance , max_attempts = 30 ):
130
135
wait_for_balance (lambda : int (get_sifchain_balance (user , denom , network_password )), target_balance , max_attempts )
131
136
132
137
133
- def wait_for_sifchain_addr_balance (sif_addr , denom , target_balance , max_attempts = 30 ):
134
- wait_for_balance (lambda : int (get_sifchain_addr_balance (sif_addr , denom )), target_balance , max_attempts )
138
+ def wait_for_sifchain_addr_balance (sif_addr , denom , target_balance , max_attempts = 30 , debug_prefix = "" ):
139
+ if not max_attempts : max_attempts = 30
140
+ wait_for_balance (lambda : int (get_sifchain_addr_balance (sif_addr , denom )), target_balance , max_attempts ,
141
+ debug_prefix )
142
+
143
+
144
+ def sif_tx_send (from_address , to_address , amount , currency , network_password ):
145
+ cmd = f"yes { network_password } | sifnodecli tx send { from_address } { to_address } { amount } { currency } -y"
146
+ return get_shell_output (cmd )
135
147
136
148
137
149
def burn_peggy_coin (user , eth_user , amount ):
@@ -143,6 +155,60 @@ def burn_peggy_coin(user, eth_user, amount):
143
155
return get_shell_output (command_line )
144
156
145
157
158
+ # Send eth from ETHEREUM_PRIVATE_KEY to BridgeBank, lock the eth on bridgebank, ceth should end up in sifchain_user
159
+ def send_eth_lock (sifchain_user , symbol , amount ):
160
+ return send_ethereum_currency_to_sifchain_addr (get_user_account (sifchain_user , network_password ), symbol , amount )
161
+
162
+
163
+ def send_ethereum_currency_to_sifchain_addr (sif_addr , symbol , amount ):
164
+ command_line = f"{ cd_smart_contracts_dir } yarn peggy:lock { sif_addr } { symbol } { amount } "
165
+ return get_shell_output (command_line )
166
+
167
+
168
+ currency_pairs = {
169
+ "eth" : "ceth" ,
170
+ "ceth" : "eth" ,
171
+ "rowan" : "erowan" ,
172
+ "erowan" : "rowan"
173
+ }
174
+
175
+
176
+ def mirror_of (currency ):
177
+ return currency_pairs .get (currency )
178
+
179
+
180
+ def wait_for_sif_account (sif_addr , max_attempts = 30 ):
181
+ command = f"sifnodecli q account { sif_addr } "
182
+ attempts = 0
183
+ while True :
184
+ try :
185
+ result = get_shell_output (command )
186
+ print (f"account { sif_addr } is now created" )
187
+ return result
188
+ except :
189
+ attempts += 1
190
+ if attempts > max_attempts :
191
+ raise Exception (f"too many attempts to get sif account { sif_addr } " )
192
+ time .sleep (1 )
193
+
194
+
195
+ def transact_ethereum_currency_to_sifchain_addr (sif_addr , ethereum_symbol , amount ):
196
+ sifchain_symbol = mirror_of (ethereum_symbol )
197
+ try :
198
+ starting_balance = get_sifchain_addr_balance (sif_addr , sifchain_symbol )
199
+ except :
200
+ # Sometimes we're creating an account by sending it currency for the
201
+ # first time, so you can't get a balance.
202
+ print ("exception is OK, we are creating the account now" )
203
+ starting_balance = 0
204
+ print (f"starting balance for { sif_addr } is { starting_balance } " )
205
+ send_ethereum_currency_to_sifchain_addr (sif_addr , ethereum_symbol , amount )
206
+ advance_n_ethereum_blocks (n_wait_blocks )
207
+ wait_for_sif_account (sif_addr )
208
+ wait_for_sifchain_addr_balance (sif_addr , sifchain_symbol , starting_balance + amount , 6 ,
209
+ f"{ sif_addr } / c{ sifchain_symbol } / { amount } " )
210
+
211
+
146
212
def advance_n_ethereum_blocks (n = 50 ):
147
213
return run_yarn_command (f"{ cd_smart_contracts_dir } yarn advance { n } " )
148
214
0 commit comments