@gala-chain/test ∙ API
API > TestClients
Variable: TestClients
constTestClients:object
Factory object for creating different types of test clients. Provides methods to create regular chain clients and admin clients with user management capabilities.
Example
// Create regular clients
const clients = await TestClients.create();
// Create admin clients for test setup
const adminClients = await TestClients.createForAdmin();
const testUser = await adminClients.createRegisteredUser();
// Cleanup
await clients.disconnect();
await adminClients.disconnect();
Type declaration
create
create: (
user?) =>Promise\<ChainClients\<DefaultChainClientOptions>>\<T>(user?,opts?) =>Promise\<ChainClients\<T>>\<T>(opts) =>Promise\<ChainClients\<T>>
Creates chain clients for testing GalaChain contracts.
This function has multiple overloads to support different configuration scenarios:
- create() - Creates clients with default user and configuration
- create(user) - Creates clients with specific user and default configuration
- create(opts) - Creates clients with default user and custom configuration
- create(user, opts) - Creates clients with specific user and custom configuration
Parameters
▪ user?: string | ChainUser
Chain user, user name string, or configuration object
Returns
Promise resolving to configured chain clients
Example
// Default configuration with random curator user
const clients1 = await create();
// Specific user with default configuration
const clients2 = await create(ChainUser.withRandomKeys(\"alice\"));
// Custom configuration with default user
const clients3 = await create({
myContract: { channel: \"ch1\", chaincode: \"cc1\", contract: \"MyContract\", api: myAPI }
});
// Specific user with custom configuration
const clients4 = await create(\"bob\", customConfig);
Type parameters
▪ T extends ChainClientOptions
Parameters
▪ user?: string | ChainUser
▪ opts?: T
Type parameters
▪ T extends ChainClientOptions
Parameters
▪ opts: T
createForAdmin
createForAdmin: \<
T>(opts?) =>Promise\<AdminChainClients\<T>>
Creates admin chain clients with elevated privileges for test setup. Admin clients can create and register new users, and have access to all configured contracts.
Type parameters
▪ T extends ChainClientOptions
The chain client options configuration
Parameters
▪ opts?: T
Optional configuration for contracts. If not provided, uses default configuration
Returns
Promise resolving to admin chain clients with user creation capabilities
Example
// Create with default configuration
const adminClients = await createForAdmin();
// Create with custom configuration
const customAdminClients = await createForAdmin({
myContract: {
channel: "my-channel",
chaincode: "my-chaincode",
contract: "MyContract",
api: myContractAPI
}
});