@@ -157,13 +157,6 @@ impl ExtBuilder {
157
157
}
158
158
}
159
159
160
- fn new_test_ext ( existential_deposit : u64 , gas_price : u64 ) -> runtime_io:: TestExternalities {
161
- ExtBuilder :: default ( )
162
- . existential_deposit ( existential_deposit)
163
- . gas_price ( gas_price)
164
- . build ( )
165
- }
166
-
167
160
const CODE_TRANSFER : & str = r#"
168
161
(module
169
162
;; ext_transfer(transfer_to: u32, transfer_to_len: u32, value_ptr: u32, value_len: u32)
@@ -193,7 +186,7 @@ fn contract_transfer() {
193
186
194
187
let code_transfer = wabt:: wat2wasm ( CODE_TRANSFER ) . unwrap ( ) ;
195
188
196
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
189
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
197
190
<CodeOf < Test > >:: insert ( 1 , code_transfer. to_vec ( ) ) ;
198
191
199
192
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
@@ -226,7 +219,7 @@ fn contract_transfer_oog() {
226
219
227
220
let code_transfer = wabt:: wat2wasm ( CODE_TRANSFER ) . unwrap ( ) ;
228
221
229
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
222
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
230
223
<CodeOf < Test > >:: insert ( 1 , code_transfer. to_vec ( ) ) ;
231
224
232
225
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
@@ -256,7 +249,7 @@ fn contract_transfer_max_depth() {
256
249
257
250
let code_transfer = wabt:: wat2wasm ( CODE_TRANSFER ) . unwrap ( ) ;
258
251
259
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
252
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
260
253
<CodeOf < Test > >:: insert ( CONTRACT_SHOULD_TRANSFER_TO , code_transfer. to_vec ( ) ) ;
261
254
262
255
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
@@ -354,7 +347,7 @@ fn contract_create() {
354
347
let code_ctor_transfer = wabt:: wat2wasm ( & code_ctor ( & code_transfer) ) . unwrap ( ) ;
355
348
let code_create = wabt:: wat2wasm ( & code_create ( & code_ctor_transfer) ) . unwrap ( ) ;
356
349
357
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
350
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
358
351
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
359
352
Staking :: set_free_balance ( & 1 , 0 ) ;
360
353
Staking :: set_free_balance ( & 9 , 30 ) ;
@@ -401,7 +394,7 @@ fn top_level_create() {
401
394
let code_transfer = wabt:: wat2wasm ( CODE_TRANSFER ) . unwrap ( ) ;
402
395
let code_ctor_transfer = wabt:: wat2wasm ( & code_ctor ( & code_transfer) ) . unwrap ( ) ;
403
396
404
- with_externalities ( & mut new_test_ext ( 0 , 3 ) , || {
397
+ with_externalities ( & mut ExtBuilder :: default ( ) . gas_price ( 3 ) . build ( ) , || {
405
398
let derived_address = <Test as Trait >:: DetermineContractAddress :: contract_address_for (
406
399
& code_ctor_transfer,
407
400
& 0 ,
@@ -444,7 +437,7 @@ const CODE_NOP: &'static str = r#"
444
437
fn refunds_unused_gas ( ) {
445
438
let code_nop = wabt:: wat2wasm ( CODE_NOP ) . unwrap ( ) ;
446
439
447
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
440
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
448
441
<CodeOf < Test > >:: insert ( 1 , code_nop. to_vec ( ) ) ;
449
442
450
443
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
@@ -457,7 +450,7 @@ fn refunds_unused_gas() {
457
450
458
451
#[ test]
459
452
fn call_with_zero_value ( ) {
460
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
453
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
461
454
<CodeOf < Test > >:: insert ( 1 , vec ! [ ] ) ;
462
455
463
456
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
@@ -472,7 +465,7 @@ fn call_with_zero_value() {
472
465
fn create_with_zero_endowment ( ) {
473
466
let code_nop = wabt:: wat2wasm ( CODE_NOP ) . unwrap ( ) ;
474
467
475
- with_externalities ( & mut new_test_ext ( 0 , 2 ) , || {
468
+ with_externalities ( & mut ExtBuilder :: default ( ) . build ( ) , || {
476
469
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
477
470
478
471
assert_ok ! ( Contract :: create( & 0 , 0 , 100_000 , code_nop, Vec :: new( ) ) ) ;
@@ -488,40 +481,43 @@ fn create_with_zero_endowment() {
488
481
489
482
#[ test]
490
483
fn account_removal_removes_storage ( ) {
491
- with_externalities ( & mut new_test_ext ( 100 , 2 ) , || {
492
- // Setup two accounts with free balance above than exsistential threshold.
493
- {
494
- Staking :: set_free_balance ( & 1 , 110 ) ;
495
- <StorageOf < Test > >:: insert ( 1 , b"foo" . to_vec ( ) , b"1" . to_vec ( ) ) ;
496
- <StorageOf < Test > >:: insert ( 1 , b"bar" . to_vec ( ) , b"2" . to_vec ( ) ) ;
497
-
498
- Staking :: set_free_balance ( & 2 , 110 ) ;
499
- <StorageOf < Test > >:: insert ( 2 , b"hello" . to_vec ( ) , b"3" . to_vec ( ) ) ;
500
- <StorageOf < Test > >:: insert ( 2 , b"world" . to_vec ( ) , b"4" . to_vec ( ) ) ;
501
- }
502
-
503
- // Transfer funds from account 1 of such amount that after this transfer
504
- // the balance of account 1 is will be below than exsistential threshold.
505
- //
506
- // This should lead to the removal of all storage associated with this account.
507
- assert_ok ! ( Staking :: transfer( & 1 , 2 . into( ) , 20 ) ) ;
508
-
509
- // Verify that all entries from account 1 is removed, while
510
- // entries from account 2 is in place.
511
- {
512
- assert_eq ! ( <StorageOf <Test >>:: get( 1 , b"foo" . to_vec( ) ) , None ) ;
513
- assert_eq ! ( <StorageOf <Test >>:: get( 1 , b"bar" . to_vec( ) ) , None ) ;
514
-
515
- assert_eq ! (
516
- <StorageOf <Test >>:: get( 2 , b"hello" . to_vec( ) ) ,
517
- Some ( b"3" . to_vec( ) )
518
- ) ;
519
- assert_eq ! (
520
- <StorageOf <Test >>:: get( 2 , b"world" . to_vec( ) ) ,
521
- Some ( b"4" . to_vec( ) )
522
- ) ;
523
- }
524
- } ) ;
484
+ with_externalities (
485
+ & mut ExtBuilder :: default ( ) . existential_deposit ( 100 ) . build ( ) ,
486
+ || {
487
+ // Setup two accounts with free balance above than exsistential threshold.
488
+ {
489
+ Staking :: set_free_balance ( & 1 , 110 ) ;
490
+ <StorageOf < Test > >:: insert ( 1 , b"foo" . to_vec ( ) , b"1" . to_vec ( ) ) ;
491
+ <StorageOf < Test > >:: insert ( 1 , b"bar" . to_vec ( ) , b"2" . to_vec ( ) ) ;
492
+
493
+ Staking :: set_free_balance ( & 2 , 110 ) ;
494
+ <StorageOf < Test > >:: insert ( 2 , b"hello" . to_vec ( ) , b"3" . to_vec ( ) ) ;
495
+ <StorageOf < Test > >:: insert ( 2 , b"world" . to_vec ( ) , b"4" . to_vec ( ) ) ;
496
+ }
497
+
498
+ // Transfer funds from account 1 of such amount that after this transfer
499
+ // the balance of account 1 is will be below than exsistential threshold.
500
+ //
501
+ // This should lead to the removal of all storage associated with this account.
502
+ assert_ok ! ( Staking :: transfer( & 1 , 2 . into( ) , 20 ) ) ;
503
+
504
+ // Verify that all entries from account 1 is removed, while
505
+ // entries from account 2 is in place.
506
+ {
507
+ assert_eq ! ( <StorageOf <Test >>:: get( 1 , b"foo" . to_vec( ) ) , None ) ;
508
+ assert_eq ! ( <StorageOf <Test >>:: get( 1 , b"bar" . to_vec( ) ) , None ) ;
509
+
510
+ assert_eq ! (
511
+ <StorageOf <Test >>:: get( 2 , b"hello" . to_vec( ) ) ,
512
+ Some ( b"3" . to_vec( ) )
513
+ ) ;
514
+ assert_eq ! (
515
+ <StorageOf <Test >>:: get( 2 , b"world" . to_vec( ) ) ,
516
+ Some ( b"4" . to_vec( ) )
517
+ ) ;
518
+ }
519
+ } ,
520
+ ) ;
525
521
}
526
522
527
523
const CODE_UNREACHABLE : & ' static str = r#"
@@ -536,7 +532,7 @@ const CODE_UNREACHABLE: &'static str = r#"
536
532
#[ test]
537
533
fn top_level_call_refunds_even_if_fails ( ) {
538
534
let code_unreachable = wabt:: wat2wasm ( CODE_UNREACHABLE ) . unwrap ( ) ;
539
- with_externalities ( & mut new_test_ext ( 0 , 4 ) , || {
535
+ with_externalities ( & mut ExtBuilder :: default ( ) . gas_price ( 4 ) . build ( ) , || {
540
536
<CodeOf < Test > >:: insert ( 1 , code_unreachable. to_vec ( ) ) ;
541
537
542
538
Staking :: set_free_balance ( & 0 , 100_000_000 ) ;
0 commit comments