@cosmology/ast
Version:
Cosmos TypeScript AST generation
80 lines (76 loc) • 3.69 kB
text/typescript
import {
getUrlTemplateString,
createLCDClient
} from './lcd';
import { traverse } from '@cosmology/proto-parser'
import { getNestedProto } from '@cosmology/utils'
import { defaultTelescopeOptions, ProtoService } from '@cosmology/types';
import { GenericParseContext } from '../../../encoding';
import { getTestProtoStore, expectCode } from '../../../../test-utils';
const store = getTestProtoStore();
store.traverseAll();
it('service info template', () => {
expect(getUrlTemplateString('/osmosis/{gamm}/v1beta1/estimate/swap_exact_amount_in')).toMatchSnapshot();
expect(getUrlTemplateString('/osmosis/{gamm}/v1beta1/{estimate}/swap_exact_amount_in')).toMatchSnapshot();
expect(getUrlTemplateString('/osmosis/{gamm}/{v1beta1}/{estimate}/{swap_exact_amount_in}')).toMatchSnapshot();
expect(getUrlTemplateString('/osmosis/gamm/v1beta1/estimate/{swap_exact_amount_in}')).toMatchSnapshot();
expect(getUrlTemplateString('/cosmos/feegrant/v1beta1/allowance/{granter}/{grantee}')).toMatchSnapshot();
});
it('osmosis LCDClient', () => {
const ref = store.findProto('osmosis/gamm/v1beta1/query.proto');
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});
it('cosmos LCDClient', () => {
const ref = store.findProto('cosmos/bank/v1beta1/query.proto');
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});
it('cosmos fee LCDClient', () => {
const ref = store.findProto('cosmos/feegrant/v1beta1/query.proto');
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});
it('cosmos/staking/v1beta1/query.proto', () => {
const ref = store.findProto('cosmos/staking/v1beta1/query.proto');
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});
it('cosmos/app/v1alpha1/query.proto', () => {
const ref = store.findProto('cosmos/app/v1alpha1/query.proto');
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});
it('cosmos/group/v1/query.proto', () => {
const ref = store.findProto('cosmos/group/v1/query.proto');
store.options.prototypes.parser.keepCase = true;
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});
it('cosmos/gov/v1beta1/query.proto', () => {
const ref = store.findProto('cosmos/gov/v1beta1/query.proto');
store.options.prototypes.parser.keepCase = true;
const res = traverse(store, ref);
const service: ProtoService = getNestedProto(res).Query;
const context = new GenericParseContext(ref, store, defaultTelescopeOptions);
const ast = createLCDClient(context, service);
expectCode(ast);
});