Skip to content

Commit

Permalink
fix: πŸ› asset.compliance.requirements.canSettle check (#891)
Browse files Browse the repository at this point in the history
* fix: πŸ› asset.compliance.requirements.canSettle check

resolve issue where the types were not being created as Option for
canSettle checks

βœ… Closes: #889

* docs: ✏️ add note to Requirements.canSettle deprecation notice
  • Loading branch information
polymath-eric committed Nov 18, 2022
1 parent 3192c40 commit 6f967fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
11 changes: 4 additions & 7 deletions src/api/entities/Asset/Compliance/Requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import {
assetComplianceResultToCompliance,
boolToBoolean,
complianceRequirementToRequirement,
signerToString,
stringToIdentityId,
stringToTicker,
trustedIssuerToTrustedClaimIssuer,
} from '~/utils/conversion';
Expand Down Expand Up @@ -216,7 +214,7 @@ export class Requirements extends Namespace<Asset> {
* @param args.from - sender Identity (optional, defaults to the signing Identity)
* @param args.to - receiver Identity
*
* @deprecated in favor of `settlements.canTransfer`
* @deprecated in favor of `settlements.canTransfer` (set amount to 0 to imitate this call)
*/
public async checkSettle(args: {
from?: string | Identity;
Expand All @@ -231,14 +229,13 @@ export class Requirements extends Namespace<Asset> {
} = this;

const { from = await context.getSigningIdentity(), to } = args;

const fromDid = stringToIdentityId(signerToString(from), context);
const toDid = signerToString(to);
const fromDid = typeof from === 'string' ? from : from.did;
const toDid = typeof to === 'string' ? to : to.did;

const res: AssetComplianceResult = await rpc.compliance.canTransfer(
stringToTicker(ticker, context),
fromDid,
stringToIdentityId(toDid, context)
toDid
);

return assetComplianceResultToCompliance(res, context);
Expand Down
18 changes: 4 additions & 14 deletions src/api/entities/Asset/Compliance/__tests__/Requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,20 +541,15 @@ describe('Requirements class', () => {
let signingDid: string;
let fromDid: string;
let toDid: string;
let rawFromDid: PolymeshPrimitivesIdentityId;
let rawToDid: PolymeshPrimitivesIdentityId;
let rawCurrentDid: PolymeshPrimitivesIdentityId;
let rawTicker: PolymeshPrimitivesTicker;

let stringToIdentityIdStub: sinon.SinonStub;
let assetComplianceResultToRequirementComplianceStub: sinon.SinonStub;
let stringToTickerStub: sinon.SinonStub;

beforeAll(() => {
fromDid = 'fromDid';
toDid = 'toDid';

stringToIdentityIdStub = sinon.stub(utilsConversionModule, 'stringToIdentityId');
assetComplianceResultToRequirementComplianceStub = sinon.stub(
utilsConversionModule,
'assetComplianceResultToCompliance'
Expand All @@ -568,14 +563,8 @@ describe('Requirements class', () => {
requirements = new Requirements(asset, context);
({ did: signingDid } = await context.getSigningIdentity());

rawFromDid = dsMockUtils.createMockIdentityId(fromDid);
rawToDid = dsMockUtils.createMockIdentityId(toDid);
rawCurrentDid = dsMockUtils.createMockIdentityId(signingDid);
rawTicker = dsMockUtils.createMockTicker(asset.ticker);

stringToIdentityIdStub.withArgs(signingDid, context).returns(rawCurrentDid);
stringToIdentityIdStub.withArgs(fromDid, context).returns(rawFromDid);
stringToIdentityIdStub.withArgs(toDid, context).returns(rawToDid);
stringToTickerStub.withArgs(asset.ticker, context).returns(rawTicker);
});

Expand All @@ -588,7 +577,7 @@ describe('Requirements class', () => {

dsMockUtils
.createRpcStub('compliance', 'canTransfer')
.withArgs(rawTicker, rawCurrentDid, rawToDid)
.withArgs(rawTicker, signingDid, toDid)
.resolves(rawResponse);

const fakeResult = 'result';
Expand All @@ -602,17 +591,18 @@ describe('Requirements class', () => {

it('should return the current requirement compliance and whether the transfer complies with another Identity', async () => {
const rawResponse = 'response' as unknown as AssetComplianceResult;
const toIdentity = entityMockUtils.getIdentityInstance({ did: toDid });

dsMockUtils
.createRpcStub('compliance', 'canTransfer')
.withArgs(rawTicker, rawFromDid, rawToDid)
.withArgs(rawTicker, fromDid, toDid)
.resolves(rawResponse);

const fakeResult = 'result';

assetComplianceResultToRequirementComplianceStub.withArgs(rawResponse).returns(fakeResult);

const result = await requirements.checkSettle({ from: fromDid, to: toDid });
const result = await requirements.checkSettle({ from: fromDid, to: toIdentity });

expect(result).toBe(fakeResult);
});
Expand Down

0 comments on commit 6f967fb

Please sign in to comment.