@@ -33,17 +33,17 @@ import { connect, init } from '../kilt'
3333export const EXISTENTIAL_DEPOSIT = new BN ( 10 ** 13 )
3434const ENDOWMENT = EXISTENTIAL_DEPOSIT . muln ( 10000 )
3535
36- const containerPromise = new GenericContainer (
37- process . env . TESTCONTAINERS_NODE_IMG || 'kiltprotocol/mashnet-node:latest'
38- )
39- . withCmd ( [ '--dev' , '--ws-port' , '9944' , '--ws-external' ] )
40- . withExposedPorts ( 9944 )
41- . withWaitStrategy ( Wait . forLogMessage ( 'Idle' ) )
42- . start ( )
43-
4436async function getStartedTestContainer ( ) : Promise < StartedTestContainer > {
4537 try {
46- return await containerPromise
38+ const image =
39+ process . env . TESTCONTAINERS_NODE_IMG || 'kiltprotocol/mashnet-node'
40+ console . log ( `using testcontainer with image ${ image } ` )
41+ const testcontainer = new GenericContainer ( image )
42+ . withCmd ( [ '--dev' , '--ws-port' , '9944' , '--ws-external' ] )
43+ . withExposedPorts ( 9944 )
44+ . withWaitStrategy ( Wait . forLogMessage ( / i d l e / i) )
45+ const started = await testcontainer . start ( )
46+ return started
4747 } catch ( error ) {
4848 console . error (
4949 'Could not start the docker container via testcontainers, run with DEBUG=testcontainers* to debug'
@@ -53,20 +53,21 @@ async function getStartedTestContainer(): Promise<StartedTestContainer> {
5353}
5454
5555export async function initializeApi ( ) : Promise < void > {
56- const started = await getStartedTestContainer ( )
57- const port = started . getMappedPort ( 9944 )
58- const host = started . getHost ( )
59- const WS_ADDRESS = `ws://${ host } :${ port } `
60- await init ( { address : WS_ADDRESS } )
61- const api = await connect ( )
62-
63- api . once ( 'disconnected' , async ( ) => {
64- try {
65- await started . stop ( )
66- } catch ( error ) {
67- console . error ( error )
68- }
69- } )
56+ if ( process . env . TEST_WS_ADDRESS ) {
57+ console . log ( `connecting to node ${ process . env . TEST_WS_ADDRESS } ` )
58+ await init ( { address : process . env . TEST_WS_ADDRESS } )
59+ connect ( )
60+ } else {
61+ const started = await getStartedTestContainer ( )
62+ const port = started . getMappedPort ( 9944 )
63+ const host = started . getHost ( )
64+ const WS_ADDRESS = `ws://${ host } :${ port } `
65+ console . log ( `connecting to node ${ WS_ADDRESS } ` )
66+ await init ( { address : WS_ADDRESS } )
67+ connect ( ) . then ( ( api ) =>
68+ api . once ( 'disconnected' , ( ) => started . stop ( ) . catch ( ) )
69+ )
70+ }
7071}
7172
7273const keyring = new Keyring ( { ss58Format, type : 'ed25519' } )
0 commit comments