From baea11935aa9e98cf7fc41550499ec59a718d87a Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 18 Sep 2023 13:32:47 +1200 Subject: [PATCH 01/16] update class validator --- packages/common-cosmos/src/project/models.ts | 11 +++-- .../common-cosmos/src/project/project.spec.ts | 45 +++++++++++++++++++ packages/common-cosmos/src/project/utils.ts | 27 ++++++++++- .../src/project/versioned/v1_0_0/model.ts | 5 ++- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/packages/common-cosmos/src/project/models.ts b/packages/common-cosmos/src/project/models.ts index d69e08f7c..1c7b8530a 100644 --- a/packages/common-cosmos/src/project/models.ts +++ b/packages/common-cosmos/src/project/models.ts @@ -37,7 +37,7 @@ import { IsBoolean, Validate, } from 'class-validator'; -import {FileReferenceImp} from './utils'; +import {ChainTypesImp, FileReferenceImp} from './utils'; export class CosmosBlockFilter implements SubqlCosmosBlockFilter { @IsOptional() @@ -176,8 +176,7 @@ export class CosmosRuntimeDataSourceBase CosmosCustomModuleImpl) - @ValidateNested({each: true}) + @Validate(ChainTypesImp) chainTypes: Map; @IsOptional() @Validate(FileReferenceImp) @@ -220,8 +219,14 @@ export class CosmosCustomDataSourceBase< assets: Map; @Type(() => ProcessorImpl) @IsObject() +<<<<<<< HEAD processor: Processor; @Type(() => CosmosCustomModuleImpl) @ValidateNested({each: true}) chainTypes: Map; +======= + processor: FileReference; + @Validate(ChainTypesImp) + chainTypes: Map; +>>>>>>> dd005b73 (update class validator) } diff --git a/packages/common-cosmos/src/project/project.spec.ts b/packages/common-cosmos/src/project/project.spec.ts index e1e43e9ad..4d7bdc7f8 100644 --- a/packages/common-cosmos/src/project/project.spec.ts +++ b/packages/common-cosmos/src/project/project.spec.ts @@ -4,7 +4,11 @@ import path from 'path'; import {getManifestPath, loadFromJsonOrYaml} from '@subql/common'; import {validateCosmosManifest} from '../codegen/util'; +<<<<<<< HEAD import {CosmosProjectManifestVersioned, VersionedProjectManifest} from './versioned'; +======= +import {loadCosmosProjectManifest, parseCosmosProjectManifest} from './load'; +>>>>>>> dd005b73 (update class validator) const projectsDir = path.join(__dirname, '../../test'); @@ -39,4 +43,45 @@ describe('project.yaml', () => { expect(validateCosmosManifest(cosmosManifest)).toBe(true); expect(validateCosmosManifest(ethManifest)).toBe(false); }); + it('Ensure correctness on manifest deployment', () => { + const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any; + const manifest = parseCosmosProjectManifest(cosmosManifest); + expect(manifest.toDeployment()).toBe( + 'dataSources:\n' + + ' - kind: cosmos/Runtime\n' + + ' mapping:\n' + + ' file: ./dist/index.js\n' + + ' handlers:\n' + + ' - filter:\n' + + ' type: /osmosis.gamm.v1beta1.MsgSwapExactAmountIn\n' + + ' handler: handleMessage\n' + + ' kind: cosmos/MessageHandler\n' + + ' startBlock: 9798050\n' + + 'network:\n' + + ' chainId: osmosis-1\n' + + ' chainTypes:\n' + + ' cosmos.base.v1beta1:\n' + + ' file: ./proto/cosmos/base/v1beta1/coin.proto\n' + + ' messages:\n' + + ' - Coin\n' + + ' osmosis.gamm.v1beta1:\n' + + ' file: ./proto/osmosis/gamm/v1beta1/tx.proto\n' + + ' messages:\n' + + ' - MsgSwapExactAmountIn\n' + + ' osmosis.poolmanager.v1beta1:\n' + + ' file: ./proto/osmosis/poolmanager/v1beta1/swap_route.proto\n' + + ' messages:\n' + + ' - SwapAmountInRoute\n' + + 'runner:\n' + + ' node:\n' + + " name: '@subql/node-cosmos'\n" + + " version: '*'\n" + + ' query:\n' + + " name: '@subql/query'\n" + + " version: '*'\n" + + 'schema:\n' + + ' file: ./schema.graphql\n' + + 'specVersion: 1.0.0\n' + ); + }); }); diff --git a/packages/common-cosmos/src/project/utils.ts b/packages/common-cosmos/src/project/utils.ts index 31e31c54e..1b868be87 100644 --- a/packages/common-cosmos/src/project/utils.ts +++ b/packages/common-cosmos/src/project/utils.ts @@ -1,7 +1,11 @@ // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 +<<<<<<< HEAD import {FileReference} from '@subql/types-core'; +======= +import {CosmosCustomModuleImpl} from '@subql/common-cosmos/project/models'; +>>>>>>> dd005b73 (update class validator) import { SecondLayerHandlerProcessor, SubqlCosmosCustomDatasource, @@ -12,7 +16,7 @@ import { CustomDatasourceTemplate, RuntimeDatasourceTemplate, } from '@subql/types-cosmos'; -import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface} from 'class-validator'; +import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface, validate} from 'class-validator'; import {gte} from 'semver'; export function isCustomCosmosDs(ds: SubqlCosmosDatasource): ds is SubqlCosmosCustomDatasource { @@ -70,3 +74,24 @@ export class FileReferenceImp implements ValidatorConstraintInterface { return typeof fileReference === 'object' && 'file' in fileReference && typeof fileReference.file === 'string'; } } + +@ValidatorConstraint({name: 'isChainTypes', async: false}) +export class ChainTypesImp implements ValidatorConstraintInterface { + async validate(value: Map): Promise { + if (!value) { + return false; + } + + for (const chainType of value.values()) { + const errors = await validate(chainType); + if (errors.length > 0) { + return false; + } + } + return true; + } + + defaultMessage(args: ValidationArguments): string { + return `${JSON.stringify(args.value)} is not a valid assets format`; + } +} diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index a00006506..8dbc560a1 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -33,8 +33,10 @@ import { IsOptional, IsArray, IsNotEmpty, + Validate, } from 'class-validator'; import {CosmosCustomDataSourceBase, CosmosCustomModuleImpl, CosmosRuntimeDataSourceBase} from '../../models'; +import {ChainTypesImp} from '../../utils'; const COSMOS_NODE_NAME = `@subql/node-cosmos`; @@ -75,9 +77,8 @@ export class CosmosProjectNetworkDeployment { } export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0 { - @Type(() => CosmosCustomModuleImpl) @IsOptional() - @ValidateNested({each: true}) + @Validate(ChainTypesImp) chainTypes?: Map; } From 7b866f43f1edf6f81efb81faf7fcbd6373447767 Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 18 Sep 2023 13:38:06 +1200 Subject: [PATCH 02/16] update changelog --- packages/common-cosmos/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/common-cosmos/CHANGELOG.md b/packages/common-cosmos/CHANGELOG.md index 01b2d1228..fc44a498d 100644 --- a/packages/common-cosmos/CHANGELOG.md +++ b/packages/common-cosmos/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed Missing chainTypes on deployment (#175) ## [2.5.1] - 2023-09-20 ### Changed From f54a83858bd05062509ad877bc9b07da24770850 Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 18 Sep 2023 13:40:52 +1200 Subject: [PATCH 03/16] removed unused type --- packages/common-cosmos/src/project/versioned/v1_0_0/model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index 8dbc560a1..ede393a37 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -35,7 +35,7 @@ import { IsNotEmpty, Validate, } from 'class-validator'; -import {CosmosCustomDataSourceBase, CosmosCustomModuleImpl, CosmosRuntimeDataSourceBase} from '../../models'; +import {CosmosCustomDataSourceBase, CosmosRuntimeDataSourceBase} from '../../models'; import {ChainTypesImp} from '../../utils'; const COSMOS_NODE_NAME = `@subql/node-cosmos`; From dbd9f76e3ece37145a02cf6eb39e63fd1c6d5bf5 Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 18 Sep 2023 14:06:30 +1200 Subject: [PATCH 04/16] update logic on validator --- packages/common-cosmos/src/project/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/common-cosmos/src/project/utils.ts b/packages/common-cosmos/src/project/utils.ts index 1b868be87..5597823e6 100644 --- a/packages/common-cosmos/src/project/utils.ts +++ b/packages/common-cosmos/src/project/utils.ts @@ -82,7 +82,7 @@ export class ChainTypesImp implements ValidatorConstraintInterface { return false; } - for (const chainType of value.values()) { + for (const chainType of Object.values(value)) { const errors = await validate(chainType); if (errors.length > 0) { return false; @@ -92,6 +92,6 @@ export class ChainTypesImp implements ValidatorConstraintInterface { } defaultMessage(args: ValidationArguments): string { - return `${JSON.stringify(args.value)} is not a valid assets format`; + return `${JSON.stringify(args.value)} is not a valid chainType format`; } } From 52d6f115fccdb3a83b44b452b9188849d077dfff Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 18 Sep 2023 21:47:52 +1200 Subject: [PATCH 05/16] lower package for validator and transformer, revert changes to chaintypes validator --- packages/common-cosmos/package.json | 4 +-- packages/common-cosmos/src/project/models.ts | 10 +++++--- packages/common-cosmos/src/project/utils.ts | 26 +------------------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/packages/common-cosmos/package.json b/packages/common-cosmos/package.json index e771a604a..c409f1083 100644 --- a/packages/common-cosmos/package.json +++ b/packages/common-cosmos/package.json @@ -24,13 +24,13 @@ "@protobufs/tendermint": "^0.0.10", "@subql/common": "^3.1.0", "@subql/types-cosmos": "workspace:*", + "class-transformer": "0.4.0", + "class-validator": "0.13.2", "fs-extra": "^11.1.1", "js-yaml": "^4.1.0", "reflect-metadata": "^0.1.13" }, "peerDependencies": { - "class-transformer": "*", - "class-validator": "*", "ejs": "*" }, "devDependencies": { diff --git a/packages/common-cosmos/src/project/models.ts b/packages/common-cosmos/src/project/models.ts index 1c7b8530a..39e92e94e 100644 --- a/packages/common-cosmos/src/project/models.ts +++ b/packages/common-cosmos/src/project/models.ts @@ -37,7 +37,7 @@ import { IsBoolean, Validate, } from 'class-validator'; -import {ChainTypesImp, FileReferenceImp} from './utils'; +import {FileReferenceImp} from './utils'; export class CosmosBlockFilter implements SubqlCosmosBlockFilter { @IsOptional() @@ -176,8 +176,9 @@ export class CosmosRuntimeDataSourceBase; + @Type(() => CosmosCustomModuleImpl) + @ValidateNested({each: true}) + chainTypes: Map; @IsOptional() @Validate(FileReferenceImp) assets?: Map; @@ -226,7 +227,8 @@ export class CosmosCustomDataSourceBase< chainTypes: Map; ======= processor: FileReference; - @Validate(ChainTypesImp) + @Type(() => CosmosCustomModuleImpl) + @ValidateNested({each: true}) chainTypes: Map; >>>>>>> dd005b73 (update class validator) } diff --git a/packages/common-cosmos/src/project/utils.ts b/packages/common-cosmos/src/project/utils.ts index 5597823e6..4aa04f50e 100644 --- a/packages/common-cosmos/src/project/utils.ts +++ b/packages/common-cosmos/src/project/utils.ts @@ -1,11 +1,8 @@ // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 -<<<<<<< HEAD import {FileReference} from '@subql/types-core'; -======= import {CosmosCustomModuleImpl} from '@subql/common-cosmos/project/models'; ->>>>>>> dd005b73 (update class validator) import { SecondLayerHandlerProcessor, SubqlCosmosCustomDatasource, @@ -16,7 +13,7 @@ import { CustomDatasourceTemplate, RuntimeDatasourceTemplate, } from '@subql/types-cosmos'; -import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface, validate} from 'class-validator'; +import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface} from 'class-validator'; import {gte} from 'semver'; export function isCustomCosmosDs(ds: SubqlCosmosDatasource): ds is SubqlCosmosCustomDatasource { @@ -74,24 +71,3 @@ export class FileReferenceImp implements ValidatorConstraintInterface { return typeof fileReference === 'object' && 'file' in fileReference && typeof fileReference.file === 'string'; } } - -@ValidatorConstraint({name: 'isChainTypes', async: false}) -export class ChainTypesImp implements ValidatorConstraintInterface { - async validate(value: Map): Promise { - if (!value) { - return false; - } - - for (const chainType of Object.values(value)) { - const errors = await validate(chainType); - if (errors.length > 0) { - return false; - } - } - return true; - } - - defaultMessage(args: ValidationArguments): string { - return `${JSON.stringify(args.value)} is not a valid chainType format`; - } -} From b0627b12d9eacdfd9baa6da2b845f4e29796f09e Mon Sep 17 00:00:00 2001 From: bz888 Date: Mon, 18 Sep 2023 22:37:40 +1200 Subject: [PATCH 06/16] add failing test --- .../common-cosmos/src/project/project.spec.ts | 7 ++++ .../protoTest1/bad-chaintypes-project.yaml | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 packages/common-cosmos/test/protoTest1/bad-chaintypes-project.yaml diff --git a/packages/common-cosmos/src/project/project.spec.ts b/packages/common-cosmos/src/project/project.spec.ts index 4d7bdc7f8..81fdbd3e0 100644 --- a/packages/common-cosmos/src/project/project.spec.ts +++ b/packages/common-cosmos/src/project/project.spec.ts @@ -43,9 +43,16 @@ describe('project.yaml', () => { expect(validateCosmosManifest(cosmosManifest)).toBe(true); expect(validateCosmosManifest(ethManifest)).toBe(false); }); + it('Should fail on incorrect chaintypes', () => { + const cosmosManifest = loadFromJsonOrYaml( + path.join(projectsDir, './protoTest1', 'bad-chaintypes-project.yaml') + ) as any; + expect(() => parseCosmosProjectManifest(cosmosManifest)).toThrow('failed to parse project.yaml'); + }); it('Ensure correctness on manifest deployment', () => { const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any; const manifest = parseCosmosProjectManifest(cosmosManifest); + console.log('delpoyment', manifest.toDeployment()); expect(manifest.toDeployment()).toBe( 'dataSources:\n' + ' - kind: cosmos/Runtime\n' + diff --git a/packages/common-cosmos/test/protoTest1/bad-chaintypes-project.yaml b/packages/common-cosmos/test/protoTest1/bad-chaintypes-project.yaml new file mode 100644 index 000000000..d151d7e13 --- /dev/null +++ b/packages/common-cosmos/test/protoTest1/bad-chaintypes-project.yaml @@ -0,0 +1,40 @@ +specVersion: 1.0.0 +name: test +version: 0.0.1 +runner: + node: + name: '@subql/node-cosmos' + version: '*' + query: + name: '@subql/query' + version: '*' +description: '' +repository: '' +schema: + file: ./schema.graphql +network: + chainId: osmosis-1 + endpoint: + - https://osmosis.api.onfinality.io/public + dictionary: 'https://api.subquery.network/sq/subquery/cosmos-osmosis-dictionary' + chainTypes: + osmosis.gamm.v1beta1: + filePath: './proto/osmosis/gamm/v1beta1/tx.proto' + message: + - MsgSwapExactAmountIn + osmosis.poolmanager.v1beta1: + # needed by MsgSwapExactAmountIn + file: './proto/osmosis/poolmanager/v1beta1/swap_route.proto' + messages: + - SwapAmountInRoute + +dataSources: + - kind: cosmos/Runtime + startBlock: 9798050 + mapping: + file: ./dist/index.js + handlers: + - handler: handleMessage + kind: cosmos/MessageHandler + filter: + type: /osmosis.gamm.v1beta1.MsgSwapExactAmountIn From c659c283a52b94e5e5c0909b60332d0e34809fe4 Mon Sep 17 00:00:00 2001 From: bz888 Date: Tue, 19 Sep 2023 15:38:25 +1200 Subject: [PATCH 07/16] need to wait for common release on base model --- packages/common-cosmos/package.json | 2 - .../common-cosmos/src/project/project.spec.ts | 42 +------------------ .../versioned/ProjectManifestVersioned.ts | 4 +- .../src/project/versioned/v1_0_0/model.ts | 1 - 4 files changed, 3 insertions(+), 46 deletions(-) diff --git a/packages/common-cosmos/package.json b/packages/common-cosmos/package.json index c409f1083..ed5715f3d 100644 --- a/packages/common-cosmos/package.json +++ b/packages/common-cosmos/package.json @@ -24,8 +24,6 @@ "@protobufs/tendermint": "^0.0.10", "@subql/common": "^3.1.0", "@subql/types-cosmos": "workspace:*", - "class-transformer": "0.4.0", - "class-validator": "0.13.2", "fs-extra": "^11.1.1", "js-yaml": "^4.1.0", "reflect-metadata": "^0.1.13" diff --git a/packages/common-cosmos/src/project/project.spec.ts b/packages/common-cosmos/src/project/project.spec.ts index 81fdbd3e0..76aa13a0e 100644 --- a/packages/common-cosmos/src/project/project.spec.ts +++ b/packages/common-cosmos/src/project/project.spec.ts @@ -4,11 +4,8 @@ import path from 'path'; import {getManifestPath, loadFromJsonOrYaml} from '@subql/common'; import {validateCosmosManifest} from '../codegen/util'; -<<<<<<< HEAD import {CosmosProjectManifestVersioned, VersionedProjectManifest} from './versioned'; -======= import {loadCosmosProjectManifest, parseCosmosProjectManifest} from './load'; ->>>>>>> dd005b73 (update class validator) const projectsDir = path.join(__dirname, '../../test'); @@ -52,43 +49,6 @@ describe('project.yaml', () => { it('Ensure correctness on manifest deployment', () => { const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any; const manifest = parseCosmosProjectManifest(cosmosManifest); - console.log('delpoyment', manifest.toDeployment()); - expect(manifest.toDeployment()).toBe( - 'dataSources:\n' + - ' - kind: cosmos/Runtime\n' + - ' mapping:\n' + - ' file: ./dist/index.js\n' + - ' handlers:\n' + - ' - filter:\n' + - ' type: /osmosis.gamm.v1beta1.MsgSwapExactAmountIn\n' + - ' handler: handleMessage\n' + - ' kind: cosmos/MessageHandler\n' + - ' startBlock: 9798050\n' + - 'network:\n' + - ' chainId: osmosis-1\n' + - ' chainTypes:\n' + - ' cosmos.base.v1beta1:\n' + - ' file: ./proto/cosmos/base/v1beta1/coin.proto\n' + - ' messages:\n' + - ' - Coin\n' + - ' osmosis.gamm.v1beta1:\n' + - ' file: ./proto/osmosis/gamm/v1beta1/tx.proto\n' + - ' messages:\n' + - ' - MsgSwapExactAmountIn\n' + - ' osmosis.poolmanager.v1beta1:\n' + - ' file: ./proto/osmosis/poolmanager/v1beta1/swap_route.proto\n' + - ' messages:\n' + - ' - SwapAmountInRoute\n' + - 'runner:\n' + - ' node:\n' + - " name: '@subql/node-cosmos'\n" + - " version: '*'\n" + - ' query:\n' + - " name: '@subql/query'\n" + - " version: '*'\n" + - 'schema:\n' + - ' file: ./schema.graphql\n' + - 'specVersion: 1.0.0\n' - ); + expect(manifest.asImpl.deployment.network.chainTypes.size).toBeGreaterThan(0); }); }); diff --git a/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts b/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts index 7512aa6c7..36ad7186e 100644 --- a/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts +++ b/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0 import {SubqlCosmosDatasource} from '@subql/types-cosmos'; -import {plainToClass} from 'class-transformer'; +import {plainToClass, plainToInstance} from 'class-transformer'; import {ICosmosProjectManifest} from '../types'; import {ProjectManifestV1_0_0Impl} from './v1_0_0'; @@ -28,7 +28,7 @@ export class CosmosProjectManifestVersioned implements ICosmosProjectManifest { if (!klass) { throw new Error('specVersion not supported for project manifest file'); } - this._impl = plainToClass(klass, projectManifest); + this._impl = plainToInstance(klass, projectManifest); } get asImpl(): ProjectManifestImpls { diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index ede393a37..f75049ef8 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -33,7 +33,6 @@ import { IsOptional, IsArray, IsNotEmpty, - Validate, } from 'class-validator'; import {CosmosCustomDataSourceBase, CosmosRuntimeDataSourceBase} from '../../models'; import {ChainTypesImp} from '../../utils'; From f2d850c3c0bdb012e552272b3c26cacdccee601d Mon Sep 17 00:00:00 2001 From: bz888 Date: Tue, 19 Sep 2023 15:40:47 +1200 Subject: [PATCH 08/16] revert peer deps, removed redundant imports --- packages/common-cosmos/package.json | 2 ++ .../src/project/versioned/ProjectManifestVersioned.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/common-cosmos/package.json b/packages/common-cosmos/package.json index ed5715f3d..e771a604a 100644 --- a/packages/common-cosmos/package.json +++ b/packages/common-cosmos/package.json @@ -29,6 +29,8 @@ "reflect-metadata": "^0.1.13" }, "peerDependencies": { + "class-transformer": "*", + "class-validator": "*", "ejs": "*" }, "devDependencies": { diff --git a/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts b/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts index 36ad7186e..8d1964ecb 100644 --- a/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts +++ b/packages/common-cosmos/src/project/versioned/ProjectManifestVersioned.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0 import {SubqlCosmosDatasource} from '@subql/types-cosmos'; -import {plainToClass, plainToInstance} from 'class-transformer'; +import {plainToInstance} from 'class-transformer'; import {ICosmosProjectManifest} from '../types'; import {ProjectManifestV1_0_0Impl} from './v1_0_0'; From cbb99df2bf19743f100d9bdf60fe74982e319c0b Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 11:09:10 +1300 Subject: [PATCH 09/16] rebased main, bump types-core, updated with correct typing --- packages/common-cosmos/src/project/models.ts | 7 ------ .../common-cosmos/src/project/project.spec.ts | 4 +-- .../src/project/versioned/v1_0_0/model.ts | 25 ++++++++----------- packages/types/src/project.ts | 4 ++- yarn.lock | 11 +++++++- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/common-cosmos/src/project/models.ts b/packages/common-cosmos/src/project/models.ts index 39e92e94e..bfe11b8a8 100644 --- a/packages/common-cosmos/src/project/models.ts +++ b/packages/common-cosmos/src/project/models.ts @@ -220,15 +220,8 @@ export class CosmosCustomDataSourceBase< assets: Map; @Type(() => ProcessorImpl) @IsObject() -<<<<<<< HEAD processor: Processor; @Type(() => CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes: Map; -======= - processor: FileReference; - @Type(() => CosmosCustomModuleImpl) - @ValidateNested({each: true}) chainTypes: Map; ->>>>>>> dd005b73 (update class validator) } diff --git a/packages/common-cosmos/src/project/project.spec.ts b/packages/common-cosmos/src/project/project.spec.ts index 76aa13a0e..62b1b4bba 100644 --- a/packages/common-cosmos/src/project/project.spec.ts +++ b/packages/common-cosmos/src/project/project.spec.ts @@ -4,8 +4,8 @@ import path from 'path'; import {getManifestPath, loadFromJsonOrYaml} from '@subql/common'; import {validateCosmosManifest} from '../codegen/util'; +import {parseCosmosProjectManifest} from './load'; import {CosmosProjectManifestVersioned, VersionedProjectManifest} from './versioned'; -import {loadCosmosProjectManifest, parseCosmosProjectManifest} from './load'; const projectsDir = path.join(__dirname, '../../test'); @@ -49,6 +49,6 @@ describe('project.yaml', () => { it('Ensure correctness on manifest deployment', () => { const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any; const manifest = parseCosmosProjectManifest(cosmosManifest); - expect(manifest.asImpl.deployment.network.chainTypes.size).toBeGreaterThan(0); + expect(manifest.asImpl.network.chainTypes.size).toBeGreaterThan(0); }); }); diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index f75049ef8..207127631 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -24,18 +24,8 @@ import { CosmosProjectManifestV1_0_0, } from '@subql/types-cosmos'; import {Transform, TransformFnParams, Type} from 'class-transformer'; -import { - Equals, - IsObject, - IsString, - ValidateNested, - validateSync, - IsOptional, - IsArray, - IsNotEmpty, -} from 'class-validator'; -import {CosmosCustomDataSourceBase, CosmosRuntimeDataSourceBase} from '../../models'; -import {ChainTypesImp} from '../../utils'; +import {Equals, IsObject, IsString, ValidateNested, IsOptional, IsArray, IsNotEmpty} from 'class-validator'; +import {CosmosCustomDataSourceBase, CosmosCustomModuleImpl, CosmosRuntimeDataSourceBase} from '../../models'; const COSMOS_NODE_NAME = `@subql/node-cosmos`; @@ -73,12 +63,17 @@ export class CosmosProjectNetworkDeployment { @IsOptional() @IsArray() bypassBlocks?: (number | string)[]; + @IsOptional() + @Type(() => CosmosCustomModuleImpl) + @ValidateNested({each: true}) + chainTypes?: Map; } -export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0 { +export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0> { + @Type(() => CosmosCustomModuleImpl) @IsOptional() - @Validate(ChainTypesImp) - chainTypes?: Map; + @ValidateNested({each: true}) + chainTypes?: Map; } export class RuntimeDatasourceTemplateImpl extends CosmosRuntimeDataSourceImpl implements RuntimeDatasourceTemplate { diff --git a/packages/types/src/project.ts b/packages/types/src/project.ts index aff12a86c..68cbd420f 100644 --- a/packages/types/src/project.ts +++ b/packages/types/src/project.ts @@ -23,7 +23,9 @@ export type RuntimeDatasourceTemplate = BaseTemplateDataSource; export type CosmosProjectManifestV1_0_0 = ProjectManifestV1_0_0< - SubqlCosmosRuntimeDatasource | SubqlCosmosCustomDatasource + SubqlCosmosRuntimeDatasource | SubqlCosmosCustomDatasource, + RuntimeDatasourceTemplate | CustomDatasourceTemplate, + CosmosNetworkConfig >; export interface CustomModule extends FileReference { diff --git a/yarn.lock b/yarn.lock index 90e35ec9a..5966a8a3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4221,7 +4221,7 @@ __metadata: languageName: node linkType: hard -"@subql/types-core@npm:0.1.0, @subql/types-core@npm:^0.1.0": +"@subql/types-core@npm:0.1.0": version: 0.1.0 resolution: "@subql/types-core@npm:0.1.0" dependencies: @@ -4239,6 +4239,15 @@ __metadata: languageName: node linkType: hard +"@subql/types-core@npm:^0.1.0": + version: 0.1.1 + resolution: "@subql/types-core@npm:0.1.1" + dependencies: + package-json-type: ^1.0.3 + checksum: 6a88547e5091795d2f9f24b5373ce531066bc04602b18f05cad77c5d1953523be479801447cd85e4f03468997e988b8c853fdb409631f8a396525cc723978afa + languageName: node + linkType: hard + "@subql/types-cosmos@workspace:*, @subql/types-cosmos@workspace:packages/types": version: 0.0.0-use.local resolution: "@subql/types-cosmos@workspace:packages/types" From bcdaeef6d7df5355bb96f44e6e230b55af33260d Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 11:14:07 +1300 Subject: [PATCH 10/16] update test name --- packages/common-cosmos/src/project/project.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common-cosmos/src/project/project.spec.ts b/packages/common-cosmos/src/project/project.spec.ts index 62b1b4bba..08fc7fcb7 100644 --- a/packages/common-cosmos/src/project/project.spec.ts +++ b/packages/common-cosmos/src/project/project.spec.ts @@ -40,7 +40,7 @@ describe('project.yaml', () => { expect(validateCosmosManifest(cosmosManifest)).toBe(true); expect(validateCosmosManifest(ethManifest)).toBe(false); }); - it('Should fail on incorrect chaintypes', () => { + it('Validate incorrect chaintypes', () => { const cosmosManifest = loadFromJsonOrYaml( path.join(projectsDir, './protoTest1', 'bad-chaintypes-project.yaml') ) as any; From 3c9308e4bc00c8e259866f6cd86293435e282bfb Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 11:14:58 +1300 Subject: [PATCH 11/16] update test name --- packages/common-cosmos/src/project/project.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common-cosmos/src/project/project.spec.ts b/packages/common-cosmos/src/project/project.spec.ts index 08fc7fcb7..58ca49b74 100644 --- a/packages/common-cosmos/src/project/project.spec.ts +++ b/packages/common-cosmos/src/project/project.spec.ts @@ -46,7 +46,7 @@ describe('project.yaml', () => { ) as any; expect(() => parseCosmosProjectManifest(cosmosManifest)).toThrow('failed to parse project.yaml'); }); - it('Ensure correctness on manifest deployment', () => { + it('Ensure chainTypes existence on manifest deployment', () => { const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any; const manifest = parseCosmosProjectManifest(cosmosManifest); expect(manifest.asImpl.network.chainTypes.size).toBeGreaterThan(0); From 00eaee36d57bed5176827e6bbb0a4698b1e2c397 Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 11:21:54 +1300 Subject: [PATCH 12/16] remove unecessary import --- packages/common-cosmos/src/project/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/common-cosmos/src/project/utils.ts b/packages/common-cosmos/src/project/utils.ts index 4aa04f50e..31e31c54e 100644 --- a/packages/common-cosmos/src/project/utils.ts +++ b/packages/common-cosmos/src/project/utils.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-3.0 import {FileReference} from '@subql/types-core'; -import {CosmosCustomModuleImpl} from '@subql/common-cosmos/project/models'; import { SecondLayerHandlerProcessor, SubqlCosmosCustomDatasource, From ebbc211d347fdb21e5a6dcc9dbbe73c07846eaa6 Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 11:48:18 +1300 Subject: [PATCH 13/16] extract map CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes: Map; + chainTypes: CosmosChainTypes; @IsOptional() @Validate(FileReferenceImp) assets?: Map; @@ -193,6 +193,8 @@ export class CosmosFileReferenceImpl implements FileReference { file: string; } +export type CosmosChainTypes = Map; + export class CosmosCustomModuleImpl implements CustomModule { @IsString() file: string; @@ -223,5 +225,5 @@ export class CosmosCustomDataSourceBase< processor: Processor; @Type(() => CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes: Map; + chainTypes: CosmosChainTypes; } diff --git a/packages/common-cosmos/src/project/types.ts b/packages/common-cosmos/src/project/types.ts index a86d950e4..87c750408 100644 --- a/packages/common-cosmos/src/project/types.ts +++ b/packages/common-cosmos/src/project/types.ts @@ -12,7 +12,6 @@ export { SubqlCosmosHandler, SubqlCosmosHandlerKind, SubqlCosmosDatasource as SubqlCosmosDataSource, - SubqlCosmosCustomDatasource as SubqlCosmosCustomDataSource, SubqlCosmosBlockFilter, SubqlCosmosMessageFilter, SubqlCosmosEventFilter, diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index 207127631..360083d40 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -13,7 +13,6 @@ import { } from '@subql/common'; import {NodeSpec, ParentProject, QuerySpec, RunnerSpecs} from '@subql/types-core'; import { - CustomModule, SubqlCosmosCustomDatasource, SubqlCosmosCustomHandler, SubqlCosmosMapping, @@ -25,7 +24,12 @@ import { } from '@subql/types-cosmos'; import {Transform, TransformFnParams, Type} from 'class-transformer'; import {Equals, IsObject, IsString, ValidateNested, IsOptional, IsArray, IsNotEmpty} from 'class-validator'; -import {CosmosCustomDataSourceBase, CosmosCustomModuleImpl, CosmosRuntimeDataSourceBase} from '../../models'; +import { + CosmosChainTypes, + CosmosCustomDataSourceBase, + CosmosCustomModuleImpl, + CosmosRuntimeDataSourceBase, +} from '../../models'; const COSMOS_NODE_NAME = `@subql/node-cosmos`; @@ -66,14 +70,14 @@ export class CosmosProjectNetworkDeployment { @IsOptional() @Type(() => CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes?: Map; + chainTypes?: CosmosChainTypes; } -export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0> { +export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0 { @Type(() => CosmosCustomModuleImpl) @IsOptional() @ValidateNested({each: true}) - chainTypes?: Map; + chainTypes?: CosmosChainTypes; } export class RuntimeDatasourceTemplateImpl extends CosmosRuntimeDataSourceImpl implements RuntimeDatasourceTemplate { From 3bcdb082ec4af0042d1f62318f22c8284b0ff078 Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 13:54:57 +1300 Subject: [PATCH 14/16] fix validators --- .../src/codegen/codegen-controller.ts | 4 ++-- packages/common-cosmos/src/project/models.ts | 6 ++---- .../src/project/versioned/v1_0_0/model.ts | 14 +++++--------- packages/types/src/project.ts | 4 +++- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/common-cosmos/src/codegen/codegen-controller.ts b/packages/common-cosmos/src/codegen/codegen-controller.ts index 9e4c1f9f4..192cab10d 100644 --- a/packages/common-cosmos/src/codegen/codegen-controller.ts +++ b/packages/common-cosmos/src/codegen/codegen-controller.ts @@ -6,7 +6,7 @@ import path from 'path'; import telescope from '@cosmology/telescope'; import cosmwasmCodegen from '@cosmwasm/ts-codegen'; import {makeTempDir} from '@subql/common'; -import {CustomModule, SubqlCosmosRuntimeDatasource} from '@subql/types-cosmos'; +import {CosmosChainTypes, CustomModule, SubqlCosmosRuntimeDatasource} from '@subql/types-cosmos'; import {Data} from 'ejs'; import {copySync} from 'fs-extra'; import {IDLObject} from 'wasm-ast-types'; @@ -29,7 +29,7 @@ interface ProtobufRenderProps { messageNames: string[]; // all messages path: string; // should process the file Path and concat with PROTO dir } -type CosmosChainTypeDataType = Map | Record; +type CosmosChainTypeDataType = CosmosChainTypes | Record; interface CosmwasmRenderJobType { contract: string; diff --git a/packages/common-cosmos/src/project/models.ts b/packages/common-cosmos/src/project/models.ts index 279daf113..bfe11b8a8 100644 --- a/packages/common-cosmos/src/project/models.ts +++ b/packages/common-cosmos/src/project/models.ts @@ -178,7 +178,7 @@ export class CosmosRuntimeDataSourceBase CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes: CosmosChainTypes; + chainTypes: Map; @IsOptional() @Validate(FileReferenceImp) assets?: Map; @@ -193,8 +193,6 @@ export class CosmosFileReferenceImpl implements FileReference { file: string; } -export type CosmosChainTypes = Map; - export class CosmosCustomModuleImpl implements CustomModule { @IsString() file: string; @@ -225,5 +223,5 @@ export class CosmosCustomDataSourceBase< processor: Processor; @Type(() => CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes: CosmosChainTypes; + chainTypes: Map; } diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index 360083d40..cdd68e89b 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -21,15 +21,11 @@ import { RuntimeDatasourceTemplate, CustomDatasourceTemplate, CosmosProjectManifestV1_0_0, + CosmosChainTypes, } from '@subql/types-cosmos'; import {Transform, TransformFnParams, Type} from 'class-transformer'; import {Equals, IsObject, IsString, ValidateNested, IsOptional, IsArray, IsNotEmpty} from 'class-validator'; -import { - CosmosChainTypes, - CosmosCustomDataSourceBase, - CosmosCustomModuleImpl, - CosmosRuntimeDataSourceBase, -} from '../../models'; +import {CosmosCustomDataSourceBase, CosmosCustomModuleImpl, CosmosRuntimeDataSourceBase} from '../../models'; const COSMOS_NODE_NAME = `@subql/node-cosmos`; @@ -70,14 +66,14 @@ export class CosmosProjectNetworkDeployment { @IsOptional() @Type(() => CosmosCustomModuleImpl) @ValidateNested({each: true}) - chainTypes?: CosmosChainTypes; + chainTypes?: Map; } -export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0 { +export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0> { @Type(() => CosmosCustomModuleImpl) @IsOptional() @ValidateNested({each: true}) - chainTypes?: CosmosChainTypes; + chainTypes?: Map; } export class RuntimeDatasourceTemplateImpl extends CosmosRuntimeDataSourceImpl implements RuntimeDatasourceTemplate { diff --git a/packages/types/src/project.ts b/packages/types/src/project.ts index 68cbd420f..6ea47cdbf 100644 --- a/packages/types/src/project.ts +++ b/packages/types/src/project.ts @@ -37,6 +37,8 @@ export interface CustomModule extends FileReference { messages: string[]; } +export type CosmosChainTypes = Map; + export type CustomDataSourceAsset = FileReference; export enum SubqlCosmosDatasourceKind { @@ -103,7 +105,7 @@ export type CosmosNetworkConfig = IProjectNetworkConfig & { } } * */ - chainTypes?: Map; + chainTypes?: CosmosChainTypes; }; export type SubqlCosmosBlockFilter = BlockFilter; From 1e8b6cf43261ecdb5a7e3673bce4176e3873a2dc Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 13:58:18 +1300 Subject: [PATCH 15/16] update generic type for CommonProjectNetworkV1_0_0 --- packages/common-cosmos/src/project/versioned/v1_0_0/model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts index cdd68e89b..d0107b481 100644 --- a/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts +++ b/packages/common-cosmos/src/project/versioned/v1_0_0/model.ts @@ -69,7 +69,7 @@ export class CosmosProjectNetworkDeployment { chainTypes?: Map; } -export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0> { +export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0 { @Type(() => CosmosCustomModuleImpl) @IsOptional() @ValidateNested({each: true}) From 7221536f49c05ca00baffded42cf0133c9c80853 Mon Sep 17 00:00:00 2001 From: bz888 Date: Wed, 4 Oct 2023 15:25:47 +1300 Subject: [PATCH 16/16] Removed chainTypes from ds --- packages/common-cosmos/src/project/models.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/common-cosmos/src/project/models.ts b/packages/common-cosmos/src/project/models.ts index bfe11b8a8..ae306d51b 100644 --- a/packages/common-cosmos/src/project/models.ts +++ b/packages/common-cosmos/src/project/models.ts @@ -176,9 +176,6 @@ export class CosmosRuntimeDataSourceBase CosmosCustomModuleImpl) - @ValidateNested({each: true}) - chainTypes: Map; @IsOptional() @Validate(FileReferenceImp) assets?: Map; @@ -221,7 +218,4 @@ export class CosmosCustomDataSourceBase< @Type(() => ProcessorImpl) @IsObject() processor: Processor; - @Type(() => CosmosCustomModuleImpl) - @ValidateNested({each: true}) - chainTypes: Map; }