diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
index a4f3d13..3de2e87 100644
--- a/.github/workflows/linux.yml
+++ b/.github/workflows/linux.yml
@@ -37,6 +37,9 @@ jobs:
profile: minimal
override: false
+ - name: install virtualenv
+ run: pip install virtualenv
+
- name: install dependencies
run: make env
@@ -52,19 +55,6 @@ jobs:
- name: stop docker container
run: make docker-stop
- # - name: build
- # uses: actions-rs/cargo@v1
- # with:
- # command: build
- # args: --all --bins --examples --tests
- #
- # - name: tests
- # uses: actions-rs/cargo@v1
- # timeout-minutes: 40
- # with:
- # command: test
- # args: --all --all-features --no-fail-fast
- #
- name: Generate coverage file
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
uses: actions-rs/tarpaulin@v0.1
@@ -74,25 +64,6 @@ jobs:
- name: Upload to Codecov
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v2
with:
file: cobertura.xml
-
- # - name: generate documentation
- # if: matrix.version == 'stable' && (github.repository == 'mcaptcha/cache')
- # run: make doc
- #
- # # - name: generate documentation
- # # if: matrix.version == 'stable' && (github.repository == 'realaravinth/damn-vuln-blockchain')
- # # uses: actions-rs/cargo@v1
- # # with:
- # # command: doc
- # # args: --no-deps --workspace --all-features
- #
- # - name: Deploy to GitHub Pages
- # if: matrix.version == 'stable' && (github.repository == 'mcaptcha/cache')
- # uses: JamesIves/github-pages-deploy-action@3.7.1
- # with:
- # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- # BRANCH: gh-pages
- # FOLDER: target/doc
diff --git a/.gitignore b/.gitignore
index 6fab820..ead4112 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
*.rdb
tmp/
tarpaulin-report.html
+*.profraw
diff --git a/Makefile b/Makefile
index 4f4d4fa..723e5c6 100644
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,8 @@ docker-stop:
docker rm $(DOCKER_CONTAINER)
env:
./scripts/setup.sh
+ @-virtualenv venv || true
+ @-pip install codespell
test:
cargo test --all --all-features --no-fail-fast
@@ -52,8 +54,12 @@ run-redis:
stop-redis:
killall redis-server
-help:
+lint: ## Lint codebase
+ @ . venv/bin/activate && ./scripts/spellcheck.sh -w
+ cargo fmt -v --all -- --emit files
+ cargo clippy --workspace --tests --all-features
+help:
@echo ' bench - run benchmarks'
@echo ' clean - drop builds and environments'
@echo ' coverage - build test coverage in HTML format'
diff --git a/scripts/coverage.sh b/scripts/coverage.sh
new file mode 100755
index 0000000..8a86d84
--- /dev/null
+++ b/scripts/coverage.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+set -Eeuo pipefail
+
+readonly GRCOV_DOWNLOAD="https://github.com/mozilla/grcov/releases/download/v0.8.2/grcov-linux-x86_64.tar.bz2"
+readonly PROJECT_ROOT=$(pwd)
+readonly TMP_DIR=$PROJECT_ROOT/tmp
+readonly GRCOV_TARBAL="$TMP_DIR/grcov.tar.bz2"
+readonly GRCOV="$TMP_DIR/grcov"
+
+source $(pwd)/scripts/lib.sh
+
+
+clean_up() {
+ trap - SIGINT SIGTERM ERR EXIT
+ cd $PROJECT_ROOT
+ /bin/rm default.profraw lcov.info *.profraw || true
+ cd target
+ /bin/rm default.profraw lcov.info *.profraw || true
+}
+
+trap cleanup SIGINT SIGTERM ERR EXIT
+setup_colors
+
+download() {
+ if [ ! -e $GRCOV ];
+ then
+ msg "${GREEN}- Downloading grcov"
+ wget --quiet --output-doc=$GRCOV_TARBAL $GRCOV_DOWNLOAD;
+ cd $TMP_DIR
+ tar -xf $GRCOV_TARBAL;
+ cd $PROJECT_ROOT
+ fi
+}
+
+build_and_test() {
+ export RUSTFLAGS="-Zinstrument-coverage"
+ cd $PROJECT_ROOT
+
+ msg "${GREEN}- Building project"
+ cargo build
+
+ export LLVM_PROFILE_FILE="target/mcatpcha-cache-%p-%m.profraw"
+
+ msg "${GREEN}- Running tests"
+ cargo test --lib
+
+ msg "${GREEN}- Generating coverage"
+ $GRCOV target/ --binary-path \
+ ./target/debug/ \
+ -s . -t lcov --branch \
+ --ignore-not-existing \
+ --ignore "../*" -o target/lcov.info
+}
+
+run_coverage() {
+ cd $PROJECT_ROOT
+ mkdir $TMP_DIR || true
+ clean_up
+ download
+ build_and_test
+}
+
+check_arg $1
+
+if match_arg $1 '-c' '--coverage'
+then
+ run_coverage
+else
+ msg "${RED}[!] Undefined option"
+ exit 1
+fi
diff --git a/scripts/lib.sh b/scripts/lib.sh
new file mode 100755
index 0000000..f9ea586
--- /dev/null
+++ b/scripts/lib.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+setup_colors() {
+ if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
+ NOCOLOR='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
+ else
+ NOCOLOR='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
+ fi
+}
+
+msg() {
+ echo >&2 -e "${1-}"
+}
+
+get_file_name() {
+ basename -- $1
+}
+
+check_arg(){
+ if [ -z $1 ]
+ then
+ help
+ exit 1
+ fi
+}
+
+match_arg() {
+ if [ $1 == $2 ] || [ $1 == $3 ]
+ then
+ return 0
+ else
+ return 1
+ fi
+}
diff --git a/scripts/spellcheck.sh b/scripts/spellcheck.sh
new file mode 100755
index 0000000..e51ae93
--- /dev/null
+++ b/scripts/spellcheck.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+set -Eeuo pipefail
+trap cleanup SIGINT SIGTERM ERR EXIT
+
+
+readonly MISSPELL_DOWNLOAD="https://github.com/client9/misspell/releases/download/v0.3.4/misspell_0.3.4_linux_64bit.tar.gz"
+readonly PROJECT_ROOT=$(pwd)
+readonly TMP_DIR=$PROJECT_ROOT/tmp
+readonly MISSPELL_TARBALL="$TMP_DIR/misspell.tar.bz2"
+readonly MISSPELL="$TMP_DIR/misspell"
+
+cleanup() {
+ trap - SIGINT SIGTERM ERR EXIT
+ # script cleanup here
+}
+
+
+source $PROJECT_ROOT/scripts/lib.sh
+setup_colors
+
+FLAGS=""
+
+download() {
+ if [ ! -e $MISSPELL ];
+ then
+ msg "${GREEN}- Downloading misspell"
+ wget --quiet --output-doc=$MISSPELL_TARBALL $MISSPELL_DOWNLOAD;
+ cd $TMP_DIR
+ tar -xf $MISSPELL_TARBALL;
+ cd $PROJECT_ROOT
+ fi
+}
+
+spell_check_codespell() {
+ codespell $FLAGS $PROJECT_ROOT/tests
+ codespell $FLAGS $PROJECT_ROOT/docs/
+ codespell $FLAGS --ignore-words-list crate .$PROJECT_ROOT/src
+ codespell $FLAGS --ignore-words-list crate .$PROJECT_ROOT/README.md
+}
+
+spell_check_misspell() {
+ mkdir $TMP_DIR || true
+ download
+ $MISSPELL $FLAGS $PROJECT_ROOT/docs
+ $MISSPELL $FLAGS $PROJECT_ROOT/tests
+ $MISSPELL $FLAGS -i crate $PROJECT_ROOT/src
+ $MISSPELL $FLAGS -i crate $PROJECT_ROOT/README.md
+}
+
+check_arg $1
+
+if match_arg $1 '-w' '--write'
+then
+ msg "${GREEN}- Checking and correcting typos"
+ FLAGS="-w"
+ spell_check_misspell
+ spell_check_codespell
+elif match_arg $1 '-c' '--check'
+then
+ msg "${GREEN}- Scaning for typos"
+ spell_check_misspell
+ spell_check_codespell
+else
+ msg "${RED}[!] Undefined option"
+ exit 1
+fi
diff --git a/src/bucket.rs b/src/bucket.rs
index 2efaa6b..745c51a 100644
--- a/src/bucket.rs
+++ b/src/bucket.rs
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-//! Leaky bucket algorithim is implemantation for mcatpcha using batch processing Everytime count
+//! Leaky bucket algorithm is implemantation for mcatpcha using batch processing Everytime count
//! is increased for an mcaptcha object, a decrement job is added to a batch that is scheduled to
//! be executed at that mcaptcha object's expiry rate(MCaptcha.get_duration())
use std::collections::HashMap;
diff --git a/src/lib.rs b/src/lib.rs
index 9e9b58a..1ad05f6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,7 +33,7 @@ use challenge::MCAPTCHA_CHALLENGE_TYPE;
use mcaptcha::MCAPTCHA_MCAPTCHA_TYPE;
use safety::MCAPTCHA_SAFETY_TYPE;
-/// Initial allocation ammount of bucket[bucket::Bucket]
+/// Initial allocation amount of bucket[bucket::Bucket]
pub const HIT_PER_SECOND: usize = 100;
pub const PKG_NAME: &str = "mcap";
pub const PKG_VERSION: usize = 0;
diff --git a/src/mcaptcha.rs b/src/mcaptcha.rs
index eb7dc5b..4e6df29 100644
--- a/src/mcaptcha.rs
+++ b/src/mcaptcha.rs
@@ -289,48 +289,38 @@ mod tests {
use libmcaptcha::defense::LevelBuilder;
fn get_levels() -> Vec {
- let mut levels = Vec::default();
- levels.push(
+ vec![
LevelBuilder::default()
.visitor_threshold(50)
.difficulty_factor(50)
.unwrap()
.build()
.unwrap(),
- );
- levels.push(
LevelBuilder::default()
.visitor_threshold(500)
.difficulty_factor(5000)
.unwrap()
.build()
.unwrap(),
- );
- levels.push(
LevelBuilder::default()
.visitor_threshold(5000)
.difficulty_factor(50000)
.unwrap()
.build()
.unwrap(),
- );
- levels.push(
LevelBuilder::default()
.visitor_threshold(50000)
.difficulty_factor(500000)
.unwrap()
.build()
.unwrap(),
- );
- levels.push(
LevelBuilder::default()
.visitor_threshold(500000)
.difficulty_factor(5000000)
.unwrap()
.build()
.unwrap(),
- );
- levels
+ ]
}
#[test]
diff --git a/src/safety.rs b/src/safety.rs
index ecb8267..fe85f4a 100644
--- a/src/safety.rs
+++ b/src/safety.rs
@@ -57,7 +57,7 @@ impl MCaptchaSafety {
let mcaptcha_val = MCaptcha::get_mcaptcha(&mcaptcha);
if mcaptcha_val.is_err() {
ctx.log_warning(&format!(
- "error occured while trying to access mcaptcha {}. error {} is empty",
+ "error occurred while trying to access mcaptcha {}. error {} is empty",
mcaptcha_name,
mcaptcha_val.err().unwrap()
));
@@ -66,7 +66,7 @@ impl MCaptchaSafety {
let mcaptcha_val = mcaptcha_val.unwrap();
if mcaptcha_val.is_none() {
ctx.log_warning(&format!(
- "error occured while trying to access mcaptcha {}. is none",
+ "error occurred while trying to access mcaptcha {}. is none",
mcaptcha_name,
));
return;
@@ -77,7 +77,7 @@ impl MCaptchaSafety {
if Self::new(ctx, duration, mcaptcha_name).is_err() {
ctx.log_warning(&format!(
- "error occured while creating safety for mcaptcha {}.",
+ "error occurred while creating safety for mcaptcha {}.",
mcaptcha_name,
));
};
diff --git a/tests/runner.py b/tests/runner.py
index c39bf47..4098346 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -51,6 +51,6 @@ class Runner(object):
for task in self.__tasks:
await task
- """Runs in seperate threads"""
+ """Runs in separate threads"""
def __init__(self):
super(Runner, self).__init__()