Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make receiver msg non-optional in cw20 contracts #321

Merged
merged 3 commits into from
Jul 12, 2021
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
3 changes: 1 addition & 2 deletions contracts/cw20-escrow/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ fn escrow_happy_path_cw20_tokens() {
end_time: None,
cw20_whitelist: None,
});
let create_bin = to_binary(&create_msg).unwrap();
let send_msg = Cw20ExecuteMsg::Send {
contract: escrow_addr.to_string(),
amount: Uint128::new(1200),
msg: Some(create_bin),
msg: to_binary(&create_msg).unwrap(),
};
let res = router
.execute_contract(owner.clone(), cash_addr.clone(), &send_msg, &[])
Expand Down
10 changes: 2 additions & 8 deletions contracts/cw721-base/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,15 @@
"type": "object",
"required": [
"contract",
"msg",
"token_id"
],
"properties": {
"contract": {
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"token_id": {
"type": "string"
Expand Down
8 changes: 4 additions & 4 deletions contracts/cw721-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn execute_send_nft(
info: MessageInfo,
contract: String,
token_id: String,
msg: Option<Binary>,
msg: Binary,
) -> Result<Response, ContractError> {
// Transfer token
_transfer_nft(deps, &env, &info, &contract, &token_id)?;
Expand Down Expand Up @@ -797,7 +797,7 @@ mod tests {
let send_msg = ExecuteMsg::SendNft {
contract: target.clone(),
token_id: token_id.clone(),
msg: Some(msg.clone()),
msg: msg.clone(),
};

let random = mock_info("random", &[]);
Expand All @@ -811,7 +811,7 @@ mod tests {
let payload = Cw721ReceiveMsg {
sender: String::from("venus"),
token_id: token_id.clone(),
msg: Some(msg),
msg,
};
let expected = SubMsg::new(payload.into_cosmos_msg(target.clone()).unwrap());
// ensure expected serializes as we think it should
Expand Down Expand Up @@ -1009,7 +1009,7 @@ mod tests {
let send_msg = ExecuteMsg::SendNft {
contract: String::from("another_contract"),
token_id: token_id2,
msg: Some(to_binary(&msg).unwrap()),
msg: to_binary(&msg).unwrap(),
};
execute(deps.as_mut(), mock_env(), random, send_msg).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion contracts/cw721-base/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum ExecuteMsg {
SendNft {
contract: String,
token_id: String,
msg: Option<Binary>,
msg: Binary,
},
/// Allows operator to transfer / send the token from the owner's account.
/// If expiration is set, then this allowance has a time/height limit
Expand Down
22 changes: 5 additions & 17 deletions packages/cw20/schema/cw20_execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"type": "object",
"required": [
"amount",
"contract"
"contract",
"msg"
],
"properties": {
"amount": {
Expand All @@ -69,14 +70,7 @@
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
}
}
}
Expand Down Expand Up @@ -194,6 +188,7 @@
"required": [
"amount",
"contract",
"msg",
"owner"
],
"properties": {
Expand All @@ -204,14 +199,7 @@
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"owner": {
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions packages/cw20/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Cw20ExecuteMsg {
Send {
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
},
/// Only with "approval" extension. Allows spender to access an additional amount tokens
/// from the owner's (env.sender) account. If expires is Some(), overwrites current allowance
Expand Down Expand Up @@ -47,7 +47,7 @@ pub enum Cw20ExecuteMsg {
owner: String,
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
},
/// Only with "approval" extension. Destroys tokens forever
BurnFrom { owner: String, amount: Uint128 },
Expand Down
10 changes: 2 additions & 8 deletions packages/cw721/schema/cw721_execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@
"type": "object",
"required": [
"contract",
"msg",
"token_id"
],
"properties": {
"contract": {
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"token_id": {
"type": "string"
Expand Down
10 changes: 2 additions & 8 deletions packages/cw721/schema/cw721_receive_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
"description": "Cw721ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg",
"type": "object",
"required": [
"msg",
"sender",
"token_id"
],
"properties": {
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"sender": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion packages/cw721/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum Cw721ExecuteMsg {
SendNft {
contract: String,
token_id: String,
msg: Option<Binary>,
msg: Binary,
},
/// Allows operator to transfer / send the token from the owner's account.
/// If expiration is set, then this allowance has a time/height limit
Expand Down
2 changes: 1 addition & 1 deletion packages/cw721/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cosmwasm_std::{to_binary, Binary, CosmosMsg, StdResult, WasmMsg};
pub struct Cw721ReceiveMsg {
pub sender: String,
pub token_id: String,
pub msg: Option<Binary>,
pub msg: Binary,
}

impl Cw721ReceiveMsg {
Expand Down