actually update deduct_block when paying rent (#2490)

* actually update deduct_block when paying rent

* add test

* remove println

* same block call test

* bump version
This commit is contained in:
thiolliere
2019-05-07 14:13:56 +02:00
committed by GitHub
parent 1436e6d734
commit d380db706b
3 changed files with 33 additions and 5 deletions
+24
View File
@@ -718,7 +718,31 @@ fn deduct_blocks() {
* 4; // blocks to rent
let bob_contract = super::ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap();
assert_eq!(bob_contract.rent_allowance, 1_000 - rent);
assert_eq!(bob_contract.deduct_block, 5);
assert_eq!(Balances::free_balance(BOB), 30_000 - rent);
// Advance 7 blocks more
System::initialize(&12, &[0u8; 32].into(), &[0u8; 32].into());
// Trigger rent through call
assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null()));
// Check result
let rent_2 = (8 + 4 - 2) // storage size = size_offset + deploy_set_storage - deposit_offset
* 4 // rent byte price
* 7; // blocks to rent
let bob_contract = super::ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap();
assert_eq!(bob_contract.rent_allowance, 1_000 - rent - rent_2);
assert_eq!(bob_contract.deduct_block, 12);
assert_eq!(Balances::free_balance(BOB), 30_000 - rent - rent_2);
// Second call on same block should have no effect on rent
assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null()));
let bob_contract = super::ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap();
assert_eq!(bob_contract.rent_allowance, 1_000 - rent - rent_2);
assert_eq!(bob_contract.deduct_block, 12);
assert_eq!(Balances::free_balance(BOB), 30_000 - rent - rent_2);
}
);
}