mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 03:31:10 +00:00
srml-contract: Contract refactors (#2924)
* srml-contract: Refactor away unnecessary Option. * srml-contract: Add assertion to gas_left test. * srml-contract: Refactor try_evict_or_and_pay_rent to make tests pass. * srml-contract: Add tests and comments for bugs in rent payment logic. * srml-contract: Minor cleanup using GasMeter constructor. * Bump node runtime impl version.
This commit is contained in:
committed by
Sergei Pepyakin
parent
62b7c05def
commit
068d99d481
@@ -742,7 +742,7 @@ mod call {
|
||||
pub fn null() -> Vec<u8> { vec![0, 0, 0] }
|
||||
}
|
||||
|
||||
/// Test correspondance of set_rent code and its hash.
|
||||
/// Test correspondence of set_rent code and its hash.
|
||||
/// Also test that encoded extrinsic in code correspond to the correct transfer
|
||||
#[test]
|
||||
fn test_set_rent_code_and_hash() {
|
||||
@@ -954,9 +954,12 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
let subsistence_threshold = 50 /*existential_deposit*/ + 16 /*tombstone_deposit*/;
|
||||
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000);
|
||||
assert_eq!(Balances::free_balance(&BOB), 100);
|
||||
|
||||
// Advance blocks
|
||||
System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
|
||||
@@ -964,6 +967,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent through call
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
assert_eq!(Balances::free_balance(&BOB), subsistence_threshold);
|
||||
|
||||
// Advance blocks
|
||||
System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
|
||||
@@ -971,6 +975,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
assert_eq!(Balances::free_balance(&BOB), subsistence_threshold);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -991,6 +996,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 100);
|
||||
assert_eq!(Balances::free_balance(&BOB), 1_000);
|
||||
|
||||
// Advance blocks
|
||||
System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
|
||||
@@ -998,6 +1004,8 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent through call
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
// Balance should be initial balance - initial rent_allowance
|
||||
assert_eq!(Balances::free_balance(&BOB), 900);
|
||||
|
||||
// Advance blocks
|
||||
System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
|
||||
@@ -1005,6 +1013,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).unwrap().get_tombstone().is_some());
|
||||
assert_eq!(Balances::free_balance(&BOB), 900);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1025,10 +1034,12 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000);
|
||||
assert_eq!(Balances::free_balance(&BOB), 50 + Balances::minimum_balance());
|
||||
|
||||
// Transfer funds
|
||||
assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::transfer()));
|
||||
assert_eq!(ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000);
|
||||
assert_eq!(Balances::free_balance(&BOB), Balances::minimum_balance());
|
||||
|
||||
// Advance blocks
|
||||
System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
|
||||
@@ -1036,6 +1047,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent through call
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).is_none());
|
||||
assert_eq!(Balances::free_balance(&BOB), Balances::minimum_balance());
|
||||
|
||||
// Advance blocks
|
||||
System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default());
|
||||
@@ -1043,6 +1055,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
// Trigger rent must have no effect
|
||||
assert!(trigger_call());
|
||||
assert!(ContractInfoOf::<Test>::get(BOB).is_none());
|
||||
assert_eq!(Balances::free_balance(&BOB), Balances::minimum_balance());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user