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

feat: Candid checker #490

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat: Candid checker #490

wants to merge 5 commits into from

Conversation

chenyan-dfinity
Copy link
Contributor

@chenyan-dfinity chenyan-dfinity commented May 8, 2024

Given a did file and a Rust file, check if the Rust code implements the Candid interface correctly.

To try it out:

$ candid-checker test.rs test.did test.toml
error: Checking Candid method f
   ┌─ test.rs:14:11
   │
14 │ #[ic_cdk::update]
   │           ^^^^^^
   │           │
   │           Expect mode: query
   │           Expect attribute: name = "f"
   │           Expect attribute: composite = true
15 │ #[candid_method(update)]
16 │ pub async fn f(test: MyType, argument: Vec/* whatever */<Profile>) -> (List, u8) {
   │     ---------^-------^^^^^^----------------------------------------^^^^^^^^^^^^^
   │              │       │                                             │
   │              │       │                                             Argument count mismatch
   │              │       │                                             Suggestion: -> List
   │              │       Expect type: CanisterId2
   │              Expect function name: FFF

error: Checking Candid method g
   ┌─ test.rs:29:19
   │
29 │ #[::ic_cdk::query(name="test")]
   │                   ^^^^^^^^^^^ You may want to remove the name attribute
30 │ fn g() -> () {
   │    - This function name matches the Candid method name

error: Checking Candid method inner
   ┌─ test.rs:25:5
   │
25 │   #[query(composite = true)]
   │     ^^^^^ Expect mode: update
26 │   async fn inner(a: List) -> Result<List> {}
   │   --------------^^^^^^^^^-^^^^^^^^^^^^^^^
   │                 │         │
   │                 │         Argument count mismatch
   │                 │         Suggestion: remove the return type
   │                 Argument count mismatch
   │                 Suggestion: ()

error: Checking Candid method missing
 = Method "missing" is missing from Rust code. Use this signature to get started:
   #[query]
   fn missing(arg0: candid::Int) -> candid::Nat

error: Checking init args
   ┌─ test.rs:22:13
   │
22 │ fn take_init() {}
   │             ^^
   │             │
   │             Argument count mismatch
   │             Suggestion: (arg0: Profile)

warning: Function h doesn't appear in Candid file
   ┌─ test.rs:33:5
   │
33 │     #[query]
   │ ╭─────'
34 │ │   fn h(&mut self) -> (u8,u16) {}
   │ ╰─────────────────────────────'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant