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

dep(fmt,chisel,doc): update solang-parser to 0.2.3 #4477

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
58 changes: 24 additions & 34 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use ethers::{
prelude::{BlockNumber, GethTraceFrame, TxHash, H256, U256, U64},
types::{
transaction::eip2930::AccessList, Address, Block as EthersBlock, BlockId, Bytes,
DefaultFrame, Filter, FilteredParams, GethDebugTracingOptions, GethTrace, Log, Trace,
Transaction, TransactionReceipt,
DefaultFrame, Filter, FilteredParams, GethDebugTracingOptions, GethTrace, Log, OtherFields,
Trace, Transaction, TransactionReceipt,
},
utils::{get_contract_address, hex, keccak256, rlp},
};
Expand Down Expand Up @@ -1752,6 +1752,7 @@ impl Backend {
logs_bloom,
transaction_type: transaction_type.map(Into::into),
effective_gas_price: Some(effective_gas_price),
other: OtherFields::default(),
};

Some(MinedTransactionReceipt { inner, out: info.out })
Expand Down
2 changes: 1 addition & 1 deletion chisel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ reqwest = { version = "0.11", default-features = false, features = ["rustls"] }
# misc
clap = { version = "4.0", features = ["derive", "env", "wrap_help"] }
rustyline = "10.0.0"
solang-parser = "=0.2.2"
solang-parser = "=0.2.3"
yansi = "0.5.1"
strum = { version = "0.24.1", features = ["derive"] }
serde = "1.0.145"
Expand Down
54 changes: 29 additions & 25 deletions chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ impl Type {
pt::Expression::Parenthesis(_, inner) | // (<inner>)
pt::Expression::New(_, inner) | // new <inner>
pt::Expression::UnaryPlus(_, inner) | // +<inner>
pt::Expression::Unit(_, inner, _) | // <inner> *unit*
// ops
pt::Expression::Complement(_, inner) | // ~<inner>
pt::Expression::ArraySlice(_, inner, _, _) | // <inner>[*start*:*end*]
Expand Down Expand Up @@ -486,7 +485,7 @@ impl Type {

// address
pt::Expression::AddressLiteral(_, _) => Some(Self::Builtin(ParamType::Address)),
pt::Expression::HexNumberLiteral(_, s) => {
pt::Expression::HexNumberLiteral(_, s, _) => {
match s.parse() {
Ok(addr) => {
let checksummed = ethers::utils::to_checksum(&addr, None);
Expand All @@ -504,7 +503,7 @@ impl Type {

// uint and int
// invert
pt::Expression::UnaryMinus(_, inner) => Self::from_expression(inner).map(Self::invert_int),
pt::Expression::Negate(_, inner) => Self::from_expression(inner).map(Self::invert_int),

// int if either operand is int
// TODO: will need an update for Solidity v0.8.18 user defined operators:
Expand Down Expand Up @@ -533,10 +532,10 @@ impl Type {
pt::Expression::BitwiseXor(_, _, _) |
pt::Expression::ShiftRight(_, _, _) |
pt::Expression::ShiftLeft(_, _, _) |
pt::Expression::NumberLiteral(_, _, _) => Some(Self::Builtin(ParamType::Uint(256))),
pt::Expression::NumberLiteral(_, _, _, _) => Some(Self::Builtin(ParamType::Uint(256))),

// TODO: Rational numbers
pt::Expression::RationalNumberLiteral(_, _, _, _) => {
pt::Expression::RationalNumberLiteral(_, _, _, _, _) => {
Some(Self::Builtin(ParamType::Uint(256)))
}

Expand Down Expand Up @@ -1124,39 +1123,44 @@ fn types_to_parameters(

fn parse_number_literal(expr: &pt::Expression) -> Option<U256> {
match expr {
pt::Expression::NumberLiteral(_, num, exp) => {
pt::Expression::NumberLiteral(_, num, exp, unit) => {
let num = U256::from_dec_str(num).unwrap_or(U256::zero());
let exp = exp.parse().unwrap_or(0u32);
if exp > 77 {
None
} else {
Some(num * U256::from(10usize.pow(exp)))
let exp = U256::from(10usize.pow(exp));
let unit_mul = unit_multiplier(unit).ok()?;
Some(num * exp * unit_mul)
}
}
pt::Expression::HexNumberLiteral(_, num) => num.parse::<U256>().ok(),
// TODO: Rational numbers
pt::Expression::RationalNumberLiteral(_, _, _, _) => None,

pt::Expression::Unit(_, expr, unit) => {
parse_number_literal(expr).map(|x| x * unit_multiplier(unit))
pt::Expression::HexNumberLiteral(_, num, unit) => {
let unit_mul = unit_multiplier(unit).ok()?;
num.parse::<U256>().map(|num| num * unit_mul).ok()
}

// TODO: Rational numbers
pt::Expression::RationalNumberLiteral(..) => None,
_ => None,
}
}

#[inline]
const fn unit_multiplier(unit: &pt::Unit) -> usize {
use pt::Unit::*;
match unit {
Seconds(_) => 1,
Minutes(_) => 60,
Hours(_) => 60 * 60,
Days(_) => 60 * 60 * 24,
Weeks(_) => 60 * 60 * 24 * 7,
Wei(_) => 1,
Gwei(_) => 10_usize.pow(9),
Ether(_) => 10_usize.pow(18),
fn unit_multiplier(unit: &Option<pt::Identifier>) -> Result<U256> {
if let Some(unit) = unit {
let mul = match unit.name.as_str() {
"seconds" => 1,
"minutes" => 60,
"hours" => 60 * 60,
"days" => 60 * 60 * 24,
"weeks" => 60 * 60 * 24 * 7,
"wei" => 1,
"gwei" => 10_usize.pow(9),
"ether" => 10_usize.pow(18),
other => eyre::bail!("unknown unit: {other}"),
};
Ok(mul.into())
} else {
Ok(U256::one())
}
}

Expand Down
17 changes: 5 additions & 12 deletions chisel/src/solidity_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,16 @@ impl<'a> TokenStyle for Token<'a> {
HexNumber(_) |
True |
False |
Seconds |
Minutes |
Hours |
Days |
Weeks |
Gwei |
Wei |
Ether |
This => Color::Yellow.style(),
Memory | Storage | Calldata | Public | Private | Internal | External | Constant |
Pure | View | Payable | Anonymous | Indexed | Abstract | Virtual | Override |
Modifier | Immutable | Unchecked => Color::Cyan.style(),
Contract | Library | Interface | Function | Pragma | Import | Struct | Event |
Error | Enum | Type | Constructor | As | Is | Using | New | Delete | Do |
Continue | Break | Throw | Emit | Return | Returns | Revert | For | While | If |
Else | Try | Catch | Assembly | Let | Leave | Switch | Case | Default | YulArrow |
Arrow => Color::Magenta.style(),
Enum | Type | Constructor | As | Is | Using | New | Delete | Do | Continue |
Break | Throw | Emit | Return | Returns | Revert | For | While | If | Else | Try |
Catch | Assembly | Let | Leave | Switch | Case | Default | YulArrow | Arrow => {
Color::Magenta.style()
}
Uint(_) | Int(_) | Bytes(_) | Byte | DynamicBytes | Bool | Address | String |
Mapping => Color::Blue.style(),
Identifier(_) => Style::default(),
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ui = { path = "../ui" }

# eth
ethers = { git = "https://github.com/gakonst/ethers-rs", default-features = false, features = ["rustls"] }
solang-parser = "=0.2.2"
solang-parser = "=0.2.3"

# cli
clap = { version = "4.0", features = ["derive", "env", "unicode", "wrap_help"] }
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cmd/forge/geiger/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Visitor for CheatcodeVisitor {
Expression::UnaryPlus(_, expr) => {
expr.visit(self)?;
}
Expression::UnaryMinus(_, expr) => {
Expression::Negate(_, expr) => {
expr.visit(self)?;
}
Expression::Power(_, lhs, rhs) => {
Expand Down
2 changes: 1 addition & 1 deletion doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
futures-util = "0.3.4"

# misc
solang-parser = "=0.2.2"
solang-parser = "=0.2.3"
eyre = "0.6"
thiserror = "1.0.30"
rayon = "1.5.1"
Expand Down
Loading