Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[explorer] fix: Expired mosaic namespace. #1193

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion __tests__/config/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

/* Mock init http */
jest.mock('../../src/infrastructure/http', () => {
const { Address } = require('symbol-sdk');

return {
networkType: 152,
epochAdjustment: 1615853185,
Expand All @@ -15,7 +18,8 @@ jest.mock('../../src/infrastructure/http', () => {
NetworkType: 152,
NemsisTimestamp: 1637848847,
NamespaceGraceDuration: 2880,
TotalChainImportance: 7842928625000000
TotalChainImportance: 7842928625000000,
MosaicRentalSinkAddress: Address.createFromRawAddress('TATYW7IJN2TDBINTESRU66HHS5HMC4YVW7GGDRA')
},
nativeNamespaces: [
{
Expand Down
132 changes: 96 additions & 36 deletions __tests__/helper.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TestHelper from './TestHelper';
import Helper from '../src/helper';
import { MosaicService, NamespaceService } from '../src/infrastructure';
import { MosaicService, NamespaceService, ReceiptService } from '../src/infrastructure';
import http from '../src/infrastructure/http';
import { restore, stub } from 'sinon';
import { Mosaic, MosaicId, NamespaceId, NamespaceName, UInt64 } from 'symbol-sdk';
Expand Down Expand Up @@ -219,6 +219,44 @@ describe('Helper', () => {
expect(result).toStrictEqual(new MosaicId(mockTestMosaic.idHex));
expect(stubGetLinkedMosaicId.callCount).toBe(1);
});

it('returns mosaic id and called mosaic statement query', async () => {
// Arrange:
const mockNamespaceId = new NamespaceId(mockTestMosaic.namespaceName);

const stubSearchMosaicResolutionStatements = jest.spyOn(ReceiptService, 'searchMosaicResolutionStatements')
.mockReturnValue(Promise.resolve({
data: [{
height: UInt64.fromUint(10),
mosaicResolutionEntries: ['22D2D90A27738AA0'],
resolutionEntries: [
{
resolved: new MosaicId('22D2D90A27738AA0'),
source: {
primaryId: 0,
secondaryId: 0
}
}
],
resolutionType: 'Mosaic',
unresolved: 'C6D6C5A3883DF4F4'
}]
}));

// Act:
const result = await Helper.resolveMosaicId(mockNamespaceId, {
height: UInt64.fromUint(10),
primaryId: 1,
secondaryId: 0
});

// Assert:
expect(result).toStrictEqual(new MosaicId('22D2D90A27738AA0'));
expect(stubGetLinkedMosaicId.callCount).toBe(0);
expect(stubSearchMosaicResolutionStatements).toHaveBeenCalledWith({
height: UInt64.fromUint(10)
});
});
});

describe('getNetworkCurrencyBalance', () => {
Expand Down Expand Up @@ -275,21 +313,19 @@ describe('Helper', () => {
describe('getTransactionMosaicInfoAndNamespace', () => {
it('returns mosaics mapping, empty mosaic info and namespace when transaction included network mosaic', async () => {
// Arrange:
const mockTransactions = [
{
...TestHelper.mockTransaction({
height: 1,
timestamp: 10
}),
mosaics: [
new Mosaic(new NamespaceId(http.networkCurrency.namespaceName), UInt64.fromUint(20)),
new Mosaic(new MosaicId(http.networkCurrency.mosaicId), UInt64.fromUint(1))
]
}
];
const mockTransactions = {
...TestHelper.mockTransaction({
height: 1,
timestamp: 10
}),
mosaics: [
new Mosaic(new NamespaceId(http.networkCurrency.namespaceName), UInt64.fromUint(20)),
new Mosaic(new MosaicId(http.networkCurrency.mosaicId), UInt64.fromUint(1))
]
};

// Act:
const { unresolvedMosaicsMap, mosaicInfos, mosaicNames} = await Helper.getTransactionMosaicInfoAndNamespace(mockTransactions);
const { unresolvedMosaicsMap, mosaicInfos, mosaicNames } = await Helper.getTransactionMosaicInfoAndNamespace(mockTransactions);

// Assert:
expect(unresolvedMosaicsMap).toStrictEqual({
Expand All @@ -302,27 +338,33 @@ describe('Helper', () => {

it('returns mosaics mapping, mosaic info and namespace when transaction exits', async () => {
// Arrange:
const mockTransactions = [
{
...TestHelper.mockTransaction({
height: 1,
timestamp: 10
}),
mosaics: [
new Mosaic(new NamespaceId(http.networkCurrency.namespaceName), UInt64.fromUint(20)),
new Mosaic(new MosaicId(http.networkCurrency.mosaicId), UInt64.fromUint(1))
]
const mockAggregateTransaction = {
transactionInfo: {
height: 10,
index: 1
},
TestHelper.mockLockFundsTransaction(),
TestHelper.mockMosaicSupplyRevocationTransaction(new Mosaic(
new MosaicId(mockTestMosaic.idHex),
UInt64.fromUint(1)
)),
TestHelper.mockSecretLockTransaction(new Mosaic(
new NamespaceId(mockTestSecretLockMosaic.namespaceName),
UInt64.fromUint(20)
))
];
innerTransactions: [
{
...TestHelper.mockTransaction({
height: 1,
timestamp: 10
}),
mosaics: [
new Mosaic(new NamespaceId(http.networkCurrency.namespaceName), UInt64.fromUint(20)),
new Mosaic(new MosaicId(http.networkCurrency.mosaicId), UInt64.fromUint(1))
]
},
TestHelper.mockLockFundsTransaction(),
TestHelper.mockMosaicSupplyRevocationTransaction(new Mosaic(
new MosaicId(mockTestMosaic.idHex),
UInt64.fromUint(1)
)),
TestHelper.mockSecretLockTransaction(new Mosaic(
new NamespaceId(mockTestSecretLockMosaic.namespaceName),
UInt64.fromUint(20)
))
]
};

const mockMosaicInfos = [
TestHelper.mockMosaicInfo(mockTestMosaic.idHex, 'TC46AZWUIZYZ2WVGLVEZYNZHSIFAD3AFDPUJMEA', 10, 0),
Expand Down Expand Up @@ -359,9 +401,27 @@ describe('Helper', () => {
.resolves(Promise.resolve(mockMosaicNames));

stub(NamespaceService, 'getLinkedMosaicId').resolves(Promise.resolve(new MosaicId(mockTestSecretLockMosaic.idHex)));
stub(ReceiptService, 'searchMosaicResolutionStatements').resolves(Promise.resolve({
data: [{
height: UInt64.fromUint(10),
mosaicResolutionEntries: ['22D2D90A27738AA0'],
resolutionEntries: [
{
resolved: new MosaicId('22D2D90A27738AA0'),
source: {
primaryId: 1,
secondaryId: 2
}
}
],
resolutionType: 'Mosaic',
unresolved: 'DEBBC3DA600F2B48'
}]
}));

// Act:
const { unresolvedMosaicsMap, mosaicInfos, mosaicNames} = await Helper.getTransactionMosaicInfoAndNamespace(mockTransactions);
const { unresolvedMosaicsMap, mosaicInfos, mosaicNames } =
await Helper.getTransactionMosaicInfoAndNamespace(mockAggregateTransaction);

// Assert:
expect(unresolvedMosaicsMap).toStrictEqual({
Expand All @@ -376,7 +436,7 @@ describe('Helper', () => {

it('returns empty when transactions empty', async () => {
// Arrange:
const transactions = [];
const transactions = {};

// Act:
const {mosaicInfos, mosaicNames, unresolvedMosaicsMap} = await Helper.getTransactionMosaicInfoAndNamespace(transactions);
Expand Down
124 changes: 120 additions & 4 deletions __tests__/infrastructure/CreateTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Convert,
Mosaic,
MosaicId,
MosaicNonce,
NamespaceId,
NamespaceName,
NetworkType,
Expand Down Expand Up @@ -70,11 +71,16 @@ describe('CreateTransaction', () => {
targetMosaicId: new MosaicId('7F2D26E89342D398')
};

const getMosaicAliasNamesStub = stub(Helper, 'getMosaicAliasNames');
getMosaicAliasNamesStub.returns(Promise.resolve(['N/A']));

// Act:
const mosaicMetadataObject = await CreateTransaction.mosaicMetadata(mockMosaicMetadata);
const mosaicMetadataObject = await CreateTransaction.mosaicMetadata(mockMosaicMetadata, {
mosaicNames: [{
names: [],
mosaicId: '7F2D26E89342D398'
}],
unresolvedMosaicsMap: {
'7F2D26E89342D398': '7F2D26E89342D398'
}
});

// Assert:
expect(mosaicMetadataObject.transactionBody).toEqual({
Expand Down Expand Up @@ -282,4 +288,114 @@ describe('CreateTransaction', () => {
}]
});
});

it('returns mosaicDefinition', async () => {
// Arrange:
const mockMosaicDefinition = {
type: 16717,
network: 152,
version: 1,
mosaicId: new MosaicId('7F2D26E89342D398'),
divisibility: 0,
duration: UInt64.fromUint(1000),
nonce: MosaicNonce.createRandom(),
flags: {
supplyMutable: false,
transferable: true,
restrictable: true,
revokable: true
}
};

// Act:
const mosaicDefinitionObject = await CreateTransaction.mosaicDefinition(mockMosaicDefinition, {
unresolvedMosaicsMap: {
'7F2D26E89342D398': '7F2D26E89342D398'
}
});

// Assert:
expect(mosaicDefinitionObject.transactionBody).toEqual({
transactionType: mockMosaicDefinition.type,
recipient: 'TATYW7IJN2TDBINTESRU66HHS5HMC4YVW7GGDRA',
mosaicId: '7F2D26E89342D398',
divisibility: 0,
duration: 1000,
nonce: mockMosaicDefinition.nonce.toHex(),
supplyMutable: false,
transferable: true,
restrictable: true,
revokable: true
});
});

const assertMosaicSupplyChange = async (action, expectedAction) => {
// Arrange:
const mockMosaicSupplyChange = {
type: 16973,
mosaicId: new MosaicId('7F2D26E89342D398'),
action: action,
delta: UInt64.fromUint(100)
};

// Act:
const mosaicSupplyChangeObject = await CreateTransaction.mosaicSupplyChange(mockMosaicSupplyChange, {
unresolvedMosaicsMap: {
'7F2D26E89342D398': '7F2D26E89342D398'
}
});

// Assert:
expect(mosaicSupplyChangeObject.transactionBody).toEqual({
transactionType: mockMosaicSupplyChange.type,
mosaicId: '7F2D26E89342D398',
action: expectedAction,
delta: 100
});
};

it('returns mosaicSupplyChange in increase action', async () => {
await assertMosaicSupplyChange(1, 'Increase');
});

it('returns mosaicSupplyChange in decrease action', async () => {
await assertMosaicSupplyChange(0, 'Decrease');
});

it('returns mosaicAddressRestriction', async () => {
// Arrange:
const mockMosaicAddressRestriction = {
type: 16977,
mosaicId: new MosaicId('7F2D26E89342D398'),
targetAddress: randomAddress,
restrictionKey: UInt64.fromUint(1),
previousRestrictionValue: UInt64.fromUint(10),
newRestrictionValue: UInt64.fromUint(20),
transactionInfo: {
height: UInt64.fromUint(1)
}
};

// Act:
const mosaicAddressRestrictionObject = await CreateTransaction.mosaicAddressRestriction(mockMosaicAddressRestriction, {
mosaicNames: [{
names: [],
mosaicId: '7F2D26E89342D398'
}],
unresolvedMosaicsMap: {
'7F2D26E89342D398': '7F2D26E89342D398'
}
});

// Assert:
expect(mosaicAddressRestrictionObject.transactionBody).toEqual({
transactionType: mockMosaicAddressRestriction.type,
mosaicId: '7F2D26E89342D398',
mosaicAliasNames: ['N/A'],
targetAddress: randomAddress.plain(),
restrictionKey: '0000000000000001',
previousRestrictionValue: '10',
newRestrictionValue: '20'
});
});
});
Loading