evm-tokenvote

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

test_registry.py (3325B)


      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 from eth_accounts_index import AccountsIndex
     12 
     13 # local imports
     14 from evm_tokenvote.unittest import TestEvmVoteRegistry
     15 from evm_tokenvote.unittest.base import hash_of_foo
     16 from evm_tokenvote import Voter
     17 from evm_tokenvote import ProposalState
     18 
     19 
     20 logging.basicConfig(level=logging.DEBUG)
     21 logg = logging.getLogger()
     22 
     23 
     24 class TestVoteRegistry(TestEvmVoteRegistry):
     25 
     26     def test_accounts_registry_vote(self):
     27         half_supply = self.initial_supply / 2
     28         description = hash_of_foo
     29         nonce_oracle = RPCNonceOracle(self.ivan, conn=self.conn)
     30         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     31         (tx_hash, o) = c.propose(self.voter_address, self.ivan, description, 100)
     32         self.rpc.do(o)
     33         o = receipt(tx_hash)
     34         r = self.rpc.do(o)
     35         self.assertEqual(r['status'], 0)
     36 
     37         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     38         c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     39         (tx_hash, o) = c.add(self.proposer_registry_address, self.accounts[0], self.ivan)
     40         self.rpc.do(o)
     41 
     42         nonce_oracle = RPCNonceOracle(self.ivan, conn=self.conn)
     43         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     44         (tx_hash, o) = c.propose(self.voter_address, self.ivan, description, 100)
     45         self.rpc.do(o)
     46         o = receipt(tx_hash)
     47         r = self.rpc.do(o)
     48         self.assertEqual(r['status'], 1)
     49 
     50         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     51         c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     52         (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.alice, half_supply)
     53         self.rpc.do(o)
     54         o = receipt(tx_hash)
     55         r = self.rpc.do(o)
     56         self.assertEqual(r['status'], 1)
     57 
     58         nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
     59         c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     60         (tx_hash, o) = c.approve(self.address, self.alice, self.voter_address, half_supply)
     61         self.rpc.do(o)
     62 
     63         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     64         (tx_hash, o) = c.vote(self.voter_address, self.alice, half_supply)
     65         self.rpc.do(o)
     66         o = receipt(tx_hash)
     67         r = self.rpc.do(o)
     68         self.assertEqual(r['status'], 0)
     69 
     70         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     71         c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     72         (tx_hash, o) = c.add(self.registry_address, self.accounts[0], self.alice)
     73         self.rpc.do(o)
     74 
     75         nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn)
     76         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     77         (tx_hash, o) = c.vote(self.voter_address, self.alice, half_supply)
     78         self.rpc.do(o)
     79         o = receipt(tx_hash)
     80         r = self.rpc.do(o)
     81         self.assertEqual(r['status'], 1)
     82 
     83 
     84 if __name__ == '__main__':
     85     unittest.main()