diff --git a/contracts/warp-account-tracker/src/execute/account.rs b/contracts/warp-account-tracker/src/execute/account.rs index 75f951a..88929e1 100644 --- a/contracts/warp-account-tracker/src/execute/account.rs +++ b/contracts/warp-account-tracker/src/execute/account.rs @@ -76,9 +76,11 @@ pub fn free_job_account(deps: DepsMut, data: FreeJobAccountMsg) -> Result Ok(data.last_job_id), - Some(_) => Err(ContractError::AccountAlreadyFreeError {}), + |s| -> Result { + match s { + None => Ok(data.last_job_id), + Some(last_job_id) => Ok(last_job_id), // idempotent use case, if already freed, do nothing + } }, )?; @@ -180,9 +182,11 @@ pub fn free_funding_account( FREE_FUNDING_ACCOUNTS.update( deps.storage, (account_owner_addr_ref, account_addr_ref), - |s| match s { - None => Ok(vec![data.job_id]), - Some(_) => Err(ContractError::AccountAlreadyFreeError {}), + |s| -> Result, ContractError> { + match s { + None => Ok(vec![data.job_id]), + Some(job_ids) => Ok(job_ids), // idempotent use case, if already freed, do nothing + } }, )?; } else { diff --git a/contracts/warp-account-tracker/src/integration_tests.rs b/contracts/warp-account-tracker/src/integration_tests.rs index 90faf8a..c42cb4c 100644 --- a/contracts/warp-account-tracker/src/integration_tests.rs +++ b/contracts/warp-account-tracker/src/integration_tests.rs @@ -144,19 +144,16 @@ mod tests { &[], ); - // Cannot free account twice - assert_err( - app.execute_contract( - Addr::unchecked(USER_1), - warp_account_tracker_contract_addr.clone(), - &ExecuteMsg::FreeJobAccount(FreeJobAccountMsg { - account_owner_addr: USER_1.to_string(), - account_addr: DUMMY_WARP_ACCOUNT_1_ADDR.to_string(), - last_job_id: DUMMY_JOB_1_ID, - }), - &[], - ), - ContractError::AccountAlreadyFreeError {}, + // free account idempotent + let _ = app.execute_contract( + Addr::unchecked(USER_1), + warp_account_tracker_contract_addr.clone(), + &ExecuteMsg::FreeJobAccount(FreeJobAccountMsg { + account_owner_addr: USER_1.to_string(), + account_addr: DUMMY_WARP_ACCOUNT_1_ADDR.to_string(), + last_job_id: DUMMY_JOB_1_ID, + }), + &[], ); // Mark second account as free