Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion runtime-sdk/modules/rofl-market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl<Cfg: Config> Module<Cfg> {
return Ok(());
}

let provider = state::get_provider(body.provider).ok_or(Error::ProviderNotFound)?;
let mut provider = state::get_provider(body.provider).ok_or(Error::ProviderNotFound)?;
let mut instance =
state::get_instance(body.provider, body.id).ok_or(Error::InstanceNotFound)?;
Self::ensure_caller_is_instance_admin(&instance)?;
Expand All @@ -694,6 +694,14 @@ impl<Cfg: Config> Module<Cfg> {
// We can also directly remove the instance.
state::remove_instance(body.provider, body.id);

// Update provider metadata.
provider.instances_count = provider
.instances_count
.checked_sub(1)
.ok_or(Error::InvalidArgument)?;
provider.updated_at = ctx.now();
state::set_provider(provider);

CurrentState::with(|state| {
state.emit_event(Event::InstanceRemoved {
provider: body.provider,
Expand Down
27 changes: 27 additions & 0 deletions runtime-sdk/modules/rofl-market/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,33 @@ fn test_instance_accept_timeout() {
assert_eq!(balance, 0);
let balance = Accounts::get_balance(keys::charlie::address(), Denomination::NATIVE).unwrap();
assert_eq!(balance, 1_000_000);

// Instance should be removed.
let instances: Vec<types::Instance> = signer_alice
.query(
&ctx,
"roflmarket.Instances",
types::ProviderQuery {
provider: keys::alice::address(),
},
)
.unwrap();
assert_eq!(instances.len(), 0, "instance should be removed");

// Provider should have no instances.
let provider: types::Provider = signer_alice
.query(
&ctx,
"roflmarket.Provider",
types::ProviderQuery {
provider: keys::alice::address(),
},
)
.unwrap();
assert_eq!(
provider.instances_count, 0,
"provider should have no instances"
);
}

#[test]
Expand Down
Loading