evm-tokenvote

Voting machine using ERC20 tokens as votes.
Info | Log | Files | Refs | README

test_cancel.py (2993B)


      1 # standard imports
      2 import unittest
      3 import logging
      4 import os
      5 from chainlib.eth.nonce import RPCNonceOracle
      6 from chainlib.eth.tx import receipt
      7 from chainlib.eth.block import block_latest
      8 from hexathon import same as same_hex
      9 from eth_erc20 import ERC20
     10 from giftable_erc20_token import GiftableToken
     11 
     12 # local imports
     13 from evm_tokenvote.unittest import TestEvmVoteProposal
     14 from evm_tokenvote.unittest.base import hash_of_foo
     15 from evm_tokenvote import Voter
     16 from evm_tokenvote import ProposalState
     17 
     18 
     19 logging.basicConfig(level=logging.DEBUG)
     20 logg = logging.getLogger()
     21 
     22 class TestVoteBase(TestEvmVoteProposal):
     23 
     24     def test_cancel(self):
     25         half_supply = int(self.initial_supply / 2)
     26         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     27         c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     28         (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.alice, half_supply)
     29         self.rpc.do(o)
     30 
     31         nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
     32         c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     33         (tx_hash, o) = c.approve(self.address, self.alice, self.voter_address, half_supply)
     34         self.rpc.do(o)
     35 
     36         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     37         (tx_hash, o) = c.vote_cancel(self.voter_address, self.alice, half_supply - 1)
     38         self.rpc.do(o)
     39         o = receipt(tx_hash)
     40         r = self.rpc.do(o)
     41         self.assertEqual(r['status'], 1)
     42 
     43         nonce_oracle = RPCNonceOracle(self.trent, conn=self.conn)
     44         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     45         (tx_hash, o) = c.scan(self.voter_address, self.trent, 0, 0)
     46         self.rpc.do(o)
     47         o = receipt(tx_hash)
     48         r = self.rpc.do(o)
     49         self.assertEqual(r['status'], 0)
     50 
     51         nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
     52         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     53         (tx_hash, o) = c.vote_cancel(self.voter_address, self.alice, 1)
     54         self.rpc.do(o)
     55         o = receipt(tx_hash)
     56         r = self.rpc.do(o)
     57         self.assertEqual(r['status'], 1)
     58 
     59         nonce_oracle = RPCNonceOracle(self.trent, conn=self.conn)
     60         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     61         (tx_hash, o) = c.scan(self.voter_address, self.trent, 0, 0)
     62         self.rpc.do(o)
     63         o = receipt(tx_hash)
     64         r = self.rpc.do(o)
     65         self.assertEqual(r['status'], 1)
     66 
     67         o = c.get_proposal(self.voter_address, 0, sender_address=self.accounts[0])
     68         r = self.rpc.do(o)
     69         proposal = c.parse_proposal(r)
     70         self.assertEqual(proposal.state & ProposalState.SCANNED, ProposalState.SCANNED)
     71         self.assertEqual(proposal.state & ProposalState.IMMEDIATE, ProposalState.IMMEDIATE)
     72         self.assertEqual(proposal.state & ProposalState.CANCELLED, ProposalState.CANCELLED)
     73 
     74 
     75 if __name__ == '__main__':
     76     unittest.main()