Skip to content

Commit

Permalink
tested attack
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-gai committed Aug 18, 2023
1 parent a7a36fa commit c0842b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/Battleship.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract Battleship {
targetBoard = player1Board;
}

require(targetBoard[_x][_y] == CellState.Empty, "Cell already attacked");
// require(targetBoard[_x][_y] == CellState.Empty, "Cell already attacked");

if (targetBoard[_x][_y] == CellState.Ship) {
targetBoard[_x][_y] = CellState.Hit;
Expand Down
16 changes: 15 additions & 1 deletion test/battleship.ts/Battleship.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,20 @@ export function shouldBehaveLikeBattleship(): void {
await waitForBlock(hre);

expect(player1Ready).to.equal(true);
expect(player2Ready).to.equal(true); // Player 2 hasn't placed ships yet
expect(player2Ready).to.equal(true);
});

it("should attack a valid cell location", async function () {
const player1Ready = await this.battleship.player1Ready();
const player2Ready = await this.battleship.player2Ready();
await waitForBlock(hre);

expect(player1Ready).to.equal(true);
expect(player2Ready).to.equal(true);

await this.battleship.connect(this.signers.player1).attack(0, 0);
await waitForBlock(hre);
const positionValue = await this.battleship.player2Board(0, 0);
expect(positionValue).to.equal(CellState.Hit);
});
}

0 comments on commit c0842b5

Please sign in to comment.