Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

feat: add __experimental_info export to core #2529

Merged
merged 5 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { ConnectorsByName, DefaultFlavor, FlavorName } from "@ganache/flavors";
import { KNOWN_CHAINIDS } from "@ganache/utils";
import ConnectorLoader from "./src/connector-loader";
import { ProviderOptions, ServerOptions } from "./src/options";
import Server from "./src/server";
export { Server, ServerStatus, _DefaultServerOptions } from "./src/server";

export type { Provider, EthereumProvider, FilecoinProvider } from "@ganache/flavors";
export type { ProviderOptions, ServerOptions } from "./src/options";
export type _ExperimentalInfo = Readonly<{
version: string,
fork: Readonly<{
/**
* Chains Ganache is known to be compatible with. Operations performed
* locally at historic block numbers will use the Ethereum Virtual Machine
* OPCODEs, gas prices, and EIPs that were active at the time the historic
* block originally took place.
*/
knownChainIds: number[],
}>
}>


const version = process.env.VERSION || "DEV";

/**
* @public
Expand Down Expand Up @@ -46,6 +61,18 @@ const Ganache = {
): ConnectorsByName[T]["provider"] => {
const loader = ConnectorLoader.initialize<T>(options);
return loader.connector.provider;
},
/**
*
* @experimental
*/
__experimental_info(): _ExperimentalInfo {
return {
version,
fork: {
knownChainIds: Array.from(KNOWN_CHAINIDS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method seems good enough for me! Earlier you made it sound like there might be a more expansive thing with more info about the various chains, which might be nice for later, but if that's a bunch more work, well, knownChainIds does the job! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, we could potentially stuff a whole bunch of interesting stuff in here in the future.

}
};
}
};

Expand All @@ -57,6 +84,10 @@ export const server = Ganache.server;
* @public
*/
export const provider = Ganache.provider;
/**
* @experimental
*/
export const __experimental_info = Ganache.__experimental_info;
/**
* @public
*/
Expand Down
8 changes: 6 additions & 2 deletions src/packages/core/tests/interface.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import Ganache from "..";
import * as assert from "assert";
import { KNOWN_CHAINIDS } from "@ganache/utils";

describe("interface", () => {
it("has an interface", () => {
assert.ok(Ganache.server);
assert.ok(Ganache.provider);
assert.strictEqual(Object.keys(Ganache).length, 2);
const info = Ganache.__experimental_info();
assert.deepStrictEqual(info.fork.knownChainIds, Array.from(KNOWN_CHAINIDS));
assert.deepStrictEqual(info.version, "DEV");
assert.strictEqual(Object.keys(Ganache).length, 3);

// in v3 these two properties were *removed* because it was confusing.
// these tests are kinda unncessary, but I just want to intent to be
// these tests are kinda unnecessary, but I just want to intent to be
// explicit.
assert.strictEqual("Server" in Ganache, false);
assert.strictEqual("Provider" in Ganache, false);
Expand Down
7 changes: 6 additions & 1 deletion src/packages/ganache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ export type {
ProviderOptions,
EthereumProvider,
FilecoinProvider,
_ExperimentalInfo
} from "@ganache/core";
export {
server,
provider
provider,
/**
* @experimental
*/
__experimental_info
} from "@ganache/core";
import Ganache from "@ganache/core";
export default Ganache;