Skip to content

Commit

Permalink
Let tests work with new node and config
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Oct 26, 2021
1 parent 6299b09 commit 350e360
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
7 changes: 5 additions & 2 deletions test/integration.test.ts
Expand Up @@ -184,11 +184,13 @@ describe('Starting cardano-wallet (and its node)', () => {
it(
'handles case where cardano-node fails during initialisation',
async () => {
expect.assertions(4);
expect.assertions(5);
let chainDir: string;
await withMainnetConfigDir(async configurationDir => {
const launcher = await setupTestLauncher(stateDir => {
// cardano-node will expect this to be a directory, and exit with an error
fs.writeFileSync(path.join(stateDir, 'chain'), 'bomb');
chainDir = path.join(stateDir, 'chain');
fs.writeFileSync(chainDir, 'bomb');

return {
stateDir,
Expand All @@ -202,6 +204,7 @@ describe('Starting cardano-wallet (and its node)', () => {
});

await launcher.start().catch(passthroughErrorLogger);
expect((await fs.promises.stat(chainDir)).isFile()).toBe(true);

const expectations = new Promise<void>((done, fail) =>
launcher.walletBackend.events.on('exit', (status: ExitStatus) => {
Expand Down
29 changes: 13 additions & 16 deletions test/utils.ts
Expand Up @@ -160,6 +160,7 @@ export async function withMainnetConfigDir<T>(
configuration: 'configuration.json',
genesisByron: 'genesis-byron.json',
genesisShelley: 'genesis-shelley.json',
genesisAlonzo: 'genesis-alonzo.json',
topology: 'topology.json',
},
(f: string) => {
Expand All @@ -170,22 +171,18 @@ export async function withMainnetConfigDir<T>(
}
);

await fs.promises.copyFile(
configs.genesisByron.src,
configs.genesisByron.dst
);
await fs.promises.copyFile(
configs.genesisShelley.src,
configs.genesisShelley.dst
);
await fs.promises.copyFile(configs.topology.src, configs.topology.dst);

const config = await fs.promises.readFile(
configs.configuration.src,
'utf-8'
);
const configFixed = config.replace(/^.*SocketPath.*$/gm, '');
await fs.promises.writeFile(configs.configuration.dst, configFixed);
for (const [name, file] of _.toPairs(configs)) {
if (name === 'configuration') {
const config = await fs.promises.readFile(
configs.configuration.src,
'utf-8'
);
const configFixed = config.replace(/^.*SocketPath.*$/gm, '');
await fs.promises.writeFile(configs.configuration.dst, configFixed);
} else {
await fs.promises.copyFile(file.src, file.dst);
}
}

return await cb(o.path);
},
Expand Down

0 comments on commit 350e360

Please sign in to comment.