Skip to content

Commit

Permalink
stdout for test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-valerio committed Aug 30, 2024
1 parent 3fdb0f5 commit a980f08
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "dummy"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
ink = { version = "5.0.0", default-features = false }
ink_prelude = { version = "5.0.0", default-features = false }

[dev-dependencies]
ink_e2e = { version = "5.0.0" }
hex = { version = "0.4.3" }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
]

phink = []

ink-as-dependency = []
e2e-tests = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
27 changes: 27 additions & 0 deletions test_assert_output_created_when_fuzzing_instrumented/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "dummy"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
ink = { version = "5.0.0", default-features = false }
ink_prelude = { version = "5.0.0", default-features = false }

[dev-dependencies]
ink_e2e = { version = "5.0.0" }
hex = { version = "0.4.3" }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
]

phink = []

ink-as-dependency = []
e2e-tests = []
72 changes: 72 additions & 0 deletions test_assert_output_created_when_fuzzing_instrumented/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#[ink::contract]
mod dummy {
use ink::{
prelude::vec::Vec,
storage::{
Mapping,
StorageVec,
},
};
use ink_prelude::string::String;
#[ink(storage)]
pub struct MyBuggedContract {
forbidden_number: u32,
}
impl Default for MyBuggedContract {
fn default() -> Self {
ink::env::debug_println!("COV={}", 0);
Self {
forbidden_number: 0,
}
}
}
#[derive(Debug, PartialEq, Eq)]
#[ink::scale_derive(Encode, Decode, TypeInfo)]
pub enum Error {}
pub type Result<T> = core::result::Result<T, Error>;
impl MyBuggedContract {
/// Creates a new domain name service contract.
#[ink(constructor)]
pub fn new() -> Self {
ink::env::debug_println!("COV={}", 1);
Default::default()
}
#[ink(message)]
pub fn crash_with_invariant(&mut self, data: String) -> Result<()> {
ink::env::debug_println!("COV={}", 2);
if data.len() == 4 {
ink::env::debug_println!("COV={}", 3);
if data.chars().nth(0).unwrap() == 'f' {
ink::env::debug_println!("COV={}", 4);
if data.chars().nth(1).unwrap() == 'u' {
ink::env::debug_println!("COV={}", 5);
if data.chars().nth(2).unwrap() == 'z' {
ink::env::debug_println!("COV={}", 6);
if data.chars().nth(3).unwrap() == 'z' {
ink::env::debug_println!("COV={}", 7);
self.forbidden_number = 69;
}
}
}
}
}
ink::env::debug_println!("COV={}", 8);
Ok(())
}
}
#[cfg(feature = "phink")]
#[ink(impl)]
impl MyBuggedContract {
#[cfg(feature = "phink")]
#[ink(message)]
pub fn phink_assert_dangerous_number(&self) {
ink::env::debug_println!("COV={}", 9);
let forbidden_number = 69;
ink::env::debug_println!("COV={}", 10);
ink::env::debug_println!("xx");
ink::env::debug_println!("COV={}", 11);
assert_ne!(self.forbidden_number, forbidden_number);
}
}
}

0 comments on commit a980f08

Please sign in to comment.