evm-tokenvote

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

test_internal.py (2048B)


      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 TestEvmVote
     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(TestEvmVote):
     23 
     24     def test_propose_internal_blockwait(self):
     25         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
     26         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     27         (tx_hash, o) = c.propose_blockwait(self.voter_address, self.accounts[0], 123, 100)
     28         self.rpc.do(o)
     29         o = receipt(tx_hash)
     30         r = self.rpc.do(o)
     31         self.assertEqual(r['status'], 1)
     32 
     33         o = c.block_wait_limit(self.voter_address, sender_address=self.ivan)
     34         r = self.rpc.do(o)
     35         self.assertEqual(int(r, 16), 0)
     36 
     37         c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     38         (tx_hash, o) = c.approve(self.address, self.accounts[0], self.voter_address, self.initial_supply)
     39         self.rpc.do(o)
     40 
     41         c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     42         (tx_hash, o) = c.vote(self.voter_address, self.accounts[0], self.initial_supply)
     43         self.rpc.do(o)
     44 
     45         (tx_hash, o) = c.scan(self.voter_address, self.accounts[0], 0, 0)
     46         self.rpc.do(o)
     47 
     48         (tx_hash, o) = c.finalize_vote(self.voter_address, self.accounts[0])
     49         self.rpc.do(o)
     50         o = receipt(tx_hash)
     51         r = self.rpc.do(o)
     52         self.assertEqual(r['status'], 1)
     53 
     54         o = c.block_wait_limit(self.voter_address, sender_address=self.ivan)
     55         r = self.rpc.do(o)
     56         self.assertEqual(int(r, 16), 123) 
     57 
     58 if __name__ == '__main__':
     59     unittest.main()