forked from CommonsBuild/proposal-inverter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from patriacaelum/process-for-whitelisting-brokers
Process for whitelisting brokers
- Loading branch information
Showing
5 changed files
with
373 additions
and
49 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
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,134 @@ | ||
import pytest | ||
|
||
from .proposal_inverter import Wallet, ProposalInverter | ||
from .whitelist_mechanism import NoVote, OwnerVote, PayerVote, EqualVote, WeightedVote, UnanimousVote | ||
|
||
|
||
@pytest.fixture | ||
def owner(): | ||
owner = Wallet() | ||
owner.funds = 500 | ||
|
||
return owner | ||
|
||
|
||
@pytest.fixture | ||
def payer1(): | ||
payer1 = Wallet() | ||
payer1.funds = 500 | ||
|
||
return payer1 | ||
|
||
|
||
@pytest.fixture | ||
def payer2(): | ||
payer2 = Wallet() | ||
payer2.funds = 500 | ||
|
||
return payer2 | ||
|
||
|
||
@pytest.fixture | ||
def inverter(owner, payer1, payer2): | ||
inverter = owner.deploy(300) | ||
payer1 = inverter.pay(payer1, 200) | ||
payer2 = inverter.pay(payer2, 100) | ||
|
||
return inverter | ||
|
||
|
||
@pytest.fixture | ||
def broker(): | ||
broker = Wallet() | ||
broker.funds = 100 | ||
|
||
return broker | ||
|
||
|
||
def test_no_vote(owner, payer1, inverter, broker): | ||
mechanism = NoVote() | ||
|
||
# Votes should not impact whitelisting, and should whitelist all brokers | ||
mechanism.vote(inverter, payer1, broker, False) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == True | ||
|
||
|
||
def test_owner_vote(owner, payer1, inverter, broker): | ||
mechanism = OwnerVote() | ||
|
||
# Case where payer cannot whitelist a broker | ||
mechanism.vote(inverter, payer1, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == False | ||
|
||
# Case where only the owner can whitelist a broker | ||
mechanism.vote(inverter, owner, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == True | ||
|
||
|
||
def test_payer_vote(payer1, payer2, inverter, broker): | ||
mechanism = PayerVote() | ||
|
||
# Case where any payer can whitelist a broker and override a blacklist vote | ||
mechanism.vote(inverter, payer1, broker, False) | ||
|
||
assert mechanism.in_waitlist(broker) == True | ||
assert mechanism.in_whitelist(broker) == False | ||
|
||
mechanism.vote(inverter, payer2, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == True | ||
|
||
|
||
def test_equal_vote(payer1, payer2, inverter, broker): | ||
mechanism = EqualVote(min_vote=0.5) | ||
|
||
mechanism.vote(inverter, payer1, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == True | ||
assert mechanism.in_whitelist(broker) == False | ||
|
||
mechanism.vote(inverter, payer2, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == True | ||
|
||
|
||
def test_weighted_vote(payer1, payer2, inverter, broker): | ||
mechanism = WeightedVote(min_vote=0.6) | ||
|
||
# Case where two voters do not have enough combined funds | ||
mechanism.vote(inverter, payer1, broker, True) | ||
mechanism.vote(inverter, payer2, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == True | ||
assert mechanism.in_whitelist(broker) == False | ||
|
||
# Case where a payer increases their funds to increase their weight | ||
payer1 = inverter.pay(payer1, 200) | ||
|
||
mechanism.vote(inverter, payer1, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == True | ||
|
||
|
||
def test_unanimous_vote(owner, payer1, payer2, inverter, broker): | ||
mechanism = UnanimousVote() | ||
|
||
mechanism.vote(inverter, payer1, broker, True) | ||
mechanism.vote(inverter, payer2, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == True | ||
assert mechanism.in_whitelist(broker) == False | ||
|
||
mechanism.vote(inverter, owner, broker, True) | ||
|
||
assert mechanism.in_waitlist(broker) == False | ||
assert mechanism.in_whitelist(broker) == True |
Oops, something went wrong.