12
12
13
13
14
14
# Test EVM contracts
15
- serpent_code = '''
15
+ serpent_code = """
16
16
def main(a,b):
17
17
return(a ^ b)
18
- '''
18
+ """
19
19
20
20
21
21
def test_evm ():
@@ -31,8 +31,7 @@ def test_evm():
31
31
32
32
# Test serpent compilation of variables using _with_, doing a simple
33
33
# arithmetic calculation 20 * 30 + 10 = 610
34
- sixten_code = \
35
- '''
34
+ sixten_code = """
36
35
(with 'x 10
37
36
(with 'y 20
38
37
(with 'z 30
@@ -43,7 +42,7 @@ def test_evm():
43
42
)
44
43
)
45
44
)
46
- '''
45
+ """
47
46
48
47
49
48
def test_sixten ():
@@ -54,8 +53,7 @@ def test_sixten():
54
53
assert utils .big_endian_to_int (o1 ) == 610
55
54
56
55
57
- with_code = \
58
- """
56
+ with_code = """
59
57
def f1():
60
58
o = array(4)
61
59
with x = 5:
@@ -103,23 +101,21 @@ def test_with():
103
101
104
102
# Test Serpent's import mechanism
105
103
106
- mul2_code = \
107
- '''
104
+ mul2_code = """
108
105
def double(v):
109
106
log(v)
110
107
return(v*2)
111
- '''
108
+ """
112
109
113
110
filename = "mul2_qwertyuioplkjhgfdsa.se"
114
111
115
- returnten_code = \
116
- '''
112
+ returnten_code = """
117
113
extern mul2: [double:i]
118
114
119
115
x = create("%s")
120
116
log(x)
121
117
return(x.double(5))
122
- ''' % filename
118
+ """ % filename
123
119
124
120
125
121
def test_returnten ():
@@ -133,25 +129,23 @@ def test_returnten():
133
129
134
130
# Test inset
135
131
136
- inset_inner_code = \
137
- '''
132
+ inset_inner_code = """
138
133
def g(n):
139
134
return(n + 10)
140
135
141
136
def f(n):
142
137
return n*2
143
- '''
138
+ """
144
139
145
140
filename2 = "inner_qwertyuioplkjhgfdsa.se"
146
141
147
- inset_outer_code = \
148
- '''
142
+ inset_outer_code = """
149
143
inset("%s")
150
144
151
145
def foo():
152
146
res = self.g(12)
153
147
return res
154
- ''' % filename2
148
+ """ % filename2
155
149
156
150
157
151
def test_inset ():
@@ -163,26 +157,23 @@ def test_inset():
163
157
164
158
# Inset at the end instead
165
159
166
- inset_inner_code2 = \
167
- '''
160
+ inset_inner_code2 = """
168
161
def g(n):
169
162
return(n + 10)
170
163
171
164
def f(n):
172
165
return n*2
173
- '''
166
+ """
174
167
175
168
filename25 = "inner_qwertyuioplkjhgfdsa.se"
176
169
177
- inset_outer_code2 = \
178
- '''
179
-
170
+ inset_outer_code2 = """
180
171
def foo():
181
172
res = self.g(12)
182
173
return res
183
174
184
175
inset("%s")
185
- ''' % filename25
176
+ """ % filename25
186
177
187
178
188
179
def test_inset2 ():
@@ -195,15 +186,14 @@ def test_inset2():
195
186
196
187
# Test a simple namecoin implementation
197
188
198
- namecoin_code = \
199
- '''
189
+ namecoin_code = """
200
190
def main(k, v):
201
191
if !self.storage[k]:
202
192
self.storage[k] = v
203
193
return(1)
204
194
else:
205
195
return(0)
206
- '''
196
+ """
207
197
208
198
209
199
def test_namecoin ():
@@ -220,7 +210,7 @@ def test_namecoin():
220
210
221
211
# Test a simple currency implementation
222
212
223
- currency_code = '''
213
+ currency_code = """
224
214
data balances[2^160]
225
215
226
216
def init():
@@ -239,7 +229,7 @@ def send(to, value):
239
229
return(1)
240
230
else:
241
231
return(0)
242
- '''
232
+ """
243
233
244
234
245
235
def test_currency ():
@@ -256,7 +246,7 @@ def test_currency():
256
246
257
247
# Test a data feed
258
248
259
- data_feed_code = '''
249
+ data_feed_code = """
260
250
data creator
261
251
data values[]
262
252
@@ -273,7 +263,7 @@ def set(k, v):
273
263
274
264
def get(k):
275
265
return(self.values[k])
276
- '''
266
+ """
277
267
278
268
279
269
def test_data_feeds ():
@@ -294,7 +284,7 @@ def test_data_feeds():
294
284
# Test an example hedging contract, using the data feed. This tests
295
285
# contracts calling other contracts
296
286
297
- hedge_code = '''
287
+ hedge_code = """
298
288
extern datafeed: [set:ii, get:i]
299
289
300
290
data partyone
@@ -333,7 +323,7 @@ def main(datafeed, index):
333
323
return(4)
334
324
else:
335
325
return(5)
336
- '''
326
+ """
337
327
338
328
339
329
def test_hedge ():
@@ -370,7 +360,7 @@ def test_hedge():
370
360
371
361
372
362
# Test the LIFO nature of call
373
- arither_code = '''
363
+ arither_code = """
374
364
def init():
375
365
self.storage[0] = 10
376
366
@@ -384,7 +374,7 @@ def f2():
384
374
385
375
def f3():
386
376
return(self.storage[0])
387
- '''
377
+ """
388
378
389
379
390
380
def test_lifo ():
@@ -395,7 +385,7 @@ def test_lifo():
395
385
396
386
397
387
# Test suicides and suicide reverts
398
- suicider_code = '''
388
+ suicider_code = """
399
389
def mainloop(rounds):
400
390
self.storage[15] = 40
401
391
self.suicide()
@@ -416,7 +406,7 @@ def suicide():
416
406
417
407
def ping_storage15():
418
408
return(self.storage[15])
419
- '''
409
+ """
420
410
421
411
422
412
def test_suicider ():
@@ -442,7 +432,7 @@ def test_suicider():
442
432
443
433
# Test reverts
444
434
445
- reverter_code = '''
435
+ reverter_code = """
446
436
def entry():
447
437
self.non_recurse(gas=100000)
448
438
self.recurse(gas=100000)
@@ -459,7 +449,7 @@ def recurse():
459
449
self.recurse()
460
450
while msg.gas > 0:
461
451
self.storage["waste_some_gas"] = 0
462
- '''
452
+ """
463
453
464
454
465
455
def test_reverter ():
@@ -473,16 +463,14 @@ def test_reverter():
473
463
474
464
# Test stateless contracts
475
465
476
- add1_code = \
477
- '''
466
+ add1_code = """
478
467
def main(x):
479
468
self.storage[1] += x
480
- '''
469
+ """
481
470
482
471
filename3 = "stateless_qwertyuioplkjhgfdsa.se"
483
472
484
- callcode_test_code = \
485
- '''
473
+ callcode_test_code = """
486
474
extern add1: [main:i]
487
475
488
476
x = create("%s")
@@ -491,7 +479,7 @@ def main(x):
491
479
x.main(60, call=code)
492
480
x.main(40)
493
481
return(self.storage[1])
494
- ''' % filename3
482
+ """ % filename3
495
483
496
484
497
485
def test_callcode ():
@@ -505,26 +493,26 @@ def test_callcode():
505
493
506
494
507
495
# https://github.com/ethereum/serpent/issues/8
508
- array_code = '''
496
+ array_code = """
509
497
def main():
510
498
a = array(1)
511
499
a[0] = 1
512
500
return(a, items=1)
513
- '''
501
+ """
514
502
515
503
516
504
def test_array ():
517
505
c = tester .Chain ()
518
506
x = c .contract (array_code , language = 'serpent' )
519
507
assert x .main () == [1 ]
520
508
521
- array_code2 = '''
509
+ array_code2 = """
522
510
def main():
523
511
a = array(1)
524
512
something = 2
525
513
a[0] = 1
526
514
return(a, items=1)
527
- '''
515
+ """
528
516
529
517
530
518
def test_array2 ():
@@ -1057,8 +1045,7 @@ def test_sort():
1057
1045
1058
1046
filename9 = "mul2_qwertyuioplkjhgfdsabarbar.se"
1059
1047
1060
- sort_tester_code = \
1061
- '''
1048
+ sort_tester_code = """
1062
1049
extern sorter: [sort:a]
1063
1050
data sorter
1064
1051
@@ -1067,7 +1054,7 @@ def init():
1067
1054
1068
1055
def test(args:arr):
1069
1056
return(self.sorter.sort(args, outsz=len(args)):arr)
1070
- ''' % filename9
1057
+ """ % filename9
1071
1058
1072
1059
1073
1060
@pytest .mark .timeout (100 )
0 commit comments