def test_extract_object(): from decimal import Decimal import binascii expected = { 'type': 1, 'name': 'build-trive-governance', 'url': 'https://gov.trivechain.com/proposal/build-trive-governance', 'start_epoch': 1584083153, 'end_epoch': 1586804753, 'payment_address': 'TRbXtNoqNVP9AQ2v1UotfM7BJ9PXcAZx9B', 'payment_amount': Decimal('100000'), } # test proposal format json_str = binascii.unhexlify(proposal_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # same expected trigger data expected = { 'type': 2, 'event_block_height': 62500, 'payment_addresses': 'tCa7rDMXs1KeqaqmcFoXxXMmwT9eq9r7oK|t7RKTBNZsTbjwAoXYfsSsTSwimxzDKh5Fu', 'payment_amounts': '5|3', 'proposal_hashes': 'e8a0057914a2e1964ae8a945c4723491caae2077a90a00a2aabee22b40081a87|d1ce73527d7cd6f2218f8ca893990bc7d5c6b9334791ce7973bfa22f155f826e' } # test trigger format json_str = binascii.unhexlify(trigger_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected
def test_extract_object(): return from decimal import Decimal import binascii # jack sparrow needs a new ship - same expected proposal data for both new & # old formats expected = { 'type': 1, 'name': 'jack-sparrow-new-ship', 'url': 'https://www.voting.galactrum.org/black-pearl', 'start_epoch': 1521429194, 'end_epoch': 1547183994, 'payment_address': 'yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui', 'payment_amount': Decimal('49'), } # test proposal old format json_str = binascii.unhexlify(proposal_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test proposal new format json_str = binascii.unhexlify(proposal_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # same expected trigger data for both new & old formats expected = { 'type': 2, 'event_block_height': 62500, 'payment_addresses': 'yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui|yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV', 'payment_amounts': '5|3', } # test trigger old format json_str = binascii.unhexlify(trigger_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test trigger new format json_str = binascii.unhexlify(trigger_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected
def test_extract_object(): from decimal import Decimal import binascii # jack sparrow needs a new ship - same expected proposal data for both new & # old formats expected = { 'type': 1, 'name': 'jack-sparrow-new-ship-using-syscoin', 'url': 'https://whitepaper.syscoin.org', 'start_epoch': 1527708518, 'end_epoch': 1547183994, 'payment_address': 'TSTfeMeWwQiCDwMSTWRaj9wwVGNjZFfvFk', 'payment_amount': Decimal('49'), } # test proposal old format json_str = binascii.unhexlify(proposal_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test proposal new format json_str = binascii.unhexlify(proposal_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # same expected trigger data for both new & old formats expected = { 'type': 2, 'event_block_height': 43800, 'payment_addresses': 'TSTfeMeWwQiCDwMSTWRaj9wwVGNjZFfvFk|TEjMnhB5mAPrpg7R4CUCSGQNnJqPeAFBTH', 'payment_amounts': '5|3', } # test trigger old format json_str = binascii.unhexlify(trigger_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test trigger new format json_str = binascii.unhexlify(trigger_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected
def test_extract_object(): from decimal import Decimal import binascii # jack sparrow needs a new ship - same expected proposal data for both new & # old formats expected = { 'type': 1, 'name': 'jack-sparrow-new-ship', 'url': 'https://www.dashcentral.org/black-pearl', 'start_epoch': 1521429194, 'end_epoch': 1547183994, 'payment_address': 'TXDSaTXerg68SCyLkWw2ERsqoTMWRBZiZQ', 'payment_amount': Decimal('49'), } # test proposal old format json_str = binascii.unhexlify(proposal_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test proposal new format json_str = binascii.unhexlify(proposal_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # same expected trigger data for both new & old formats expected = { 'type': 2, 'event_block_height': 62500, 'payment_addresses': 'TXDSaTXerg68SCyLkWw2ERsqoTMWRBZiZQ|TDWz9KfMo55wzj2brbgaXxnDz28nAbdPcY', 'payment_amounts': '5|3', } # test trigger old format json_str = binascii.unhexlify(trigger_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test trigger new format json_str = binascii.unhexlify(trigger_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected
def test_extract_object(): from decimal import Decimal import binascii # jack sparrow needs a new ship - same expected proposal data for both new & # old formats expected = { 'type': 1, 'name': 'jack-sparrow-new-ship', 'url': 'https://www.gobytecentral.org/black-pearl', 'start_epoch': 1521429194, 'end_epoch': 1547183994, 'payment_address': 'nLLGSuauCV21NBpHJpLHKevWpwE3t6CHGc', 'payment_amount': Decimal('49'), } # test proposal old format json_str = binascii.unhexlify(proposal_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test proposal new format json_str = binascii.unhexlify(proposal_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # same expected trigger data for both new & old formats expected = { 'type': 2, 'event_block_height': 62500, 'payment_addresses': 'nLLGSuauCV21NBpHJpLHKevWpwE3t6CHGc|yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV', 'payment_amounts': '5|3', } # test trigger old format json_str = binascii.unhexlify(trigger_hex_old()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected # test trigger new format json_str = binascii.unhexlify(trigger_hex_new()).decode('utf-8') assert gobject_json.extract_object(json_str) == expected
def import_gobject_from_emralsd(self, emralsd, rec): import decimal import emralslib import binascii import gobject_json object_hash = rec['Hash'] gobj_dict = { 'object_hash': object_hash, 'object_fee_tx': rec['CollateralHash'], 'absolute_yes_count': rec['AbsoluteYesCount'], 'abstain_count': rec['AbstainCount'], 'yes_count': rec['YesCount'], 'no_count': rec['NoCount'], } # deserialise and extract object json_str = binascii.unhexlify(rec['DataHex']).decode('utf-8') dikt = gobject_json.extract_object(json_str) subobj = None type_class_map = { 1: Proposal, 2: Superblock, } subclass = type_class_map[dikt['type']] # set object_type in govobj table gobj_dict['object_type'] = subclass.govobj_type # exclude any invalid model data from emralsd... valid_keys = subclass.serialisable_fields() subdikt = {k: dikt[k] for k in valid_keys if k in dikt} # get/create, then sync vote counts from emralsd, with every run govobj, created = self.get_or_create(object_hash=object_hash, defaults=gobj_dict) if created: printdbg("govobj created = %s" % created) count = govobj.update(**gobj_dict).where(self.id == govobj.id).execute() if count: printdbg("govobj updated = %d" % count) subdikt['governance_object'] = govobj # get/create, then sync payment amounts, etc. from emralsd - Emralsd is the master try: newdikt = subdikt.copy() newdikt['object_hash'] = object_hash if subclass(**newdikt).is_valid() is False: govobj.vote_delete(emralsd) return (govobj, None) subobj, created = subclass.get_or_create(object_hash=object_hash, defaults=subdikt) except Exception as e: # in this case, vote as delete, and log the vote in the DB printdbg("Got invalid object from emralsd! %s" % e) govobj.vote_delete(emralsd) return (govobj, None) if created: printdbg("subobj created = %s" % created) count = subobj.update(**subdikt).where(subclass.id == subobj.id).execute() if count: printdbg("subobj updated = %d" % count) # ATM, returns a tuple w/gov attributes and the govobj return (govobj, subobj)