17
17
from eth .vm .transaction_context import (
18
18
BaseTransactionContext ,
19
19
)
20
- from tests .core .vm .conftest import CANONICAL_ADDRESS_A , CANONICAL_ADDRESS_B , NORMALIZED_ADDRESS_A
21
20
22
21
23
22
class DummyComputation (BaseComputation ):
@@ -36,10 +35,10 @@ def get_intrinsic_gas(self):
36
35
37
36
38
37
@pytest .fixture
39
- def message ():
38
+ def message (canonical_address_a , canonical_address_b ):
40
39
message = Message (
41
- to = CANONICAL_ADDRESS_A ,
42
- sender = CANONICAL_ADDRESS_B ,
40
+ to = canonical_address_a ,
41
+ sender = canonical_address_b ,
43
42
value = 100 ,
44
43
data = b'' ,
45
44
code = b'' ,
@@ -59,23 +58,23 @@ def computation(message, transaction_context):
59
58
60
59
61
60
@pytest .fixture
62
- def child_message (computation ):
61
+ def child_message (computation , canonical_address_b ):
63
62
child_message = computation .prepare_child_message (
64
63
gas = 100 ,
65
- to = CANONICAL_ADDRESS_B ,
64
+ to = canonical_address_b ,
66
65
value = 200 ,
67
66
data = b'' ,
68
67
code = b''
69
68
)
70
69
return child_message
71
70
72
71
73
- def test_is_origin_computation (computation , transaction_context ):
72
+ def test_is_origin_computation (computation , transaction_context , canonical_address_a ):
74
73
assert computation .is_origin_computation
75
74
message2 = Message (
76
- to = CANONICAL_ADDRESS_A ,
75
+ to = canonical_address_a ,
77
76
# Different sender than the tx context origin
78
- sender = CANONICAL_ADDRESS_A ,
77
+ sender = canonical_address_a ,
79
78
value = 100 ,
80
79
data = b'' ,
81
80
code = b'' ,
@@ -132,87 +131,91 @@ def test_extend_memory_doesnt_increase_until_32_bytes_are_used(computation):
132
131
assert computation ._gas_meter .gas_remaining == 94
133
132
134
133
135
- def test_register_accounts_for_deletion_raises_if_address_isnt_canonical (computation ):
134
+ def test_register_accounts_for_deletion_raises_if_address_isnt_canonical (
135
+ computation , normalized_address_a
136
+ ):
136
137
with pytest .raises (ValidationError ):
137
- computation .register_account_for_deletion (NORMALIZED_ADDRESS_A )
138
+ computation .register_account_for_deletion (normalized_address_a )
138
139
139
140
140
- def test_register_accounts_for_deletion_cannot_register_the_same_address_twice (computation ):
141
- computation .register_account_for_deletion (CANONICAL_ADDRESS_A )
141
+ def test_register_accounts_for_deletion_cannot_register_the_same_address_twice (
142
+ computation , canonical_address_a
143
+ ):
144
+ computation .register_account_for_deletion (canonical_address_a )
142
145
with pytest .raises (ValueError ):
143
- computation .register_account_for_deletion (CANONICAL_ADDRESS_A )
146
+ computation .register_account_for_deletion (canonical_address_a )
144
147
145
148
146
- def test_register_accounts_for_deletion (computation ):
147
- computation .register_account_for_deletion (CANONICAL_ADDRESS_A )
148
- assert computation .accounts_to_delete [computation .msg .storage_address ] == CANONICAL_ADDRESS_A
149
+ def test_register_accounts_for_deletion (computation , canonical_address_a , canonical_address_b ):
150
+ computation .register_account_for_deletion (canonical_address_a )
151
+ assert computation .accounts_to_delete [computation .msg .storage_address ] == canonical_address_a
149
152
# Another account can be registered for deletion
150
- computation .msg .storage_address = CANONICAL_ADDRESS_B
151
- computation .register_account_for_deletion (CANONICAL_ADDRESS_A )
153
+ computation .msg .storage_address = canonical_address_b
154
+ computation .register_account_for_deletion (canonical_address_a )
152
155
153
156
154
157
def test_get_accounts_for_deletion_starts_empty (computation ):
155
158
assert computation .get_accounts_for_deletion () == ()
156
159
157
160
158
- def test_get_accounts_for_deletion_returns (computation ):
159
- computation .register_account_for_deletion (CANONICAL_ADDRESS_A )
161
+ def test_get_accounts_for_deletion_returns (computation , canonical_address_a , canonical_address_b ):
162
+ computation .register_account_for_deletion (canonical_address_a )
160
163
# Get accounts for deletion returns the correct account
161
- assert computation .get_accounts_for_deletion () == ((CANONICAL_ADDRESS_A , CANONICAL_ADDRESS_A ),)
164
+ assert computation .get_accounts_for_deletion () == ((canonical_address_a , canonical_address_a ),)
162
165
# Get accounts for deletion can return multiple accounts
163
- computation .msg .storage_address = CANONICAL_ADDRESS_B
164
- computation .register_account_for_deletion (CANONICAL_ADDRESS_B )
166
+ computation .msg .storage_address = canonical_address_b
167
+ computation .register_account_for_deletion (canonical_address_b )
165
168
accounts_for_deletion = sorted (computation .get_accounts_for_deletion (),
166
169
key = lambda item : item [0 ])
167
- assert CANONICAL_ADDRESS_A == accounts_for_deletion [0 ][0 ]
168
- assert CANONICAL_ADDRESS_B == accounts_for_deletion [1 ][0 ]
170
+ assert canonical_address_a == accounts_for_deletion [0 ][0 ]
171
+ assert canonical_address_b == accounts_for_deletion [1 ][0 ]
169
172
170
173
171
174
def test_add_log_entry_starts_empty (computation ):
172
175
assert computation .get_log_entries () == ()
173
176
174
177
175
- def test_add_log_entry_raises_if_address_isnt_canonical (computation ):
178
+ def test_add_log_entry_raises_if_address_isnt_canonical (computation , normalized_address_a ):
176
179
with pytest .raises (ValidationError ):
177
- computation .add_log_entry (NORMALIZED_ADDRESS_A , [1 , 2 , 3 ], b'' )
180
+ computation .add_log_entry (normalized_address_a , [1 , 2 , 3 ], b'' )
178
181
179
182
180
- def test_add_log_entry_raises_if_topic_elements_arent_uint256 (computation ):
183
+ def test_add_log_entry_raises_if_topic_elements_arent_uint256 (computation , canonical_address_a ):
181
184
with pytest .raises (ValidationError ):
182
- computation .add_log_entry (CANONICAL_ADDRESS_A , [- 1 , 2 , 3 ], b'' )
185
+ computation .add_log_entry (canonical_address_a , [- 1 , 2 , 3 ], b'' )
183
186
with pytest .raises (ValidationError ):
184
- computation .add_log_entry (CANONICAL_ADDRESS_A , ['1' , 2 , 3 ], b'' )
187
+ computation .add_log_entry (canonical_address_a , ['1' , 2 , 3 ], b'' )
185
188
186
189
187
- def test_add_log_entry_raises_if_data_isnt_in_bytes (computation ):
190
+ def test_add_log_entry_raises_if_data_isnt_in_bytes (computation , canonical_address_a ):
188
191
with pytest .raises (ValidationError ):
189
- computation .add_log_entry (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], 1 )
192
+ computation .add_log_entry (canonical_address_a , [1 , 2 , 3 ], 1 )
190
193
with pytest .raises (ValidationError ):
191
- computation .add_log_entry (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], '' )
194
+ computation .add_log_entry (canonical_address_a , [1 , 2 , 3 ], '' )
192
195
193
196
194
- def test_add_log_entry (computation ):
197
+ def test_add_log_entry (computation , canonical_address_a ):
195
198
# Adds log entry to log entries
196
- computation .add_log_entry (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], b'' )
199
+ computation .add_log_entry (canonical_address_a , [1 , 2 , 3 ], b'' )
197
200
assert computation .get_log_entries () == tuple (
198
201
[(b'\x0f W.R\x95 \xc5 \x7f \x15 \x88 o\x9b &>/m-l\x7b ^\xc6 ' , [1 , 2 , 3 ], b'' )])
199
202
# Can add multiple entries
200
- computation .add_log_entry (CANONICAL_ADDRESS_A , [4 , 5 , 6 ], b'2' )
201
- computation .add_log_entry (CANONICAL_ADDRESS_A , [7 , 8 , 9 ], b'3' )
203
+ computation .add_log_entry (canonical_address_a , [4 , 5 , 6 ], b'2' )
204
+ computation .add_log_entry (canonical_address_a , [7 , 8 , 9 ], b'3' )
202
205
203
206
assert len (computation .get_log_entries ()) == 3
204
207
205
208
206
- def test_get_log_entries (computation ):
207
- computation .add_log_entry (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], b'' )
209
+ def test_get_log_entries (computation , canonical_address_a ):
210
+ computation .add_log_entry (canonical_address_a , [1 , 2 , 3 ], b'' )
208
211
assert computation .get_log_entries () == (
209
212
(b'\x0f W.R\x95 \xc5 \x7f \x15 \x88 o\x9b &>/m-l\x7b ^\xc6 ' , [1 , 2 , 3 ], b'' ),)
210
213
211
214
212
- def test_get_log_entries_order_with_children (computation , child_message ):
213
- parent_log = (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], b'' )
214
- parent_log2 = (CANONICAL_ADDRESS_A , [4 , 5 , 6 ], b'2' )
215
- child_log = (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], b'child' )
215
+ def test_get_log_entries_order_with_children (computation , child_message , canonical_address_a ):
216
+ parent_log = (canonical_address_a , [1 , 2 , 3 ], b'' )
217
+ parent_log2 = (canonical_address_a , [4 , 5 , 6 ], b'2' )
218
+ child_log = (canonical_address_a , [1 , 2 , 3 ], b'child' )
216
219
computation .add_log_entry (* parent_log )
217
220
child_computation = computation .apply_child_computation (child_message )
218
221
# Pretend the child computation logged something.
@@ -228,18 +231,18 @@ def test_get_log_entries_order_with_children(computation, child_message):
228
231
assert logs [2 ] == parent_log2
229
232
230
233
231
- def test_get_log_entries_with_vmerror (computation ):
234
+ def test_get_log_entries_with_vmerror (computation , canonical_address_a ):
232
235
# Trigger an out of gas error causing get log entries to be ()
233
- computation .add_log_entry (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], b'' )
236
+ computation .add_log_entry (canonical_address_a , [1 , 2 , 3 ], b'' )
234
237
with computation :
235
238
raise VMError ('Triggered VMError for tests' )
236
239
assert computation .is_error
237
240
assert computation .get_log_entries () == ()
238
241
239
242
240
- def test_get_log_entries_with_revert (computation ):
243
+ def test_get_log_entries_with_revert (computation , canonical_address_a ):
241
244
# Trigger an out of gas error causing get log entries to be ()
242
- computation .add_log_entry (CANONICAL_ADDRESS_A , [1 , 2 , 3 ], b'' )
245
+ computation .add_log_entry (canonical_address_a , [1 , 2 , 3 ], b'' )
243
246
with computation :
244
247
raise Revert ('Triggered VMError for tests' )
245
248
assert computation .is_error
0 commit comments