Best Python code snippet using Airtest
migrate_export_from_v1.4.3_to_v1.6.0.py
Source:migrate_export_from_v1.4.3_to_v1.6.0.py  
1import json2in_file = 'exported_step_1.json'3out_file = 'genesis.json'4# Load genesis5with open(in_file, 'r') as f:6    data = json.load(f)7# ------------------------------------------------------------ 1.4.3 to 1.5.08# Migrating auth9# Removing treasury module account, adding transfer module account10found_treasury = False11for acc in data['app_state']['auth']['accounts']:12    if acc['@type'] == "/cosmos.auth.v1beta1.ModuleAccount" and acc['name'] == "treasury":13        found_treasury = True14        acc['name'] = "transfer"15        acc['base_account']['address'] = "ixo1yl6hdjhmkf37639730gffanpzndzdpmh32gmns"16if not found_treasury:17    first_unused_acc_number = str(len(data['app_state']['auth']['accounts']))18    data['app_state']['auth']['accounts'].append(19        {20            '@type': '/cosmos.auth.v1beta1.ModuleAccount',21            'base_account': {22                'account_number': first_unused_acc_number,23                'address': 'ixo1yl6hdjhmkf37639730gffanpzndzdpmh32gmns',24                'pub_key': None,25                'sequence': '0'26            },27            'name': 'transfer',28            'permissions': ['minter', 'burner']29        }30    )31# Add mint account32first_unused_acc_number = str(len(data['app_state']['auth']['accounts']))33data['app_state']['auth']['accounts'].append(34    {35        '@type': '/cosmos.auth.v1beta1.ModuleAccount',36        'base_account': {37            'account_number': first_unused_acc_number,38            'address': 'ixo1m3h30wlvsf8llruxtpukdvsy0km2kum8hye2rn',39            'pub_key': None,40            'sequence': '0'41        },42        'name': 'mint',43        'permissions': ['minter']44    })45# Migrating bank46data['app_state']['bank']['denom_metadata'] = [47    {48        "base": "uatom",49        "denom_units": [50            {"aliases": ["microatom"], "denom": "uatom", "exponent": 0},51            {"aliases": ["milliatom"], "denom": "matom", "exponent": 3},52            {"aliases": [], "denom": "atom", "exponent": 6}53        ],54        "description": "The native staking token of the Cosmos Hub.",55        "display": "atom"56    },57    {58        "base": "uixo",59        "denom_units": [60            {"aliases": ["microixo"], "denom": "uixo", "exponent": 0},61            {"aliases": ["milliixo"], "denom": "mixo", "exponent": 3},62            {"aliases": [], "denom": "ixo", "exponent": 6}63        ],64        "description": "The native staking token of ixo.",65        "display": "ixo"66    },67]68# Migrating bonds69if data['app_state']['bonds'] and data['app_state']['bonds']['batches']:70    for batch in data['app_state']['bonds']['batches']:71        if batch['buy_prices'] is None:72            batch['buy_prices'] = []73        if batch['buys'] is None:74            batch['buys'] = []75        if batch['sell_prices'] is None:76            batch['sell_prices'] = []77        if batch['sells'] is None:78            batch['sells'] = []79        if batch['swaps'] is None:80            batch['swaps'] = []81if data['app_state']['bonds'] and data['app_state']['bonds']['bonds']:82    for bond in data['app_state']['bonds']['bonds']:83        if bond['function_parameters'] is None:84            bond['function_parameters'] = []85if data['app_state']['bonds']['params']['reserved_bond_tokens'] is None:86    data['app_state']['bonds']['params']['reserved_bond_tokens'] = []87# Adding capability88data['app_state']['capability'] = {"index": "2", "owners": []}89data['app_state']['capability']['owners'].append({"index": "1", "index_owners": {"owners": []}})90data['app_state']['capability']['owners'][0]['index_owners']['owners'].append({"module": "ibc", "name": "ports/transfer"})91data['app_state']['capability']['owners'][0]['index_owners']['owners'].append({"module": "transfer", "name": "ports/transfer"})92# Migrating did93for el in data['app_state']['did']['did_docs']:94    el['@type'] = "/did.BaseDidDoc"95    del el['type']96    if el['value']['credentials'] is not None:97        for cred in el['value']['credentials']:98            cred['claim']['KYC_validated'] = cred['claim']['KYCValidated']99            del cred['claim']['KYCValidated']100            cred['cred_type'] = cred['type']101            del cred['type']102    if el['value']['credentials'] is None:103        el['value']['credentials'] = []104    el['credentials'] = el['value']['credentials']105    el['did'] = el['value']['did']106    el['pub_key'] = el['value']['pubKey']107    del el['value']108# Adding ibc109data['app_state']['ibc'] = {"channel_genesis": {"ack_sequences": [], "acknowledgements": [], "channels": [],110                                                "commitments": [], "next_channel_sequence": "0", "receipts": [], "recv_sequences": [],111                                                "send_sequences": []},112                            "client_genesis": {"clients": [], "clients_consensus": [], "clients_metadata": [],113                                               "create_localhost": False, "next_client_sequence": "0", "params": {"allowed_clients": []}},114                            "connection_genesis": {"client_connection_paths": [], "connections": [], "next_connection_sequence": "0"}}115data['app_state']['ibc']['client_genesis']['params']['allowed_clients'].append("07-tendermint")116# Removing oracles117del data['app_state']['oracles']118# Migrating payments119if data['app_state']['payments']['payment_templates'] is not None:120    for temp in data['app_state']['payments']['payment_templates']:121        if temp['discounts'] is None:122            temp['discounts'] = []123if data['app_state']['payments']['subscriptions'] is None:124    data['app_state']['payments']['subscriptions'] = []125# Migrating project126if data['app_state']['project'] and data['app_state']['project']['account_maps']:127    if len(data['app_state']['project']['account_maps']) > 0:128        maps = []129        for acc_map in data['app_state']['project']['account_maps']:130            maps.append(acc_map)131            del acc_map132        for i, acc_map in enumerate(maps):133            data['app_state']['project']['account_maps'][i] = {"map": acc_map}134if data['app_state']['project'] and data['app_state']['project']['claims']:135    if len(data['app_state']['project']['claims']) > 0:136        claims = []137        for claims_list in data['app_state']['project']['claims']:138            claims.append(claims_list)139            del claims_list140        for i, claims_list in enumerate(claims):141            if claims_list is None:142                data['app_state']['project']['claims'][i] = {"claims_list": []}143            else:144                data['app_state']['project']['claims'][i] = {"claims_list": claims_list}145if data['app_state']['project'] and data['app_state']['project']['project_docs']:146    for project_doc in data['app_state']['project']['project_docs']:147        project_doc['project_did'] = project_doc['projectDid']148        del project_doc['projectDid']149        project_doc['pub_key'] = project_doc['pubKey']150        del project_doc['pubKey']151        project_doc['sender_did'] = project_doc['senderDid']152        del project_doc['senderDid']153        project_doc['tx_hash'] = project_doc['txHash']154        del project_doc['txHash']155if data['app_state']['project'] and data['app_state']['project']['withdrawal_infos']:156    if len(data['app_state']['project']['withdrawal_infos']) > 0:157        wds = []158        for wd_list in data['app_state']['project']['withdrawal_infos']:159            wds.append(wd_list)160            del wd_list161        for i, wd_list in enumerate(wds):162            if wd_list is None:163                data['app_state']['project']['withdrawal_infos'][i] = {"docs_list": []}164            else:165                data['app_state']['project']['withdrawal_infos'][i] = {"docs_list": wd_list}166data['app_state']['project']['withdrawals_infos'] = data['app_state']['project']['withdrawal_infos']167del data['app_state']['project']['withdrawal_infos']168# Migrate staking169data['app_state']['staking']['exported'] = True170# Removing treasury171del data['app_state']['treasury']172# Adding transfer173data['app_state']['transfer'] = {"denom_traces": [], "params": {"receive_enabled": False, "send_enabled": False}, "port_id": "transfer"}174# Adding vesting175data['app_state']['vesting'] = {}176# Migrate evidence177data['consensus_params']['evidence']['max_bytes'] = "50000"178# ------------------------------------------------------------ 1.5.0 to 1.6.0179# Migrating bonds180if data['app_state']['bonds'] and data['app_state']['bonds']['bonds']:181    for bond in data['app_state']['bonds']['bonds']:182        bond['reserve_withdrawal_address'] = bond['fee_address']183        bond['allow_reserve_withdrawals'] = False184        bond['available_reserve'] = bond['current_reserve']185# ------------------------------------------------------------ GENERAL186# Update chain ID187data['chain_id'] = 'impacthub-3'188# Update genesis time189data['genesis_time'] = '2021-08-19T12:00:00Z'190# Update initial height191data['initial_height'] = '1'192# Change max validators to 50 as indicated in:193# https://github.com/ixofoundation/governance/blob/main/proposals/001-stargate-upgrade/readme.md194data['app_state']['staking']['params']['max_validators'] = 50195# Finishing touches (replace & with unicode)196data = json.dumps(data, indent=2, sort_keys=True, ensure_ascii=False)197data = data.replace('&', '\\u0026')198# Output migrated genesis199with open(out_file, 'w') as f:...migrate_export_to_v1.5.0.py
Source:migrate_export_to_v1.5.0.py  
1import json2in_file = 'exported_step_1.json'3out_file = 'genesis.json'4# Load genesis5with open(in_file, 'r') as f:6    data = json.load(f)7# Migrating auth8# Removing treasury module account, adding transfer module account9found_treasury = False10for acc in data['app_state']['auth']['accounts']:11    if acc['@type'] == "/cosmos.auth.v1beta1.ModuleAccount" and acc['name'] == "treasury":12        found_treasury = True13        acc['name'] = "transfer"14        acc['base_account']['address'] = "ixo1yl6hdjhmkf37639730gffanpzndzdpmh32gmns"15if not found_treasury:16    raise Exception("Did not find treasury account in exported.json.")17# Migrating bank18data['app_state']['bank']['denom_metadata'] = [19    {20        "base": "uatom",21        "denom_units": [22            {"aliases": ["microatom"], "denom": "uatom", "exponent": 0},23            {"aliases": ["milliatom"], "denom": "matom", "exponent": 3},24            {"aliases": [], "denom": "atom", "exponent": 6}25        ],26        "description": "The native staking token of the Cosmos Hub.",27        "display": "atom"28    },29    {30        "base": "uixo",31        "denom_units": [32            {"aliases": ["microixo"], "denom": "uixo", "exponent": 0},33            {"aliases": ["milliixo"], "denom": "mixo", "exponent": 3},34            {"aliases": [], "denom": "ixo", "exponent": 6}35        ],36        "description": "The native staking token of ixo.",37        "display": "ixo"38    },39]40# Migrating bonds41for batch in data['app_state']['bonds']['batches']:42    if batch['buy_prices'] is None:43        batch['buy_prices'] = []44    if batch['buys'] is None:45        batch['buys'] = []46    if batch['sell_prices'] is None:47        batch['sell_prices'] = []48    if batch['sells'] is None:49        batch['sells'] = []50    if batch['swaps'] is None:51        batch['swaps'] = []52for bond in data['app_state']['bonds']['bonds']:53    if bond['function_parameters'] is None:54        bond['function_parameters'] = []55if data['app_state']['bonds']['params']['reserved_bond_tokens'] is None:56    data['app_state']['bonds']['params']['reserved_bond_tokens'] = []57# Adding capability58data['app_state']['capability'] = {"index": "2", "owners": []}59data['app_state']['capability']['owners'].append({"index": "1", "index_owners": {"owners": []}})60data['app_state']['capability']['owners'][0]['index_owners']['owners'].append({"module": "ibc", "name": "ports/transfer"})61data['app_state']['capability']['owners'][0]['index_owners']['owners'].append({"module": "transfer", "name": "ports/transfer"})62# Migrating did63for el in data['app_state']['did']['did_docs']:64    el['@type'] = "/did.BaseDidDoc"65    del el['type']66    if el['value']['credentials'] is not None:67        for cred in el['value']['credentials']:68            cred['claim']['KYC_validated'] = cred['claim']['KYCValidated']69            del cred['claim']['KYCValidated']70            cred['cred_type'] = cred['type']71            del cred['type']72    if el['value']['credentials'] is None:73        el['value']['credentials'] = []74    el['credentials'] = el['value']['credentials']75    el['did'] = el['value']['did']76    el['pub_key'] = el['value']['pubKey']77    del el['value']78# Adding ibc79data['app_state']['ibc'] = {"channel_genesis": {"ack_sequences": [], "acknowledgements": [], "channels": [],80                                                "commitments": [], "next_channel_sequence": "0", "receipts": [], "recv_sequences": [],81                                                "send_sequences": []},82                            "client_genesis": {"clients": [], "clients_consensus": [], "clients_metadata": [],83                                               "create_localhost": False, "next_client_sequence": "0", "params": {"allowed_clients": []}},84                            "connection_genesis": {"client_connection_paths": [], "connections": [], "next_connection_sequence": "0"}}85data['app_state']['ibc']['client_genesis']['params']['allowed_clients'].append("07-tendermint")86# Removing oracles87del data['app_state']['oracles']88# Migrating payments89if data['app_state']['payments']['payment_templates'] is not None:90    for temp in data['app_state']['payments']['payment_templates']:91        if temp['discounts'] is None:92            temp['discounts'] = []93if data['app_state']['payments']['subscriptions'] is None:94    data['app_state']['payments']['subscriptions'] = []95# Migrating project96if len(data['app_state']['project']['account_maps']) > 0:97    maps = []98    for acc_map in data['app_state']['project']['account_maps']:99        maps.append(acc_map)100        del acc_map101    for i, acc_map in enumerate(maps):102        data['app_state']['project']['account_maps'][i] = {"map": acc_map}103if len(data['app_state']['project']['claims']) > 0:104    claims = []105    for claims_list in data['app_state']['project']['claims']:106        claims.append(claims_list)107        del claims_list108    for i, claims_list in enumerate(claims):109        if claims_list is None:110            data['app_state']['project']['claims'][i] = {"claims_list": []}111        else:112            data['app_state']['project']['claims'][i] = {"claims_list": claims_list}113for project_doc in data['app_state']['project']['project_docs']:114    project_doc['project_did'] = project_doc['projectDid']115    del project_doc['projectDid']116    project_doc['pub_key'] = project_doc['pubKey']117    del project_doc['pubKey']118    project_doc['sender_did'] = project_doc['senderDid']119    del project_doc['senderDid']120    project_doc['tx_hash'] = project_doc['txHash']121    del project_doc['txHash']122if len(data['app_state']['project']['withdrawal_infos']) > 0:123    wds = []124    for wd_list in data['app_state']['project']['withdrawal_infos']:125        wds.append(wd_list)126        del wd_list127    for i, wd_list in enumerate(wds):128        if wd_list is None:129            data['app_state']['project']['withdrawal_infos'][i] = {"docs_list": []}130        else:131            data['app_state']['project']['withdrawal_infos'][i] = {"docs_list": wd_list}132data['app_state']['project']['withdrawals_infos'] = data['app_state']['project']['withdrawal_infos']133del data['app_state']['project']['withdrawal_infos']134# Migrate staking135data['app_state']['staking']['exported'] = True136# Removing treasury137del data['app_state']['treasury']138# Adding transfer139data['app_state']['transfer'] = {"denom_traces": [], "params": {"receive_enabled": True, "send_enabled": True}, "port_id": "transfer"}140# Adding vesting141data['app_state']['vesting'] = {}142# Migrate evidence143data['consensus_params']['evidence']['max_bytes'] = "50000"144# Update chain ID145data['chain_id'] = 'pandora-3'146# Update genesis time147data['genesis_time'] = '2021-06-30T12:00:00Z'148# Finishing touches (replace & with unicode)149data = json.dumps(data, indent=2, sort_keys=True, ensure_ascii=False)150data = data.replace('&', '\\u0026')151# Output migrated genesis152with open(out_file, 'w') as f:...migrate_export_to_v1.4.3.py
Source:migrate_export_to_v1.4.3.py  
1import json2in_file = 'exported.json'3out_file = 'genesis.json'4# Load genesis5with open(in_file, 'r') as f:6    data = json.load(f)7# Migrate auth/accounts8data['app_state']['auth']['accounts'] = []9accs = data['app_state']['accounts']10for i, _ in enumerate(accs):11    acc = accs[i]12    is_module_account = acc['module_name'] != ""13    is_continuous_vesting_account = acc['start_time'] != "0" and acc['end_time'] != "0"14    is_delayed_vesting_account = acc['end_time'] != "0"15    if is_module_account:16        new_acc = {17            "type": "cosmos-sdk/ModuleAccount",18            "value": {19                "account_number": acc['account_number'],20                "address": acc['address'],21                "coins": acc['coins'],22                "name": acc['module_name'],23                "permissions": acc['module_permissions'],24                "public_key": "",25                "sequence": acc['sequence_number']26            }27        }28    elif is_continuous_vesting_account:29        new_acc = {30            "type": "cosmos-sdk/ContinuousVestingAccount",31            "value": {32                "account_number": acc['account_number'],33                "address": acc['address'],34                "coins": acc['coins'],35                "delegated_free": acc['delegated_free'],36                "delegated_vesting": acc['delegated_vesting'],37                "end_time": acc['end_time'],38                "original_vesting": acc['original_vesting'],39                "public_key": None,40                "sequence": acc['sequence_number'],41                "start_time": acc['start_time']42            }43        }44    elif is_delayed_vesting_account:45        new_acc = {46            "type": "cosmos-sdk/DelayedVestingAccount",47            "value": {48                "account_number": acc['account_number'],49                "address": acc['address'],50                "coins": acc['coins'],51                "delegated_free": acc['delegated_free'],52                "delegated_vesting": acc['delegated_vesting'],53                "end_time": acc['end_time'],54                "original_vesting": acc['original_vesting'],55                "public_key": None,56                "sequence": acc['sequence_number']57            }58        }59    else:60        new_acc = {61            "type": "cosmos-sdk/Account",62            "value": {63                "account_number": acc['account_number'],64                "address": acc['address'],65                "coins": acc['coins'],66                "public_key": None,67                "sequence": acc['sequence_number']68            }69        }70    data['app_state']['auth']['accounts'].append(new_acc)71del data['app_state']['accounts']72# Migrate distribution73data['app_state']['distribution']['params'] = {74    "base_proposer_reward": data['app_state']['distribution']['base_proposer_reward'],75    "bonus_proposer_reward": data['app_state']['distribution']['bonus_proposer_reward'],76    "community_tax": data['app_state']['distribution']['community_tax'],77    "withdraw_addr_enabled": data['app_state']['distribution']['withdraw_addr_enabled'],78}79del data['app_state']['distribution']['base_proposer_reward']80del data['app_state']['distribution']['bonus_proposer_reward']81del data['app_state']['distribution']['community_tax']82del data['app_state']['distribution']['withdraw_addr_enabled']83# Migrate evidence84data['app_state']['evidence'] = {85    "evidence": None,86    "params": {87        "max_evidence_age": data['app_state']['slashing']['params'][88            'max_evidence_age']89    }90}91# Migrate genutil92data['app_state']['genutil'] = {93    "gentxs": []94}95# Migrate gov96if len(data['app_state']['gov']['proposals']) == 0:97    data['app_state']['gov']['proposals'] = None98# Migrate project99data['app_state']['project']['claims'] = []100# Migrate slashing101del data['app_state']['slashing']['params']['max_evidence_age']102# Migrate staking103data['app_state']['staking']['params']['historical_entries'] = 0104validators = data['app_state']['staking']['validators']105for i, _ in enumerate(validators):106    validators[i]['description']['security_contact'] = ""107# Migrate upgrade108data['app_state']['upgrade'] = {}109# Update chain ID110data['chain_id'] = 'impacthub-2'111# Update genesis time112data['genesis_time'] = '2021-03-23T12:00:00Z'113# Migrate evidence consensus params114data['consensus_params']['evidence']['max_age_num_blocks'] = \115data['consensus_params']['evidence']['max_age']116del data['consensus_params']['evidence']['max_age']117data['consensus_params']['evidence']['max_age_duration'] = "172800000000000"118# Finishing touches (replace & with unicode)119data = json.dumps(data, indent=2, sort_keys=True, ensure_ascii=False)120data = data.replace('&', '\\u0026')121# Output migrated genesis122with open(out_file, 'w') as f:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
