evm-booking

EVM smart contract for ERC20 backed time slot booking
Info | Log | Files | Refs | README

base.py (1639B)


      1 # standard imports
      2 import logging
      3 import datetime
      4 
      5 # external imports
      6 from chainlib.eth.unittest.ethtester import EthTesterCase
      7 from chainlib.connection import RPCConnection
      8 from chainlib.eth.nonce import RPCNonceOracle
      9 from chainlib.eth.tx import receipt
     10 from chainlib.eth.address import to_checksum_address
     11 from giftable_erc20_token.unittest import TestGiftableToken
     12 from evm_booking import Booking
     13 from chainlib.eth.block import block_latest
     14 
     15 # local imports
     16 from evm_booking import Booking
     17 
     18 logg = logging.getLogger(__name__)
     19 
     20 DEFAULT_RESOLUTION = 366*24
     21 
     22 class TestBooking(TestGiftableToken):
     23 
     24     expire = 0
     25     booking_expire = datetime.datetime.utcnow() + datetime.timedelta(days=365)
     26 
     27     def setUp(self):
     28         super(TestBooking, self).setUp()
     29 
     30         self.alice = self.accounts[1]
     31         self.bob = self.accounts[2]
     32         self.token_address = self.address
     33 
     34 
     35     def publish(self, resolution=DEFAULT_RESOLUTION):
     36         nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.rpc)
     37         c = Booking(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
     38         (tx_hash, o) = c.constructor(self.accounts[0], self.token_address, resolution, self.booking_expire)
     39         self.rpc.do(o)
     40         o = receipt(tx_hash)
     41         r = self.rpc.do(o)
     42         self.assertEqual(r['status'], 1)
     43         self.address = to_checksum_address(r['contract_address'])
     44         self.booking_address = self.address
     45         logg.debug('published booker on address {} with hash {}'.format(self.booking_address, tx_hash))
     46 
     47         self.resolution = resolution
     48         self.resolution_unit = int(self.initial_supply / self.resolution)