-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for delegate feature (using MockClient)
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
from ape_safe.exceptions import SafeClientException | ||
|
||
|
||
def test_manage_delegates(safe, delegate, OWNERS): | ||
owner = OWNERS[0] | ||
assert owner.address not in safe.client.get_delegates() | ||
|
||
safe.client.add_delegate(delegate, "pepito", owner) | ||
assert delegate.address in safe.client.get_delegates()[owner.address] | ||
assert delegate.address in safe.all_delegates() | ||
# NOTE: Only in MockSafeClient | ||
assert safe.client.delegator_for_delegate(delegate.address) == owner.address | ||
|
||
safe.client.remove_delegate(delegate, owner) | ||
assert owner.address not in safe.client.get_delegates() | ||
|
||
with pytest.raises(SafeClientException): | ||
# Only signers can create a delegate | ||
safe.client.add_delegate(owner, "root privledges", delegate) | ||
|
||
|
||
def test_delegate_can_propose_safe_tx(safe, delegate, OWNERS): | ||
owner = OWNERS[0] | ||
|
||
safe_tx = safe.create_safe_tx( | ||
safe.contract.addOwnerWithThreshold.as_transaction(delegate, safe.confirmations_required) | ||
) | ||
|
||
with pytest.raises(SafeClientException): | ||
# Not a delegate or signer | ||
safe.propose_safe_tx(safe_tx, submitter=delegate) | ||
|
||
safe.client.add_delegate(delegate, "pepito", owner) | ||
safe.propose_safe_tx(safe_tx, submitter=delegate) | ||
|
||
assert len(safe.get_api_confirmations(safe_tx)) == 0 | ||
assert list( | ||
(safe_tx.signable_message, confs) for safe_tx, confs in safe.pending_transactions() | ||
) == [(safe_tx.signable_message, [])] |