Skip to content

Commit

Permalink
add bytes test cases, update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jan 21, 2020
1 parent 6d90d79 commit 5046636
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Correctly isolate path and nodeid from test cases inside classes
- Allow `""` and `"0x"` when converting to bytes, disallow booleans

## [1.5.0](https://github.com/iamdefinitelyahuman/brownie/tree/v1.5.0) - 2020-01-20
### Added
Expand Down
21 changes: 20 additions & 1 deletion tests/main/convert/test_to_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_type_bounds():
with pytest.raises(ValueError):
to_bytes("0x00", "bytes0")
with pytest.raises(ValueError):
to_bytes("0x", "bytes33")
to_bytes("0x00", "bytes33")


def test_length_bounds():
Expand Down Expand Up @@ -44,3 +44,22 @@ def test_int_bounds():
assert to_bytes(2 ** (i * 8) - 1, type_).hex() == "ff" * i
with pytest.raises(OverflowError):
to_bytes(2 ** (i * 8), type_)


def test_byte_is_bytes1():
assert to_bytes(42, "byte") == to_bytes(42, "bytes1")


def test_zero_value():
assert to_bytes("", "bytes1").hex() == "00"
assert to_bytes("0x", "bytes1").hex() == "00"
assert to_bytes(0, "bytes1").hex() == "00"


def test_invalid_type():
with pytest.raises(TypeError):
to_bytes(None)
with pytest.raises(TypeError):
to_bytes(3.1337)
with pytest.raises(TypeError):
to_bytes(True)

0 comments on commit 5046636

Please sign in to comment.