Skip to content

Class Wei used in CLI arguments can differ from original input #2240

@acuarica

Description

@acuarica

CLI arguments of type Wei might differ from their original input when they are large.

For example, if we set the CLI argument --seed-account-sweep-amount='70000 ether'

sender_group.addoption(
"--seed-account-sweep-amount",
action="store",
dest="seed_account_sweep_amount",
type=Wei,
default=None,
help="Amount of wei to sweep from the seed account to the sender account. "
"Default=None (Entire balance)",
)
)

what we actually from seed_account_sweep_amount

@pytest.fixture(scope="session")
def seed_account_sweep_amount(request: pytest.FixtureRequest) -> int | None:
"""Get the seed account sweep amount."""
return request.config.option.seed_account_sweep_amount

is 70000000000000004194304, but the expected value is 70000000000000000000000.

The root cause comes from these float conversions in the Wei class.

value: float
if "**" in value_str:
base, exp = value_str.split("**")
value = float(base) ** int(exp)
else:
value = float(value_str)
return super(Number, cls).__new__(cls, value * multiplier)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions