Skip to content

Commit

Permalink
Fix: Update detection (#314)
Browse files Browse the repository at this point in the history
* fix update detection

* update version

* fix comments
  • Loading branch information
josemarinas authored Dec 12, 2023
1 parent da44044 commit a33232d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
5 changes: 5 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ TEMPLATE:
-->

## [UPCOMING]
### Fixed

- Fixed update proposal detection

## [1.20.3]

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion modules/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client",
"author": "Aragon Association",
"version": "1.20.3",
"version": "1.20.4",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down
24 changes: 10 additions & 14 deletions modules/client/src/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
TransferSortBy,
} from "../../types";
import {
ProposalActionTypes,
SubgraphBalance,
SubgraphDao,
SubgraphDaoListItem,
Expand All @@ -82,9 +83,7 @@ import {
} from "../types";
import {
classifyProposalActions,
containsDaoUpdateAction,
containsPluginUpdateActionBlock,
containsPluginUpdateActionBlockWithRootPermission,
startsWithDaoUpdateAction,
toAssetBalance,
toDaoActions,
toDaoDetails,
Expand Down Expand Up @@ -1125,7 +1124,9 @@ export class ClientMethods extends ClientCore implements IClientMethods {
const subgraphActions = iproposal.actions;
let actions = toDaoActions(subgraphActions);
const classifiedActions = classifyProposalActions(actions);
return containsDaoUpdateAction(classifiedActions);
return classifiedActions.includes(
ProposalActionTypes.UPGRADE_TO_AND_CALL,
) || classifiedActions.includes(ProposalActionTypes.UPGRADE_TO);
}
/**
* Given a proposal id returns if that proposal is a plugin update proposal
Expand All @@ -1148,14 +1149,9 @@ export class ClientMethods extends ClientCore implements IClientMethods {
if (!iproposal) {
return false;
}
const subgraphActions = iproposal.actions;
let actions = toDaoActions(subgraphActions);
let actions = toDaoActions(iproposal.actions);
let classifiedActions = classifyProposalActions(actions);
if (containsDaoUpdateAction(classifiedActions)) {
classifiedActions = classifiedActions.slice(1);
}
return containsPluginUpdateActionBlock(classifiedActions) ||
containsPluginUpdateActionBlockWithRootPermission(classifiedActions);
return classifiedActions.includes(ProposalActionTypes.APPLY_UPDATE);
}
/**
* Check if the specified proposal id is valid for updating a plugin
Expand Down Expand Up @@ -1198,12 +1194,12 @@ export class ClientMethods extends ClientCore implements IClientMethods {
],
};
}

let daoActions = toDaoActions(iproposal.actions);
const classifiedActions = classifyProposalActions(daoActions);

// remove upgradeToAndCall action
if (containsDaoUpdateAction(classifiedActions)) {
// remove upgradeToAndCall action
if (startsWithDaoUpdateAction(classifiedActions)) {
daoActions = daoActions.slice(1);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/client/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ export function containsPluginUpdateActionBlock(
* @param {ProposalActionTypes[]} actions
* @return {*} {boolean}
*/
export function containsDaoUpdateAction(
export function startsWithDaoUpdateAction(
actions: ProposalActionTypes[],
): boolean {
// UpgradeTo or UpgradeToAndCall should be the first action
Expand All @@ -1426,7 +1426,7 @@ export function validateUpdateDaoProposalActions(
const actionErrorCauses: DaoUpdateProposalInvalidityCause[] = [];
const proposalSettingsErrorCauses: ProposalSettingsErrorCause[] = [];
// check if the actions are valid
if (!containsDaoUpdateAction(classifiedActions)) {
if (!startsWithDaoUpdateAction(classifiedActions)) {
// If actions are not valid, add the cause to the causes array
// and return
return {
Expand Down
4 changes: 3 additions & 1 deletion modules/client/test/integration/client/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,9 @@ describe("Client", () => {
TEST_MULTISIG_PROPOSAL_ID,
);
expect(res.isValid).toBe(false);
expect(res.proposalSettingsErrorCauses).toMatchObject([ProposalSettingsErrorCause.PROPOSAL_NOT_FOUND]);
expect(res.proposalSettingsErrorCauses).toMatchObject([
ProposalSettingsErrorCause.PROPOSAL_NOT_FOUND,
]);
expect(res.actionErrorCauses).toMatchObject([]);
});
});
Expand Down
6 changes: 3 additions & 3 deletions modules/client/test/unit/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
TOKEN_VOTING_BUILD_METADATA,
} from "../../integration/constants";
import {
containsDaoUpdateAction,
startsWithDaoUpdateAction,
containsPluginUpdateActionBlock,
containsPluginUpdateActionBlockWithRootPermission,
validateApplyUpdateFunction,
Expand Down Expand Up @@ -1323,7 +1323,7 @@ describe("Test client utils", () => {
expect(result.proposalSettingsErrorCauses).toMatchObject([]);
});
});
describe("containsDaoUpdateAction", () => {
describe("startsWithDaoUpdateAction", () => {
it("should return the expected output given a specific input", () => {
const cases = [
{ input: [ProposalActionTypes.UPGRADE_TO], expected: true },
Expand Down Expand Up @@ -1389,7 +1389,7 @@ describe("Test client utils", () => {
},
];
for (const { input, expected } of cases) {
const result = containsDaoUpdateAction(input);
const result = startsWithDaoUpdateAction(input);
expect(result).toEqual(expected);
}
});
Expand Down

0 comments on commit a33232d

Please sign in to comment.