• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

helix-onchain / filecoin / 4191081979

pending completion
4191081979

Pull #197

github

GitHub
Merge f696a6385 into b20a4687a
Pull Request #197: pin toolchain version to match ref-fvm

19 of 19 new or added lines in 3 files covered. (100.0%)

3600 of 4162 relevant lines covered (86.5%)

12.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/frc42_dispatch/macros/src/lib.rs
1
use frc42_hasher::hash::MethodResolver;
1✔
2
use proc_macro::TokenStream;
3
use quote::quote;
4
use syn::parse::{Parse, ParseStream};
5
use syn::{parse_macro_input, LitStr, Result};
6

7
mod hash;
8
use crate::hash::Blake2bHasher;
9

10
struct MethodName(LitStr);
66✔
11

12
impl MethodName {
13
    /// Hash the method name
14
    fn hash(&self) -> u64 {
66✔
15
        let resolver = MethodResolver::new(Blake2bHasher {});
66✔
16
        resolver.method_number(&self.0.value()).unwrap()
66✔
17
    }
66✔
18
}
19

20
impl Parse for MethodName {
21
    fn parse(input: ParseStream) -> Result<Self> {
66✔
22
        let lookahead = input.lookahead1();
66✔
23

24
        if lookahead.peek(LitStr) {
66✔
25
            input.parse().map(MethodName)
66✔
26
        } else {
27
            Err(lookahead.error())
×
28
        }
29
    }
66✔
30
}
31

32
#[proc_macro]
33
pub fn method_hash(input: TokenStream) -> TokenStream {
66✔
34
    let name: MethodName = parse_macro_input!(input);
66✔
35
    let hash = name.hash();
66✔
36
    quote!(#hash).into()
66✔
37
}
66✔
38

39
#[cfg(test)]
40
mod tests {
41
    #[test]
42
    fn it_works() {
2✔
43
        let t = trybuild::TestCases::new();
1✔
44
        t.pass("tests/build-success.rs");
1✔
45
    }
2✔
46

47
    #[test]
48
    fn empty_names() {
2✔
49
        let t = trybuild::TestCases::new();
1✔
50
        // NOTE: these need to live in a separate directory under `tests`
51
        // otherwise cargo tries to build them every time and everything breaks
52
        t.compile_fail("tests/naming/empty-name-string.rs");
1✔
53
        t.compile_fail("tests/naming/missing-name.rs");
1✔
54
    }
2✔
55

56
    #[test]
57
    fn bad_names() {
2✔
58
        let t = trybuild::TestCases::new();
1✔
59
        t.compile_fail("tests/naming/illegal-chars.rs");
1✔
60
        t.compile_fail("tests/naming/non-capital-start.rs");
1✔
61
    }
2✔
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc