-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Error on wrong
sv::data
and sv::payload
usage
- Loading branch information
Showing
9 changed files
with
217 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#![allow(unused_imports, unused_variables)] | ||
use sylvia::ctx::{InstantiateCtx, ReplyCtx}; | ||
use sylvia::cw_std::{Addr, Binary, Response, StdResult}; | ||
|
||
pub mod attributes_swapped { | ||
use super::*; | ||
|
||
pub struct Contract {} | ||
|
||
#[sylvia::contract] | ||
#[sv::features(replies)] | ||
impl Contract { | ||
pub const fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
#[sv::msg(instantiate)] | ||
fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[sv::msg(reply, reply_on=success)] | ||
fn reply( | ||
&self, | ||
_ctx: ReplyCtx, | ||
#[sv::payload(raw)] param: Binary, | ||
#[sv::data(opt, raw)] _data: Option<Binary>, | ||
) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
} | ||
} | ||
|
||
pub mod error_handler { | ||
use super::*; | ||
|
||
pub struct Contract {} | ||
|
||
#[sylvia::contract] | ||
#[sv::features(replies)] | ||
impl Contract { | ||
pub const fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
#[sv::msg(instantiate)] | ||
fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[sv::msg(reply, reply_on=error)] | ||
fn reply( | ||
&self, | ||
_ctx: ReplyCtx, | ||
#[sv::data(opt, raw)] _data: Option<Binary>, | ||
#[sv::payload(raw)] param: Binary, | ||
) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: Wrong usage of `#[sv::data]` attribute. | ||
|
||
= note: The `#[sv::data]` attribute can only be used on the first parameter after the `ReplyCtx`. | ||
|
||
--> tests/ui/attributes/data/invalid_usage.rs:27:35 | ||
| | ||
27 | #[sv::data(opt, raw)] _data: Option<Binary>, | ||
| ^^^^^ | ||
|
||
error: Redundant payload parameter. | ||
|
||
= note: Expected no parameters after the parameter marked with `#[sv::payload(raw)]`. | ||
|
||
--> tests/ui/attributes/data/invalid_usage.rs:27:35 | ||
| | ||
27 | #[sv::data(opt, raw)] _data: Option<Binary>, | ||
| ^^^^^ | ||
|
||
error: Wrong usage of `#[sv::data]` attribute. | ||
|
||
= note: The `#[sv::data]` attribute can only be used in `success` scenario. | ||
= note: Found usage in `error` scenario. | ||
|
||
--> tests/ui/attributes/data/invalid_usage.rs:55:35 | ||
| | ||
55 | #[sv::data(opt, raw)] _data: Option<Binary>, | ||
| ^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![allow(unused_imports, unused_variables)] | ||
use sylvia::ctx::{InstantiateCtx, ReplyCtx}; | ||
use sylvia::cw_std::{Addr, Binary, Response, StdResult}; | ||
|
||
pub mod used_on_context { | ||
use super::*; | ||
|
||
pub struct Contract {} | ||
|
||
#[sylvia::contract] | ||
#[sv::features(replies)] | ||
impl Contract { | ||
pub const fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
#[sv::msg(instantiate)] | ||
fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[sv::msg(reply, reply_on=success)] | ||
fn reply(&self, #[sv::payload(raw)] _ctx: ReplyCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: Missing payload parameter. | ||
|
||
= note: Expected at least one payload parameter at the end of parameter list. | ||
|
||
--> tests/ui/attributes/payload/invalid_usage.rs:23:12 | ||
| | ||
23 | fn reply(&self, #[sv::payload(raw)] _ctx: ReplyCtx) -> StdResult<Response> { | ||
| ^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters