Skip to content

Commit

Permalink
Merge pull request #29 from osmosis-labs/asset-removal
Browse files Browse the repository at this point in the history
Corrupted Assets
  • Loading branch information
iboss-ptk authored Mar 28, 2024
2 parents 47bbb02 + c720190 commit fcf45f1
Show file tree
Hide file tree
Showing 15 changed files with 1,295 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/transmuter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ thiserror = {version = "1.0.44"}

[dev-dependencies]
itertools = "0.12.0"
osmosis-test-tube = "22.0.0"
osmosis-test-tube = "22.1.0"
rstest = "0.18.2"
36 changes: 36 additions & 0 deletions contracts/transmuter/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl AssetConfig {
amount: Uint128::zero(),
denom: self.denom,
normalization_factor: self.normalization_factor,
is_corrupted: false,
})
}
}
Expand All @@ -52,6 +53,7 @@ pub struct Asset {
amount: Uint128,
denom: String,
normalization_factor: Uint128,
is_corrupted: bool,
}

impl Asset {
Expand All @@ -64,6 +66,7 @@ impl Asset {
amount: amount.into(),
denom: denom.to_string(),
normalization_factor: normalization_factor.into(),
is_corrupted: false,
}
}

Expand Down Expand Up @@ -112,6 +115,16 @@ impl Asset {
Ok(self)
}

pub fn mark_as_corrupted(&'_ mut self) -> &'_ Self {
self.is_corrupted = true;
self
}

pub fn unmark_as_corrupted(&'_ mut self) -> &'_ Self {
self.is_corrupted = false;
self
}

pub fn denom(&self) -> &str {
&self.denom
}
Expand All @@ -124,6 +137,10 @@ impl Asset {
self.normalization_factor
}

pub fn is_corrupted(&self) -> bool {
self.is_corrupted
}

pub fn config(&self) -> AssetConfig {
AssetConfig {
denom: self.denom.clone(),
Expand All @@ -144,6 +161,7 @@ impl Asset {
amount,
denom: denom.to_string(),
normalization_factor,
is_corrupted: false,
}
}

Expand Down Expand Up @@ -350,6 +368,7 @@ mod tests {
amount: Uint128::zero(),
denom: "denom1".to_string(),
normalization_factor: Uint128::one(),
is_corrupted: false,
}
);

Expand All @@ -364,6 +383,7 @@ mod tests {
amount: Uint128::zero(),
denom: "denom2".to_string(),
normalization_factor: Uint128::from(1000000u128),
is_corrupted: false,
}
);

Expand All @@ -383,6 +403,7 @@ mod tests {
amount: Uint128::zero(),
denom: "denom1".to_string(),
normalization_factor: Uint128::one(),
is_corrupted: false,
};

assert_eq!(
Expand All @@ -398,4 +419,19 @@ mod tests {
ContractError::NormalizationFactorMustBePositive {}
);
}

#[test]
fn test_mark_as_corrupted() {
let mut asset = Asset {
amount: Uint128::zero(),
denom: "denom1".to_string(),
normalization_factor: Uint128::one(),
is_corrupted: false,
};

assert_eq!(asset.is_corrupted(), false);

assert_eq!(asset.mark_as_corrupted().is_corrupted(), true);
assert_eq!(asset.is_corrupted(), true);
}
}
Loading

0 comments on commit fcf45f1

Please sign in to comment.