This repository has been archived on 2023-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
erc20-demurrage-token-archive/python/tests/test_pure.py

71 lines
2.2 KiB
Python
Raw Normal View History

2021-02-06 15:18:30 +01:00
# standard imports
import os
import unittest
import json
import logging
import math
2021-06-04 11:48:17 +02:00
# external imports
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
from chainlib.error import JSONRPCException
2021-02-06 15:18:30 +01:00
import eth_tester
2021-06-04 11:48:17 +02:00
# local imports
from erc20_demurrage_token import DemurrageToken
# test imports
from tests.base import TestDemurrageDefault
2021-02-06 15:18:30 +01:00
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
testdir = os.path.dirname(__file__)
2021-06-04 11:48:17 +02:00
class Test(TestDemurrageDefault):
2021-02-06 15:18:30 +01:00
def test_fractional_state(self):
2021-06-04 11:48:17 +02:00
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
with self.assertRaises(JSONRPCException):
o = c.remainder(self.address, 2, 1, sender_address=self.accounts[0])
self.rpc.do(o)
with self.assertRaises(JSONRPCException):
o = c.remainder(self.address, 0, 100001, sender_address=self.accounts[0])
self.rpc.do(o)
o = c.remainder(self.address, 1, 2, sender_address=self.accounts[0])
r = self.rpc.do(o)
remainder = c.parse_remainder(r)
2021-02-06 15:18:30 +01:00
self.assertEqual(remainder, 0);
2021-06-04 11:48:17 +02:00
2021-02-06 15:18:30 +01:00
whole = 5000001
parts = 20000
expect = whole - (math.floor(whole/parts) * parts)
2021-06-04 11:48:17 +02:00
o = c.remainder(self.address, parts, whole, sender_address=self.accounts[0])
r = self.rpc.do(o)
remainder = c.parse_remainder(r)
2021-02-06 15:18:30 +01:00
self.assertEqual(remainder, expect)
parts = 30000
expect = whole - (math.floor(whole/parts) * parts)
2021-06-04 11:48:17 +02:00
o = c.remainder(self.address, parts, whole, sender_address=self.accounts[0])
r = self.rpc.do(o)
remainder = c.parse_remainder(r)
2021-02-06 15:18:30 +01:00
self.assertEqual(remainder, expect)
parts = 40001
expect = whole - (math.floor(whole/parts) * parts)
2021-06-04 11:48:17 +02:00
o = c.remainder(self.address, parts, whole, sender_address=self.accounts[0])
r = self.rpc.do(o)
remainder = c.parse_remainder(r)
2021-02-06 15:18:30 +01:00
self.assertEqual(remainder, expect)
2021-06-04 11:48:17 +02:00
2021-02-06 15:18:30 +01:00
if __name__ == '__main__':
unittest.main()