diff --git a/src-network-providers/apiNetworkProvider.ts b/src-network-providers/apiNetworkProvider.ts index 170b2fb9..3d6bc556 100644 --- a/src-network-providers/apiNetworkProvider.ts +++ b/src-network-providers/apiNetworkProvider.ts @@ -1,12 +1,14 @@ import axios from "axios"; import { AccountOnNetwork, GuardianData } from "./accounts"; import { defaultAxiosConfig, defaultPagination } from "./config"; +import { BaseUserAgent } from "./constants"; import { ContractQueryRequest } from "./contractQueryRequest"; import { ContractQueryResponse } from "./contractQueryResponse"; import { ErrContractQuery, ErrNetworkProvider } from "./errors"; import { IAddress, IContractQuery, INetworkProvider, IPagination, ITransaction, ITransactionNext } from "./interface"; import { NetworkConfig } from "./networkConfig"; import { NetworkGeneralStatistics } from "./networkGeneralStatistics"; +import { NetworkProviderConfig } from "./networkProviderConfig"; import { NetworkStake } from "./networkStake"; import { NetworkStatus } from "./networkStatus"; import { PairOnNetwork } from "./pairs"; @@ -17,8 +19,6 @@ import { FungibleTokenOfAccountOnNetwork, NonFungibleTokenOfAccountOnNetwork } f import { TransactionOnNetwork, prepareTransactionForBroadcasting } from "./transactions"; import { TransactionStatus } from "./transactionStatus"; import { extendUserAgent } from "./userAgent"; -import { NetworkProviderConfig } from "./networkProviderConfig"; -import { BaseUserAgent } from "./constants"; // TODO: Find & remove duplicate code between "ProxyNetworkProvider" and "ApiNetworkProvider". export class ApiNetworkProvider implements INetworkProvider { @@ -36,7 +36,7 @@ export class ApiNetworkProvider implements INetworkProvider { } private getProxyConfig(config: NetworkProviderConfig | undefined) { - let proxyConfig = JSON.parse(JSON.stringify(config)); + let proxyConfig = JSON.parse(JSON.stringify(config || {})); proxyConfig = { ...defaultAxiosConfig, ...proxyConfig }; return proxyConfig; } diff --git a/src-network-providers/providers.dev.net.spec.ts b/src-network-providers/providers.dev.net.spec.ts index 890c0e55..8c603c43 100644 --- a/src-network-providers/providers.dev.net.spec.ts +++ b/src-network-providers/providers.dev.net.spec.ts @@ -1,4 +1,5 @@ -import { assert, expect } from "chai"; +import { AxiosHeaders } from "axios"; +import { assert } from "chai"; import { ApiNetworkProvider } from "./apiNetworkProvider"; import { INetworkProvider, ITransactionNext } from "./interface"; import { Address } from "./primitives"; @@ -7,7 +8,6 @@ import { MockQuery } from "./testscommon/dummyQuery"; import { NonFungibleTokenOfAccountOnNetwork } from "./tokens"; import { TransactionEventData } from "./transactionEvents"; import { TransactionOnNetwork } from "./transactions"; -import { AxiosHeaders } from "axios"; describe("test network providers on devnet: Proxy and API", function () { let alice = new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); @@ -18,6 +18,17 @@ describe("test network providers on devnet: Proxy and API", function () { let apiProvider: INetworkProvider = new ApiNetworkProvider("https://devnet-api.multiversx.com", { timeout: 10000, clientName: 'test' }); let proxyProvider: INetworkProvider = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com", { timeout: 10000, clientName: 'test' }); + it("should create providers without configuration", async function () { + const apiProviderWithoutConfig = new ApiNetworkProvider("https://devnet-api.multiversx.com"); + const proxyProviderWithoutConfig = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com"); + + const apiResponse = await apiProviderWithoutConfig.getNetworkConfig(); + const proxyResponse = await proxyProviderWithoutConfig.getNetworkConfig(); + + assert.equal(apiResponse.ChainID, "D"); + assert.equal(proxyResponse.ChainID, "D"); + }); + it("should have same response for getNetworkConfig()", async function () { let apiResponse = await apiProvider.getNetworkConfig(); let proxyResponse = await proxyProvider.getNetworkConfig();