contracts: Fix some minor bugs around instantiation (#8879)

* Fix output of wrongly outputted error

The "Tombstoned a contract that is below the subsistence threshold: {:?}" was
triggered when too few balance was provided. It was a false alarm.

* Fix return of wrong code_len

* Split up `NotCallable` into more fine grained errors

* Fix typos in docs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* RentNotPayed -> RentNotPaid

* Fix typo: payed -> paid

It is OK to change the in-storage field name because:

1. The SCALE encoding is not based on names only on position.
2. The struct is not public (only to the crate).

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Alexander Theißen
2021-05-26 00:29:55 +02:00
committed by GitHub
parent a28a517c53
commit c92d4a2638
8 changed files with 67 additions and 40 deletions
+11 -11
View File
@@ -366,7 +366,7 @@ fn calling_plain_account_fails() {
Contracts::call(Origin::signed(ALICE), BOB, 0, GAS_LIMIT, Vec::new()),
Err(
DispatchErrorWithPostInfo {
error: Error::<Test>::NotCallable.into(),
error: Error::<Test>::ContractNotFound.into(),
post_info: PostDispatchInfo {
actual_weight: Some(base_cost),
pays_fee: Default::default(),
@@ -396,7 +396,7 @@ fn account_removal_does_not_remove_storage() {
deduct_block: System::block_number(),
code_hash: H256::repeat_byte(1),
rent_allowance: 40,
rent_payed: 0,
rent_paid: 0,
last_write: None,
_reserved: None,
});
@@ -412,7 +412,7 @@ fn account_removal_does_not_remove_storage() {
deduct_block: System::block_number(),
code_hash: H256::repeat_byte(2),
rent_allowance: 40,
rent_payed: 0,
rent_paid: 0,
last_write: None,
_reserved: None,
});
@@ -1088,7 +1088,7 @@ fn call_removed_contract() {
// Calling contract should deny access because rent cannot be paid.
assert_err_ignore_postinfo!(
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, call::null()),
Error::<Test>::NotCallable
Error::<Test>::RentNotPaid,
);
// No event is generated because the contract is not actually removed.
assert_eq!(System::events(), vec![]);
@@ -1096,7 +1096,7 @@ fn call_removed_contract() {
// Subsequent contract calls should also fail.
assert_err_ignore_postinfo!(
Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, call::null()),
Error::<Test>::NotCallable
Error::<Test>::RentNotPaid,
);
// A snitch can now remove the contract
@@ -1321,7 +1321,7 @@ fn restoration(
Contracts::call(
Origin::signed(ALICE), addr_bob.clone(), 0, GAS_LIMIT, call::null()
),
Error::<Test>::NotCallable
Error::<Test>::RentNotPaid,
);
assert!(System::events().is_empty());
assert!(ContractInfoOf::<Test>::get(&addr_bob).unwrap().get_alive().is_some());
@@ -2669,11 +2669,11 @@ fn surcharge_reward_is_capped() {
let balance = Balances::free_balance(&ALICE);
let reward = <Test as Config>::SurchargeReward::get();
// some rent should have payed due to instantiation
assert_ne!(contract.rent_payed, 0);
// some rent should have paid due to instantiation
assert_ne!(contract.rent_paid, 0);
// the reward should be parameterized sufficiently high to make this test useful
assert!(reward > contract.rent_payed);
assert!(reward > contract.rent_paid);
// make contract eligible for eviction
initialize_block(40);
@@ -2682,13 +2682,13 @@ fn surcharge_reward_is_capped() {
assert_ok!(Contracts::claim_surcharge(Origin::none(), addr.clone(), Some(ALICE)));
// this reward does not take into account the last rent payment collected during eviction
let capped_reward = reward.min(contract.rent_payed);
let capped_reward = reward.min(contract.rent_paid);
// this is smaller than the actual reward because it does not take into account the
// rent collected during eviction
assert!(Balances::free_balance(&ALICE) > balance + capped_reward);
// the full reward is not payed out because of the cap introduced by rent_payed
// the full reward is not paid out because of the cap introduced by rent_paid
assert!(Balances::free_balance(&ALICE) < balance + reward);
});
}