From 8bb0755416463744834a0e0c1de258fa479a348d Mon Sep 17 00:00:00 2001 From: Zetazzz Date: Tue, 1 Aug 2023 07:23:28 +0800 Subject: [PATCH] add test --- .../__snapshots__/proto.type.spec.ts.snap | 21 +++ .../ast/src/encoding/proto/proto.type.spec.ts | 24 +++ packages/ast/types/test-utils/index.d.ts | 152 +----------------- packages/types/types/telescope.d.ts | 2 + 4 files changed, 48 insertions(+), 151 deletions(-) diff --git a/packages/ast/src/encoding/proto/__snapshots__/proto.type.spec.ts.snap b/packages/ast/src/encoding/proto/__snapshots__/proto.type.spec.ts.snap index f1d892e320..dc67cbfbc5 100644 --- a/packages/ast/src/encoding/proto/__snapshots__/proto.type.spec.ts.snap +++ b/packages/ast/src/encoding/proto/__snapshots__/proto.type.spec.ts.snap @@ -97,6 +97,27 @@ exports[`createCreateProtoType ValidatorUpdate 1`] = ` }" `; +exports[`createCreateProtoType orginal logic Header 1`] = ` +"function createBaseHeader(): Header { + return { + version: Consensus.fromPartial({}), + chainId: "", + height: Long.ZERO, + time: undefined, + lastBlockId: BlockID.fromPartial({}), + lastCommitHash: new Uint8Array(), + dataHash: new Uint8Array(), + validatorsHash: new Uint8Array(), + nextValidatorsHash: new Uint8Array(), + consensusHash: new Uint8Array(), + appHash: new Uint8Array(), + lastResultsHash: new Uint8Array(), + evidenceHash: new Uint8Array(), + proposerAddress: new Uint8Array() + }; +}" +`; + exports[`oneofs Value 1`] = ` "/** * \`Value\` represents a dynamically typed value which can be either diff --git a/packages/ast/src/encoding/proto/proto.type.spec.ts b/packages/ast/src/encoding/proto/proto.type.spec.ts index 926f7b5128..cc01f5aa7d 100644 --- a/packages/ast/src/encoding/proto/proto.type.spec.ts +++ b/packages/ast/src/encoding/proto/proto.type.spec.ts @@ -8,6 +8,7 @@ import { traverse, getNestedProto } from '@cosmology/proto-parser' import { defaultTelescopeOptions } from '@cosmology/types' import { ProtoParseContext } from '../context'; import { getTestProtoStore, expectCode, printCode } from '../../../test-utils'; +import deepmerge from 'deepmerge'; const store = getTestProtoStore(); store.traverseAll(); @@ -87,6 +88,29 @@ describe('createCreateProtoType', () => { }); }); +describe('createCreateProtoType orginal logic', () => { + const ref = store.findProto('tendermint/types/types.proto'); + + const options = deepmerge(defaultTelescopeOptions, { + prototypes: { + typingsFormat:{ + setDefaultEnumTo0: true, + setDefaultOtherTypesToUndefined: true, + } + } + }); + + const context = new ProtoParseContext(ref, store, options); + + it('Header', () => { + expectCode(createCreateProtoType( + context, + 'Header', + getNestedProto(types_tendermint).Header + )); + }); +}); + describe('traversed', () => { it('osmosis/claim/v1beta1/params', async () => { const ref = store.findProto('osmosis/claim/v1beta1/params.proto'); diff --git a/packages/ast/types/test-utils/index.d.ts b/packages/ast/types/test-utils/index.d.ts index b9d24415be..49294474ec 100644 --- a/packages/ast/types/test-utils/index.d.ts +++ b/packages/ast/types/test-utils/index.d.ts @@ -1,160 +1,10 @@ -import { ProtoType, TelescopeOptions } from '@cosmology/types'; +import { ProtoType } from '@cosmology/types'; import { ProtoStore } from '@cosmology/proto-parser'; import { AminoParseContext } from '../src/encoding/context'; import { GenericParseContext } from '../src/encoding'; export declare const expectCode: (ast: any) => void; export declare const printCode: (ast: any) => void; export declare const defaultTelescopeOptions: { - env: "default" | "v-next"; - removeUnusedImports: boolean; - classesUseArrowFunctions: boolean; - useSDKTypes: boolean; - includeExternalHelpers: boolean; - logLevel: import("@cosmology/types").TelescopeLogLevel; - interfaces: { - enabled?: boolean; - useUnionTypes?: boolean; - }; - prototypes: { - enabled?: boolean; - parser?: { - keepCase?: boolean; - alternateCommentMode?: boolean; - preferTrailingComment?: boolean; - }; - methods?: { - encode?: boolean; - decode?: boolean; - fromJSON?: boolean; - toJSON?: boolean; - fromPartial?: boolean; - toSDK?: boolean; - fromSDK?: boolean; - fromSDKJSON?: boolean; - toAmino?: boolean; - fromAmino?: boolean; - toProto?: boolean; - fromProto?: boolean; - }; - includePackageVar?: boolean; - fieldDefaultIsOptional?: boolean; - useOptionalNullable?: boolean; - allowUndefinedTypes?: boolean; - optionalQueryParams?: boolean; - optionalPageRequests?: boolean; - addTypeUrlToObjects?: boolean; - addAminoTypeToObjects?: boolean; - addTypeUrlToDecoders?: boolean; - excluded?: { - packages?: string[]; - protos?: string[]; - }; - includes?: { - packages?: string[]; - protos?: string[]; - }; - typingsFormat?: { - customTypes?: { - useCosmosSDKDec?: boolean; - }; - num64?: "bigint" | "long"; - useDeepPartial?: boolean; - useExact?: boolean; - timestamp?: "date" | "timestamp"; - duration?: "string" | "duration"; - updatedDuration?: boolean; - }; - }; - tsDisable: { - files?: string[]; - disableAll?: boolean; - patterns?: string[]; - }; - eslintDisable: { - files?: string[]; - disableAll?: boolean; - patterns?: string[]; - }; - bundle: { - enabled: boolean; - }; - cosmwasm: import("@cosmwasm/ts-codegen").TSBuilderInput; - aggregatedLCD: { - dir: string; - filename: string; - packages: string[]; - protos?: string[]; - addToBundle: boolean; - }; - stargateClients: { - enabled: boolean; - includeCosmosDefaultTypes?: boolean; - }; - aminoEncoding: { - enabled: boolean; - casingFn?: Function; - exceptions?: import("@cosmology/types").AminoExceptions; - typeUrlToAmino?: (typeUrl: string) => string; - useRecursiveV2encoding?: boolean; - }; - lcdClients: { - enabled: boolean; - scopedIsExclusive?: boolean; - bundle?: boolean; - scoped?: { - dir: string; - filename?: string; - packages: string[]; - protos?: string[]; - addToBundle: boolean; - methodName?: string; - }[]; - }; - rpcClients: { - type?: "tendermint" | "grpc-web" | "grpc-gateway"; - enabled: boolean; - inline?: boolean; - extensions?: boolean; - camelCase?: boolean; - scopedIsExclusive?: boolean; - bundle?: boolean; - enabledServices?: string[]; - scoped?: { - dir: string; - filename?: string; - packages: string[]; - protos?: string[]; - addToBundle: boolean; - methodNameQuery?: string; - methodNameTx?: string; - }[]; - }; - reactQuery: { - enabled: boolean; - include?: { - patterns?: string[]; - packages?: string[]; - protos?: string[]; - }; - }; - mobx: { - enabled: boolean; - include?: { - patterns?: string[]; - packages?: string[]; - protos?: string[]; - }; - }; - pinia: { - enabled: boolean; - include?: { - patterns?: string[]; - packages?: string[]; - protos?: string[]; - }; - }; - packages: Record; -} & { prototypes: { parser: { keepCase: boolean; diff --git a/packages/types/types/telescope.d.ts b/packages/types/types/telescope.d.ts index db6be67cea..6e324dfbdc 100644 --- a/packages/types/types/telescope.d.ts +++ b/packages/types/types/telescope.d.ts @@ -65,6 +65,8 @@ interface TelescopeOpts { useExact?: boolean; timestamp?: 'date' | 'timestamp'; duration?: 'duration' | 'string'; + setDefaultEnumTo0?: boolean; + setDefaultOtherTypesToUndefined?: boolean; updatedDuration?: boolean; }; };