Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/oraichain/cw-plus into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamle2 committed Mar 23, 2023
2 parents c1adb69 + 5a66df9 commit 344fecc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
36 changes: 8 additions & 28 deletions contracts/cw20-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ pub fn execute_transfer(
recipient: String,
amount: Uint128,
) -> Result<Response, ContractError> {
if amount == Uint128::zero() {
return Err(ContractError::InvalidZeroAmount {});
}

let rcpt_addr = deps.api.addr_validate(&recipient)?;

BALANCES.update(
Expand Down Expand Up @@ -276,10 +272,6 @@ pub fn execute_burn(
info: MessageInfo,
amount: Uint128,
) -> Result<Response, ContractError> {
if amount == Uint128::zero() {
return Err(ContractError::InvalidZeroAmount {});
}

// lower balance
BALANCES.update(
deps.storage,
Expand Down Expand Up @@ -308,10 +300,6 @@ pub fn execute_mint(
recipient: String,
amount: Uint128,
) -> Result<Response, ContractError> {
if amount == Uint128::zero() {
return Err(ContractError::InvalidZeroAmount {});
}

let mut config = TOKEN_INFO
.may_load(deps.storage)?
.ok_or(ContractError::Unauthorized {})?;
Expand Down Expand Up @@ -358,10 +346,6 @@ pub fn execute_send(
amount: Uint128,
msg: Binary,
) -> Result<Response, ContractError> {
if amount == Uint128::zero() {
return Err(ContractError::InvalidZeroAmount {});
}

let rcpt_addr = deps.api.addr_validate(&contract)?;

// move the tokens to the contract
Expand Down Expand Up @@ -910,15 +894,14 @@ mod tests {
assert_eq!(get_balance(deps.as_ref(), genesis), amount);
assert_eq!(get_balance(deps.as_ref(), winner.clone()), prize);

// but cannot mint nothing
// Allows minting 0
let msg = ExecuteMsg::Mint {
recipient: winner.clone(),
amount: Uint128::zero(),
};
let info = mock_info(minter.as_ref(), &[]);
let env = mock_env();
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::InvalidZeroAmount {});
execute(deps.as_mut(), env, info, msg).unwrap();

// but if it exceeds cap (even over multiple rounds), it fails
// cap is enforced
Expand Down Expand Up @@ -1171,15 +1154,14 @@ mod tests {

do_instantiate(deps.as_mut(), &addr1, amount1);

// cannot transfer nothing
// Allows transferring 0
let info = mock_info(addr1.as_ref(), &[]);
let env = mock_env();
let msg = ExecuteMsg::Transfer {
recipient: addr2.clone(),
amount: Uint128::zero(),
};
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::InvalidZeroAmount {});
execute(deps.as_mut(), env, info, msg).unwrap();

// cannot send more than we have
let info = mock_info(addr1.as_ref(), &[]);
Expand Down Expand Up @@ -1230,14 +1212,13 @@ mod tests {

do_instantiate(deps.as_mut(), &addr1, amount1);

// cannot burn nothing
// Allows burning 0
let info = mock_info(addr1.as_ref(), &[]);
let env = mock_env();
let msg = ExecuteMsg::Burn {
amount: Uint128::zero(),
};
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::InvalidZeroAmount {});
execute(deps.as_mut(), env, info, msg).unwrap();
assert_eq!(
query_token_info(deps.as_ref()).unwrap().total_supply,
amount1
Expand Down Expand Up @@ -1281,16 +1262,15 @@ mod tests {

do_instantiate(deps.as_mut(), &addr1, amount1);

// cannot send nothing
// Allows sending 0
let info = mock_info(addr1.as_ref(), &[]);
let env = mock_env();
let msg = ExecuteMsg::Send {
contract: contract.clone(),
amount: Uint128::zero(),
msg: send_msg.clone(),
};
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::InvalidZeroAmount {});
execute(deps.as_mut(), env, info, msg).unwrap();

// cannot send more than we have
let info = mock_info(addr1.as_ref(), &[]);
Expand Down
2 changes: 2 additions & 0 deletions contracts/cw20-base/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub enum ContractError {
#[error("Cannot set to own account")]
CannotSetOwnAccount {},

// Unused error case. Zero is now treated like every other value.
#[deprecated(note = "Unused. All zero amount checks have been removed")]
#[error("Invalid zero amount")]
InvalidZeroAmount {},

Expand Down

0 comments on commit 344fecc

Please sign in to comment.