Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct formatting of decimals in ds-test logs [WIP] #361

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions evm-adapters/src/sputnik/cheatcodes/cheatcode_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub(crate) fn convert_log(log: Log) -> Option<String> {
),
LogNamedDecimalUintFilter(inner) => {
format!(
"{}: {:?}",
"{}: {}",
inner.key,
ethers::utils::parse_units(inner.val, inner.decimals.as_u32()).unwrap()
ethers::utils::format_units(inner.val, inner.decimals.as_u32()).unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need this same change a few lines up for LogNamedDecimalIntFilter right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, although that may have to be an ethers-rs fix, getting this error when changing parse_units to format_units

ethers::utils::format_units(inner.val, inner.decimals.as_u32()).unwrap()
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<ethers::prelude::I256>` is not implemented for `ethers::prelude::U256`

Copy link
Member

@gakonst gakonst Jan 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we do not support I256 for format units:

You could do this here by getting the absolute value of the I256, formatting it as string, and then prepending a minus if its sign is a negative number.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding support for I256 to ethers-rs is probably the best way to do this right? If so we can merge this PR, and I (or @nanexcool if you'd rather do it) can take a shot at adding I256 support to ethers-rs format_units, then follow up with a PR here to change LogNamedDecimalIntFilter to use format_units

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mds1 I think I'm gonna do a couple of Rust tutorials first instead of heading straight for another PR 😂 Go for it!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good! I've been working my way through rustlings which has been pretty good, but please share any good rust tutorials you find! 😛

)
}
LogNamedIntFilter(inner) => format!("{}: {:?}", inner.key, inner.val),
Expand Down Expand Up @@ -1283,7 +1283,7 @@ mod tests {
"addr: 0x2222222222222222222222222222222222222222",
"key: 0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d",
"key: 123000000000000000000",
"key: 1234000000000000000000",
"key: 0.000000000000001234",
"key: 123",
"key: 1234",
"key: 0x4567",
Expand Down