-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from CoinFabrik/182-update-contribution-guide…
…line-for-detectors 182 update contribution guideline for detectors
- Loading branch information
Showing
15 changed files
with
340 additions
and
30 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,11 @@ | ||
[target.aarch64-apple-darwin] | ||
linker = "dylint-link" | ||
|
||
[target.x86_64-apple-darwin] | ||
linker = "dylint-link" | ||
|
||
[target.x86_64-unknown-linux-gnu] | ||
linker = "dylint-link" | ||
|
||
[target.x86_64-pc-windows-msvc] | ||
linker = "dylint-link" |
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,21 @@ | ||
[package] | ||
name = "detector-name" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "1480cea393d0cee195e59949eabdfbcf1230f7f9" } | ||
dylint_linting = "2.1.5" | ||
if_chain = "1.0.2" | ||
|
||
[dev-dependencies] | ||
dylint_testing = "2.1.5" | ||
|
||
[package.metadata.rust-analyzer] | ||
rustc_private = true | ||
|
||
|
||
|
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,3 @@ | ||
[toolchain] | ||
channel = "nightly-2023-01-27" | ||
components = ["llvm-tools-preview", "rustc-dev"] |
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,56 @@ | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_ast; | ||
extern crate rustc_span; | ||
|
||
use clippy_utils::diagnostics::span_lint_and_help; | ||
use rustc_ast::visit::{FnKind, Visitor}; | ||
use rustc_ast::{Expr, ExprKind}; | ||
use rustc_lint::{EarlyContext, EarlyLintPass}; | ||
use rustc_span::Span; | ||
|
||
dylint_linting::declare_early_lint! { | ||
/// ### What it does | ||
/// Describe what the lint does. | ||
/// | ||
/// ### Why is this bad? | ||
/// Describe why the linted code is considered bad. | ||
/// | ||
/// ### Example | ||
/// ```rust | ||
/// // example code where a warning is issued | ||
/// ``` | ||
/// Use instead: | ||
/// ```rust | ||
/// // example code that does not raise a warning | ||
/// ``` | ||
pub YOUR_LINT_NAME, | ||
Warn, | ||
"Short description of the lint" | ||
} | ||
|
||
struct YourVisitor { | ||
// Add any fields necessary for your lint | ||
} | ||
|
||
impl<'ast> Visitor<'ast> for YourVisitor { | ||
fn visit_expr(&mut self, ex: &'ast Expr) { | ||
// Implement the logic of your lint here | ||
|
||
// Call `walk_expr` to visit the descendants of `ex` | ||
rustc_ast::visit::walk_expr(self, ex); | ||
} | ||
} | ||
|
||
impl EarlyLintPass for YourLint { | ||
fn check_fn( | ||
&mut self, | ||
cx: &EarlyContext<'_>, | ||
fn_kind: FnKind<'_>, | ||
_: Span, | ||
_: rustc_ast::NodeId, | ||
) { | ||
// Implement check_fn and emit any necessary diagnostic messages | ||
} | ||
} | ||
|
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 @@ | ||
fn main() {} |
Empty file.
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,11 @@ | ||
[target.aarch64-apple-darwin] | ||
linker = "dylint-link" | ||
|
||
[target.x86_64-apple-darwin] | ||
linker = "dylint-link" | ||
|
||
[target.x86_64-unknown-linux-gnu] | ||
linker = "dylint-link" | ||
|
||
[target.x86_64-pc-windows-msvc] | ||
linker = "dylint-link" |
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,21 @@ | ||
[package] | ||
name = "detector-name" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "1480cea393d0cee195e59949eabdfbcf1230f7f9" } | ||
dylint_linting = "2.1.5" | ||
if_chain = "1.0.2" | ||
|
||
[dev-dependencies] | ||
dylint_testing = "2.1.5" | ||
|
||
[package.metadata.rust-analyzer] | ||
rustc_private = true | ||
|
||
|
||
|
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,3 @@ | ||
[toolchain] | ||
channel = "nightly-2023-01-27" | ||
components = ["llvm-tools-preview", "rustc-dev"] |
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,60 @@ | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_hir; | ||
extern crate rustc_span; | ||
|
||
use clippy_utils::diagnostics::span_lint_and_help; | ||
use rustc_hir::intravisit::{self, FnKind, Visitor}; | ||
use rustc_hir::*; | ||
use rustc_lint::{LateContext, LateLintPass}; | ||
use rustc_span::Span; | ||
|
||
dylint_linting::declare_late_lint! { | ||
/// ### What it does | ||
/// Describe what the lint does. | ||
/// | ||
/// ### Why is this bad? | ||
/// Describe why the linted code is considered bad. | ||
/// | ||
/// ### Example | ||
/// ```rust | ||
/// // example code where a warning is issued | ||
/// ``` | ||
/// Use instead: | ||
/// ```rust | ||
/// // example code that does not raise a warning | ||
/// ``` | ||
pub YOUR_LINT_NAME, | ||
Warn, | ||
"Short description of the lint" | ||
} | ||
|
||
struct YourVisitor<'tcx> { | ||
// Add any fields necessary for your lint | ||
} | ||
|
||
impl<'tcx> Visitor<'tcx> for YourVisitor<'tcx> { | ||
fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { | ||
// Implement the logic of your lint here | ||
|
||
// Call `walk_expr` to visit the descendants of `ex` | ||
intravisit::walk_expr(self, ex); | ||
} | ||
|
||
// Implement other methods of the `Visitor` trait as needed | ||
} | ||
|
||
impl<'tcx> LateLintPass<'tcx> for YourLint { | ||
fn check_fn( | ||
&mut self, | ||
cx: &LateContext<'tcx>, | ||
fn_kind: FnKind<'tcx>, | ||
decl: &'tcx FnDecl<'tcx>, | ||
body: &'tcx Body<'tcx>, | ||
span: Span, | ||
hir_id: HirId, | ||
) { | ||
// Implement check_fn and emit any necessary diagnostic messages | ||
} | ||
} | ||
|
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 @@ | ||
fn main() {} |
Empty file.
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,32 @@ | ||
[package] | ||
name = "flipper" | ||
version = "0.1.0" | ||
authors = ["[your_name] <[your_email]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
path = "lib.rs" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink/std", | ||
"scale/std", | ||
"scale-info/std", | ||
] | ||
ink-as-dependency = [] | ||
e2e-tests = [] | ||
|
||
[dependencies] | ||
ink = { version = "4.2.1", default-features = false } | ||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } | ||
|
||
[dev-dependencies] | ||
ink_e2e = "4.2.1" | ||
|
||
[profile.dev] | ||
overflow-checks = false | ||
|
||
[profile.release] | ||
overflow-checks = false |
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,109 @@ | ||
#![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
||
#[ink::contract] | ||
pub mod flipper { | ||
#[ink(storage)] | ||
pub struct Flipper { | ||
value: bool, | ||
} | ||
|
||
impl Flipper { | ||
/// Creates a new flipper smart contract initialized with the given value. | ||
#[ink(constructor)] | ||
pub fn new(init_value: bool) -> Self { | ||
Self { value: init_value } | ||
} | ||
|
||
/// Flips the current value of the Flipper's boolean. | ||
#[ink(message)] | ||
pub fn flip(&mut self) { | ||
self.value = !self.value; | ||
} | ||
|
||
/// Returns the current value of the Flipper's boolean. | ||
#[ink(message)] | ||
pub fn get(&self) -> bool { | ||
self.value | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[ink::test] | ||
fn default_works() { | ||
let flipper = Flipper::new_default(); | ||
assert!(!flipper.get()); | ||
} | ||
|
||
#[ink::test] | ||
fn it_works() { | ||
let mut flipper = Flipper::new(false); | ||
assert!(!flipper.get()); | ||
flipper.flip(); | ||
assert!(flipper.get()); | ||
} | ||
} | ||
|
||
#[cfg(all(test, feature = "e2e-tests"))] | ||
mod e2e_tests { | ||
use super::*; | ||
use ink_e2e::build_message; | ||
|
||
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
||
#[ink_e2e::test] | ||
async fn it_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> { | ||
// given | ||
let constructor = FlipperRef::new(false); | ||
let contract_acc_id = client | ||
.instantiate("flipper", &ink_e2e::alice(), constructor, 0, None) | ||
.await | ||
.expect("instantiate failed") | ||
.account_id; | ||
|
||
let get = build_message::<FlipperRef>(contract_acc_id.clone()) | ||
.call(|flipper| flipper.get()); | ||
let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; | ||
assert!(matches!(get_res.return_value(), false)); | ||
|
||
// when | ||
let flip = build_message::<FlipperRef>(contract_acc_id.clone()) | ||
.call(|flipper| flipper.flip()); | ||
let _flip_res = client | ||
.call(&ink_e2e::bob(), flip, 0, None) | ||
.await | ||
.expect("flip failed"); | ||
|
||
// then | ||
let get = build_message::<FlipperRef>(contract_acc_id.clone()) | ||
.call(|flipper| flipper.get()); | ||
let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; | ||
assert!(matches!(get_res.return_value(), true)); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[ink_e2e::test] | ||
async fn default_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> { | ||
// given | ||
let constructor = FlipperRef::new_default(); | ||
|
||
// when | ||
let contract_acc_id = client | ||
.instantiate("flipper", &ink_e2e::bob(), constructor, 0, None) | ||
.await | ||
.expect("instantiate failed") | ||
.account_id; | ||
|
||
// then | ||
let get = build_message::<FlipperRef>(contract_acc_id.clone()) | ||
.call(|flipper| flipper.get()); | ||
let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; | ||
assert!(matches!(get_res.return_value(), false)); | ||
|
||
Ok(()) | ||
} | ||
} | ||
} |