erc20-demurrage-token

ERC20 token with redistributed continual demurrage
Info | Log | Files | Refs | README

tests_sim.py (2301B)


      1 # standard imports
      2 import unittest
      3 import logging
      4 
      5 # local imports
      6 from erc20_demurrage_token import DemurrageTokenSettings
      7 from erc20_demurrage_token.sim import DemurrageTokenSimulation
      8 
      9 logging.basicConfig(level=logging.INFO)
     10 logg = logging.getLogger()
     11 
     12 
     13 class TestSim(unittest.TestCase):
     14 
     15     def setUp(self):
     16         self.cap = 0
     17         settings = DemurrageTokenSettings()
     18         settings.name = 'Simulated Demurrage Token'
     19         settings.symbol = 'SIM'
     20         settings.decimals = 6
     21         settings.demurrage_level = 5010590837337300000000000000000000 # equals approx 2% per month
     22         settings.period_minutes = 10800 # 1 week in minutes
     23         self.sim = DemurrageTokenSimulation('evm:foochain:42', settings, redistribute=True, cap=self.cap, actors=10)
     24 
     25 
     26     def test_mint(self):
     27         self.sim.mint(self.sim.actors[0], 1024)
     28         self.sim.next()
     29         balance = self.sim.balance(self.sim.actors[0])
     30         self.assertEqual(balance, 1023)
     31 
     32 
     33     def test_transfer(self):
     34         self.sim.mint(self.sim.actors[0], 1024)
     35         self.sim.transfer(self.sim.actors[0], self.sim.actors[1], 500)
     36         self.sim.next()
     37         balance = self.sim.balance(self.sim.actors[0])
     38         self.assertEqual(balance, 523)
     39 
     40         balance = self.sim.balance(self.sim.actors[1])
     41         self.assertEqual(balance, 499)
     42 
     43 
     44     def test_more_periods(self):
     45         self.sim.mint(self.sim.actors[0], 1024)
     46         self.sim.mint(self.sim.actors[1], 1024)
     47         self.sim.next()
     48 
     49         self.sim.mint(self.sim.actors[0], 1024)
     50         self.sim.next()
     51 
     52         balance = self.sim.balance(self.sim.actors[0])
     53         self.assertEqual(balance, 2047)
     54 
     55 
     56     def test_demurrage(self):
     57         self.sim.mint(self.sim.actors[0], self.sim.from_units(100))
     58         self.sim.mint(self.sim.actors[1], self.sim.from_units(100))
     59         self.sim.transfer(self.sim.actors[0], self.sim.actors[2], self.sim.from_units(10))
     60         self.sim.next()
     61 
     62         balance = self.sim.balance(self.sim.actors[0])
     63         self.assertEqual(balance, 90005520)
     64         
     65         balance = self.sim.balance(self.sim.actors[1])
     66         self.assertEqual(balance, 99995000)
     67 
     68         balance = self.sim.balance(self.sim.actors[1], base=True)
     69         self.assertEqual(balance, 100000000)
     70 
     71 
     72 if __name__ == '__main__':
     73     unittest.main()