Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Jul 31, 2023
1 parent 857603f commit 8bb0755
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions packages/ast/src/encoding/proto/proto.type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand Down
152 changes: 1 addition & 151 deletions packages/ast/types/test-utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;
} & {
prototypes: {
parser: {
keepCase: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/types/types/telescope.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ interface TelescopeOpts {
useExact?: boolean;
timestamp?: 'date' | 'timestamp';
duration?: 'duration' | 'string';
setDefaultEnumTo0?: boolean;
setDefaultOtherTypesToUndefined?: boolean;
updatedDuration?: boolean;
};
};
Expand Down

0 comments on commit 8bb0755

Please sign in to comment.