Skip to content

Commit f6b87f0

Browse files
committed
refactor: hoist stub chain sync data to util-dev
hoist a few types from golden-test-generator to util-dev in order to avoid circular dependencies
1 parent 8f15f6f commit f6b87f0

16 files changed

+65
-40
lines changed

packages/e2e/test/projection/offline-fork.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {
77
ObservableCardanoNode,
88
Point
99
} from '@cardano-sdk/core';
10+
import { ChainSyncDataSet, chainSyncData, logger } from '@cardano-sdk/util-dev';
1011
import { ConnectionConfig } from '@cardano-ogmios/client';
1112
import { InMemory, Projections, projectIntoSink } from '@cardano-sdk/projection';
1213
import { Observable, filter, firstValueFrom, lastValueFrom, of, share, take } from 'rxjs';
1314
import { OgmiosObservableCardanoNode } from '@cardano-sdk/ogmios';
14-
import { dataWithStakeKeyDeregistration } from '../../../projection/test/events';
1515
import { getEnv } from '../../src';
16-
import { logger } from '@cardano-sdk/util-dev';
16+
17+
const dataWithStakeKeyDeregistration = chainSyncData(ChainSyncDataSet.WithStakeKeyDeregistration);
1718

1819
const connectionConfig = ((): ConnectionConfig => {
1920
const { OGMIOS_URL } = getEnv(['OGMIOS_URL']);

packages/golden-test-generator/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"ts-log": "^2.2.3"
7474
},
7575
"devDependencies": {
76+
"@cardano-sdk/util-dev": "^0.7.1",
7677
"@types/cli-progress": "^3.9.2",
7778
"@types/fs-extra": "^9.0.12",
7879
"@types/object-hash": "^2.1.1",

packages/golden-test-generator/src/ChainSyncEvents/chainSyncEvents.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { ChainSyncEventType, ChainSyncRollBackward, ChainSyncRollForward, Intersection } from '@cardano-sdk/core';
1+
import { ChainSyncEventType, Intersection } from '@cardano-sdk/core';
22
import { GeneratorMetadata } from '../Content';
33
import { Logger } from 'ts-log';
44
import { Ogmios, ogmiosToCore } from '@cardano-sdk/ogmios';
5+
import type { SerializedChainSyncEvent } from '@cardano-sdk/util-dev';
56

67
type CardanoMetadata = Pick<GeneratorMetadata['metadata'], 'cardano'>;
78

8-
export type SerializedChainSyncEvent =
9-
| Omit<ChainSyncRollForward, 'requestNext'>
10-
| Omit<ChainSyncRollBackward, 'requestNext'>;
11-
129
export type GetChainSyncEventsResponse = {
1310
events: SerializedChainSyncEvent[];
1411
metadata: CardanoMetadata;

packages/golden-test-generator/src/Content.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { Cardano, Intersection } from '@cardano-sdk/core';
21
import { Commit } from 'git-last-commit';
32
import { getLastCommitPromise } from './util';
3+
import type { ChainSyncMetadata } from '@cardano-sdk/util-dev';
44
const packageJson = require('../../package.json');
55

66
export type Metadata = {
7-
cardano: {
8-
compactGenesis: Cardano.CompactGenesis;
9-
intersection: Intersection;
10-
};
7+
cardano: ChainSyncMetadata['cardano'];
118
software: {
129
name: string;
1310
version: string;

packages/projection/test/operators/withNetworkInfo.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
2+
import { ChainSyncDataSet, chainSyncData, createTestScheduler } from '@cardano-sdk/util-dev';
23
import { Operators, RollForwardEvent, UnifiedProjectorEvent } from '../../src';
3-
import { createTestScheduler } from '@cardano-sdk/util-dev';
4-
import { dataWithPoolRetirement } from '../events';
54

6-
const networkInfo = dataWithPoolRetirement.networkInfo;
5+
const { networkInfo, cardanoNode } = chainSyncData(ChainSyncDataSet.WithPoolRetirement);
76

87
const createEvent = (eventType: ChainSyncEventType) =>
98
({
@@ -18,7 +17,7 @@ describe('withNetworkInfo', () => {
1817
a: createEvent(ChainSyncEventType.RollForward),
1918
b: createEvent(ChainSyncEventType.RollBackward)
2019
});
21-
expectObservable(source$.pipe(Operators.withNetworkInfo(dataWithPoolRetirement.cardanoNode))).toBe('ab', {
20+
expectObservable(source$.pipe(Operators.withNetworkInfo(cardanoNode))).toBe('ab', {
2221
a: {
2322
...createEvent(ChainSyncEventType.RollForward),
2423
eraSummaries: networkInfo.eraSummaries,

packages/projection/test/operators/withRolledBackBlock.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Cardano, ChainSyncEventType, ChainSyncRollBackward } from '@cardano-sdk/core';
2+
import { ChainSyncDataSet, chainSyncData, createTestScheduler } from '@cardano-sdk/util-dev';
23
import { InMemory, Operators, StabilityWindowBuffer, UnifiedProjectorEvent } from '../../src';
34
import { WithNetworkInfo } from '../../src/operators';
4-
import { createTestScheduler } from '@cardano-sdk/util-dev';
5-
import { dataWithStakeKeyDeregistration } from '../events';
65
import { stubBlockId } from '../util';
76

7+
const dataWithStakeKeyDeregistration = chainSyncData(ChainSyncDataSet.WithPoolRetirement);
8+
89
const createEvent = (eventType: ChainSyncEventType, slot: number, tipSlot = slot) =>
910
({
1011
block: { header: { blockNo: Cardano.BlockNo(slot), hash: stubBlockId(slot), slot: Cardano.Slot(slot) } },

packages/projection/test/projectIntoSink.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as Crypto from '@cardano-sdk/crypto';
22
import { Cardano, CardanoNodeErrors, ChainSyncEventType, ChainSyncRollForward } from '@cardano-sdk/core';
3+
import { ChainSyncDataSet, StubChainSyncData, chainSyncData, logger } from '@cardano-sdk/util-dev';
34
import { InMemory, Projections, RollForwardEvent, Sinks, projectIntoSink } from '../src';
4-
import { StubChainSyncData, dataWithPoolRetirement, dataWithStakeKeyDeregistration } from './events';
55
import { WithNetworkInfo } from '../src/operators';
66
import { from, lastValueFrom, of, toArray } from 'rxjs';
7-
import { logger } from '@cardano-sdk/util-dev';
7+
8+
const dataWithPoolRetirement = chainSyncData(ChainSyncDataSet.WithPoolRetirement);
9+
const dataWithStakeKeyDeregistration = chainSyncData(ChainSyncDataSet.WithStakeKeyDeregistration);
810

911
const projectAll = ({ cardanoNode }: StubChainSyncData, projectionSinks: Sinks<Projections.AllProjections>) =>
1012
lastValueFrom(

packages/projection/test/sinks/inMemory/InMemoryStabilityWindowBuffer.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Cardano, ChainSyncEventType, Seconds } from '@cardano-sdk/core';
22
import { InMemory, UnifiedProjectorEvent } from '../../../src';
33
import { WithNetworkInfo } from '../../../src/operators';
44
import { firstValueFrom, from, take, toArray } from 'rxjs';
5-
import { genesisToEraSummary } from '../../events/genesisToEraSummary';
5+
import { genesisToEraSummary } from '@cardano-sdk/util-dev';
66
import { stubBlockId } from '../../util';
77

88
const genesisParameters = {

packages/util-dev/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"scripts": {
3737
"build:esm": "tsc -p src/tsconfig.json --outDir ./dist/esm --module es2020",
3838
"build:cjs": "tsc --build src",
39-
"build": "run-s build:cjs build:esm module-fixup",
39+
"build:copy": "shx cp -r src/chainSync/data dist/cjs/chainSync/data",
40+
"build": "run-s build:cjs build:esm module-fixup build:copy",
4041
"circular-deps:check": "madge --circular dist",
4142
"module-fixup": "shx cp ../../build/cjs-package.json ./dist/cjs/package.json && cp ../../build/esm-package.json ./dist/esm/package.json",
4243
"tscNoEmit": "shx echo typescript --noEmit command not implemented yet",
@@ -72,6 +73,7 @@
7273
"envalid": "^7.3.1",
7374
"get-port-please": "^2.5.0",
7475
"json-bigint": "^1.0.0",
76+
"lodash": "^4.17.21",
7577
"rxjs": "^7.4.0",
7678
"ts-log": "^2.2.4"
7779
},

packages/projection/test/events/index.ts renamed to packages/util-dev/src/chainSync/index.ts

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
import {
2+
Cardano,
23
CardanoNodeErrors,
34
ChainSyncEvent,
45
ChainSyncEventType,
6+
ChainSyncRollBackward,
7+
ChainSyncRollForward,
8+
Intersection,
59
ObservableCardanoNode,
610
Point,
711
PointOrOrigin
812
} from '@cardano-sdk/core';
9-
import { ChainSyncData } from '../../../golden-test-generator/src';
1013
import { Observable, of } from 'rxjs';
11-
import { SerializedChainSyncEvent } from '../../../golden-test-generator/src/ChainSyncEvents';
1214
import { genesisToEraSummary } from './genesisToEraSummary';
15+
import memoize from 'lodash/memoize';
16+
17+
export type SerializedChainSyncEvent =
18+
| Omit<ChainSyncRollForward, 'requestNext'>
19+
| Omit<ChainSyncRollBackward, 'requestNext'>;
20+
21+
export type ChainSyncMetadata = {
22+
cardano: {
23+
compactGenesis: Cardano.CompactGenesis;
24+
intersection: Intersection;
25+
};
26+
};
27+
28+
export type ChainSyncData = {
29+
body: SerializedChainSyncEvent[];
30+
metadata: ChainSyncMetadata;
31+
};
32+
33+
export * from './genesisToEraSummary';
1334

1435
const intersect = (events: ChainSyncData['body'], points: PointOrOrigin[]) => {
1536
const blockPoints = points.filter((point): point is Point => point !== 'origin');
@@ -65,13 +86,18 @@ const intersect = (events: ChainSyncData['body'], points: PointOrOrigin[]) => {
6586
throw new CardanoNodeErrors.CardanoClientErrors.IntersectionNotFoundError(points as any[]);
6687
};
6788

68-
const prepareData = (dataFileName: string) => {
89+
export enum ChainSyncDataSet {
90+
WithPoolRetirement = 'with-pool-retirement.json',
91+
WithStakeKeyDeregistration = 'with-stake-key-deregistration.json'
92+
}
93+
94+
export const chainSyncData = memoize((dataSet: ChainSyncDataSet) => {
6995
const {
7096
body: allEvents,
7197
metadata: {
7298
cardano: { compactGenesis }
7399
}
74-
} = require(`./data/${dataFileName}`) as ChainSyncData;
100+
} = require(`./data/${dataSet}`) as ChainSyncData;
75101
const eraSummaries = [genesisToEraSummary(compactGenesis)];
76102
const cardanoNode: ObservableCardanoNode = {
77103
eraSummaries$: of(eraSummaries),
@@ -106,8 +132,6 @@ const prepareData = (dataFileName: string) => {
106132
genesisParameters: compactGenesis
107133
}
108134
};
109-
};
110-
export type StubChainSyncData = ReturnType<typeof prepareData>;
135+
});
111136

112-
export const dataWithPoolRetirement = prepareData('with-pool-retirement.json');
113-
export const dataWithStakeKeyDeregistration = prepareData('with-stake-key-deregistration');
137+
export type StubChainSyncData = ReturnType<typeof chainSyncData>;

packages/util-dev/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * as AssetId from './assetId';
22
export * as CmlTestUtil from './cmlTestUtil';
33
export * as TxTestUtil from './txTestUtil';
44
export * as DockerUtil from './docker';
5+
export * from './chainSync';
56
export * from './TestLogger';
67
export * from './util';
78
export * from './createStubStakePoolProvider';

yarn-project.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ cacheEntries = {
17611761
"lru-cache@npm:4.1.5" = { filename = "lru-cache-npm-4.1.5-ede304cc43-4bb4b58a36.zip"; sha512 = "4bb4b58a36cd7dc4dcec74cbe6a8f766a38b7426f1ff59d4cf7d82a2aa9b9565cd1cb98f6ff60ce5cd174524868d7bc9b7b1c294371851356066ca9ac4cf135a"; };
17621762
"lru-cache@npm:5.1.1" = { filename = "lru-cache-npm-5.1.1-f475882a51-c154ae1cbb.zip"; sha512 = "c154ae1cbb0c2206d1501a0e94df349653c92c8cbb25236d7e85190bcaf4567a03ac6eb43166fabfa36fd35623694da7233e88d9601fbf411a9a481d85dbd2cb"; };
17631763
"lru-cache@npm:6.0.0" = { filename = "lru-cache-npm-6.0.0-b4c8668fe1-f97f499f89.zip"; sha512 = "f97f499f898f23e4585742138a22f22526254fdba6d75d41a1c2526b3b6cc5747ef59c5612ba7375f42aca4f8461950e925ba08c991ead0651b4918b7c978297"; };
1764-
"lru-cache@npm:7.14.0" = { filename = "lru-cache-npm-7.14.0-354cf654ec-efdd329f2c.zip"; sha512 = "efdd329f2c1bb790b71d497c6c59272e6bc2d7dd060ba55fc136becd3dd31fc8346edb446275504d94cb60d3c8385dbf5267b79b23789e409b2bdf302d13f0d7"; };
1764+
"lru-cache@npm:7.18.1" = { filename = "lru-cache-npm-7.18.1-1ae5fcb8ef-ab0ec1360c.zip"; sha512 = "ab0ec1360c552f1ffa54b1eaf0026126c5116a07bee156b92d1e971f4c8c88e9160f0fad4ab6fed4e0fdea84f25a4590ece085bc57ed9ab1d90b17f0b138c556"; };
17651765
"ltgt@npm:2.2.1" = { filename = "ltgt-npm-2.2.1-443b5da86d-7e3874296f.zip"; sha512 = "7e3874296f7538bc8087b428ac4208008d7b76916354b34a08818ca7c83958c1df10ec427eeeaad895f6b81e41e24745b18d30f89abcc21d228b94f6961d50a2"; };
17661766
"lunr@npm:2.3.9" = { filename = "lunr-npm-2.3.9-fa3aa9c2d6-176719e24f.zip"; sha512 = "176719e24fcce7d3cf1baccce9dd5633cd8bdc1f41ebe6a180112e5ee99d80373fe2454f5d4624d437e5a8319698ca6837b9950566e15d2cae5f2a543a3db4b8"; };
17671767
"madge@npm:5.0.1" = { filename = "madge-npm-5.0.1-9f3b536039-821db88fdc.zip"; sha512 = "821db88fdcb6259cf4bf1665abb976dd859fb7157a712886468d4172ab6d758f3446212fcd3fa92be21e9e2b408854f96e9495b7119d7387e6fe5690bd9786c4"; };
@@ -1820,7 +1820,7 @@ cacheEntries = {
18201820
"minipass-pipeline@npm:1.2.4" = { filename = "minipass-pipeline-npm-1.2.4-5924cb077f-b14240dac0.zip"; sha512 = "b14240dac0d29823c3d5911c286069e36d0b81173d7bdf07a7e4a91ecdef92cdff4baaf31ea3746f1c61e0957f652e641223970870e2353593f382112257971b"; };
18211821
"minipass-sized@npm:1.0.3" = { filename = "minipass-sized-npm-1.0.3-306d86f432-79076749fc.zip"; sha512 = "79076749fcacf21b5d16dd596d32c3b6bf4d6e62abb43868fac21674078505c8b15eaca4e47ed844985a4514854f917d78f588fcd029693709417d8f98b2bd60"; };
18221822
"minipass@npm:3.3.5" = { filename = "minipass-npm-3.3.5-a555b091e7-f89f02bcaa.zip"; sha512 = "f89f02bcaa0e0e4bb4c44ec796008e69fbca62db0aba6ead1bc57d25bdaefdf42102130f4f9ecb7d9c6b6cd35ff7b0c7b97d001d3435da8e629fb68af3aea57e"; };
1823-
"minipass@npm:4.0.0" = { filename = "minipass-npm-4.0.0-2520d5ae3c-7a609afbf3.zip"; sha512 = "7a609afbf394abfcf9c48e6c90226f471676c8f2a67f07f6838871afb03215ede431d1433feffe1b855455bcb13ef0eb89162841b9796109d6fed8d89790f381"; };
1823+
"minipass@npm:4.2.4" = { filename = "minipass-npm-4.2.4-20f938f2dd-c664f2ae44.zip"; sha512 = "c664f2ae4401408d1e7a6e4f50aca45f87b1b0634bc9261136df5c378e313e77355765f73f59c4a5abcadcdf43d83fcd3eb14e4a7cdcce8e36508e2290345753"; };
18241824
"minizlib@npm:2.1.2" = { filename = "minizlib-npm-2.1.2-ea89cd0cfb-f1fdeac0b0.zip"; sha512 = "f1fdeac0b07cf8f30fcf12f4b586795b97be856edea22b5e9072707be51fc95d41487faec3f265b42973a304fe3a64acd91a44a3826a963e37b37bafde0212c3"; };
18251825
"mixpanel@npm:0.13.0" = { filename = "mixpanel-npm-0.13.0-da020f2419-b7486d763a.zip"; sha512 = "b7486d763aa8f57670e99590db0488bc722178b8844c0508d127c8f1b160fd36053e3e90f0cc11d0669dfd7778b170b3638200b481005c6583122ae343c5f069"; };
18261826
"mkdirp-classic@npm:0.5.3" = { filename = "mkdirp-classic-npm-0.5.3-3b5c991910-3f4e088208.zip"; sha512 = "3f4e088208270bbcc148d53b73e9a5bd9eef05ad2cbf3b3d0ff8795278d50dd1d11a8ef1875ff5aea3fa888931f95bfcb2ad5b7c1061cfefd6284d199e6776ac"; };

yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,7 @@ __metadata:
25722572
"@cardano-sdk/core": ^0.9.0
25732573
"@cardano-sdk/ogmios": ^0.9.0
25742574
"@cardano-sdk/util": ^0.8.1
2575+
"@cardano-sdk/util-dev": ^0.7.1
25752576
"@types/cli-progress": ^3.9.2
25762577
"@types/fs-extra": ^9.0.12
25772578
"@types/object-hash": ^2.1.1
@@ -2769,6 +2770,7 @@ __metadata:
27692770
get-port-please: ^2.5.0
27702771
jest: ^28.1.3
27712772
json-bigint: ^1.0.0
2773+
lodash: ^4.17.21
27722774
madge: ^5.0.1
27732775
npm-run-all: ^4.1.5
27742776
rxjs: ^7.4.0
@@ -17414,9 +17416,9 @@ __metadata:
1741417416
linkType: hard
1741517417

1741617418
"lru-cache@npm:^7.4.4, lru-cache@npm:^7.5.1, lru-cache@npm:^7.7.1":
17417-
version: 7.14.0
17418-
resolution: "lru-cache@npm:7.14.0"
17419-
checksum: efdd329f2c1bb790b71d497c6c59272e6bc2d7dd060ba55fc136becd3dd31fc8346edb446275504d94cb60d3c8385dbf5267b79b23789e409b2bdf302d13f0d7
17419+
version: 7.18.1
17420+
resolution: "lru-cache@npm:7.18.1"
17421+
checksum: ab0ec1360c552f1ffa54b1eaf0026126c5116a07bee156b92d1e971f4c8c88e9160f0fad4ab6fed4e0fdea84f25a4590ece085bc57ed9ab1d90b17f0b138c556
1742017422
languageName: node
1742117423
linkType: hard
1742217424

@@ -18019,11 +18021,9 @@ __metadata:
1801918021
linkType: hard
1802018022

1802118023
"minipass@npm:^4.0.0":
18022-
version: 4.0.0
18023-
resolution: "minipass@npm:4.0.0"
18024-
dependencies:
18025-
yallist: ^4.0.0
18026-
checksum: 7a609afbf394abfcf9c48e6c90226f471676c8f2a67f07f6838871afb03215ede431d1433feffe1b855455bcb13ef0eb89162841b9796109d6fed8d89790f381
18024+
version: 4.2.4
18025+
resolution: "minipass@npm:4.2.4"
18026+
checksum: c664f2ae4401408d1e7a6e4f50aca45f87b1b0634bc9261136df5c378e313e77355765f73f59c4a5abcadcdf43d83fcd3eb14e4a7cdcce8e36508e2290345753
1802718027
languageName: node
1802818028
linkType: hard
1802918029

0 commit comments

Comments
 (0)