Skip to content

Commit

Permalink
add defaults where applicable and skip for unviable and timeout mutants
Browse files Browse the repository at this point in the history
  • Loading branch information
ASuciuX committed Jan 8, 2025
1 parent 79e7f30 commit 5dd69b8
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
Runehook.toml
.DS_Store
/mutants.out
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ maplit = "1.0.2"

[dev-dependencies]
test-case = "3.1.0"
mutants = "0.0.3"

[features]
debug = ["hiro-system-kit/debug"]
Expand Down
1 change: 1 addition & 0 deletions src/bitcoind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use chainhook_sdk::{

use crate::{config::Config, try_error};

#[cfg_attr(test, mutants::skip)]
fn get_client(config: &Config, ctx: &Context) -> Client {
loop {
let auth = Auth::UserPass(
Expand Down
3 changes: 3 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Config {
}

impl Config {
#[cfg_attr(test, mutants::skip)]
pub fn from_file_path(file_path: &str) -> Result<Config, String> {
let file = File::open(file_path)
.map_err(|e| format!("unable to read file {}\n{:?}", file_path, e))?;
Expand All @@ -49,6 +50,7 @@ impl Config {
Config::from_config_file(config_file)
}

#[cfg_attr(test, mutants::skip)]
pub fn from_config_file(config_file: ConfigFile) -> Result<Config, String> {
let event_observer =
EventObserverConfig::new_using_overrides(config_file.network.as_ref())?;
Expand All @@ -75,6 +77,7 @@ impl Config {
Ok(config)
}

#[cfg_attr(test, mutants::skip)]
pub fn get_bitcoin_network(&self) -> Network {
match self.event_observer.bitcoin_network {
BitcoinNetwork::Mainnet => Network::Bitcoin,
Expand Down
2 changes: 1 addition & 1 deletion src/db/cache/input_rune_balance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct InputRuneBalance {
/// Previous owner of this balance. If this is `None`, it means the balance was just minted or premined.
pub address: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions src/db/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn get_rune_genesis_block_height(network: Network) -> u64 {

/// Transforms a Bitcoin transaction from a Chainhook format to a rust bitcoin crate format so it can be parsed by the ord crate
/// to look for `Artifact`s. Also, takes all non-OP_RETURN outputs and returns them so they can be used later to receive runes.
#[cfg_attr(test, mutants::skip)]
fn bitcoin_tx_from_chainhook_tx(
block: &BitcoinBlockData,
tx: &BitcoinTransactionData,
Expand Down
2 changes: 2 additions & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async fn pg_run_migrations(pg_client: &mut Client, ctx: &Context) {
try_info!(ctx, "Postgres migrations complete");
}

#[cfg_attr(test, mutants::skip)]
pub async fn pg_connect(config: &Config, run_migrations: bool, ctx: &Context) -> Client {
let mut pg_config = tokio_postgres::Config::new();
pg_config
Expand Down Expand Up @@ -441,6 +442,7 @@ pub async fn pg_get_rune_total_mints(
/// Retrieves the rune balance for an array of transaction inputs represented by `(vin, tx_id, vout)` where `vin` is the index of
/// this transaction input, `tx_id` is the transaction ID that produced this input and `vout` is the output index of this previous
/// tx.
#[cfg_attr(test, mutants::skip)]
pub async fn pg_get_input_rune_balances(
outputs: Vec<(u32, String, u32)>,
db_tx: &mut Transaction<'_>,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/db_balance_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::db::types::{
pg_bigint_u32::PgBigIntU32, pg_numeric_u128::PgNumericU128, pg_numeric_u64::PgNumericU64,
};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct DbBalanceChange {
pub rune_id: String,
pub block_height: PgNumericU64,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/db_ledger_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::db::types::{
use super::db_ledger_operation::DbLedgerOperation;

/// A row in the `ledger` table.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct DbLedgerEntry {
pub rune_id: String,
pub block_hash: String,
Expand Down
4 changes: 3 additions & 1 deletion src/db/models/db_ledger_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use bytes::BytesMut;
use tokio_postgres::types::{to_sql_checked, FromSql, IsNull, ToSql, Type};

/// A value from the `ledger_operation` enum type.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Default)]
pub enum DbLedgerOperation {
#[default]
Etching,
Mint,
Burn,
Expand Down Expand Up @@ -47,6 +48,7 @@ impl std::str::FromStr for DbLedgerOperation {
}

impl ToSql for DbLedgerOperation {
#[cfg_attr(test, mutants::skip)]
fn to_sql(
&self,
_ty: &Type,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/db_rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::db::{
};

/// A row in the `runes` table.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct DbRune {
pub id: String,
pub number: PgBigIntU32,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/db_supply_change.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::db::types::{pg_numeric_u128::PgNumericU128, pg_numeric_u64::PgNumericU64};

/// An update to a rune that affects its total counts.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct DbSupplyChange {
pub rune_id: String,
pub block_height: PgNumericU64,
Expand Down
23 changes: 21 additions & 2 deletions src/db/types/pg_bigint_u32.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{error::Error, ops::AddAssign};
use std::{error::Error, ops::{AddAssign, DivAssign, MulAssign, SubAssign}};

use bytes::{BufMut, BytesMut};
use tokio_postgres::types::{to_sql_checked, FromSql, IsNull, ToSql, Type};

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Default)]
pub struct PgBigIntU32(pub u32);

impl ToSql for PgBigIntU32 {
#[cfg_attr(test, mutants::skip)]
fn to_sql(
&self,
_ty: &Type,
Expand Down Expand Up @@ -41,6 +42,24 @@ impl AddAssign<u32> for PgBigIntU32 {
}
}

impl SubAssign<u32> for PgBigIntU32 {
fn sub_assign(&mut self, other: u32) {
self.0 -= other;
}
}

impl MulAssign<u32> for PgBigIntU32 {
fn mul_assign(&mut self, other: u32) {
self.0 *= other;
}
}

impl DivAssign<u32> for PgBigIntU32 {
fn div_assign(&mut self, other: u32) {
self.0 /= other;
}
}

#[cfg(test)]
mod test {
use chainhook_sdk::utils::Context;
Expand Down
42 changes: 40 additions & 2 deletions src/db/types/pg_numeric_u128.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::{
error::Error,
io::{Cursor, Read},
ops::AddAssign,
ops::{AddAssign, DivAssign, MulAssign, SubAssign},
};

use bytes::{BufMut, BytesMut};
use num_traits::{ToPrimitive, Zero};
use tokio_postgres::types::{to_sql_checked, FromSql, IsNull, ToSql, Type};

/// Transforms a u128 value into postgres' `numeric` wire format.
#[cfg_attr(test, mutants::skip)]
pub fn u128_into_pg_numeric_bytes(number: u128, out: &mut BytesMut) {
let mut num = number.clone();
let mut digits = vec![];
Expand Down Expand Up @@ -64,10 +65,11 @@ pub fn pg_numeric_bytes_to_u128(raw: &[u8]) -> u128 {
result
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct PgNumericU128(pub u128);

impl ToSql for PgNumericU128 {
#[cfg_attr(test, mutants::skip)]
fn to_sql(
&self,
_ty: &Type,
Expand Down Expand Up @@ -107,6 +109,42 @@ impl AddAssign<u128> for PgNumericU128 {
}
}

impl SubAssign for PgNumericU128 {
fn sub_assign(&mut self, other: Self) {
self.0 -= other.0;
}
}

impl SubAssign<u128> for PgNumericU128 {
fn sub_assign(&mut self, other: u128) {
self.0 -= other;
}
}

impl MulAssign for PgNumericU128 {
fn mul_assign(&mut self, other: Self) {
self.0 *= other.0;
}
}

impl MulAssign<u128> for PgNumericU128 {
fn mul_assign(&mut self, other: u128) {
self.0 *= other;
}
}

impl DivAssign for PgNumericU128 {
fn div_assign(&mut self, other: Self) {
self.0 /= other.0;
}
}

impl DivAssign<u128> for PgNumericU128 {
fn div_assign(&mut self, other: u128) {
self.0 /= other;
}
}

#[cfg(test)]
mod test {
use chainhook_sdk::utils::Context;
Expand Down
3 changes: 2 additions & 1 deletion src/db/types/pg_numeric_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use tokio_postgres::types::{to_sql_checked, FromSql, IsNull, ToSql, Type};

use super::pg_numeric_u128::{pg_numeric_bytes_to_u128, u128_into_pg_numeric_bytes};

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Default)]
pub struct PgNumericU64(pub u64);

impl ToSql for PgNumericU64 {
#[cfg_attr(test, mutants::skip)]
fn to_sql(
&self,
_ty: &Type,
Expand Down
3 changes: 2 additions & 1 deletion src/db/types/pg_smallint_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::error::Error;
use bytes::{BufMut, BytesMut};
use tokio_postgres::types::{to_sql_checked, FromSql, IsNull, ToSql, Type};

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Default)]
pub struct PgSmallIntU8(pub u8);

impl ToSql for PgSmallIntU8 {
#[cfg_attr(test, mutants::skip)]
fn to_sql(
&self,
_ty: &Type,
Expand Down
1 change: 1 addition & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub async fn start_service(config: &Config, ctx: &Context) -> Result<(), String>
Ok(())
}

#[cfg_attr(test, mutants::skip)]
pub async fn set_up_observer_sidecar_runloop(
config: &Config,
ctx: &Context,
Expand Down

0 comments on commit 5dd69b8

Please sign in to comment.