@muirglacier/testcontainers
Similar to testcontainers in the Java ecosystem, this package provides a lightweight,
throwaway instances of regtest
, testnet
or mainnet
provisioned automatically in Docker container.
@muirglacier/testcontainers
encapsulate on top of defi/defichain:v1.x
and directly interface with the Docker REST API.
With @muirglacier/testcontainers
, it allows the JS developers to:
- End-to-end test their application without hassle of setting up the toolchain
- Run parallel tests as port number and container are dynamically generated on demand
- Supercharge our CI workflow; run locally, anywhere or CI (as long as it has Docker installed)
- Supercharge your
@muirglacier/jellyfish-*
implementation with 100% day 1 compatibility (mono repo!) - Bring quality and reliability to dApps on the DeFiChain JS ecosystem
Usage Example
Install as dev only as you don't need this in production. Please don't use this in production!
npm i defichain
npm i -D @muirglacier/testcontainers
Use your favourite jest runner and start building dApps!
Basic RegTestContainer
setup
import { RegTestDocker } from '@muirglacier/testcontainers'
describe('reg test container', () => {
const container = new RegTestContainer()
beforeEach(async () => {
await container.start()
await container.waitForReady()
})
afterEach(async () => {
await container.stop()
})
it('should getmininginfo and chain should be regtest', async () => {
const result = await container.call('getmininginfo', [])
expect(result.chain).toStrictEqual('regtest')
})
})
MasterNodeRegTestContainer
with auto-minting
import { MasterNodeRegTestContainer } from '@muirglacier/testcontainers'
import waitForExpect from "wait-for-expect";
describe('master node pos minting', () => {
const container = new MasterNodeRegTestContainer()
beforeEach(async () => {
await container.start()
await container.waitForReady()
})
afterEach(async () => {
await container.stop()
})
it('should wait until coinbase maturity with spendable balance', async () => {
await container.waitForWalletCoinbaseMaturity()
await waitForExpect(async () => {
const info = await container.getMiningInfo()
expect(info.blocks).toBeGreaterThan(100)
})
const address = await container.getNewAddress()
const payload: { [key: string]: string } = {}
payload[address] = "100@0"
await container.call("utxostoaccount", [payload])
})
})
Endpoint?
const container = new MasterNodeRegTestContainer()
const rpcURL = await container.getCachedRpcUrl()
const port = await container.getPort('8555/tcp')
Included container.call('method', [])
for convenience RPC calls
const container = new MasterNodeRegTestContainer()
await container.start()
await container.waitForReady()
const { blocks } = await container.call('getmininginfo')
const address = await container.call('getnewaddress', ['label', 'legacy'])
const count = await container.getBlockCount()
const info = await container.getMiningInfo()
const newAddress = await container.getNewAddress()