2021-02-18 09:29:52 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from chainlib.chain import ChainSpec
|
|
|
|
|
|
|
|
from tests.base import TestBase
|
|
|
|
|
|
|
|
|
|
|
|
class TestChain(TestBase):
|
|
|
|
|
2021-10-18 13:25:00 +02:00
|
|
|
def test_chain_spec_str(self):
|
|
|
|
s = ChainSpec('foo', 'bar', 3, 'baz')
|
|
|
|
self.assertEqual('foo:bar:3:baz', str(s))
|
|
|
|
|
|
|
|
s = ChainSpec('foo', 'bar', 3)
|
|
|
|
self.assertEqual('foo:bar:3', str(s))
|
|
|
|
|
2021-02-18 09:29:52 +01:00
|
|
|
def test_chain_spec(self):
|
|
|
|
|
|
|
|
s = ChainSpec.from_chain_str('foo:bar:3')
|
|
|
|
s = ChainSpec.from_chain_str('foo:bar:3:baz')
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
s = ChainSpec.from_chain_str('foo:bar:a')
|
|
|
|
s = ChainSpec.from_chain_str('foo:bar')
|
|
|
|
s = ChainSpec.from_chain_str('foo')
|
|
|
|
|
|
|
|
|
2021-10-18 13:25:00 +02:00
|
|
|
def test_chain_spec_dict(self):
|
|
|
|
s = 'foo:bar:3:baz'
|
|
|
|
c = ChainSpec.from_chain_str('foo:bar:3:baz')
|
|
|
|
d = c.asdict()
|
|
|
|
self.assertEqual(d['arch'], 'foo')
|
|
|
|
self.assertEqual(d['fork'], 'bar')
|
|
|
|
self.assertEqual(d['network_id'], 3)
|
|
|
|
self.assertEqual(d['common_name'], 'baz')
|
|
|
|
cc = ChainSpec.from_dict(d)
|
|
|
|
self.assertEqual(s, str(cc))
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-18 09:29:52 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|