commit bb565a7ec05ca77b6f45a82fa27679b00fc2b52a
parent c1551e1a32b90ce5a0675ffa75783ebe75036ff3
Author: lash <dev@holbrook.no>
Date: Sat, 6 May 2023 14:36:03 +0100
Add tied vote test
Diffstat:
1 file changed, 88 insertions(+), 2 deletions(-)
diff --git a/python/tests/test_option.py b/python/tests/test_option.py
@@ -170,7 +170,22 @@ class TestVoteBase(TestEvmVote):
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash, o) = c.propose(self.voter_address, self.accounts[0], hash_of_foo, 100, target_vote_ppm=1000000, options=[hash_of_bar, hash_of_baz])
+ (tx_hash, o) = c.propose(self.voter_address, self.accounts[0], hash_of_foo, 100, target_vote_ppm=1000000, options=[hash_of_foo, hash_of_bar, hash_of_baz])
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.vote(self.voter_address, self.alice, third_of_supply, option=1)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.bob, conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.vote(self.voter_address, self.bob, third_of_supply, option=0)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.carol, conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.vote(self.voter_address, self.carol, third_of_supply, option=1)
self.rpc.do(o)
o = block_latest()
@@ -183,7 +198,7 @@ class TestVoteBase(TestEvmVote):
nonce_oracle = RPCNonceOracle(self.trent, conn=self.conn)
c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
- (tx_hash, o) = c.scan(self.voter_address, self.trent, 0, 2)
+ (tx_hash, o) = c.scan(self.voter_address, self.trent, 0, 3)
self.rpc.do(o)
(tx_hash, o) = c.finalize_vote(self.voter_address, self.trent)
@@ -194,8 +209,79 @@ class TestVoteBase(TestEvmVote):
proposal = c.parse_proposal(r)
self.assertEqual(proposal.state & ProposalState.SCANNED, ProposalState.SCANNED)
self.assertEqual(proposal.state & ProposalState.FINAL, ProposalState.FINAL)
+ self.assertEqual(proposal.state & ProposalState.TIED, 0)
self.assertEqual(proposal.state & ProposalState.INSUFFICIENT, ProposalState.INSUFFICIENT)
+ def test_vote_tied(self):
+ third_of_supply = int(self.initial_supply / 3)
+ nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
+ c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.alice, third_of_supply)
+ self.rpc.do(o)
+
+ c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.bob, third_of_supply)
+ self.rpc.do(o)
+
+ c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.carol, third_of_supply)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
+ c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.approve(self.address, self.alice, self.voter_address, third_of_supply)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.bob, conn=self.conn)
+ c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.approve(self.address, self.bob, self.voter_address, third_of_supply)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.carol, conn=self.conn)
+ c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.approve(self.address, self.carol, self.voter_address, third_of_supply)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.propose(self.voter_address, self.accounts[0], hash_of_foo, 100, options=[hash_of_foo, hash_of_bar, hash_of_baz])
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.vote(self.voter_address, self.alice, third_of_supply, option=1)
+ self.rpc.do(o)
+
+ nonce_oracle = RPCNonceOracle(self.bob, conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.vote(self.voter_address, self.bob, third_of_supply, option=0)
+ self.rpc.do(o)
+
+ o = block_latest()
+ proposal_block_height = self.rpc.do(o)
+ o = block_latest()
+ now_block_height = self.rpc.do(o)
+
+ need_blocks = proposal_block_height + 100 - now_block_height + 1
+ self.backend.mine_blocks(need_blocks)
+
+ nonce_oracle = RPCNonceOracle(self.trent, conn=self.conn)
+ c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ (tx_hash, o) = c.scan(self.voter_address, self.trent, 0, 3)
+ self.rpc.do(o)
+
+ (tx_hash, o) = c.finalize_vote(self.voter_address, self.trent)
+ self.rpc.do(o)
+
+ o = c.get_proposal(self.voter_address, 0, sender_address=self.accounts[0])
+ r = self.rpc.do(o)
+ proposal = c.parse_proposal(r)
+ self.assertEqual(proposal.state & ProposalState.SCANNED, ProposalState.SCANNED)
+ self.assertEqual(proposal.state & ProposalState.FINAL, ProposalState.FINAL)
+ self.assertEqual(proposal.state & ProposalState.TIED, ProposalState.TIED)
+ self.assertEqual(proposal.state & ProposalState.INSUFFICIENT, 0)
+
+
if __name__ == '__main__':
unittest.main()