Skip to content

Commit

Permalink
feat: 🎸 throw error from getAuthorization
Browse files Browse the repository at this point in the history
getAuth is run first so error needs to be thrown there
  • Loading branch information
sansan committed Oct 4, 2024
1 parent 46ff3f1 commit efa196c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
54 changes: 28 additions & 26 deletions src/api/procedures/__tests__/joinCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,38 +168,13 @@ describe('joinCreator procedure', () => {
resolver: undefined,
});
});

it('should throw an error if called from v7', async () => {
mockContext = dsMockUtils.getContextInstance({ isV6: false });

const proc = procedureMockUtils.getInstance<Params, void>(mockContext);

const expectedError = new PolymeshError({
code: ErrorCode.ValidationError,
message:
'This method is deprecated. MultiSig automatically is attached to the creators identity on creation.',
});

await expect(
prepareJoinCreator.call(proc, {
asPrimary: false,
multiSig,
permissions: {
assets: {
type: PermissionType.Include,
values: [entityMockUtils.getFungibleAssetInstance()],
},
},
})
).rejects.toThrow(expectedError);
});
});

describe('getAuthorization', () => {
let mockContext: Context;

beforeEach(() => {
mockContext = dsMockUtils.getContextInstance();
mockContext = dsMockUtils.getContextInstance({ isV6: true });
});

it('should return the appropriate roles and permissions for as primary', () => {
Expand Down Expand Up @@ -256,4 +231,31 @@ describe('getAuthorization', () => {
},
});
});

it('should throw an error if called from v7', () => {
mockContext = dsMockUtils.getContextInstance({ isV6: false });

const proc = procedureMockUtils.getInstance<Params, void>(mockContext);

const boundFunc = getAuthorization.bind(proc);

let expectedError = new PolymeshError({
code: ErrorCode.ValidationError,
message: 'This method is deprecated. Use `identities.rotatePrimaryKey` instead.',
});

expect(() =>
boundFunc({ asPrimary: true, multiSig: entityMockUtils.getMultiSigInstance() })
).toThrow(expectedError);

expectedError = new PolymeshError({
code: ErrorCode.ValidationError,
message:
'This method is deprecated. MultiSig automatically is attached as secondary key to the creators identity.',
});

expect(() =>
boundFunc({ asPrimary: false, multiSig: entityMockUtils.getMultiSigInstance() })
).toThrow(expectedError);
});
});
23 changes: 14 additions & 9 deletions src/api/procedures/joinCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,11 @@ export async function prepareJoinCreator(
> {
const {
context,
context: { polymeshApi, isV6 },
context: { polymeshApi },
} = this;
const { multiSig, asPrimary } = args;
const tx = polymeshApi.tx as unknown as LocalSubmittableExtrinsics<ApiTypes>;

if (!isV6) {
throw new PolymeshError({
code: ErrorCode.NoDataChange,
message:
'This method is deprecated. MultiSig automatically is attached to the creators identity on creation.',
});
}

const [signingIdentity, creator] = await Promise.all([
context.getSigningIdentity(),
multiSig.getCreator(),
Expand Down Expand Up @@ -162,6 +154,19 @@ export function getAuthorization(
args: Params
): ProcedureAuthorization {
const { asPrimary } = args;
const {
context: { isV6 },
} = this;

if (!isV6) {
throw new PolymeshError({
code: ErrorCode.NoDataChange,
message: asPrimary
? 'This method is deprecated. Use `identities.rotatePrimaryKey` instead.'
: 'This method is deprecated. MultiSig automatically is attached as secondary key to the creators identity.',
});
}

const transactions = [];
if (asPrimary) {
transactions.push(TxTags.multiSig.MakeMultisigPrimary);
Expand Down

0 comments on commit efa196c

Please sign in to comment.