Skip to content

Commit 7b82582

Browse files
committed
chore: add event to trebuchet for testing indexing
1 parent 55ca365 commit 7b82582

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

script/Deploy.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ contract DeploySiege is Script {
1414

1515
new BatteringRam(50);
1616
new Catapult(100);
17-
new Trebuchet(200);
17+
new Trebuchet(200, msg.sender);
1818

1919
vm.stopBroadcast();
2020
}

script/Trebuchet.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ contract DeployTrebuchet is Script {
1010

1111
vm.startBroadcast(deployerPrivateKey);
1212

13-
new Trebuchet(200);
13+
new Trebuchet(200, msg.sender);
1414

1515
vm.stopBroadcast();
1616
}

src/Trebuchet.sol

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ pragma solidity ^0.8.19;
33

44
contract Trebuchet {
55
uint256 internal _damage;
6-
uint256 constant b = 7;
6+
address immutable _owner;
77

8-
constructor(uint256 damage) {
8+
event Attack(uint256 damage);
9+
10+
error Unauthorized();
11+
12+
constructor(uint256 damage, address owner) {
913
_damage = damage;
14+
_owner = owner;
15+
}
16+
17+
modifier onlyOwner() {
18+
if (msg.sender != _owner) revert Unauthorized();
19+
_;
1020
}
1121

1222
function getAttackDamage() external view returns (uint256) {
1323
return _damage;
1424
}
1525

16-
function attack() external pure returns (string memory) {
26+
function attack() external returns (string memory) {
27+
emit Attack(_damage);
1728
return "fiumba!";
1829
}
30+
31+
function setDamage(uint256 damage) external onlyOwner {
32+
_damage = damage;
33+
}
1934
}

test/Basic.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ contract TestTrebuchet is Test {
99
Trebuchet c;
1010

1111
function setUp() public {
12-
c = new Trebuchet(1);
12+
c = new Trebuchet(1, address(this));
1313
}
1414

15-
function testData() public {
15+
function testGetDamage() public {
1616
assertEq(c.getAttackDamage(), 1);
1717
}
1818
}

0 commit comments

Comments
 (0)