Skip to content

Commit

Permalink
update peers and messages (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoalzate authored Sep 6, 2023
1 parent 764729d commit 3d29c60
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
1 change: 1 addition & 0 deletions e2e/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Node E2E Tests', function () {
const expectedPeer: GetPeersResponseType['connected'][0] = {
quality: expect.any(Number),
peerId: expect.any(String),
peerAddress: expect.any(String),
multiAddr: expect.any(String),
heartbeats: expect.objectContaining({
sent: expect.any(Number),
Expand Down
7 changes: 2 additions & 5 deletions src/api/messages/popAllMessages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
PopMessageResponseType
} from '../../types';
import { APIError } from '../../utils';
import { popMessage } from './popMessage';
import { popAllMessages } from './popAllMessages';

const API_ENDPOINT = 'http://localhost:3001';
Expand All @@ -23,8 +22,7 @@ describe('test popAllMessages', () => {
messages: [
{
tag: 12,
body: 'This is a HOPR message.',
receivedAt: 1324284684614
body: 'This is a HOPR message.'
}
]
} as PopAllMessagesResponseType);
Expand All @@ -45,8 +43,7 @@ describe('test popAllMessages', () => {
messages: [
{
tag: 12,
body: 'This is a HOPR message.',
receivedAt: 1324284684614
body: 'This is a HOPR message.'
}
]
} as PopAllMessagesResponseType);
Expand Down
74 changes: 38 additions & 36 deletions src/api/node/getPeers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,44 @@ describe('test getPeers', function () {
nock.cleanAll();
});
it('handles successful response', async function () {
nock(API_ENDPOINT)
.get(`/api/v3/node/peers`)
.reply(200, {
connected: [
{
peerId: '16Uiu2HAmVfV4GKQhdECMqYmUMGLy84RjTJQxTWDcmUX5847roBar',
multiAddr:
'/p2p/16Uiu2HAmVLfzSLQoLtCGSfQv5ac2GTQmMuxXFkZZgrmuirfT8gaJ',
heartbeats: {
sent: 10,
success: 8
},
lastSeen: 1646410980793,
quality: 0.8,
backoff: 0,
isNew: true,
reportedVersion: '1.92.12'
}
],
announced: [
{
peerId: '16Uiu2HAmVfV4GKQhdECMqYmUMGLy84RjTJQxTWDcmUX5847roBar',
multiAddr:
'/p2p/16Uiu2HAmVLfzSLQoLtCGSfQv5ac2GTQmMuxXFkZZgrmuirfT8gaJ',
heartbeats: {
sent: 10,
success: 8
},
lastSeen: 1646410980793,
quality: 0.8,
backoff: 0,
isNew: true,
reportedVersion: '1.92.12'
}
]
} as GetPeersResponseType);
const expectedResponse: GetPeersResponseType = {
connected: [
{
peerId: '16Uiu2HAmVfV4GKQhdECMqYmUMGLy84RjTJQxTWDcmUX5847roBar',
peerAddress: '0x0987654321098765432109876543210987654321',
multiAddr:
'/p2p/16Uiu2HAmVLfzSLQoLtCGSfQv5ac2GTQmMuxXFkZZgrmuirfT8gaJ',
heartbeats: {
sent: 10,
success: 8
},
lastSeen: 1646410980793,
quality: 0.8,
backoff: 0,
isNew: true,
reportedVersion: '1.92.12'
}
],
announced: [
{
peerId: '16Uiu2HAmVfV4GKQhdECMqYmUMGLy84RjTJQxTWDcmUX5847roBar',
peerAddress: '0x0987654321098765432109876543210987654321',
multiAddr:
'/p2p/16Uiu2HAmVLfzSLQoLtCGSfQv5ac2GTQmMuxXFkZZgrmuirfT8gaJ',
heartbeats: {
sent: 10,
success: 8
},
lastSeen: 1646410980793,
quality: 0.8,
backoff: 0,
isNew: true,
reportedVersion: '1.92.12'
}
]
};

nock(API_ENDPOINT).get(`/api/v3/node/peers`).reply(200, expectedResponse);

const response = await getPeers({
apiToken: API_TOKEN,
Expand Down
3 changes: 1 addition & 2 deletions src/types/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { BasePayload } from './general';

export const ReceivedMessage = z.object({
tag: z.number().nonnegative(),
body: z.string(),
receivedAt: z.number().nonnegative()
body: z.string()
});

/**
Expand Down
1 change: 1 addition & 0 deletions src/types/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type GetPeersPayloadType = z.infer<typeof GetPeersPayload>;

export const Peer = z.object({
peerId: z.string(),
peerAddress: z.string(),
multiAddr: z.string(),
heartbeats: z.object({
sent: z.number(),
Expand Down

0 comments on commit 3d29c60

Please sign in to comment.