def _multisig(org, fn, *args): id1 = org.getID(accounts[-6]) args = list(args) + [{"from": accounts[-6]}] # check for failed call, no permission with pytest.reverts("dev: not permitted"): fn(*args) # give permission and check for successful call org.setAuthoritySignatures(id1, [fn.signature], True, {"from": accounts[0]}) assert "MultiSigCallApproved" in fn(*args).events rpc.revert() # give permission, threhold to 3, check for success and fails org.setAuthoritySignatures(id1, [fn.signature], True, {"from": accounts[0]}) org.setAuthorityThreshold(id1, 3, {"from": accounts[0]}) args[-1]["from"] = accounts[-6] assert "MultiSigCallApproved" not in fn(*args).events with pytest.reverts("dev: repeat caller"): fn(*args) args[-1]["from"] = accounts[-5] assert "MultiSigCallApproved" not in fn(*args).events with pytest.reverts("dev: repeat caller"): fn(*args) args[-1]["from"] = accounts[-4] assert "MultiSigCallApproved" in fn(*args).events
def _multisig(issuer, fn, *args): auth_id = issuer.getID(accounts[3]) args = list(args) + [{'from': accounts[3]}] # check for failed call, no permission with pytest.reverts("dev: not permitted"): fn(*args) # give permission and check for successful call issuer.setAuthoritySignatures(auth_id, [fn.signature], True, {'from': accounts[0]}) assert 'MultiSigCallApproved' in fn(*args).events rpc.revert() # give permission, threhold to 3, check for success and fails issuer.setAuthoritySignatures(auth_id, [fn.signature], True, {'from': accounts[0]}) issuer.setAuthorityThreshold(auth_id, 3, {'from': accounts[0]}) args[-1]['from'] = accounts[3] assert 'MultiSigCallApproved' not in fn(*args).events with pytest.reverts("dev: repeat caller"): fn(*args) args[-1]['from'] = accounts[4] assert 'MultiSigCallApproved' not in fn(*args).events with pytest.reverts("dev: repeat caller"): fn(*args) args[-1]['from'] = accounts[5] assert 'MultiSigCallApproved' in fn(*args).events
def test_time(): assert rpc.time() == int(time.time()) rpc.sleep(25) rpc.snapshot() rpc.sleep(75) assert rpc.time() == int(time.time() + 100) rpc.revert() assert rpc.time() == int(time.time() + 25)
def test_reverts(clean_network): for i in range(3): accounts[0].transfer(accounts[1], "1 ether") rpc.snapshot() assert len(history) == 3 for i in range(3): accounts[0].transfer(accounts[1], "1 ether") assert len(history) == 6 tx = history[-1] rpc.revert() assert len(history) == 3 assert tx not in history
def console(): argv = sys.argv sys.argv = ['brownie', 'console'] original_path = os.getcwd() os.chdir(original_path+"/tests/brownie-test-project") rpc.snapshot() c = Console() c.push('from brownie.project import *') yield c rpc.revert() os.chdir(original_path) sys.argv = argv
def test_snapshot_revert(): height = web3.eth.blockNumber balance = accounts[0].balance() count = len(project.Token) rpc.snapshot() accounts[0].transfer(accounts[1], "1 ether") project.Token.deploy("", "", 0, 0, {'from': accounts[0]}) rpc.revert() assert height == web3.eth.blockNumber assert balance == accounts[0].balance() assert count == len(project.Token) rpc.revert() assert height == web3.eth.blockNumber assert balance == accounts[0].balance() assert count == len(project.Token)
def _owner_multisig(kyc, owner_id, fn, *args): args = list(args) + [{"from": accounts[0]}] with pytest.reverts("dev: only owner"): fn(*args[:-1] + [{"from": accounts[-1]}]) assert "MultiSigCallApproved" in fn(*args).events rpc.revert() kyc.setAuthorityThreshold(owner_id, 3, {"from": accounts[0]}) assert "MultiSigCallApproved" not in fn(*args).events with pytest.reverts("dev: repeat caller"): fn(*args) args[-1]["from"] = accounts[1] assert "MultiSigCallApproved" not in fn(*args).events with pytest.reverts("dev: repeat caller"): fn(*args) args[-1]["from"] = accounts[2] assert "MultiSigCallApproved" in fn(*args).events
def test_revert_exceptions(): rpc.reset() with pytest.raises(ValueError): rpc.revert()