Skip to content

Commit

Permalink
fix: handle tx log unable to be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalovelo committed Sep 28, 2022
1 parent f281165 commit 46723cf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions client/src/utils/game-channel/game-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class GameChannel {
);
this.shouldShowEndScreen = true;
this.isOpen = false;
channel.disconnect();
});
});
return channelClosing;
Expand Down
1 change: 1 addition & 0 deletions server/src/route/route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('/status', () => {
balances: jest.fn,
state: jest.fn,
poi: jest.fn,
disconnect: jest.fn,
} as unknown as Channel,
{
initiatorId: config.address,
Expand Down
23 changes: 15 additions & 8 deletions server/src/services/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export async function addGameSession(
* Removes game session from the pool after the channel is closed
*/
export function removeGameSession(onAccount: Encoded.AccountAddress) {
gameSessionPool.get(onAccount)?.channelWrapper.instance.disconnect();
gameSessionPool.delete(onAccount);
logger.info(
`Removed from pool game session with bot ID: ${onAccount}. Total sessions: ${gameSessionPool.size}`,
Expand Down Expand Up @@ -259,14 +260,20 @@ async function respondToContractCall(gameSession: GameSession) {
onAccount: gameSession.participants.initiatorId,
}),
);
await sendCallUpdateLog(
result.signedTx,
{
name: ContractEvents.player1Moved,
value: gameSession.contractState.botMove,
},
gameSession,
);
if (result.signedTx) {
await sendCallUpdateLog(
result.signedTx,
{
name: ContractEvents.player1Moved,
value: gameSession.contractState.botMove,
},
gameSession,
);
} else {
logger.warn(
`${gameSession.participants.initiatorId} - No signed transaction returned from contract call`,
);
}
gameSession.contractState.callDataToSend = null;
}

Expand Down
1 change: 1 addition & 0 deletions server/test/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface ChannelMock {
[eventName: string]: (...args: any[]) => void;
};
on: (eventName: string, listener: (...args: any[]) => void) => void;
disconnect: () => void;
}
1 change: 1 addition & 0 deletions server/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const mockChannel = () => {
return {};
},
createContract: jest.fn(),
disconnect: jest.fn(),
} as ChannelMock),
);
};

0 comments on commit 46723cf

Please sign in to comment.