Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for includes option for various modules and leverage dependency resolution #406

Merged
merged 4 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/ast/src/encoding/proto/implements/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ export const createInterfaceDecoderHelper = (
// MARKED AS NOT DRY
const allTypes: TypeUrlRef[] =
typeRefs?.reduce((m, typeRef) => {
// check excludes
const packages =
context.pluginValue('prototypes.excluded.packages') ?? [];
const protos = context.pluginValue('prototypes.excluded.protos') ?? [];
const excluded =
packages.includes(typeRef.pkg) || protos.includes(typeRef.ref);
if (excluded) return m;
return [...m, ...typeRef.types];
}, []) ?? [];

Expand Down
5 changes: 0 additions & 5 deletions packages/ast/src/encoding/proto/implements/from-amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ export const createInterfaceFromAminoHelper = (

// MARKED AS NOT DRY
const allTypes: TypeUrlRef[] = typeRefs?.reduce((m, typeRef) => {
// check excludes
const packages = context.pluginValue('prototypes.excluded.packages') ?? [];
const protos = context.pluginValue('prototypes.excluded.protos') ?? [];
const excluded = packages.includes(typeRef.pkg) || protos.includes(typeRef.ref);
if (excluded) return m;
return [...m, ...typeRef.types];
}, []) ?? [];

Expand Down
5 changes: 0 additions & 5 deletions packages/ast/src/encoding/proto/implements/to-amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ export const createInterfaceToAminoHelper = (

// MARKED AS NOT DRY
const allTypes: TypeUrlRef[] = typeRefs?.reduce((m, typeRef) => {
// check excludes
const packages = context.pluginValue('prototypes.excluded.packages') ?? [];
const protos = context.pluginValue('prototypes.excluded.protos') ?? [];
const excluded = packages.includes(typeRef.pkg) || protos.includes(typeRef.ref);
if (excluded) return m;
return [...m, ...typeRef.types];
}, []) ?? [];

Expand Down
4 changes: 4 additions & 0 deletions packages/ast/types/test-utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export declare const defaultTelescopeOptions: {
packages?: string[];
protos?: string[];
};
includes?: {
packages?: string[];
protos?: string[];
};
typingsFormat?: {
customTypes?: {
useCosmosSDKDec?: boolean;
Expand Down
222 changes: 222 additions & 0 deletions packages/parser/__tests__/store/__snapshots__/store.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cosmos/gov/v1beta1/gov.proto 1`] = `
[
"cosmos.base.v1beta1",
"cosmos.gov.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
]
`;

exports[`cosmos/gov/v1beta1/gov.proto excluded 1`] = `[]`;

exports[`cosmos/gov/v1beta1/gov.proto excluded dep 1`] = `
[
"cosmos.base.v1beta1",
"cosmos.gov.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
]
`;

exports[`get all packages 1`] = `
[
"akash.audit.v1beta1",
"akash.audit.v1beta2",
"akash.base.v1beta1",
"akash.base.v1beta2",
"akash.cert.v1beta2",
"akash.deployment.v1beta1",
"akash.deployment.v1beta2",
"akash.escrow.v1beta1",
"akash.escrow.v1beta2",
"akash.inflation.v1beta2",
"akash.market.v1beta2",
"akash.provider.v1beta1",
"akash.provider.v1beta2",
"cosmos.app.v1alpha1",
"cosmos.auth.v1beta1",
"cosmos.authz.v1beta1",
"cosmos.bank.v1beta1",
"cosmos.base.abci.v1beta1",
"cosmos.base.kv.v1beta1",
"cosmos.base.query.v1beta1",
"cosmos.base.reflection.v1beta1",
"cosmos.base.reflection.v2alpha1",
"cosmos.base.snapshots.v1beta1",
"cosmos.base.store.v1beta1",
"cosmos.base.tendermint.v1beta1",
"cosmos.base.v1beta1",
"cosmos.capability.v1beta1",
"cosmos.crisis.v1beta1",
"cosmos.crypto.ed25519",
"cosmos.crypto.hd.v1",
"cosmos.crypto.keyring.v1",
"cosmos.crypto.multisig",
"cosmos.crypto.multisig.v1beta1",
"cosmos.crypto.secp256k1",
"cosmos.crypto.secp256r1",
"cosmos.distribution.v1beta1",
"cosmos.evidence.v1beta1",
"cosmos.feegrant.v1beta1",
"cosmos.genutil.v1beta1",
"cosmos.gov.v1",
"cosmos.gov.v1beta1",
"cosmos.group.v1",
"cosmos.mint.v1beta1",
"cosmos.msg.v1",
"cosmos.nft.v1beta1",
"cosmos.orm.module.v1alpha1",
"cosmos.orm.v1",
"cosmos.orm.v1alpha1",
"cosmos.params.v1beta1",
"cosmos.slashing.v1beta1",
"cosmos.staking.v1beta1",
"cosmos.tx.signing.v1beta1",
"cosmos.tx.v1beta1",
"cosmos.upgrade.v1beta1",
"cosmos.vesting.v1beta1",
"cosmos_proto",
"cosmwasm.wasm.v1",
"evmos.claims.v1",
"evmos.epochs.v1",
"evmos.erc20.v1",
"evmos.fees.v1",
"evmos.incentives.v1",
"evmos.inflation.v1",
"evmos.recovery.v1",
"evmos.vesting.v1",
"gogoproto",
"google.api",
"google.api.expr.conformance.v1alpha1",
"google.api.expr.v1alpha1",
"google.api.expr.v1beta1",
"google.api.servicecontrol.v1",
"google.api.servicecontrol.v2",
"google.api.servicemanagement.v1",
"google.api.serviceusage.v1",
"google.api.serviceusage.v1beta1",
"google.logging.type",
"google.logging.v2",
"google.longrunning",
"google.protobuf",
"google.protobuf.compiler",
"google.rpc",
"google.rpc.context",
"ibc.applications.transfer.v1",
"ibc.applications.transfer.v2",
"ibc.core.channel.v1",
"ibc.core.client.v1",
"ibc.core.commitment.v1",
"ibc.core.connection.v1",
"ibc.core.port.v1",
"ibc.core.types.v1",
"ibc.lightclients.localhost.v1",
"ibc.lightclients.solomachine.v1",
"ibc.lightclients.solomachine.v2",
"ibc.lightclients.tendermint.v1",
"ics23",
"osmosis.claim.v1beta1",
"osmosis.epochs.v1beta1",
"osmosis.gamm.poolmodels.balancer.v1beta1",
"osmosis.gamm.poolmodels.stableswap.v1beta1",
"osmosis.gamm.v1beta1",
"osmosis.gamm.v2",
"osmosis.ibcratelimit.v1beta1",
"osmosis.incentives",
"osmosis.lockup",
"osmosis.mint.v1beta1",
"osmosis.poolincentives.v1beta1",
"osmosis.store.v1beta1",
"osmosis.superfluid",
"osmosis.superfluid.v1beta1",
"osmosis.tokenfactory.v1beta1",
"osmosis.twap.v1beta1",
"osmosis.txfees.v1beta1",
"tendermint.abci",
"tendermint.crypto",
"tendermint.libs.bits",
"tendermint.p2p",
"tendermint.types",
"tendermint.version",
]
`;

exports[`gov.proto & tx.proto & signing.proto 1`] = `
[
"cosmos.base.v1beta1",
"cosmos.crypto.multisig.v1beta1",
"cosmos.gov.v1beta1",
"cosmos.tx.signing.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
"osmosis.gamm.v1beta1",
]
`;

exports[`gov.proto & tx.proto & signing.proto excluded 1`] = `
[
"cosmos.base.v1beta1",
"cosmos.crypto.multisig.v1beta1",
"cosmos.gov.v1beta1",
"cosmos.tx.signing.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
]
`;

exports[`gov.proto & tx.proto 1`] = `
[
"cosmos.base.v1beta1",
"cosmos.gov.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
"osmosis.gamm.v1beta1",
]
`;

exports[`osmosis excluded gamm 1`] = `
[
"cosmos.bank.v1beta1",
"cosmos.base.query.v1beta1",
"cosmos.base.v1beta1",
"cosmos.msg.v1",
"cosmos.staking.v1beta1",
"cosmos_proto",
"gogoproto",
"google.api",
"google.protobuf",
"osmosis.claim.v1beta1",
"osmosis.epochs.v1beta1",
"osmosis.ibcratelimit.v1beta1",
"osmosis.incentives",
"osmosis.lockup",
"osmosis.mint.v1beta1",
"osmosis.poolincentives.v1beta1",
"osmosis.store.v1beta1",
"osmosis.superfluid",
"osmosis.superfluid.v1beta1",
"osmosis.tokenfactory.v1beta1",
"osmosis.twap.v1beta1",
"osmosis.txfees.v1beta1",
"tendermint.crypto",
"tendermint.types",
"tendermint.version",
]
`;

exports[`osmosis/gamm/v1beta1/tx.proto 1`] = `
[
"cosmos.base.v1beta1",
"cosmos_proto",
"gogoproto",
"google.protobuf",
"osmosis.gamm.v1beta1",
]
`;
126 changes: 126 additions & 0 deletions packages/parser/__tests__/store/store.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { getTestProtoStore } from '../../test-utils';

it('get all packages', () => {
const store = getTestProtoStore();
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('cosmos/gov/v1beta1/gov.proto', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:["cosmos/gov/v1beta1/gov.proto"]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('cosmos/gov/v1beta1/gov.proto excluded', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:["cosmos/gov/v1beta1/gov.proto"]
}
store.options.prototypes!.excluded = {
protos:["cosmos/gov/v1beta1/gov.proto"]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('cosmos/gov/v1beta1/gov.proto excluded dep', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:["cosmos/gov/v1beta1/gov.proto"]
}
store.options.prototypes!.excluded = {
protos:["gogoproto/gogo.proto"]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('osmosis/gamm/v1beta1/tx.proto', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:["osmosis/gamm/v1beta1/tx.proto"]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('gov.proto & tx.proto', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:[
"cosmos/gov/v1beta1/gov.proto",
"osmosis/gamm/v1beta1/tx.proto"
]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('gov.proto & tx.proto & signing.proto', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:[
"cosmos/gov/v1beta1/gov.proto",
"osmosis/gamm/v1beta1/tx.proto",
"cosmos/tx/signing/v1beta1/signing.proto"
]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('gov.proto & tx.proto & signing.proto excluded', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
protos:[
"cosmos/gov/v1beta1/gov.proto",
"osmosis/gamm/v1beta1/tx.proto",
"cosmos/tx/signing/v1beta1/signing.proto"
]
}
store.options.prototypes!.excluded = {
protos:[
"**/gamm/**",
]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});

it('osmosis excluded gamm', () => {
const store = getTestProtoStore();
store.options.prototypes!.includes = {
packages:[
"osmosis.*"
]
}
store.options.prototypes!.excluded = {
protos:[
"**/gamm/**",
]
}
store.traverseAll();
const pkgs = store.getPackages().sort();

expect(pkgs).toMatchSnapshot();
});
Loading