-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anmol <[email protected]>
- Loading branch information
Showing
6 changed files
with
191 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import path from "path"; | ||
|
||
import { Config, ConfigContext } from "../src/config"; | ||
import { ChainRegistryFetcher } from "@chain-registry/client"; | ||
|
||
// it's more recommended to use ConfigContext.init to set the config file and registry. | ||
it("1. throws without init;\n 2. init the setup and gets config;\n 3. throws when double init;\n", async () => { | ||
expect(() => ConfigContext.registry).toThrow(); | ||
expect(() => ConfigContext.configFile).toThrow(); | ||
|
||
const file = path.join(__dirname, "../../../__fixtures__", "config.yaml"); | ||
|
||
// for unit test, only setup a chain registry fetcher without fetching. | ||
await Config.init(file, new ChainRegistryFetcher()); | ||
|
||
const registry = ConfigContext.registry; | ||
const configFile = ConfigContext.configFile; | ||
|
||
expect(registry).toBeInstanceOf(ChainRegistryFetcher); | ||
expect(configFile).toBe(file); | ||
|
||
expect( | ||
async () => await ConfigContext.init(file, new ChainRegistryFetcher()) | ||
).rejects.toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import path from "path"; | ||
|
||
import { Config, ConfigContext } from "../src/config"; | ||
import { ChainRegistryFetcher } from "@chain-registry/client"; | ||
|
||
// people can still use legacy ConfigContext to set the config file and registry. | ||
it("1. throws without init;\n 2. throws only init partially;\n 3. init the setup and gets config;\n 4. throws when double init;\n", async () => { | ||
expect(() => ConfigContext.registry).toThrow(); | ||
expect(() => ConfigContext.configFile).toThrow(); | ||
|
||
const file = path.join(__dirname, "../../../__fixtures__", "config.yaml"); | ||
|
||
ConfigContext.setConfigFile(file); | ||
|
||
expect(() => ConfigContext.registry).toThrow(); | ||
expect(() => ConfigContext.configFile).toThrow(); | ||
|
||
ConfigContext.setRegistry(new ChainRegistryFetcher()); | ||
|
||
const registry = ConfigContext.registry; | ||
const configFile = ConfigContext.configFile; | ||
|
||
expect(registry).toBeInstanceOf(ChainRegistryFetcher); | ||
expect(configFile).toBe(file); | ||
|
||
expect( | ||
async () => await ConfigContext.init(file, new ChainRegistryFetcher()) | ||
).rejects.toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters