File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
substrate-node/pallets/pallet-smart-contract/src Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,15 @@ impl<T: Config> Pallet<T> {
41
41
let node_is_dedicated =
42
42
DedicatedNodesExtraFee :: < T > :: get ( node_id) > 0 || farm. dedicated_farm ;
43
43
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
45
47
// If not, allow to deploy only if node is not dedicated
46
48
match ActiveRentContractForNode :: < T > :: get ( node_id) {
47
49
Some ( contract_id) => {
48
50
let rent_contract =
49
51
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 ) {
51
53
return Err ( Error :: < T > :: NodeNotAvailableToDeploy . into ( ) ) ;
52
54
}
53
55
}
Original file line number Diff line number Diff line change @@ -934,6 +934,45 @@ fn test_create_node_contract_on_dedicated_node_rented_by_other_fails() {
934
934
} )
935
935
}
936
936
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
+
937
976
#[ test]
938
977
fn test_cancel_rent_contract_with_active_node_contracts_fails ( ) {
939
978
new_test_ext ( ) . execute_with ( || {
You can’t perform that action at this time.
0 commit comments