Skip to content

Commit 22df817

Browse files
committed
fixup! feat: dockerize blockfrost-ryo and enable blockfrost providers in e2e CI tests
1 parent f8c2745 commit 22df817

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

.github/workflows/continuous-integration-e2e-blockfrost.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ env:
2828
TEST_CLIENT_STAKE_POOL_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
2929
WS_PROVIDER_URL: 'http://localhost:4100/ws'
3030
# enable Blockfrost backed providers, the rest will use defaults
31+
BLOCKFROST_CUSTOM_NETWORK_URL: 'http://localhost:3015'
3132
ASSET_PROVIDER: 'blockfrost'
3233
UTXO_PROVIDER: 'blockfrost'
3334
CHAIN_HISTORY_PROVIDER: 'blockfrost'

packages/cardano-services/src/Program/programs/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export enum ProviderServerOptionDescriptions {
6363
UseBlockfrost = 'Enables Blockfrost cached data DB',
6464
UseSubmitApi = 'Use cardano-submit-api provider',
6565
UseTypeormAssetProvider = 'Use the TypeORM Asset Provider (default is db-sync)',
66-
UseWebSocketApi = 'Use WebSocket API'
66+
UseWebSocketApi = 'Use WebSocket API',
67+
BlockfrostCustomNetworkUrl = 'URL for custom hosted blockfrost-ryo'
6768
}
6869

6970
export type ProviderServerArgs = CommonProgramOptions &

packages/cardano-services/src/cli.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ addOptions(withOgmiosOptions(withHandlePolicyIdsOptions(providerServerWithCommon
379379
'USE_WEB_SOCKET_API',
380380
(val) => stringOptionToBoolean(val, Programs.ProviderServer, ProviderServerOptionDescriptions.UseWebSocketApi)
381381
),
382+
newOption(
383+
'--blockfrost-custom-network-url <blockfrostCustomNetworkUrl>',
384+
ProviderServerOptionDescriptions.BlockfrostCustomNetworkUrl,
385+
'BLOCKFROST_CUSTOM_NETWORK_URL',
386+
urlValidator(ProviderServerOptionDescriptions.BlockfrostCustomNetworkUrl, true)
387+
),
382388
...providerSelectionOptions
383389
]).action(async (serviceNames: ServiceNames[], args: ProviderServerArgs) =>
384390
runServer('Provider server', { args, serviceNames }, () =>

packages/cardano-services/src/util/BlockfrostProvider/BlockfrostClientFactory.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ let blockfrostApi: BlockFrostAPI | undefined;
1111
export const getBlockfrostApi = () => {
1212
if (blockfrostApi !== undefined) return blockfrostApi;
1313

14+
// custom hosted instance
15+
if (process.env.BLOCKFROST_CUSTOM_BACKEND_URL && process.env.BLOCKFROST_CUSTOM_BACKEND_URL !== '') {
16+
blockfrostApi = new BlockFrostAPI({
17+
customBackend: process.env.BLOCKFROST_CUSTOM_BACKEND_URL
18+
});
19+
20+
return blockfrostApi;
21+
}
22+
23+
// instance hosted by Blockfrost
1424
if (process.env.BLOCKFROST_API_KEY === undefined || process.env.BLOCKFROST_API_KEY === '')
15-
throw new Error('BLOCKFROST_API_KEY environment variable is required');
25+
throw new Error('BLOCKFROST_API_KEY or BLOCKFROST_CUSTOM_BACKEND_URL environment variable is required');
1626

1727
if (process.env.NETWORK === undefined) throw new Error('NETWORK environment variable is required');
1828

packages/cardano-services/test/cli.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable sonarjs/cognitive-complexity */
22
/* eslint-disable sonarjs/no-duplicate-string */
3-
import { DEFAULT_FUZZY_SEARCH_OPTIONS } from '../src';
3+
import { DEFAULT_FUZZY_SEARCH_OPTIONS, ProviderServerOptionDescriptions } from '../src';
44
import { createLogger } from '@cardano-sdk/util-dev';
55
import { fork } from 'child_process';
66
import path from 'path';
@@ -1113,6 +1113,22 @@ describe('CLI', () => {
11131113
}));
11141114
});
11151115

1116+
describe('blockfrostCustomNetworkUrl', () => {
1117+
const blockfrostCustomNetworkUrl = 'https://test/';
1118+
1119+
testCli('accepts an URL', 'provider', {
1120+
args: ['--blockfrost-custom-network-url', blockfrostCustomNetworkUrl],
1121+
env: { BLOCKFROST_CUSTOM_NETWORK_URL: blockfrostCustomNetworkUrl },
1122+
expectedArgs: { args: { blockfrostCustomNetworkUrl } }
1123+
});
1124+
1125+
testCli('expects an URL', 'provider', {
1126+
args: ['--blockfrost-custom-network-url', 'invalid'],
1127+
env: { BLOCKFROST_CUSTOM_NETWORK_URL: 'invalid' },
1128+
expectedError: `${ProviderServerOptionDescriptions.BlockfrostCustomNetworkUrl} - "invalid" is not an URL`
1129+
});
1130+
});
1131+
11161132
describe('provider implementation selection', () => {
11171133
testCli('check defaults', 'provider', {
11181134
expectedArgs: {

packages/cardano-services/test/util/BlockfrsotProvider/BlockfrostClientFactory.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('BlockfrostClientFactory', () => {
99
delete process.env.NETWORK;
1010
});
1111

12-
it('gets correctly, first time', () => {
12+
it('gets correctly', () => {
1313
process.env.BLOCKFROST_API_KEY = 'testing';
1414
process.env.NETWORK = 'preprod';
1515
const apiFirst = getBlockfrostApi();
@@ -24,11 +24,24 @@ describe('BlockfrostClientFactory', () => {
2424
expect(apiSecond).toBeInstanceOf(BlockFrostAPI);
2525
});
2626

27-
it('throws if env vars missing', () => {
28-
expect(() => getBlockfrostApi()).toThrow(new Error('BLOCKFROST_API_KEY environment variable is required'));
27+
it('gets custom backend correctly', () => {
28+
process.env.BLOCKFROST_CUSTOM_BACKEND_URL = 'http://localhost';
29+
const apiFirst = getBlockfrostApi();
30+
expect(apiFirst).toBeDefined();
31+
expect(apiFirst).toBeInstanceOf(BlockFrostAPI);
32+
33+
// deleting proves that we initialize only once
34+
delete process.env.BLOCKFROST_CUSTOM_BACKEND_URL;
35+
const apiSecond = getBlockfrostApi();
36+
expect(apiSecond).toBeDefined();
37+
expect(apiSecond).toBeInstanceOf(BlockFrostAPI);
2938
});
3039

3140
it('throws if env vars missing', () => {
41+
expect(() => getBlockfrostApi()).toThrow(
42+
new Error('BLOCKFROST_API_KEY or BLOCKFROST_CUSTOM_BACKEND_URL environment variable is required')
43+
);
44+
3245
process.env.BLOCKFROST_API_KEY = 'testing';
3346
expect(() => getBlockfrostApi()).toThrow(new Error('NETWORK environment variable is required'));
3447
});

0 commit comments

Comments
 (0)