Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Aug 26, 2024
1 parent 94aa7d0 commit 00b5fed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 0 additions & 9 deletions tests/functional/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,3 @@ def test_set_pending_timestamp_failure(chain):
def test_set_balance(chain, owner):
with pytest.raises(APINotImplementedError):
chain.set_balance(owner, "1000 ETH")


def test_get_contract_by_abi(chain, vyper_contract_instance):
contract = chain.contracts.instance_at(
vyper_contract_instance.address, abi=vyper_contract_instance.contract_type.abi
)

assert contract.address == vyper_contract_instance.address
assert contract.contract_type.abi == vyper_contract_instance.contract_type.abi
22 changes: 22 additions & 0 deletions tests/functional/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ def test_Contract_from_json_str(contract_instance):
assert contract.myNumber() == 0


def test_Contract_from_json_str_retrieval_check_fails(mocker, chain, vyper_contract_instance):
"""
Tests a bug when providing an abi= but fetch-attemp raises that we don't
raise since the abi was already given.
"""
# Make `.get()` fail.
orig = chain.contracts.get
mock_get = mocker.MagicMock()
mock_get.side_effect = Exception

abi_str = json.dumps([abi.model_dump() for abi in vyper_contract_instance.contract_type.abi])

chain.contracts.get = mock_get
try:
contract = Contract(vyper_contract_instance.address, abi=abi_str)
finally:
chain.contracts.get = orig

# Mostly, we are asserting it did not fail.
assert isinstance(contract, ContractInstance)


def test_Contract_from_file(contract_instance):
"""
need feedback about the json file specifications
Expand Down

0 comments on commit 00b5fed

Please sign in to comment.