Skip to content

Commit

Permalink
Edge case for updating expired allowance without new allowance for cw…
Browse files Browse the repository at this point in the history
…1-subkeys contract
  • Loading branch information
hashedone committed Jul 27, 2021
1 parent 441b52c commit e32b6b1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions contracts/cw1-subkeys/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ where
}

allowance.expires = exp;
} else if is_expired(&env, allow.expires) {
return Err(ContractError::SettingExpiredAllowance(allow.expires));
}

allowance.balance.add_assign(amount.clone());
Expand Down Expand Up @@ -1314,6 +1316,35 @@ mod tests {
.canonical(),
);
}

#[test]
fn previously_expired_without_expirance() {
let Suite {
mut deps, owner, ..
} = SuiteConfig::new()
.with_allowance(SPENDER1, coin(1, TOKEN1))
.expire_allowances(SPENDER1, EXPIRED_HEIGHT)
.init();

let rsp = execute(
deps.as_mut(),
mock_env(),
owner,
ExecuteMsg::IncreaseAllowance {
spender: SPENDER1.to_owned(),
amount: coin(2, TOKEN2),
expires: None,
},
)
.unwrap_err();

assert_eq!(
query_all_allowances(deps.as_ref(), mock_env(), None, None)
.unwrap()
.canonical(),
AllAllowancesResponse { allowances: vec![] }.canonical(),
);
}
}

mod decrease_allowances {
Expand Down

0 comments on commit e32b6b1

Please sign in to comment.