pattern-tech / gateway

Middleware that standardizes DEX API endpoints on different blockchain networks
Apache License 2.0
1 stars 1 forks source link

[BUG] There is no check if the network is wrong #16

Closed mehrdadmms closed 1 month ago

mehrdadmms commented 2 months ago

Case

based on the code below:

  public static getInstance(network: string): Ergo {
    const config = getErgoConfig(network);

    if (!Ergo._instances) {
      Ergo._instances = new LRUCache<string, Ergo>({
        max: config.network.maxLRUCacheInstances,
      });
    }

    if (!Ergo._instances.has(config.network.name)) {
      if (network) {
        Ergo._instances.set(config.network.name, new Ergo(network));
      } else {
        throw new Error(
          `Ergo.getInstance received an unexpected network: ${network}.`,
        );
      }
    }

    return Ergo._instances.get(config.network.name) as Ergo;
  }

when initializing a network if I enter an invalid network like “sadefcqwr,l” no error will be returned.

this is the code I write:

import { Ergo } from './ergo';
const ergo = new Ergo('sadefcqwr,l');
console.log(ergo);

and this is the output:

Ergo {
_assetMap: {},
_chain: 'ergo',
_ready: false,
ammPools: [],
_networkPrefix: 16,
_network: 'sadef cqwr,l',
_node: NodeService {
nodeURL: 'http://213.239.193.208:9053/',
timeout: 50000
},
other configs ...
}