Skip to content

Commit ffbd4ab

Browse files
committed
Fixed a bad unwrap
1 parent 9eb380a commit ffbd4ab

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

primitives/src/targeting/eval.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,11 @@ fn eval(input: &Input, output: &mut Output, rule: &Rule) -> Result<Option<Value>
895895
.try_bignum()?;
896896
let deposit_asset = &input.global.channel.deposit_asset;
897897

898-
let divisor = DEPOSIT_ASSETS_MAP.get(deposit_asset).unwrap();
899-
Some(Value::BigNum(amount.div(divisor)))
898+
let divisor = match DEPOSIT_ASSETS_MAP.get(deposit_asset) {
899+
Some(d) => Ok(d),
900+
None => Err(Error::TypeError),
901+
};
902+
Some(Value::BigNum(amount.div(divisor?)))
900903
}
901904
Function::Do(first_rule) => eval(input, output, first_rule)?,
902905
Function::Set(key, rule) => {

primitives/src/targeting/eval_test.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ mod string_and_array {
13061306
}
13071307

13081308
#[test]
1309-
fn test_get_dai_price_in_usd_eval() {
1309+
fn test_get_price_in_usd_eval() {
13101310
let mut input = get_default_input();
13111311

13121312
let mut output = Output {
@@ -1323,11 +1323,5 @@ mod string_and_array {
13231323
))));
13241324
assert_eq!(Ok(amount_usd), rule.eval(&input, &mut output));
13251325
}
1326-
let amount_dai = BigNum::from_str("100000000000000000000").expect("Should create BigNum"); // 100 DAI
1327-
let amount_usd = Some(Value::BigNum(BigNum::from(100)));
1328-
let rule = Rule::Function(Function::new_get_price_in_usd(Rule::Value(Value::BigNum(
1329-
amount_dai,
1330-
))));
1331-
assert_eq!(Ok(amount_usd), rule.eval(&input, &mut output));
13321326
}
13331327
}

0 commit comments

Comments
 (0)