Skip to content

Commit

Permalink
chore: 🤖 wip asset changes not working state
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantasdeveloper committed Oct 13, 2024
1 parent a2103cc commit 3a093f3
Show file tree
Hide file tree
Showing 43 changed files with 374 additions and 338 deletions.
2 changes: 2 additions & 0 deletions src/assets/assets.consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const MAX_TICKER_LENGTH = 12;

export const ASSET_ID_LENGTH = 34; // 32 Hex bytes + 0x prefix

export const MAX_CONTENT_HASH_LENGTH = 130;
52 changes: 28 additions & 24 deletions src/assets/assets.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { processedTxResult, testValues } from '~/test-utils/consts';
import { MockAsset, MockAuthorizationRequest } from '~/test-utils/mocks';
import { MockAssetService, mockMetadataServiceProvider } from '~/test-utils/service-mocks';

const { signer, did, txResult } = testValues;
const { signer, did, txResult, assetId } = testValues;

jest.mock('@polymeshassociation/polymesh-sdk/utils', () => ({
...jest.requireActual('@polymeshassociation/polymesh-sdk/utils'),
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('AssetsController', () => {
mockAssetsService.findOne.mockResolvedValue(mockAsset);
mockIsFungibleAsset.mockReturnValue(true);

const result = await controller.getDetails({ ticker: 'TICKER' });
const result = await controller.getDetails({ asset: 'TICKER' });

const mockResult = {
...mockAssetDetails,
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('AssetsController', () => {
it('should return the list of Asset holders', async () => {
mockAssetsService.findHolders.mockResolvedValue(mockHolders);

const result = await controller.getHolders({ ticker: 'TICKER' }, { size: new BigNumber(1) });
const result = await controller.getHolders({ asset: 'TICKER' }, { size: new BigNumber(1) });
const expectedResults = mockHolders.data.map(holder => {
return { identity: holder.identity.did, balance: holder.balance };
});
Expand All @@ -141,7 +141,7 @@ describe('AssetsController', () => {
mockAssetsService.findHolders.mockResolvedValue(mockHolders);

const result = await controller.getHolders(
{ ticker: 'TICKER' },
{ asset: 'TICKER' },
{ size: new BigNumber(1), start: 'SOME_START_KEY' }
);

Expand Down Expand Up @@ -175,10 +175,7 @@ describe('AssetsController', () => {
it('should return the list of Asset documents', async () => {
mockAssetsService.findDocuments.mockResolvedValue(mockDocuments);

const result = await controller.getDocuments(
{ ticker: 'TICKER' },
{ size: new BigNumber(1) }
);
const result = await controller.getDocuments({ asset: 'TICKER' }, { size: new BigNumber(1) });

expect(result).toEqual(
new PaginatedResultsModel({
Expand All @@ -193,7 +190,7 @@ describe('AssetsController', () => {
mockAssetsService.findDocuments.mockResolvedValue(mockDocuments);

const result = await controller.getDocuments(
{ ticker: 'TICKER' },
{ asset: 'TICKER' },
{ size: new BigNumber(1), start: 'SOME_START_KEY' }
);

Expand Down Expand Up @@ -222,7 +219,7 @@ describe('AssetsController', () => {
const ticker = 'TICKER';
mockAssetsService.setDocuments.mockResolvedValue(txResult);

const result = await controller.setDocuments({ ticker }, body);
const result = await controller.setDocuments({ asset: assetId }, body);
expect(result).toEqual(processedTxResult);
expect(mockAssetsService.setDocuments).toHaveBeenCalledWith(ticker, body);
});
Expand Down Expand Up @@ -251,7 +248,7 @@ describe('AssetsController', () => {
const amount = new BigNumber(1000);
mockAssetsService.issue.mockResolvedValue(txResult);

const result = await controller.issue({ ticker }, { signer, amount });
const result = await controller.issue({ asset: assetId }, { signer, amount });
expect(result).toEqual(processedTxResult);
expect(mockAssetsService.issue).toHaveBeenCalledWith(ticker, { signer, amount });
});
Expand All @@ -269,7 +266,7 @@ describe('AssetsController', () => {
const body = { signer: '0x6000', target: '0x1000' };
const ticker = 'SOME_TICKER';

const result = await controller.transferOwnership({ ticker }, body);
const result = await controller.transferOwnership({ asset: assetId }, body);

expect(result).toEqual({
...processedTxResult,
Expand All @@ -287,7 +284,7 @@ describe('AssetsController', () => {
const from = new BigNumber(1);
mockAssetsService.redeem.mockResolvedValue(txResult);

const result = await controller.redeem({ ticker }, { signer, amount, from });
const result = await controller.redeem({ asset: assetId }, { signer, amount, from });
expect(result).toEqual(processedTxResult);
expect(mockAssetsService.redeem).toHaveBeenCalledWith(ticker, { signer, amount, from });
});
Expand All @@ -298,7 +295,7 @@ describe('AssetsController', () => {
const ticker = 'TICKER';
mockAssetsService.freeze.mockResolvedValue(txResult);

const result = await controller.freeze({ ticker }, { signer });
const result = await controller.freeze({ asset: assetId }, { signer });
expect(result).toEqual(processedTxResult);
expect(mockAssetsService.freeze).toHaveBeenCalledWith(ticker, { signer });
});
Expand All @@ -309,7 +306,7 @@ describe('AssetsController', () => {
const ticker = 'TICKER';
mockAssetsService.unfreeze.mockResolvedValue(txResult);

const result = await controller.unfreeze({ ticker }, { signer });
const result = await controller.unfreeze({ asset: assetId }, { signer });
expect(result).toEqual(processedTxResult);
expect(mockAssetsService.unfreeze).toHaveBeenCalledWith(ticker, { signer });
});
Expand All @@ -323,7 +320,10 @@ describe('AssetsController', () => {

mockAssetsService.controllerTransfer.mockResolvedValue(txResult);

const result = await controller.controllerTransfer({ ticker }, { signer, origin, amount });
const result = await controller.controllerTransfer(
{ asset: assetId },
{ signer, origin, amount }
);

expect(result).toEqual(processedTxResult);
expect(mockAssetsService.controllerTransfer).toHaveBeenCalledWith(ticker, {
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('AssetsController', () => {
];
mockAssetsService.getOperationHistory.mockResolvedValue(mockAgentOperations);

const result = await controller.getOperationHistory({ ticker: 'TICKER' });
const result = await controller.getOperationHistory({ asset: 'TICKER' });

expect(result).toEqual([
{
Expand All @@ -374,7 +374,7 @@ describe('AssetsController', () => {

mockAssetsService.getRequiredMediators.mockResolvedValue([mockMediator]);

const result = await controller.getRequiredMediators({ ticker: 'TICKER' });
const result = await controller.getRequiredMediators({ asset: 'TICKER' });

expect(result).toEqual({
mediators: [mockMediator.did],
Expand All @@ -389,7 +389,10 @@ describe('AssetsController', () => {

mockAssetsService.addRequiredMediators.mockResolvedValue(txResult);

const result = await controller.addRequiredMediators({ ticker }, { signer, mediators });
const result = await controller.addRequiredMediators(
{ asset: assetId },
{ signer, mediators }
);

expect(result).toEqual(processedTxResult);
expect(mockAssetsService.addRequiredMediators).toHaveBeenCalledWith(ticker, {
Expand All @@ -406,7 +409,10 @@ describe('AssetsController', () => {

mockAssetsService.removeRequiredMediators.mockResolvedValue(txResult);

const result = await controller.removeRequiredMediators({ ticker }, { signer, mediators });
const result = await controller.removeRequiredMediators(
{ asset: assetId },
{ signer, mediators }
);

expect(result).toEqual(processedTxResult);
expect(mockAssetsService.removeRequiredMediators).toHaveBeenCalledWith(ticker, {
Expand All @@ -422,7 +428,7 @@ describe('AssetsController', () => {

mockAssetsService.preApprove.mockResolvedValue(txResult);

const result = await controller.preApprove({ ticker }, { signer });
const result = await controller.preApprove({ asset: assetId }, { signer });

expect(result).toEqual(processedTxResult);
expect(mockAssetsService.preApprove).toHaveBeenCalledWith(ticker, {
Expand All @@ -433,11 +439,9 @@ describe('AssetsController', () => {

describe('removePreApproval', () => {
it('should call the service and return the results', async () => {
const ticker = 'TICKER';

mockAssetsService.removePreApproval.mockResolvedValue(txResult);

const result = await controller.removePreApproval({ ticker }, { signer });
const result = await controller.removePreApproval({ asset: assetId }, { signer });

expect(result).toEqual(processedTxResult);
expect(mockAssetsService.removePreApproval).toHaveBeenCalledWith(ticker, {
Expand Down
Loading

0 comments on commit 3a093f3

Please sign in to comment.