Skip to content

Expand currency test suite to fuzz test using float values#103

Closed
dilatebrave wants to merge 1 commit intoethereum:masterfrom
dilatebrave:issue102
Closed

Expand currency test suite to fuzz test using float values#103
dilatebrave wants to merge 1 commit intoethereum:masterfrom
dilatebrave:issue102

Conversation

@dilatebrave
Copy link
Copy Markdown

@dilatebrave dilatebrave commented May 18, 2018

Fix #102
I have add test_to_wei_float in test_currency_tools, but the test fail

AssertionError: assert Decimal('2.22E-15') == Decimal('2.2204460492503135E-15')
where Decimal('2.22E-15') = from_wei(2220, 'ether')
where 2220 = to_wei(2.2204460492503135e-15, 'ether')
and   Decimal('2.2204460492503135E-15') = <class 'decimal.Decimal'>('2.2204460492503135e-15')
where <class 'decimal.Decimal'> = decimal.Decimal
and   '2.2204460492503135e-15' = str(2.2204460492503135e-15)

In to_wei, should we check decimal precision of floats to throw an error instead of silently roundup the return value int(result_value)?

Cute Animal Picture

Cute animal picture

@pipermerriam
Copy link
Copy Markdown
Member

Hrm, looking at this I think it actually makes it clear that we must disallow floats or implement some kind of internal validation that rejects floats which cannot be accurately converted. I'm skeptical that we can do the later, so.. would you be up for changing this PR to instead reject float types in to_wei and from_wei and to expand/modify the existing tests to demonstrate these types are rejected.

@pipermerriam
Copy link
Copy Markdown
Member

closing this as the removal of float support should be done in a separate PR

pacrob added a commit to pacrob/eth-utils that referenced this pull request Dec 4, 2023
* add pre-commit

* run pre-commit

* skip lint on README.md as it breaks template filling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants