Skip to content

Commit

Permalink
runtime-sdk/modules/evm: Use token denomination from config
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Apr 2, 2024
1 parent ce43275 commit 74b5090
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions runtime-sdk/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,13 @@ impl<Cfg: Config> module::TransactionHandler for Module<Cfg> {
.unwrap_or_default();

Ok(Some(
raw_tx::decode(body, Some(Cfg::CHAIN_ID), min_gas_price)
.map_err(CoreError::MalformedTransaction)?,
raw_tx::decode(
body,
Some(Cfg::CHAIN_ID),
min_gas_price,
&Cfg::TOKEN_DENOMINATION,

Check warning on line 769 in runtime-sdk/modules/evm/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

runtime-sdk/modules/evm/src/lib.rs#L764-L769

Added lines #L764 - L769 were not covered by tests
)
.map_err(CoreError::MalformedTransaction)?,
))
}
_ => Ok(None),
Expand Down
20 changes: 17 additions & 3 deletions runtime-sdk/modules/evm/src/raw_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn decode(
body: &[u8],
expected_chain_id: Option<u64>,
min_gas_price: u128,
denom: &token::Denomination,
) -> Result<transaction::Transaction, anyhow::Error> {
let (
chain_id,
Expand Down Expand Up @@ -187,7 +188,7 @@ pub fn decode(
nonce,
}],
fee: transaction::Fee {
amount: token::BaseUnits(resolved_fee_amount, token::Denomination::NATIVE),
amount: token::BaseUnits::new(resolved_fee_amount, denom.clone()),
gas: gas_limit,
consensus_messages: 0, // Dynamic number of consensus messages, limited by gas.
},
Expand Down Expand Up @@ -225,6 +226,7 @@ mod test {
&Vec::from_hex(raw).unwrap(),
expected_chain_id,
min_gas_price,
&token::Denomination::NATIVE,
)
.unwrap();
println!("{:?}", &tx);
Expand Down Expand Up @@ -263,6 +265,7 @@ mod test {
&Vec::from_hex(raw).unwrap(),
expected_chain_id,
min_gas_price,
&token::Denomination::NATIVE,
)
.unwrap();
println!("{:?}", &tx);
Expand All @@ -285,7 +288,13 @@ mod test {
}

fn decode_expect_invalid(raw: &str, expected_chain_id: Option<u64>) {
let e = decode(&Vec::from_hex(raw).unwrap(), expected_chain_id, 0).unwrap_err();
let e = decode(
&Vec::from_hex(raw).unwrap(),
expected_chain_id,
0,
&token::Denomination::NATIVE,
)
.unwrap_err();
eprintln!("Decoding error (expected): {:?}", e);
}

Expand All @@ -294,7 +303,12 @@ mod test {
expected_chain_id: Option<u64>,
unexpected_from: &str,
) {
match decode(&Vec::from_hex(raw).unwrap(), expected_chain_id, 0) {
match decode(
&Vec::from_hex(raw).unwrap(),
expected_chain_id,
0,
&token::Denomination::NATIVE,
) {
Ok(tx) => {
assert_ne!(
derive_caller::from_tx_auth_info(&tx.auth_info).unwrap(),
Expand Down

0 comments on commit 74b5090

Please sign in to comment.