diff --git a/dlt-connector/src/client/IotaClient.test.ts b/dlt-connector/src/client/IotaClient.test.ts index 38f983ac3..2ceaa085e 100644 --- a/dlt-connector/src/client/IotaClient.test.ts +++ b/dlt-connector/src/client/IotaClient.test.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -import { sendDataMessage, getMessage } from '@/client/IotaClient' +import { sendMessage, receiveMessage } from '@/client/IotaClient' jest.mock('@iota/client', () => { const mockMessageSender = jest.fn().mockImplementation(() => { @@ -50,12 +50,12 @@ jest.mock('@iota/client', () => { describe('Iota Tests', () => { it('test mocked sendDataMessage', async () => { - const result = await sendDataMessage('Test Message') + const result = await sendMessage('Test Message') expect(result).toBe('5498130bc3918e1a7143969ce05805502417e3e1bd596d3c44d6a0adeea22710') }) it('should mock getMessage', async () => { - const result = await getMessage( + const result = await receiveMessage( '5498130bc3918e1a7143969ce05805502417e3e1bd596d3c44d6a0adeea22710', ) expect(result).toMatchObject({ diff --git a/dlt-connector/src/client/IotaClient.ts b/dlt-connector/src/client/IotaClient.ts index f79d89bcd..b583746ff 100644 --- a/dlt-connector/src/client/IotaClient.ts +++ b/dlt-connector/src/client/IotaClient.ts @@ -11,7 +11,7 @@ const client = new ClientBuilder().node(CONFIG.IOTA_API_URL).build() * @param {string} message - the message as utf based string, will be converted to hex automatically from @iota/client * @return {Promise} the iota message typed */ -function sendDataMessage(message: string): Promise { +function sendMessage(message: string): Promise { return client.message().index(CONFIG.IOTA_COMMUNITY_ALIAS).data(message).submit() } @@ -20,11 +20,11 @@ function sendDataMessage(message: string): Promise { * @param {string} messageId - as hex string * @return {Promise} the iota message typed */ -function getMessage(messageId: string): Promise { +function receiveMessage(messageId: string): Promise { return client.getMessage().data(messageId) } -export { sendDataMessage, getMessage } +export { sendMessage, receiveMessage } /** * example for message: diff --git a/dlt-connector/src/index.ts b/dlt-connector/src/index.ts index 73b2a8a2b..909b3afa9 100644 --- a/dlt-connector/src/index.ts +++ b/dlt-connector/src/index.ts @@ -1,5 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { sendDataMessage, getMessage } from '@/client/IotaClient' +import { + sendMessage as iotaSendMessage, + receiveMessage as iotaReceiveMessage, +} from '@/client/IotaClient' import { CONFIG } from '@/config' import { IndexationPayload } from '@iota/client/lib/types' import { logger } from './server/logger' @@ -10,12 +13,12 @@ async function main() { const messageHexString = Buffer.from(messageString, 'utf8').toString('hex') const indexHexString = Buffer.from(CONFIG.IOTA_COMMUNITY_ALIAS, 'utf8').toString('hex') - const iotaSendedMessage = await sendDataMessage(messageString) + const iotaSendedMessage = await iotaSendMessage(messageString) if (iotaSendedMessage && iotaSendedMessage.messageId) { logger.info('Hello World Message send to iota, get messageId: %s', iotaSendedMessage.messageId) - const iotaReceivedMessage = await getMessage(iotaSendedMessage.messageId) + const iotaReceivedMessage = await iotaReceiveMessage(iotaSendedMessage.messageId) const indexationPayload = iotaReceivedMessage.message.payload as IndexationPayload if ( indexationPayload.index.toString() === indexHexString ||