Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
♻️ Unable CCU sending when receiving chain is syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
ishantiw committed Mar 12, 2024
1 parent 7126fdf commit 228050a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ export class CCUHandler {
if (!this._db.privateKey) {
throw new Error('There is no key enabled to submit CCU.');
}
const { syncing } = await this._receivingChainAPIClient.getNodeInfo();
if (syncing) {
throw new Error('Receiving node is syncing.');
}
const relayerPublicKey = cryptography.ed.getPublicKeyFromPrivateKey(this._db.privateKey);
const targetCommand = this._isReceivingChainMainchain
? COMMAND_NAME_SUBMIT_MAINCHAIN_CCU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ describe('CCUHandler', () => {
receivingChainAPIClientMock.postTransaction.mockResolvedValue({
transactionId: cryptography.utils.hash(Buffer.from('txID')).toString('hex'),
});
receivingChainAPIClientMock.getNodeInfo.mockResolvedValue({ syncing: false });
jest.spyOn(initArgs.logger as Logger, 'info');

const { activeValidatorsUpdate, certificateThreshold } = calculateActiveValidatorsUpdate(
Expand Down Expand Up @@ -813,6 +814,13 @@ describe('CCUHandler', () => {
);
});

it('should throw error when receiving chain is syncing', async () => {
receivingChainAPIClientMock.getNodeInfo.mockResolvedValue({ syncing: true });
await expect(ccuHandler['submitCCU'](ccuParams, 'txID')).rejects.toThrow(
'Receiving node is syncing.',
);
});

it('should return undefined when the tx id is equal to last sent CCU', async () => {
ccuTx.sign(config.receivingChainID as Buffer, Buffer.from(privateKey, 'hex'));
const result = await ccuHandler['submitCCU'](ccuParams, ccuTx.id.toString('hex'));
Expand Down

0 comments on commit 228050a

Please sign in to comment.