Skip to content

Commit

Permalink
[explorer] bug: fix namespace expiration (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLaw authored Aug 25, 2022
1 parent 0b58aba commit 2e74748
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
60 changes: 59 additions & 1 deletion __tests__/infrastructure/AccountService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,62 @@ describe('Account Service', () => {
});
});
});
});

describe('getAccountNamespaceList', () => {
const pageInfo = {
pageNumber: 1,
pageSize: 10
};
let searchNamespaces = {};
let getChainInfo = {};

beforeEach(() => {
searchNamespaces = stub(NamespaceService, 'searchNamespaces');
getChainInfo = stub(ChainService, 'getChainInfo');

getChainInfo.returns(Promise.resolve({
height: 1000
}));
});

afterEach(restore);

const runBasicNamespaceExpirationTests = async (namespaces, endHeight, exceptResult) => {
// Arrange:
const mockSearchAccountNamespaces = {
...pageInfo,
data: namespaces.map(namespace => {
return {
...TestHelper.mockNamespace(namespace, endHeight),
};
})
};

searchNamespaces.returns(Promise.resolve(mockSearchAccountNamespaces));

// Act:
const namespaceList = await AccountService.getAccountNamespaceList(pageInfo, {}, 'TBQ3SOJJXFO37KTGVXK7YFJYMATGJVISV2UP56I');

// Assert:
expect(namespaceList.pageNumber).toEqual(pageInfo.pageNumber);
expect(namespaceList.pageSize).toEqual(pageInfo.pageSize);
expect(namespaceList.data).toHaveLength(2);
expect(namespaceList.data[0].namespaceName).toBe(namespaces[0]);
expect(namespaceList.data[0].registrationType).toBe('subNamespace');
expect(namespaceList.data[1].namespaceName).toBe(namespaces[1]);
expect(namespaceList.data[1].registrationType).toBe('rootNamespace');
namespaceList.data.forEach(namespace => {
expect(namespace.expirationDuration).toBe(exceptResult);
expect(namespace.active).toBe('ACTIVE');
});
}

it('returns namespace expiration in infinity when native namespace', async () => {
runBasicNamespaceExpirationTests(['symbol.xym', 'symbol'], 0, 'INFINITY');
})

it('returns namespace expiration in date when non native namespace', async () => {
runBasicNamespaceExpirationTests(['hello.world', 'hello'], 1000, 'in a month');
})
})
});
4 changes: 3 additions & 1 deletion src/infrastructure/AccountService.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ class AccountService {
return {
...namespaces,
status: namespaces.active,
expirationDuration: helper.convertTimeFromNowInSec(expiredInSecond) || Constants.Message.UNLIMITED
expirationDuration: helper.isNativeNamespace(namespaces.name)
? Constants.Message.INFINITY
: helper.convertTimeFromNowInSec(expiredInSecond)
};
})
};
Expand Down

0 comments on commit 2e74748

Please sign in to comment.