Skip to content

Commit

Permalink
feat: 馃幐 allow for exempted identities to be removed
Browse files Browse the repository at this point in the history
when a user does not pass exempted identities that are exempt when
calling setTransferRestrictions the procedure will unset those
permissions

BREAKING CHANGE: 馃Ж non passed exempted identities are removed when calling
setTransferRestriction
  • Loading branch information
polymath-eric committed Aug 4, 2022
1 parent c862841 commit 5036a1d
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 120 deletions.
3 changes: 3 additions & 0 deletions src/api/entities/Asset/TransferRestrictions/ClaimCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class ClaimCount extends TransferRestrictionBase<TransferRestrictionType.
/**
* Sets all Claim Count Transfer Restrictions on this Asset
*
* @note this method set exempted Identities for restrictions as well. If an Identity is currently exempted from a Claim Count Transfer Restriction
* but not passed into this call then they will be removed
*
* @note the result is the total amount of restrictions after the procedure has run
*/
public declare setRestrictions: ProcedureMethod<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class ClaimPercentage extends TransferRestrictionBase<TransferRestriction
/**
* Sets all Claim Percentage Transfer Restrictions on this Asset
*
* @note this method set exempted Identities for restrictions as well. If an Identity is currently exempted from a Claim Percentage Transfer Restriction
* but not passed into this call then they will be removed
*
* @note the result is the total amount of restrictions after the procedure has run
*/
public declare setRestrictions: ProcedureMethod<
Expand Down
3 changes: 3 additions & 0 deletions src/api/entities/Asset/TransferRestrictions/Count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class Count extends TransferRestrictionBase<TransferRestrictionType.Count
/**
* Sets all Count Transfer Restrictions on this Asset
*
* @note this method set exempted Identities for restrictions as well. If an Identity is currently exempted from a Count Transfer Restriction
* but not passed into this call then they will be removed
*
* @note the result is the total amount of restrictions after the procedure has run
*/
public declare setRestrictions: ProcedureMethod<
Expand Down
3 changes: 3 additions & 0 deletions src/api/entities/Asset/TransferRestrictions/Percentage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class Percentage extends TransferRestrictionBase<TransferRestrictionType.
/**
* Sets all Percentage Transfer Restrictions on this Asset
*
* @note this method set exempted Identities for restrictions as well. If an Identity is currently exempted from a Percentage Transfer Restriction
* but not passed into this call then they will be removed
*
* @note the result is the total amount of restrictions after the procedure has run
*/
public declare setRestrictions: ProcedureMethod<
Expand Down
43 changes: 22 additions & 21 deletions src/api/procedures/__tests__/addTransferRestriction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ describe('addTransferRestriction procedure', () => {
let setExemptedEntitiesTransaction: PolymeshTx<
[PolymeshPrimitivesTicker, PolymeshPrimitivesTransferComplianceTransferCondition, ScopeId[]]
>;
let scopeIdsToBtreeSetIdentityIdStub: sinon.SinonStub<
[PolymeshPrimitivesIdentityId[], Context],
BTreeSet<PolymeshPrimitivesIdentityId>
>;
let statisticsOpTypeToStatOpTypeStub: sinon.SinonStub<
[StatisticsOpType, Context],
PolymeshPrimitivesStatisticsStatOpType
Expand Down Expand Up @@ -145,10 +141,6 @@ describe('addTransferRestriction procedure', () => {
'transferRestrictionToPolymeshTransferCondition'
);
stringToTickerKeyStub = sinon.stub(utilsConversionModule, 'stringToTickerKey');
scopeIdsToBtreeSetIdentityIdStub = sinon.stub(
utilsConversionModule,
'scopeIdsToBtreeSetIdentityId'
);
transferConditionsToBtreeTransferConditionsStub = sinon.stub(
utilsConversionModule,
'transferConditionsToBtreeTransferConditions'
Expand Down Expand Up @@ -381,7 +373,10 @@ describe('addTransferRestriction procedure', () => {
const rawIdentityBtree = dsMockUtils.createMockBTreeSet<PolymeshPrimitivesIdentityId>([
rawIdentityScopeId,
]);
scopeIdsToBtreeSetIdentityIdStub.returns(rawIdentityBtree);

mockContext.createType
.withArgs('BTreeSet<PolymeshPrimitivesIdentityId>', [undefined])
.returns(rawIdentityBtree);

entityMockUtils.configureMocks({
identityOptions: { getScopeId: identityScopeId },
Expand All @@ -407,7 +402,11 @@ describe('addTransferRestriction procedure', () => {
{
transaction: setExemptedEntitiesTransaction,
feeMultiplier: new BigNumber(1),
args: [true, { asset: { Ticker: rawTicker }, op: rawCountOp }, rawIdentityBtree],
args: [
true,
{ asset: { Ticker: rawTicker }, op: undefined, claimType: undefined },
rawIdentityBtree,
],
},
],
});
Expand All @@ -434,7 +433,11 @@ describe('addTransferRestriction procedure', () => {
{
transaction: setExemptedEntitiesTransaction,
feeMultiplier: new BigNumber(1),
args: [true, { asset: { Ticker: rawTicker }, op: rawBalanceOp }, rawIdentityBtree],
args: [
true,
{ asset: { Ticker: rawTicker }, op: undefined, claimType: undefined },
rawIdentityBtree,
],
},
],
});
Expand Down Expand Up @@ -519,7 +522,7 @@ describe('addTransferRestriction procedure', () => {
);
});

it('should throw an error if exempted entities are repeated', async () => {
it('should throw an error if exempted entities are repeated', () => {
args = {
type: TransferRestrictionType.Count,
exemptedIdentities: ['someScopeId', 'someScopeId'],
Expand All @@ -530,16 +533,14 @@ describe('addTransferRestriction procedure', () => {
mockContext
);

let err;

try {
await prepareAddTransferRestriction.call(proc, args);
} catch (error) {
err = error;
}
const expectedError = new PolymeshError({
code: ErrorCode.ValidationError,
message:
'One or more of the passed exempted Identities are repeated or have the same Scope ID',
});

expect(err.message).toBe(
'One or more of the passed exempted Identities are repeated or have the same Scope ID'
return expect(prepareAddTransferRestriction.call(proc, args)).rejects.toThrowError(
expectedError
);
});

Expand Down

0 comments on commit 5036a1d

Please sign in to comment.