Skip to content

Commit

Permalink
Coverage improvements (#12)
Browse files Browse the repository at this point in the history
* Improved coverage

to dev deps

separated withdrawal tests

remove container after build, update bin

removed unused PartialEq

test

profile moved to cargo config

test products with fee conversion

added lint step, some warnings fixes

install clippy

machete and typos

install toolchain

typos

enabled more lints

some more coverage

folder for common module

moved tests from contract mod.rs

* binary
  • Loading branch information
VladasZ authored Sep 13, 2023
1 parent 462a81a commit 67533b8
Show file tree
Hide file tree
Showing 33 changed files with 731 additions and 640 deletions.
11 changes: 9 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[build]
rustflags = ["-C", "link-args=-s"]
[profile.contract]
inherits = "release"
strip = true
codegen-units = 1
opt-level = "z"
lto = true
debug = false
panic = "abort"
overflow-checks = true
12 changes: 10 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ jobs:
name: sweat-jar
path: res/sweat_jar.wasm

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Lint
run: make lint

unit-tests:
needs: [ build ]
needs: [ build, lint ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -34,7 +42,7 @@ jobs:
run: make test

integration-tests:
needs: [ build ]
needs: [ build, lint ]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ jobs:
name: sweat-jar
path: res/sweat_jar.wasm

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Lint
run: make lint

unit-tests:
needs: [ build ]
needs: [ build, lint ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -34,7 +42,7 @@ jobs:
run: make test

integration-tests:
needs: [ build ]
needs: [ build, lint ]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
13 changes: 2 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
[workspace]

default-members = ["contract"]
members = ["contract", "integration-tests"]

resolver = "2"

[profile.release]
codegen-units = 1
opt-level = "z"
lto = true
debug = false
panic = "abort"
overflow-checks = true

default-members = ["contract"]
members = ["contract", "integration-tests"]

[workspace.dependencies]
near-sdk = "4.1.1"
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deploy:
./scripts/deploy.sh

cov:
./scripts/coverage.sh
cargo llvm-cov --hide-instantiations --open

test:
cargo test --package sweat_jar
Expand All @@ -22,3 +22,6 @@ int: integration

fmt:
cargo +nightly fmt --all

lint:
./scripts/lint.sh
12 changes: 5 additions & 7 deletions contract/src/claim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod tests {

use crate::{
claim::api::ClaimApi,
common::{tests::Context, UDecimal, U32},
common::{tests::Context, u32::U32, udecimal::UDecimal},
jar::{api::JarApi, model::Jar},
product::{
model::{Apy, Product},
Expand Down Expand Up @@ -39,17 +39,15 @@ mod tests {
let admin = accounts(1);

let product = generate_product();
let reference_jar = Jar::generate(0, &alice, &product.id).principal(100_000_000_000);
let mut context = Context::new(admin)
.with_products(&[product])
.with_jars(&[reference_jar.clone()]);
let jar = Jar::generate(0, &alice, &product.id).principal(100_000_000_000);
let mut context = Context::new(admin).with_products(&[product]).with_jars(&[jar.clone()]);

context.set_block_timestamp_in_days(365);

context.switch_account(&alice);
context.contract.claim_jars(vec![reference_jar.index], Some(U128(100)));
context.contract.claim_jars(vec![jar.index], Some(U128(100)));

let jar = context.contract.get_jar(U32(reference_jar.index));
let jar = context.contract.get_jar(U32(jar.index));
assert_eq!(100, jar.claimed_balance.0);
}

Expand Down
217 changes: 0 additions & 217 deletions contract/src/common.rs

This file was deleted.

15 changes: 15 additions & 0 deletions contract/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub(crate) mod tests;
pub(crate) mod u32;
pub(crate) mod udecimal;

/// Milliseconds since the Unix epoch (January 1, 1970 (midnight UTC/GMT))
pub type Timestamp = u64;

/// Duration in milliseconds
pub type Duration = u64;

/// Amount of fungible tokens
pub type TokenAmount = u128;

pub(crate) const MINUTES_IN_YEAR: u64 = 365 * 24 * 60;
pub(crate) const MS_IN_MINUTE: u64 = 1000 * 60;
Loading

0 comments on commit 67533b8

Please sign in to comment.