Skip to content

Commit 0c3708b

Browse files
committed
Merge remote-tracking branch 'origin' into development_fix_sync_contracts
2 parents 180cffd + 08321ba commit 0c3708b

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

substrate-node/pallets/pallet-smart-contract/src/grid_contract.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ impl<T: Config> Pallet<T> {
4141
let node_is_dedicated =
4242
DedicatedNodesExtraFee::<T>::get(node_id) > 0 || farm.dedicated_farm;
4343

44-
// In case there is a rent contract make sure only the contract owner can deploy
44+
// In case there is a rent contract:
45+
// 1. Ensure only the contract owner can deploy, and
46+
// 2. The rent contract is in the 'created' state
4547
// If not, allow to deploy only if node is not dedicated
4648
match ActiveRentContractForNode::<T>::get(node_id) {
4749
Some(contract_id) => {
4850
let rent_contract =
4951
Contracts::<T>::get(contract_id).ok_or(Error::<T>::ContractNotExists)?;
50-
if rent_contract.twin_id != twin_id {
52+
if rent_contract.twin_id != twin_id || !matches!(rent_contract.state, types::ContractState::Created) {
5153
return Err(Error::<T>::NodeNotAvailableToDeploy.into());
5254
}
5355
}

substrate-node/pallets/pallet-smart-contract/src/tests.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,45 @@ fn test_create_node_contract_on_dedicated_node_rented_by_other_fails() {
934934
})
935935
}
936936

937+
#[test]
938+
fn test_create_node_contract_when_having_a_rentcontract_in_graceperiod_fails() {
939+
let (mut ext, mut pool_state) = new_test_ext_with_pool_state(0);
940+
ext.execute_with(|| {
941+
run_to_block(1, None);
942+
prepare_dedicated_farm_and_node();
943+
let node_id = 1;
944+
let contract_id = 1;
945+
assert_ok!(SmartContractModule::create_rent_contract(
946+
RuntimeOrigin::signed(charlie()),
947+
node_id,
948+
None
949+
));
950+
951+
// Cycle 1
952+
// User does not have enough funds to pay
953+
pool_state
954+
.write()
955+
.should_call_bill_contract(contract_id, Ok(Pays::Yes.into()), 11);
956+
run_to_block(11, Some(&mut pool_state));
957+
958+
let r = SmartContractModule::contracts(1).unwrap();
959+
assert_eq!(r.state, types::ContractState::GracePeriod(11));
960+
961+
// try to create node contract
962+
assert_noop!(
963+
SmartContractModule::create_node_contract(
964+
RuntimeOrigin::signed(charlie()),
965+
node_id,
966+
generate_deployment_hash(),
967+
get_deployment_data(),
968+
1,
969+
None
970+
),
971+
Error::<TestRuntime>::NodeNotAvailableToDeploy
972+
);
973+
})
974+
}
975+
937976
#[test]
938977
fn test_cancel_rent_contract_with_active_node_contracts_fails() {
939978
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)