File tree Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -3,17 +3,32 @@ pragma solidity ^0.8.19;
33
44contract 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments