Skip to content

Commit

Permalink
fix: 🐛 Handle multiSig signer key in account.getPermissions
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantasdeveloper committed Nov 8, 2024
1 parent 436f319 commit 7728c68
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/api/entities/Account/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Balance,
ErrorCode,
ModuleName,
MultiSigTx,
Permissions,
PermissionType,
ResultSet,
Expand Down Expand Up @@ -561,6 +562,34 @@ describe('Account class', () => {
getIdentitySpy.mockRestore();
});

it('should return the permissions if the Account is the MultiSig Account', async () => {
const identity = entityMockUtils.getIdentityInstance({
getPrimaryAccount: {
account: entityMockUtils.getAccountInstance({ address: 'multisigAddress' }),
},
});

account = new Account({ address }, context);

const getIdentitySpy = jest.spyOn(account, 'getIdentity').mockResolvedValue(identity);

getSecondaryAccountPermissionsSpy.mockResolvedValue([]);

const result = await account.getPermissions();

expect(result).toEqual({
assets: null,
transactions: {
type: PermissionType.Include,
values: [MultiSigTx.CreateProposal, MultiSigTx.Approve, MultiSigTx.Reject],
},
transactionGroups: [],
portfolios: null,
});

getIdentitySpy.mockRestore();
});

it("should return the Account's permissions if it is a secondary Account", async () => {
const permissions = {
assets: null,
Expand Down
15 changes: 15 additions & 0 deletions src/api/entities/Account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {
CheckPermissionsResult,
ErrorCode,
ExtrinsicData,
MultiSigTx,
Permissions,
PermissionType,
ResultSet,
SignerType,
SimplePermissions,
Expand Down Expand Up @@ -367,6 +369,19 @@ export class Account extends Entity<UniqueIdentifiers, string> {
};
}

if (!permissionedAccount) {
// this is true for multisig accounts
return {
assets: null,
transactions: {
type: PermissionType.Include,
values: [MultiSigTx.CreateProposal, MultiSigTx.Approve, MultiSigTx.Reject],
},
transactionGroups: [],
portfolios: null,
};
}

return permissionedAccount.permissions;
}

Expand Down

0 comments on commit 7728c68

Please sign in to comment.