Skip to content

Commit

Permalink
test: multicall2 context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
skellet0r committed Jun 26, 2021
1 parent 02fa9b2 commit 9fd83b8
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/network/test_mulitcall2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import inspect

from lazy_object_proxy import Proxy

import brownie


def test_auto_deploy_on_testnet(config, devnetwork):
with brownie.multicall2():
# gets deployed on init
assert "multicall2" in config.active_network
addr = config.active_network["multicall2"]

with brownie.multicall2():
# uses the previously deployed instance
assert config.active_network["multicall2"] == addr


def test_proxy_object_is_returned_from_calls(accounts, tester):
addr = accounts[1]
value = ["blahblah", addr, ["yesyesyes", "0x1234"]]
tester.setTuple(value)

with brownie.multicall2() as mc2:
# the value hasn't been fetched so ret_value is just the proxy
# but if we access ret_val again it will update
# so use getattr_static to see it has yet to update
ret_val = tester.getTuple(addr, {"from": mc2})
assert inspect.getattr_static(ret_val, "__wrapped__") != value
assert isinstance(ret_val, Proxy)
assert ret_val.__wrapped__ == value


def test_flush_mid_execution(accounts, tester):
addr = accounts[1]
value = ["blahblah", addr, ["yesyesyes", "0x1234"]]
tester.setTuple(value)

with brownie.multicall2() as mc2:
tester.getTuple(addr, {"from": mc2})
assert len(mc2._pending_calls) == 1
mc2.flush()
assert len(mc2._pending_calls) == 0


def test_proxy_object_fetches_on_next_use(accounts, tester):
addr = accounts[1]
value = ["blahblah", addr, ["yesyesyes", "0x1234"]]
tester.setTuple(value)

with brownie.multicall2() as mc2:
ret_val = tester.getTuple(addr, {"from": mc2})
assert len(mc2._pending_calls) == 1
# ret_val is now fetched
assert ret_val == value
assert len(mc2._pending_calls) == 0


def test_proxy_object_updates_on_exit(accounts, tester):
addr = accounts[1]
value = ["blahblah", addr, ["yesyesyes", "0x1234"]]
tester.setTuple(value)

with brownie.multicall2() as mc2:
ret_val = tester.getTuple(addr, {"from": mc2})

assert ret_val == value


def test_standard_calls_passthrough(accounts, tester):
addr = accounts[1]
value = ["blahblah", addr, ["yesyesyes", "0x1234"]]
tester.setTuple(value)

with brownie.multicall2():
assert tester.getTuple(addr) == value


def test_standard_calls_work_after_context(accounts, tester):
addr = accounts[1]
value = ["blahblah", addr, ["yesyesyes", "0x1234"]]
tester.setTuple(value)

with brownie.multicall2():
assert tester.getTuple(addr) == value

assert tester.getTuple(addr) == value

0 comments on commit 9fd83b8

Please sign in to comment.