chainlib

Generic blockchain access library and tooling
Log | Files | Refs | README | LICENSE

commit f13b24798e79ec6808c9bffad99405d4d4f0da67
parent 58b92837ffa45ebaca3032b97abd1ec3ecccec51
Author: Louis Holbrook <accounts-gitlab@holbrook.no>
Date:   Mon, 18 Oct 2021 11:25:00 +0000

refactor: Rename chain spec members

Diffstat:
Mchainlib/chain.py | 24++++++++++++------------
Mchainlib/data/config/config.ini | 1-
Msetup.cfg | 2+-
Mtests/test_chain.py | 20++++++++++++++++++++
4 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/chainlib/chain.py b/chainlib/chain.py @@ -16,12 +16,12 @@ class ChainSpec: :param tag: Descriptive tag :type tag: str """ - def __init__(self, engine, common_name, network_id, tag=None): + def __init__(self, arch, fork, network_id, common_name=None): self.o = { - 'engine': engine, - 'common_name': common_name, + 'arch': arch, + 'fork': fork, 'network_id': network_id, - 'tag': tag, + 'common_name': common_name, } def network_id(self): @@ -48,7 +48,7 @@ class ChainSpec: :rtype: str :returns: engine """ - return self.o['engine'] + return self.o['arch'] def common_name(self): @@ -78,10 +78,10 @@ class ChainSpec: o = chain_str.split(':') if len(o) < 3: raise ValueError('Chain string must have three sections, got {}'.format(len(o))) - tag = None + common_name = None if len(o) == 4: - tag = o[3] - return ChainSpec(o[0], o[1], int(o[2]), tag) + common_name = o[3] + return ChainSpec(o[0], o[1], int(o[2]), common_name) @staticmethod @@ -100,7 +100,7 @@ class ChainSpec: :rtype: chainlib.chain.ChainSpec :returns: Resulting chain spec """ - return ChainSpec(o['engine'], o['common_name'], o['network_id'], tag=o['tag']) + return ChainSpec(o['arch'], o['fork'], o['network_id'], common_name=o['common_name']) def asdict(self): @@ -113,7 +113,7 @@ class ChainSpec: def __str__(self): - s = '{}:{}:{}'.format(self.o['engine'], self.o['common_name'], self.o['network_id']) - if self.o['tag'] != None: - s += ':' + self.o['tag'] + s = '{}:{}:{}'.format(self.o['arch'], self.o['fork'], self.o['network_id']) + if self.o['common_name'] != None: + s += ':' + self.o['common_name'] return s diff --git a/chainlib/data/config/config.ini b/chainlib/data/config/config.ini @@ -1,5 +1,4 @@ [rpc] -http_provider = provider = auth = credentials = diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib -version = 0.0.9rc1 +version = 0.0.10a1 description = Generic blockchain access library and tooling author = Louis Holbrook author_email = dev@holbrook.no diff --git a/tests/test_chain.py b/tests/test_chain.py @@ -7,6 +7,13 @@ from tests.base import TestBase class TestChain(TestBase): + 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)) + def test_chain_spec(self): s = ChainSpec.from_chain_str('foo:bar:3') @@ -18,5 +25,18 @@ class TestChain(TestBase): s = ChainSpec.from_chain_str('foo') + 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)) + + + if __name__ == '__main__': unittest.main()