Skip to content

Commit 0bc50e0

Browse files
committed
feat: enable blockfrost enabled e2e tests
1 parent 804b9c0 commit 0bc50e0

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration - E2E
1+
name: Continuous Integration (Blockfrost) - E2E
22

33
env:
44
TL_DEPTH: ${{ github.event.pull_request.head.repo.fork && '0' || fromJson(vars.TL_DEPTH) }}
@@ -28,6 +28,16 @@ env:
2828
TEST_CLIENT_STAKE_POOL_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
2929
WS_PROVIDER_URL: 'http://localhost:4100/ws'
3030

31+
# Blockfrost enablement
32+
BLOCKFROST_CUSTOM_BACKEND_URL: 'http://blockfrost-ryo:3000'
33+
ASSET_PROVIDER: 'blockfrost'
34+
UTXO_PROVIDER: 'blockfrost'
35+
CHAIN_HISTORY_PROVIDER: 'blockfrost'
36+
REWARDS_PROVIDER: 'blockfrost'
37+
NETWORK_INFO_PROVIDER: 'blockfrost'
38+
#blockfrost-ryo doesn't have submit API
39+
#TX_SUBMIT_PROVIDER: 'blockfrost'
40+
3141
on:
3242
pull_request:
3343
push:
@@ -63,7 +73,7 @@ jobs:
6373
- name: 🌐 Setup local test network
6474
working-directory: packages/e2e
6575
run: |
66-
yarn local-network:up -d
76+
yarn local-network:blockfrost:up -d
6777
env:
6878
CARDANO_NODE_CHAINDB_LOG_LEVEL: 'Warning'
6979
CARDANO_NODE_LOG_LEVEL: 'Warning'

packages/cardano-services/src/ChainHistory/BlockrostChainHistoryProvider/BlockfrostChainHistoryProvider.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
TransactionsByAddressesArgs,
2020
TransactionsByIdsArgs
2121
} from '@cardano-sdk/core';
22+
import { DB_MAX_SAFE_INTEGER } from '../DbSyncChainHistory/queries';
2223
import { Responses } from '@blockfrost/blockfrost-js';
2324

2425
type WithCertIndex<T> = T & { cert_index: number };
@@ -199,12 +200,12 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
199200
: Cardano.InputSource.collaterals;
200201

201202
return {
202-
auxiliaryData: metadata
203-
? {
204-
blob: metadata
205-
}
206-
: undefined,
207-
203+
auxiliaryData:
204+
metadata && metadata.size > 0
205+
? {
206+
blob: metadata
207+
}
208+
: undefined,
208209
blockHeader: {
209210
blockNo: Cardano.BlockNo(response.block_height),
210211
hash: Cardano.BlockId(response.block),
@@ -279,9 +280,14 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
279280

280281
public async transactionsByAddresses({
281282
addresses,
283+
pagination,
282284
blockRange
283285
}: TransactionsByAddressesArgs): Promise<Paginated<Cardano.HydratedTx>> {
286+
this.logger.info(`transactionsByAddresses: ${JSON.stringify(blockRange)} ${JSON.stringify(addresses)}`);
284287
try {
288+
const lowerBound = blockRange?.lowerBound ?? 0;
289+
const upperBound = blockRange?.upperBound ?? DB_MAX_SAFE_INTEGER;
290+
285291
const addressTransactions = await Promise.all(
286292
addresses.map(async (address) =>
287293
fetchByAddressSequentially<
@@ -300,13 +306,14 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
300306
)
301307
);
302308

303-
const allTransactions = addressTransactions
304-
.flat(1)
305-
.sort((a, b) => b.block_height - a.block_height || b.tx_index - a.tx_index);
306-
const addressTransactionsSinceBlock = blockRange?.lowerBound
307-
? allTransactions.filter(({ block_height }) => block_height >= blockRange!.lowerBound!)
308-
: allTransactions;
309-
const ids = addressTransactionsSinceBlock.map(({ tx_hash }) => Cardano.TransactionId(tx_hash));
309+
const allTransactions = addressTransactions.flat(1);
310+
311+
const ids = allTransactions
312+
.filter(({ block_height }) => block_height >= lowerBound && block_height <= upperBound)
313+
.sort((a, b) => a.block_height - b.block_height || a.tx_index - b.tx_index)
314+
.map(({ tx_hash }) => Cardano.TransactionId(tx_hash))
315+
.splice(pagination.startAt, pagination.limit);
316+
310317
const pageResults = await this.transactionsByHashes({ ids });
311318

312319
return { pageResults, totalResultCount: allTransactions.length };

packages/cardano-services/src/NetworkInfo/BlockfrostNetworkInfoProvider/BlockfrostNetworkInfoProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class BlockfrostNetworkInfoProvider extends BlockfrostProvider implements
8080
try {
8181
// Although Blockfrost have the endpoint, the blockfrost-js library don't have a call for it
8282
// https://github.com/blockfrost/blockfrost-js/issues/294
83-
const response = await this.blockfrost.instance<Schemas['network-eras']>('network-eras');
83+
const response = await this.blockfrost.instance<Schemas['network-eras']>('network/eras');
8484
return response.body;
8585
} catch (error) {
8686
throw handleError(error);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ export const BlockfrostToCore = {
105105
}),
106106

107107
txOut: (blockfrost: BlockfrostOutput): Cardano.TxOut => {
108+
const value: Cardano.Value = {
109+
coins: BigInt(blockfrost.amount.find(({ unit }) => unit === 'lovelace')!.quantity)
110+
};
111+
108112
const assets: Cardano.TokenMap = new Map();
109113
for (const { quantity, unit } of blockfrost.amount) {
110114
if (unit === 'lovelace') continue;
111115
assets.set(Cardano.AssetId(unit), BigInt(quantity));
112116
}
117+
118+
if (assets.size > 0) value.assets = assets;
119+
113120
return {
114121
address: Cardano.PaymentAddress(blockfrost.address),
115-
value: {
116-
assets,
117-
coins: BigInt(blockfrost.amount.find(({ unit }) => unit === 'lovelace')!.quantity)
118-
}
122+
value
119123
};
120124
}
121125
};

packages/cardano-services/test/ChainHistory/BlockfrostChainHistoryProvider/BlockfrostChainHistoryProvider.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ describe('blockfrostChainHistoryProvider', () => {
287287
'addr_test1qra788mu4sg8kwd93ns9nfdh3k4ufxwg4xhz2r3n064tzfgxu2hyfhlkwuxupa9d5085eunq2qywy7hvmvej456flkns6cy45x'
288288
),
289289
value: {
290-
assets: new Map(),
291290
coins: 9_731_978_536_963n
292291
}
293292
}

packages/e2e/local-network/templates/blockfrost-ryo/local-network.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ dbSync:
1111
maxConnections: 5
1212
network: "custom"
1313
genesisDataFolder: '/app/config'
14-
tokenRegistryUrl: "https://metadata.cardano-testnet.iohkdev.io"
14+
tokenRegistryUrl: "https://tokens.cardano.org"

0 commit comments

Comments
 (0)