Skip to content

Commit

Permalink
Add integration tests for RPC timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Sep 26, 2023
1 parent ae23485 commit 2a0f1a8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions integration-tests/src/test/rpc/creditcoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ describe('Creditcoin RPC', (): void => {
},
);

testIf(
(global as any).CREDITCOIN_API_URL === 'ws://127.0.0.1:9944',
'after 5:00 mins of inactivity connection will still be open and able to transmit messages',
(done: any): void => {
const ws = new WebSocket((global as any).CREDITCOIN_API_URL);

ws.on('open', () => {
setTimeout(() => {
const rpc = {
id: 1,
jsonrpc: '2.0',
method: 'task_getOffchainNonceKey',
params: ['0xThisIsNotValid'],
};
// connection is still open
expect(ws.readyState).toEqual(WebSocket.OPEN);

ws.send(JSON.stringify(rpc));
}, 300_000); // wait for 5 min before sending a message
})
.on('message', (data) => {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
const utf8Str = data.toString('utf-8');

const error = JSON.parse(utf8Str).error;
expect(error.message).toContain('Not a valid hex-string or SS58 address');
ws.close();
})
.on('close', () => done());
},
350_000,
);

testIf(
(global as any).CREDITCOIN_API_URL === 'ws://127.0.0.1:9944',
'getOffchainNonceKey() should work when passed a valid AccountId',
Expand Down

0 comments on commit 2a0f1a8

Please sign in to comment.