Skip to content

Commit

Permalink
Merge pull request #1476 from promptworks/fix-return-value-comparison…
Browse files Browse the repository at this point in the history
…-of-strings

Fix ReturnValue comparison of tuples containing strings
  • Loading branch information
iamdefinitelyahuman authored May 15, 2022
2 parents ef0d5af + 93009d4 commit 8ad14f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
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

0 comments on commit 8ad14f0

Please sign in to comment.