@muirglacier/testcontainers
Version:
A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance for Bitcoin
126 lines • 4.05 kB
TypeScript
import { DockerOptions } from 'dockerode';
import { DockerContainer } from './DockerContainer';
/**
* Types of network as per https://github.com/DeFiCh/ain/blob/bc231241/src/chainparams.cpp#L825-L836
*/
declare type Network = 'mainnet' | 'testnet' | 'devnet' | 'regtest';
/**
* Mandatory options to start defid with
*/
export interface StartOptions {
user?: string;
password?: string;
timeout?: number;
}
/**
* DeFiChain defid node managed in docker
*/
export declare abstract class DeFiDContainer extends DockerContainer {
protected readonly network: Network;
protected readonly image: string;
static readonly PREFIX = "defichain-testcontainers-";
static get image(): string;
static readonly DefaultStartOptions: {
user: string;
password: string;
};
protected startOptions?: StartOptions;
protected cachedRpcUrl?: string;
/**
* @param {Network} network of the container
* @param {string} image docker image name
* @param {DockerOptions} options
*/
protected constructor(network: Network, image?: string, options?: DockerOptions);
/**
* Convenience Cmd builder with StartOptions
*/
protected getCmd(opts: StartOptions): string[];
/**
* Create container and start it immediately waiting for defid to be ready
*/
start(startOptions?: StartOptions): Promise<void>;
/**
* Set contents of ~/.defi/defi.conf
* @param {string[]} options to set
*/
setDeFiConf(options: string[]): Promise<void>;
/**
* Generate a name for a new docker container with network type and random number
*/
generateName(): string;
/**
* Get host machine port used for defid rpc
*/
abstract getRpcPort(): Promise<string>;
/**
* Get host machine url used for defid rpc calls with auth
* TODO(fuxingloh): not a great design when network config changed, the url and ports get refresh
*/
getCachedRpcUrl(): Promise<string>;
/**
* For convenience sake, utility rpc for the current node.
* JSON 'result' is parsed and returned
* @throws DeFiDRpcError is raised for RPC errors
*/
call(method: string, params?: any): Promise<any>;
/**
* For convenience sake, HTTP post to the RPC URL for the current node.
* Not error checked, returns the raw JSON as string.
*/
post(body: string): Promise<string>;
/**
* Convenience method to getmininginfo, typing mapping is non exhaustive
*/
getMiningInfo(): Promise<{
blocks: number;
chain: string;
}>;
/**
* Convenience method to getblockcount, typing mapping is non exhaustive
*/
getBlockCount(): Promise<number>;
/**
* Convenience method to getbestblockhash, typing mapping is non exhaustive
*/
getBestBlockHash(): Promise<string>;
/**
* Connect another node
* @param {string} ip
* @return {Promise<void>}
*/
addNode(ip: string): Promise<void>;
/**
* Wait for rpc to be ready
* @param {number} [timeout=20000] in millis
*/
private waitForRpc;
/**
* @deprecated as container.start() will automatically wait for ready now, you don't need to call this anymore
*/
waitForReady(timeout?: number): Promise<void>;
/**
* Stop and remove the current node and their associated volumes.
*
* This method will also automatically stop and removes nodes that are stale.
* Stale nodes are nodes that are running for more than 1 hour
*/
stop(): Promise<void>;
/**
* Restart container and wait for defid to be ready.
* This will stop the container and start it again with old data intact.
* @param {number} [timeout=30000] in millis
*/
restart(timeout?: number): Promise<void>;
}
/**
* RPC error from container
*/
export declare class DeFiDRpcError extends Error {
constructor(error: {
code: number;
message: string;
});
}
export {};
//# sourceMappingURL=DeFiDContainer.d.ts.map