-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ pub mod pallet { | |
NewDigitalTwin(T::AccountId, u32), | ||
/// Digital twin topic was changed: [sender, id, topic, source] | ||
TopicChanged(T::AccountId, u32, H256, T::AccountId), | ||
/// Digital twin topic was removed: [sender, id, source] | ||
TopicRemoved(T::AccountId, u32, T::AccountId), | ||
} | ||
|
||
#[pallet::hooks] | ||
|
@@ -96,6 +98,23 @@ pub mod pallet { | |
<DigitalTwin<T>>::insert(id, (source, topic)); | ||
Ok(().into()) | ||
} | ||
|
||
/// Remove data source account for difital twin. | ||
#[pallet::weight(50_000)] | ||
Check warning on line 103 in frame/digital-twin-v2/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check warning on line 103 in frame/digital-twin-v2/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_2::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn remove_source( | ||
Check warning on line 104 in frame/digital-twin-v2/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check warning on line 104 in frame/digital-twin-v2/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ImplicitCallIndex_2::_w`: It is deprecated to use implicit call indices. Please instead ensure that all calls have a `pallet::call_index` attribute or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/12891> <https://github.com/paritytech/substrate/pull/11381>
|
||
origin: OriginFor<T>, | ||
id: u32, | ||
source: T::AccountId, | ||
) -> DispatchResultWithPostInfo { | ||
let sender = ensure_signed(origin)?; | ||
ensure!( | ||
<Owner<T>>::get(id) == Some(sender.clone()), | ||
"sender should be a twin owner" | ||
); | ||
Self::deposit_event(Event::TopicRemoved(sender, id, source.clone())); | ||
<DigitalTwin<T>>::remove(id); | ||
Ok(().into()) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -191,6 +210,24 @@ mod tests { | |
}) | ||
} | ||
|
||
#[test] | ||
fn test_remove_source() { | ||
new_test_ext().execute_with(|| { | ||
let sender = 1; | ||
let bad_sender = 2; | ||
assert_ok!(DigitalTwin::create(RuntimeOrigin::signed(sender))); | ||
assert_err!( | ||
DigitalTwin::remove_source(RuntimeOrigin::signed(bad_sender), 0, bad_sender), | ||
DispatchError::Other("sender should be a twin owner") | ||
); | ||
assert_ok!(DigitalTwin::remove_source( | ||
RuntimeOrigin::signed(sender), | ||
0, | ||
bad_sender | ||
)); | ||
}) | ||
} | ||
|
||
#[test] | ||
fn test_bad_origin() { | ||
new_test_ext().execute_with(|| { | ||
|