Skip to content

Commit

Permalink
fix: added typos check, fixed typos, fixed mutation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladasZ committed May 20, 2024
1 parent 9a12dd9 commit 63c3e54
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 31 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ env:
CARGO_TERM_COLOR: always

jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: crate-ci/[email protected]

lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -80,7 +85,7 @@ jobs:
path: measured.txt

push:
needs: [ build, lint, unit-tests, integration-tests, measure, mutation-tests ]
needs: [ build, typos, lint, unit-tests, integration-tests, measure, mutation-tests ]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ env:
CARGO_TERM_COLOR: always

jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: crate-ci/[email protected]

lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions contract/src/integration_test/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use sweat_jar_model::{api::IntegrationTestMethods, jar::JarView, ProductId};

use crate::{jar::model::Jar, Contract, ContractExt};

#[mutants::skip]
#[near_bindgen]
impl IntegrationTestMethods for Contract {
#[mutants::skip]
fn block_timestamp_ms(&self) -> Timestamp {
env::block_timestamp_ms()
}

#[mutants::skip]
fn bulk_create_jars(
&mut self,
account_id: AccountId,
Expand All @@ -27,6 +26,7 @@ impl IntegrationTestMethods for Contract {
}
}

#[mutants::skip]
impl Contract {
fn create_jar_for_integration_tests(
&mut self,
Expand Down
4 changes: 2 additions & 2 deletions contract/src/jar/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
};

impl Contract {
fn can_be_restacked(&self, jar: &Jar, now: u64) -> bool {
fn can_be_restaked(&self, jar: &Jar, now: u64) -> bool {
let product = self.get_product(&jar.product_id);
!jar.is_empty() && product.is_enabled && product.allows_restaking() && jar.is_liquidable(&product, now)
}
Expand Down Expand Up @@ -170,7 +170,7 @@ impl JarApi for Contract {
})
.jars
.iter()
.filter(|j| self.can_be_restacked(j, now))
.filter(|j| self.can_be_restaked(j, now))
.cloned()
.collect();

Expand Down
47 changes: 23 additions & 24 deletions contract/src/jar/tests/restake_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,67 @@ fn restake_all() {
let alice = alice();
let admin = admin();

let restackable_product = generate_product("restakable_product")
let restakable_product = generate_product("restakable_product")
.with_allows_restaking(true)
.lockup_term(MS_IN_YEAR);

let disabled_restackable_product = generate_product("disabled_restackable_product")
let disabled_restakable_product = generate_product("disabled_restakable_product")
.with_allows_restaking(true)
.enabled(false)
.lockup_term(MS_IN_YEAR);

let non_restackable_product = generate_product("non_restakable_product")
let non_restakable_product = generate_product("non_restakable_product")
.with_allows_restaking(false)
.lockup_term(MS_IN_YEAR);

let long_term_restackable_product = generate_product("long_term_restackable_product")
let long_term_restakable_product = generate_product("long_term_restakable_product")
.with_allows_restaking(true)
.lockup_term(MS_IN_YEAR * 2);

let restackable_jar_1 = Jar::generate(JAR_ID_RANGE.fake(), &alice, &restackable_product.id).principal(PRINCIPAL);
let restackable_jar_2 = Jar::generate(JAR_ID_RANGE.fake(), &alice, &restackable_product.id).principal(PRINCIPAL);
let restakable_jar_1 = Jar::generate(JAR_ID_RANGE.fake(), &alice, &restakable_product.id).principal(PRINCIPAL);
let restakable_jar_2 = Jar::generate(JAR_ID_RANGE.fake(), &alice, &restakable_product.id).principal(PRINCIPAL);

let disabled_jar =
Jar::generate(JAR_ID_RANGE.fake(), &alice, &disabled_restackable_product.id).principal(PRINCIPAL);
let disabled_jar = Jar::generate(JAR_ID_RANGE.fake(), &alice, &disabled_restakable_product.id).principal(PRINCIPAL);

let non_restackable_jar =
Jar::generate(JAR_ID_RANGE.fake(), &alice, &non_restackable_product.id).principal(PRINCIPAL);
let non_restakable_jar =
Jar::generate(JAR_ID_RANGE.fake(), &alice, &non_restakable_product.id).principal(PRINCIPAL);

let long_term_jar =
Jar::generate(JAR_ID_RANGE.fake(), &alice, &long_term_restackable_product.id).principal(PRINCIPAL);
Jar::generate(JAR_ID_RANGE.fake(), &alice, &long_term_restakable_product.id).principal(PRINCIPAL);

let mut context = Context::new(admin)
.with_products(&[
restackable_product,
disabled_restackable_product,
non_restackable_product,
long_term_restackable_product,
restakable_product,
disabled_restakable_product,
non_restakable_product,
long_term_restakable_product,
])
.with_jars(&[
restackable_jar_1.clone(),
restackable_jar_2.clone(),
restakable_jar_1.clone(),
restakable_jar_2.clone(),
disabled_jar.clone(),
non_restackable_jar.clone(),
non_restakable_jar.clone(),
long_term_jar.clone(),
]);

context.set_block_timestamp_in_days(366);

context.switch_account(&alice);

let restacked_jars = context.contract().restake_all();
let restaked_jars = context.contract().restake_all();

assert_eq!(restacked_jars.len(), 2);
assert_eq!(restacked_jars.iter().map(|j| j.id.0).collect::<Vec<_>>(), vec![1, 2]);
assert_eq!(restaked_jars.len(), 2);
assert_eq!(restaked_jars.iter().map(|j| j.id.0).collect::<Vec<_>>(), vec![1, 2]);

let all_jars = context.contract().get_jars_for_account(alice);

assert_eq!(
all_jars.iter().map(|j| j.id.0).collect::<Vec<_>>(),
[
restackable_jar_1.id,
restackable_jar_2.id,
restakable_jar_1.id,
restakable_jar_2.id,
disabled_jar.id,
non_restackable_jar.id,
non_restakable_jar.id,
long_term_jar.id,
1,
2,
Expand Down
1 change: 1 addition & 0 deletions contract/src/withdraw/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl Contract {
}

#[near_bindgen]
#[mutants::skip] // Covered by integration tests
impl WithdrawCallbacks for Contract {
#[private]
fn after_withdraw(
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/restake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ async fn restake_all() -> Result<()> {

context.sweat_jar().claim_total(None).with_user(&alice).await?;

let restacked = context.sweat_jar().restake_all().with_user(&alice).await?;
let restaked = context.sweat_jar().restake_all().with_user(&alice).await?;

assert_eq!(
restacked.into_iter().map(|j| j.principal).collect::<Vec<_>>()[..2],
restaked.into_iter().map(|j| j.principal).collect::<Vec<_>>()[..2],
vec![jar_5_min_1.principal, jar_5_min_2.principal]
);

Expand Down
Binary file modified res/sweat_jar.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default.extend-words]
# TGE - Token Generation Event
tge = "tge"

0 comments on commit 63c3e54

Please sign in to comment.