Skip to content

Commit

Permalink
fix: toString() print address with checksum (foundry-rs#2184)
Browse files Browse the repository at this point in the history
* fix: toString() print address with checksum

* fix: remove unecessery format

* fix: fix tests

* fix; optimism msg?
  • Loading branch information
odyslam authored Jul 1, 2022
1 parent 5dce8c0 commit 24a9fb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cast/src/print_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ mod tests {
let block: Block<Transaction> = serde_json::from_str(block).unwrap();
let output ="\nblockHash 0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972
blockNumber 3
from 0xfdcedc3bfca10ecb0890337fbdd1977aba84807a
from 0xFdCeDC3bFca10eCb0890337fbdD1977aba84807a
gas 90000
gasPrice 20000000000
hash 0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067
input 0x
nonce 2
r 0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88
s 0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e
to 0xdca8ce283150ab773bcbeb8d38289bdb5661de1e
to 0xdca8ce283150AB773BCbeB8d38289bdB5661dE1e
transactionIndex 0
v 37
value 0".to_string();
Expand Down Expand Up @@ -157,7 +157,7 @@ value 0".to_string();
get_pretty_tx_attr(_block.transactions[0].clone(), "blockNumber")
);
assert_eq!(
Some("0xfdcedc3bfca10ecb0890337fbdd1977aba84807a".to_string()),
Some("0xFdCeDC3bFca10eCb0890337fbdD1977aba84807a".to_string()),
get_pretty_tx_attr(_block.transactions[0].clone(), "from")
);
assert_eq!(
Expand Down Expand Up @@ -189,7 +189,7 @@ value 0".to_string();
get_pretty_tx_attr(_block.transactions[0].clone(), "s")
);
assert_eq!(
Some("0xdca8ce283150ab773bcbeb8d38289bdb5661de1e".to_string()),
Some("0xdca8ce283150AB773BCbeB8d38289bdB5661dE1e".into()),
get_pretty_tx_attr(_block.transactions[0].clone(), "to")
);
assert_eq!(
Expand Down
14 changes: 7 additions & 7 deletions common/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains a helper pretty() function to print human redeable string versions of usual ethers
//! types
use ethers_core::types::*;
use ethers_core::{types::*, utils::to_checksum};
use std::str;

/// length of the name column for pretty formatting `{:>20}{value}`
Expand Down Expand Up @@ -37,9 +37,9 @@ impl UIfmt for I256 {
}
}

impl UIfmt for H160 {
impl UIfmt for Address {
fn pretty(&self) -> String {
format!("{:#x}", self)
to_checksum(self, None)
}
}

Expand Down Expand Up @@ -308,13 +308,13 @@ mod tests {
{
"blockHash": "0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae",
"blockNumber": "0x1b4",
"from": "0x3b179dcfc5faa677044c27dce958e4bc0ad696a6",
"from": "0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6",
"gas": "0x11cbbdc",
"gasPrice": "0x0",
"hash": "0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f",
"input": "0xd294f093",
"nonce": "0xa2",
"to": "0x4a16a42407aa491564643e1dfc1fd50af29794ef",
"to": "0x4a16A42407AA491564643E1dfc1fd50af29794eF",
"transactionIndex": "0x0",
"value": "0x0",
"v": "0x38",
Expand All @@ -336,15 +336,15 @@ mod tests {
r#"
blockHash 0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae
blockNumber 436
from 0x3b179dcfc5faa677044c27dce958e4bc0ad696a6
from 0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6
gas 18660316
gasPrice 0
hash 0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f
input 0xd294f093
nonce 162
r 0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee
s 0x0e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
to 0x4a16a42407aa491564643e1dfc1fd50af29794ef
to 0x4a16A42407AA491564643E1dfc1fd50af29794eF
transactionIndex 0
v 56
value 0
Expand Down
4 changes: 2 additions & 2 deletions testdata/cheats/ToString.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ contract ToStringTest is DSTest {
Cheats constant cheats = Cheats(HEVM_ADDRESS);

function testAddressToString() public {
address testAddress = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
address testAddress = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
string memory stringAddress = cheats.toString(testAddress);
assertEq("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", stringAddress);
assertEq("0x7109709ECfa91a80626fF3989D68f67F5b1DD12D", stringAddress);
}


Expand Down

0 comments on commit 24a9fb8

Please sign in to comment.