1
- /* eslint-disable max-statements */
2
1
import { AddressType , KeyRole } from '@cardano-sdk/key-management' ;
3
2
import { Cardano } from '@cardano-sdk/core' ;
4
3
import {
@@ -13,24 +12,72 @@ import {
13
12
walletReady ,
14
13
walletVariables
15
14
} from '../../src' ;
15
+ import { containerExec } from 'dockerode-utils' ;
16
+ import { getRandomPort } from 'get-port-please' ;
16
17
import { logger } from '@cardano-sdk/util-dev' ;
18
+ import Docker from 'dockerode' ;
19
+ import path from 'path' ;
17
20
18
- const env = getEnv ( walletVariables ) ;
19
21
const vrf = Cardano . VrfVkHex ( '2ee5a4c423224bb9c42107fc18a60556d6a83cec1d9dd37a71f56af7198fc759' ) ;
20
22
21
- const wallet1Params : KeyAgentFactoryProps = {
22
- accountIndex : 0 ,
23
- chainId : env . KEY_MANAGEMENT_PARAMS . chainId ,
24
- mnemonic :
25
- // eslint-disable-next-line max-len
26
- 'phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine' ,
27
- passphrase : 'some_passphrase'
28
- } ;
29
-
30
23
describe ( 'cache invalidation' , ( ) => {
24
+ let testProviderServer : Docker . Container ;
31
25
let wallet1 : TestWallet ;
32
26
33
27
beforeAll ( async ( ) => {
28
+ const port = await getRandomPort ( ) ;
29
+
30
+ // Get environment from original provider server container
31
+ const docker = new Docker ( ) ;
32
+ const originalProviderServer = docker . getContainer ( 'local-network-e2e-provider-server-1' ) ;
33
+ const cmdOutput = await containerExec ( originalProviderServer , [
34
+ 'node' ,
35
+ '-e' ,
36
+ 'console.log(`sdk_token${JSON.stringify(process.env)}sdk_token`)'
37
+ ] ) ;
38
+ const matchResult = cmdOutput [ 0 ] . match ( / s d k _ t o k e n ( .* ) s d k _ t o k e n / ) ;
39
+
40
+ if ( ! matchResult ) throw new Error ( 'Error getting original container environment' ) ;
41
+
42
+ const [ , encodedEnv ] = matchResult ;
43
+
44
+ const Env = Object . entries ( {
45
+ ...JSON . parse ( encodedEnv ) ,
46
+ DISABLE_DB_CACHE : 'false' ,
47
+ LOGGER_MIN_SEVERITY : 'debug'
48
+ } ) . map ( ( [ key , value ] ) => `${ key } =${ value } ` ) ;
49
+
50
+ const network = docker . getNetwork ( 'local-network-e2e_default' ) ;
51
+
52
+ // Test container
53
+ testProviderServer = await docker . createContainer ( {
54
+ Env,
55
+ HostConfig : {
56
+ Binds : [ `${ path . join ( __dirname , '..' , '..' , '..' , '..' , 'compose' , 'placeholder-secrets' ) } :/run/secrets` ] ,
57
+ PortBindings : { '3000/tcp' : [ { HostPort : port . toString ( ) } ] }
58
+ } ,
59
+ Image : 'local-network-e2e-provider-server' ,
60
+ name : 'local-network-e2e-provider-server-test'
61
+ } ) ;
62
+
63
+ await network . connect ( { Container : testProviderServer . id } ) ;
64
+ await testProviderServer . start ( ) ;
65
+
66
+ const override = Object . fromEntries (
67
+ Object . entries ( process . env )
68
+ . filter ( ( [ key ] ) => walletVariables . includes ( key as typeof walletVariables [ number ] ) )
69
+ . map ( ( [ key , value ] ) => [ key , value ?. replace ( 'localhost:4000/' , `localhost:${ port } /` ) ] )
70
+ ) ;
71
+ const env = getEnv ( walletVariables , { override } ) ;
72
+ const wallet1Params : KeyAgentFactoryProps = {
73
+ accountIndex : 0 ,
74
+ chainId : env . KEY_MANAGEMENT_PARAMS . chainId ,
75
+ mnemonic :
76
+ // eslint-disable-next-line max-len
77
+ 'phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine' ,
78
+ passphrase : 'some_passphrase'
79
+ } ;
80
+
34
81
jest . setTimeout ( 180_000 ) ;
35
82
36
83
wallet1 = await getWallet ( {
@@ -45,9 +92,13 @@ describe('cache invalidation', () => {
45
92
await waitForWalletStateSettle ( wallet1 . wallet ) ;
46
93
} ) ;
47
94
48
- afterAll ( ( ) => wallet1 . wallet . shutdown ( ) ) ;
95
+ afterAll ( async ( ) => {
96
+ wallet1 . wallet . shutdown ( ) ;
97
+ await testProviderServer . stop ( ) ;
98
+ await testProviderServer . remove ( ) ;
99
+ } ) ;
49
100
50
- test . skip ( 'cache is invalidated on epoch rollover' , async ( ) => {
101
+ test ( 'cache is invalidated on epoch rollover' , async ( ) => {
51
102
const wallet = wallet1 . wallet ;
52
103
53
104
await walletReady ( wallet ) ;
0 commit comments