Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864692
D14191.id41219.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D14191.id41219.diff
View Options
diff --git a/cashtab/src/components/Common/Ticker.js b/cashtab/src/components/Common/Ticker.js
--- a/cashtab/src/components/Common/Ticker.js
+++ b/cashtab/src/components/Common/Ticker.js
@@ -23,7 +23,7 @@
eightByte: 551,
minFee: 550, // dust
},
- aliasServerBaseUrl: 'https://aliasdev.etokens.cash',
+ aliasServerBaseUrl: 'https://alias.etokens.cash',
aliasMaxLength: 21, // max byte length, refer to the Alias spec at https://reviews.bitcoinabc.org/D12972
reservedAliases: [
'avalanche',
diff --git a/cashtab/src/utils/__mocks__/mockAliasServerResponses.js b/cashtab/src/utils/__mocks__/mockAliasServerResponses.js
new file mode 100644
--- /dev/null
+++ b/cashtab/src/utils/__mocks__/mockAliasServerResponses.js
@@ -0,0 +1,7 @@
+export const mockAliasApiResponse = {
+ alias: 'twelvechar12',
+ address: 'ecash:qpmytrdsakt0axrrlswvaj069nat3p9s7cjctmjasj',
+ txid: '166b21d4631e2a6ec6110061f351c9c3bfb3a8d4e6919684df7e2824b42b0ffe',
+ blockheight: 792419,
+ isRegistered: true,
+};
diff --git a/cashtab/src/utils/__tests__/aliasUtils.test.js b/cashtab/src/utils/__tests__/aliasUtils.test.js
new file mode 100644
--- /dev/null
+++ b/cashtab/src/utils/__tests__/aliasUtils.test.js
@@ -0,0 +1,62 @@
+// Copyright (c) 2023 The Bitcoin developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'use strict';
+import { currency } from 'components/Common/Ticker';
+import { getAliasDetails } from 'utils/aliasUtils';
+import { mockAliasApiResponse } from '../__mocks__/mockAliasServerResponses';
+import { when } from 'jest-when';
+
+test('getAliasDetails() returns an alias object for a registered alias', async () => {
+ const alias = 'twelvechar12';
+ const fetchUrl = `${currency.aliasSettings.aliasServerBaseUrl}/alias/${alias}`;
+
+ // mock the fetch call to alias-server's '/alias' endpoint
+ global.fetch = jest.fn();
+ when(fetch).calledWith(fetchUrl).mockResolvedValue(mockAliasApiResponse);
+
+ expect(await getAliasDetails(alias)).toEqual(mockAliasApiResponse);
+});
+
+test('getAliasDetails() returns an api error for a non-alphanumeric alias', async () => {
+ const alias = '@@@@@@@@@@@@';
+ const fetchUrl = `${currency.aliasSettings.aliasServerBaseUrl}/alias/${alias}`;
+ const expectedError = `Error fetching /alias/${alias}: alias param cannot contain non-alphanumeric characters`;
+
+ // mock the fetch call to alias-server's '/alias' endpoint
+ global.fetch = jest.fn();
+ when(fetch)
+ .calledWith(fetchUrl)
+ .mockResolvedValue({ error: expectedError });
+
+ await expect(getAliasDetails(alias)).rejects.toThrow(expectedError);
+});
+
+test('getAliasDetails() returns an object with isRegistered as false for an unregistered alias', async () => {
+ const alias = 'foobar';
+ const fetchUrl = `${currency.aliasSettings.aliasServerBaseUrl}/alias/${alias}`;
+ const expectedResult = {
+ alias: alias,
+ isRegistered: false,
+ };
+
+ // mock the fetch call to alias-server's '/alias' endpoint
+ global.fetch = jest.fn();
+ when(fetch).calledWith(fetchUrl).mockResolvedValue(expectedResult);
+
+ expect(await getAliasDetails(alias)).toEqual(expectedResult);
+});
+
+test('getAliasDetails() returns an api error for an alias longer than 21 characters', async () => {
+ const alias = 'foobarrrrrrrrrrrrrrrrrrrrrrrrrrr';
+ const fetchUrl = `${currency.aliasSettings.aliasServerBaseUrl}/alias/${alias}`;
+ const expectedError = `Error fetching /alias/${alias}: alias param must be between 1 and 21 characters in length`;
+
+ // mock the fetch call to alias-server's '/alias' endpoint
+ global.fetch = jest.fn();
+ when(fetch)
+ .calledWith(fetchUrl)
+ .mockResolvedValue({ error: expectedError });
+
+ await expect(getAliasDetails(alias)).rejects.toThrow(expectedError);
+});
diff --git a/cashtab/src/utils/aliasUtils.js b/cashtab/src/utils/aliasUtils.js
--- a/cashtab/src/utils/aliasUtils.js
+++ b/cashtab/src/utils/aliasUtils.js
@@ -27,6 +27,39 @@
return aliasServerRespJson;
};
+/**
+ * Fetches details for an alias via the alias-server
+ *
+ * @param {string} alias the alias being queried
+ * @returns {object} aliasServerResp an alias object
+ * @throws {error} err server fetch errors from alias-server
+ * Example successful response:
+ * {
+ * alias: 'twelvechar12',
+ * address:'ecash:qpmytrdsakt0axrrlswvaj069nat3p9s7cjctmjasj',
+ * txid:'166b21d4631e2a6ec6110061f351c9c3bfb3a8d4e6919684df7e2824b42b0ffe',
+ * blockheight:792419,
+ * isRegistered:true
+ * }
+ */
+export const getAliasDetails = async alias => {
+ try {
+ const aliasServerResp = await fetch(
+ currency.aliasSettings.aliasServerBaseUrl + '/alias/' + alias,
+ );
+ if (aliasServerResp && aliasServerResp.error) {
+ throw new Error(aliasServerResp.error);
+ }
+ return aliasServerResp;
+ } catch (err) {
+ console.log(
+ `getAliasDetails(): Error retrieving alias details from alias-server`,
+ err,
+ );
+ throw err;
+ }
+};
+
/*
@response:
[
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 21:39 (10 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5862696
Default Alt Text
D14191.id41219.diff (5 KB)
Attached To
D14191: [Cashtab][Alias] Implement getAliasDetails
Event Timeline
Log In to Comment