Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Dec 4, 2023
1 parent dc8a5c4 commit b2be8af
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 57 deletions.
10 changes: 8 additions & 2 deletions modules/client/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,16 @@ export async function validateApplyUpdateFunction(
const build = release?.builds.find((
build: { build: number; metadata: string },
) => build.build === decodedParams.versionTag.build);
const metadataUri = build?.metadata;
if (!build) {
causes.push(
PluginUpdateProposalInValidityCause.INVALID_PLUGIN_REPO_METADATA,
);
return causes;
}
const metadataUri = build.metadata;

// fetch the metadata
const metadataCid = new MultiUri(metadataUri!).ipfsCid
const metadataCid = new MultiUri(metadataUri).ipfsCid
const metadata = await ipfs.fetchString(metadataCid!);
const metadataJson = JSON.parse(metadata);
let updateAbi = []
Expand Down
78 changes: 23 additions & 55 deletions modules/client/test/unit/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ describe("Test client utils", () => {
describe("validateApplyUpdateFunction", () => {
beforeEach(() => {
mockedClient.request.mockReset();
mockedIPFSClient.cat.mockReset();
});
beforeAll(() => {
applyUpdateParams = {
Expand Down Expand Up @@ -698,16 +699,12 @@ describe("Test client utils", () => {
applyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify(TOKEN_VOTING_BUILD_METADATA),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -725,16 +722,12 @@ describe("Test client utils", () => {
);
const action = applyUpdateActions[1];
action.value = BigInt(10);
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
pluginRepo: subgraphPluginRepo,
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify(TOKEN_VOTING_BUILD_METADATA),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -760,16 +753,12 @@ describe("Test client utils", () => {
updatedApplyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
pluginRepo: subgraphPluginRepo,
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify(TOKEN_VOTING_BUILD_METADATA),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -780,6 +769,7 @@ describe("Test client utils", () => {
);
expect(result).toMatchObject([
PluginUpdateProposalInValidityCause.UPDATE_TO_INCOMPATIBLE_RELEASE,
PluginUpdateProposalInValidityCause.INVALID_PLUGIN_REPO_METADATA,
]);
});
it("should return an `UPDATE_TO_OLDER_OR_SAME_BUILD` when the release is different from the one on subgraph", async () => {
Expand All @@ -795,16 +785,12 @@ describe("Test client utils", () => {
updatedApplyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify(TOKEN_VOTING_BUILD_METADATA),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -827,7 +813,7 @@ describe("Test client utils", () => {
applyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDaoWithoutPlugin,
});
const result = await validateApplyUpdateFunction(
Expand All @@ -850,16 +836,12 @@ describe("Test client utils", () => {
applyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: externalPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify(TOKEN_VOTING_BUILD_METADATA),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -878,10 +860,8 @@ describe("Test client utils", () => {
applyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: null,
});
const result = await validateApplyUpdateFunction(
Expand All @@ -904,16 +884,12 @@ describe("Test client utils", () => {
updatedApplyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
pluginRepo: subgraphPluginRepo,
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify(TOKEN_VOTING_BUILD_METADATA),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -932,16 +908,12 @@ describe("Test client utils", () => {
applyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [subgraphPluginPreparation],
});
mockedIPFSClient.cat.mockResolvedValueOnce(Buffer.from(
mockedIPFSClient.cat.mockResolvedValue(Buffer.from(
JSON.stringify({}),
));
const result = await validateApplyUpdateFunction(
Expand All @@ -960,14 +932,10 @@ describe("Test client utils", () => {
applyUpdateParams,
);
const action = applyUpdateActions[1];
mockedClient.request.mockResolvedValueOnce({
mockedClient.request.mockResolvedValue({
dao: subgraphDao,
});
mockedClient.request.mockResolvedValueOnce({
pluginRepo: subgraphPluginRepo,
});
mockedClient.request.mockResolvedValueOnce({
pluginPreparations: [],
pluginRepo: subgraphPluginRepo,
});
const result = await validateApplyUpdateFunction(
action,
Expand Down

0 comments on commit b2be8af

Please sign in to comment.