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

Fix ReturnValue comparison of tuples containing strings #1476

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion brownie/convert/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,5 @@ def _convert_str(value: Any) -> Wei:
return value
try:
return Wei(value)
except ValueError:
except (ValueError, TypeError):
return value
18 changes: 11 additions & 7 deletions tests/convert/test_return_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
from brownie.convert.datatypes import EthAddress, HexString, ReturnValue, Wei
from brownie.project import compile_source

string_fixture = "bar baz"


@pytest.fixture
def return_value(accounts, tester):
yield tester.manyValues(88, [False, False, False], accounts[2], [("0x1234", "0x6666")])
yield tester.manyValues(
88, [False, False, False], accounts[2], [("0x1234", "0x6666")], string_fixture
)


def test_type(return_value):
Expand All @@ -22,7 +26,7 @@ def test_type(return_value):


def test_len(return_value):
assert len(return_value) == 4
assert len(return_value) == 5


def test_count(return_value):
Expand Down Expand Up @@ -53,7 +57,7 @@ def test_contains_conversions(accounts, return_value):


def test_eq_conversions(accounts, return_value):
data = [88, [False, False, False], accounts[2], [("0x1234", "0x6666")]]
data = [88, [False, False, False], accounts[2], [("0x1234", "0x6666")], string_fixture]
assert return_value == data
assert return_value == tuple(data)
data[1] = tuple(data[1])
Expand All @@ -62,7 +66,7 @@ def test_eq_conversions(accounts, return_value):


def test_ne_conversions(accounts, return_value):
data = [88, [False, False, False], accounts[2], [("0x1234", "0x6666")]]
data = [88, [False, False, False], accounts[2], [("0x1234", "0x6666")], string_fixture]
assert not return_value != data
assert not return_value != tuple(data)
data[1] = tuple(data[1])
Expand All @@ -73,14 +77,14 @@ def test_ne_conversions(accounts, return_value):
def test_dict(accounts, return_value):
d = return_value.dict()
assert isinstance(d, dict)
assert len(d) == 4
assert len(d) == 5
assert len(d["_bool"]) == 3
assert sorted(d) == ["_addr", "_bool", "_bytes", "_num"]
assert sorted(d) == ["_addr", "_bool", "_bytes", "_num", "_string"]
assert d["_addr"] == accounts[2]


def test_keys(return_value):
assert list(return_value.keys()) == ["_num", "_bool", "_addr", "_bytes"]
assert list(return_value.keys()) == ["_num", "_bool", "_addr", "_bytes", "_string"]


def test_items(return_value):
Expand Down
7 changes: 4 additions & 3 deletions tests/data/brownie-test-project/contracts/BrownieTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ contract BrownieTester {
uint a,
bool[] calldata b,
address c,
bytes32[2][] calldata d
bytes32[2][] calldata d,
string calldata e
)
external
view
returns (uint _num, bool[] memory _bool, address _addr, bytes32[2][] memory _bytes)
returns (uint _num, bool[] memory _bool, address _addr, bytes32[2][] memory _bytes, string memory _string)
{
return (a, b, c, d);
return (a, b, c, d, e);
}

function useSafeMath(uint a, uint b) external returns (uint) {
Expand Down