Skip to content

Commit

Permalink
begin work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NYBACHOK committed Oct 29, 2024
1 parent 60ecc77 commit a34c19a
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions x/mint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ serde_json = { workspace = true }
# utils
anyhow = { workspace = true }
tracing = { workspace = true }
# strum = { workspace = true }

# nutypes
ibc-proto = { workspace = true }
# nutype = { workspace = true, features = ["serde"]}

#clients
clap = { workspace = true }
clap = { workspace = true }

[dev-dependencies]
data-encoding = { workspace = true }
strum = { workspace = true }
2 changes: 1 addition & 1 deletion x/mint/src/abci_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const MISSING_MINTER_ERR_MSG: &str =
pub struct MintAbciHandler<SK, PSK, BK, STK, M, MI> {
keeper: MintKeeper<SK, BK, STK, M>,
params_keeper: MintParamsKeeper<PSK>,
_marker: PhantomData<(MI, SK, PSK, M)>,
_marker: PhantomData<MI>,
}

impl<SK, PSK, BK, STK, M, MI> MintAbciHandler<SK, PSK, BK, STK, M, MI> {
Expand Down
4 changes: 2 additions & 2 deletions x/mint/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use gears::baseapp::genesis::Genesis;
use serde::{Deserialize, Serialize};

use crate::{params::MintingParams, types::minter::Minter};
use crate::{params::MintParams, types::minter::Minter};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MintGenesis {
pub minter: Minter,
pub params: MintingParams,
pub params: MintParams,
}

impl Genesis for MintGenesis {
Expand Down
10 changes: 5 additions & 5 deletions x/mint/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const GOAL_BONDED_KEY: &str = "GoalBonded";
const BLOCKS_PER_YEAR_KEY: &str = "BlocksPerYear";

#[derive(Debug, Clone, Serialize, Deserialize, Raw, Protobuf)]
pub struct MintingParams {
pub struct MintParams {
/// denom of coin to mint
#[raw(kind(string), raw = String)]
pub mint_denom: Denom,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub struct MintingParams {
pub blocks_per_year: u32,
}

impl Default for MintingParams {
impl Default for MintParams {
fn default() -> Self {
Self {
mint_denom: Denom::from_str(env!("XMOD_STAKING_PARAMS_BOND_DENOM"))
Expand All @@ -82,7 +82,7 @@ impl Default for MintingParams {
}
}

impl ParamsSerialize for MintingParams {
impl ParamsSerialize for MintParams {
fn keys() -> HashSet<&'static str> {
HashSet::from_iter([
MINT_DENOM_KEY,
Expand Down Expand Up @@ -123,7 +123,7 @@ impl ParamsSerialize for MintingParams {
}
}

impl ParamsDeserialize for MintingParams {
impl ParamsDeserialize for MintParams {
fn from_raw(fields: HashMap<&'static str, Vec<u8>>) -> Self {
Self {
mint_denom: Denom::from_str(&String::from_utf8_lossy(
Expand Down Expand Up @@ -160,7 +160,7 @@ pub struct MintParamsKeeper<PSK> {
}

impl<PSK: ParamsSubspaceKey> ParamsKeeper<PSK> for MintParamsKeeper<PSK> {
type Param = MintingParams;
type Param = MintParams;

fn psk(&self) -> &PSK {
&self.params_subspace_key
Expand Down
6 changes: 3 additions & 3 deletions x/mint/src/types/minter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use gears::{
types::decimal256::Decimal256,
};

use crate::params::MintingParams;
use crate::params::MintParams;

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, Raw, Protobuf)]
pub struct Minter {
Expand Down Expand Up @@ -40,7 +40,7 @@ impl Default for Minter {
impl Minter {
pub fn next_inflation_rate(
&self,
params: &MintingParams,
params: &MintParams,
bonded_ratio: Decimal256,
) -> Option<Decimal256> {
let inflation_change_per_year = Decimal256::one()
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Minter {
self.inflation.checked_mul(total_supply).ok()
}

pub fn block_provision(&self, params: &MintingParams) -> Option<UnsignedCoin> {
pub fn block_provision(&self, params: &MintParams) -> Option<UnsignedCoin> {
let provision_amount = self
.annual_provisions
.checked_div(Decimal256::new(Uint256::from(params.blocks_per_year)))
Expand Down
6 changes: 3 additions & 3 deletions x/mint/src/types/query/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use gears::{
types::decimal256::{CosmosDecimalProtoString, Decimal256},
};

use crate::params::{MintingParams, RawMintingParams};
use crate::params::{MintParams, RawMintParams};

#[derive(Debug, Clone, Raw, Query, Protobuf, serde::Serialize, serde::Deserialize)]
pub struct QueryParamsResponse {
#[raw(kind(message), raw = RawMintingParams)]
pub params: MintingParams,
#[raw(kind(message), raw = RawMintParams)]
pub params: MintParams,
}

#[derive(Debug, Clone, Raw, Query, Protobuf, serde::Serialize, serde::Deserialize)]
Expand Down
19 changes: 19 additions & 0 deletions x/mint/tests/abci_init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use gears::tendermint::types::time::timestamp::Timestamp;
use utils::set_node;

#[path = "./utils.rs"]
mod utils;

#[test]
fn test_init_and_few_blocks() {
let mut node = set_node();

let app_hash = &node.step(vec![], Timestamp::UNIX_EPOCH).app_hash;

assert_eq!(data_encoding::HEXLOWER.encode(app_hash), "");

node.skip_steps(100);

let app_hash = &node.step(vec![], Timestamp::UNIX_EPOCH).app_hash;
assert_eq!(data_encoding::HEXLOWER.encode(app_hash), "");
}
Loading

0 comments on commit a34c19a

Please sign in to comment.