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

File tree

16 files changed

+65
-40
lines changed

16 files changed

+65
-40
lines changed

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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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
},

0 commit comments

Comments
 (0)