def setupTxns(self, key, force: bool = False): """ Create base transactions :param key: ledger :param force: replace existing transaction files """ import data dataDir = os.path.dirname(data.__file__) # TODO: Need to get "test" and "live" from ENVS property in config.py # but that gives error due to some dependency issue allEnvs = { "local": Environment("pool_transactions_local", "domain_transactions_local"), "test": Environment("pool_transactions_sandbox", "domain_transactions_sandbox"), "live": Environment("pool_transactions_live", "domain_transactions_live") } for env in allEnvs.values(): fileName = getattr(env, key, None) if not fileName: continue sourceFilePath = os.path.join(dataDir, fileName) if not os.path.exists(sourceFilePath): continue destFilePath = os.path.join( self.base_dir, genesis_txn_file(fileName)) if os.path.exists(destFilePath) and not force: continue copyfile(sourceFilePath, destFilePath) return self
def initDirWithGenesisTxns(dirName, tconf, tdirWithPoolTxns=None, tdirWithDomainTxns=None, new_pool_txn_file=None, new_domain_txn_file=None): os.makedirs(dirName, exist_ok=True) if tdirWithPoolTxns: new_pool_txn_file = new_pool_txn_file or tconf.poolTransactionsFile copyfile( os.path.join(tdirWithPoolTxns, genesis_txn_file(tconf.poolTransactionsFile)), os.path.join(dirName, genesis_txn_file(new_pool_txn_file))) if tdirWithDomainTxns: new_domain_txn_file = new_domain_txn_file or tconf.domainTransactionsFile copyfile( os.path.join(tdirWithDomainTxns, genesis_txn_file(tconf.domainTransactionsFile)), os.path.join(dirName, genesis_txn_file(new_domain_txn_file)))
def test_genesis_txn_file_initiator(tempdir, init_genesis_txn_file, genesis_txns): # Check that initiator of genesis txns work: # It uses a text file with JsonSerializer by default genesis_file = genesis_txn_file( os.path.join(tempdir, init_genesis_txn_file)) assert os.path.exists(genesis_file) i = 0 serializer = JsonSerializer() with open(genesis_file) as f: for line in store_utils.cleanLines(f.readlines()): assert sorted(serializer.deserialize(line).items() ) == sorted(genesis_txns[i].items()) i += 1
def initDirWithGenesisTxns( dirName, tconf, tdirWithPoolTxns=None, tdirWithDomainTxns=None, new_pool_txn_file=None, new_domain_txn_file=None): os.makedirs(dirName, exist_ok=True) if tdirWithPoolTxns: new_pool_txn_file = new_pool_txn_file or tconf.poolTransactionsFile copyfile( os.path.join( tdirWithPoolTxns, genesis_txn_file( tconf.poolTransactionsFile)), os.path.join( dirName, genesis_txn_file(new_pool_txn_file))) if tdirWithDomainTxns: new_domain_txn_file = new_domain_txn_file or tconf.domainTransactionsFile copyfile( os.path.join( tdirWithDomainTxns, genesis_txn_file( tconf.domainTransactionsFile)), os.path.join( dirName, genesis_txn_file(new_domain_txn_file)))
def _update_genesis_txn_file_name_if_outdated(transaction_file): old_named_path = os.path.join(_BASE_DIR, transaction_file) new_named_path = os.path.join(_BASE_DIR, genesis_txn_file(transaction_file)) if not os.path.exists(new_named_path) and os.path.isfile(old_named_path): os.rename(old_named_path, new_named_path)
def pool_genesis_file(genesis_dir, config_helper): return os.path.join( genesis_dir, genesis_txn_file( TestNetworkSetup.pool_ledger_file_name(config_helper.config)))
def pool_genesis_file(genesis_dir, config_helper): return os.path.join(genesis_dir, genesis_txn_file(TestNetworkSetup.pool_ledger_file_name(config_helper.config)))
def __init__(self, data_dir, txn_file, serializer=JsonSerializer()): self.__data_dir = data_dir self.__db_name = genesis_txn_file(txn_file) self.__serializer = serializer