Skip to content

Commit e429fe4

Browse files
committed
WIP: Move tests to top-level
1 parent 73cfd91 commit e429fe4

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

gnosh_orig/test/KeyBroadcastContract.t.sol renamed to test/KeyBroadcastContract.t.sol

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
pragma solidity ^0.8.20;
33

44
import "forge-std/Test.sol";
5-
import "../src/IKeyBroadcastContract.sol";
6-
import "../src/KeyBroadcastContract.sol";
7-
import "../src/KeyperSetManager.sol";
8-
import "../src/KeyperSet.sol";
5+
import "../src/common/KeyBroadcastContract.sol";
6+
import "../src/common/KeyperSetManager.sol";
7+
import "../src/common/KeyperSet.sol";
98

109
contract KeyBroadcastTest is Test {
1110
KeyBroadcastContract public keyBroadcastContract;
@@ -14,24 +13,27 @@ contract KeyBroadcastTest is Test {
1413
KeyperSet public keyperSet1;
1514
address public broadcaster0;
1615
address public broadcaster1;
16+
address public deployer;
1717

1818
event EonKeyBroadcast(uint64 eon, bytes key);
1919

2020
function setUp() public {
21+
2122
broadcaster0 = address(1);
2223
broadcaster1 = address(2);
24+
deployer = address(3);
2325

24-
keyperSetManager = new KeyperSetManager();
26+
keyperSetManager = new KeyperSetManager(deployer);
2527
keyBroadcastContract = new KeyBroadcastContract(
2628
address(keyperSetManager)
2729
);
2830
keyperSet0 = new KeyperSet();
29-
keyperSet0.setKeyBroadcaster(broadcaster0);
31+
keyperSet0.setPublisher(broadcaster0);
3032
keyperSet0.setFinalized();
3133
keyperSetManager.addKeyperSet(100, address(keyperSet0));
3234

3335
keyperSet1 = new KeyperSet();
34-
keyperSet1.setKeyBroadcaster(broadcaster1);
36+
keyperSet1.setPublisher(broadcaster1);
3537
keyperSet1.setFinalized();
3638
keyperSetManager.addKeyperSet(200, address(keyperSet1));
3739
}

gnosh_orig/test/KeyperSet.t.sol renamed to test/KeyperSet.t.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.20;
33

44
import "forge-std/Test.sol";
5-
import "../src/KeyperSet.sol";
5+
import "../src/common/KeyperSet.sol";
66

77
contract KeyperSetRevertAfterFinalizedTest is Test {
88
KeyperSet public keyperSet;
@@ -23,9 +23,9 @@ contract KeyperSetRevertAfterFinalizedTest is Test {
2323
keyperSet.addMembers(members);
2424
}
2525

26-
function testSetKeyBroadcaster() public {
26+
function testSetPublisher() public {
2727
vm.expectRevert(AlreadyFinalized.selector);
28-
keyperSet.setKeyBroadcaster(address(5));
28+
keyperSet.setPublisher(address(5));
2929
}
3030
}
3131

@@ -89,7 +89,7 @@ contract KeyperSetTest is Test {
8989
function testSetKeybroadcasterOnlyOwner() public {
9090
vm.expectRevert("Ownable: caller is not the owner");
9191
vm.prank(address(1));
92-
keyperSet.setKeyBroadcaster(address(5));
92+
keyperSet.setPublisher(address(5));
9393
}
9494

9595
function testThreshold() public {
@@ -105,7 +105,7 @@ contract KeyperSetTest is Test {
105105
}
106106

107107
function testBroadcaster() public {
108-
keyperSet.setKeyBroadcaster(address(5));
108+
keyperSet.setPublisher(address(5));
109109
keyperSet.setFinalized();
110110

111111
assertEq(keyperSet.isAllowedToBroadcastEonKey(address(1)), false);

gnosh_orig/test/KeyperSetManager.t.sol renamed to test/KeyperSetManager.t.sol

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
pragma solidity ^0.8.20;
33

44
import "forge-std/Test.sol";
5-
import "../src/KeyperSetManager.sol";
6-
import "../src/KeyperSet.sol";
5+
import "../src/common/KeyperSetManager.sol";
6+
import "../src/common/KeyperSet.sol";
77

88
contract KeyperSetManagerTest is Test {
99
KeyperSetManager public keyperSetManager;
1010
KeyperSet public members0;
1111
KeyperSet public members1;
12-
12+
address public owner;
13+
1314
function setUp() public {
14-
keyperSetManager = new KeyperSetManager();
15+
owner = vm.addr(42);
16+
vm.prank(owner);
17+
keyperSetManager = new KeyperSetManager(owner);
18+
vm.prank(owner);
19+
keyperSetManager.initialize(owner, owner);
1520
members0 = new KeyperSet();
1621
members0.setFinalized();
1722
members1 = new KeyperSet();
@@ -20,15 +25,23 @@ contract KeyperSetManagerTest is Test {
2025

2126
function testGetNumKeyperSets() public {
2227
assertEq(keyperSetManager.getNumKeyperSets(), 0);
28+
vm.prank(owner);
2329
keyperSetManager.addKeyperSet(0, address(members0));
2430
assertEq(keyperSetManager.getNumKeyperSets(), 1);
31+
vm.prank(owner);
2532
keyperSetManager.addKeyperSet(1, address(members0));
2633
assertEq(keyperSetManager.getNumKeyperSets(), 2);
2734
}
2835

2936
function testAddKeyperSetOnlyOwner() public {
3037
vm.prank(address(1));
31-
vm.expectRevert("Ownable: caller is not the owner");
38+
vm.expectRevert(
39+
abi.encodeWithSelector(
40+
IAccessControl.AccessControlUnauthorizedAccount.selector,
41+
address(1),
42+
keyperSetManager.DEFAULT_ADMIN_ROLE
43+
)
44+
);
3245
keyperSetManager.addKeyperSet(0, address(members0));
3346
}
3447

@@ -50,36 +63,37 @@ contract KeyperSetManagerTest is Test {
5063
function testAddKeyperSetEmits() public {
5164
vm.expectEmit(address(keyperSetManager));
5265
emit KeyperSetAdded(1000, address(members0));
66+
vm.prank(owner);
5367
keyperSetManager.addKeyperSet(1000, address(members0));
5468
}
5569

56-
function testGetKeyperSetIndexBySlotEmpty() public {
70+
function testGetKeyperSetIndexByBlockEmpty() public {
5771
vm.expectRevert(NoActiveKeyperSet.selector);
58-
keyperSetManager.getKeyperSetIndexBySlot(0);
72+
keyperSetManager.getKeyperSetIndexByBlock(0);
5973
}
6074

61-
function testGetKeyperSetIndexBySlot() public {
75+
function testGetKeyperSetIndexByBlock() public {
6276
keyperSetManager.addKeyperSet(1000, address(members0));
6377
keyperSetManager.addKeyperSet(1100, address(members1));
6478

6579
vm.expectRevert(NoActiveKeyperSet.selector);
66-
keyperSetManager.getKeyperSetIndexBySlot(0);
80+
keyperSetManager.getKeyperSetIndexByBlock(0);
6781

6882
vm.expectRevert(NoActiveKeyperSet.selector);
69-
keyperSetManager.getKeyperSetIndexBySlot(999);
83+
keyperSetManager.getKeyperSetIndexByBlock(999);
7084

71-
assertEq(keyperSetManager.getKeyperSetIndexBySlot(1000), 0);
72-
assertEq(keyperSetManager.getKeyperSetIndexBySlot(1099), 0);
85+
assertEq(keyperSetManager.getKeyperSetIndexByBlock(1000), 0);
86+
assertEq(keyperSetManager.getKeyperSetIndexByBlock(1099), 0);
7387

74-
assertEq(keyperSetManager.getKeyperSetIndexBySlot(1100), 1);
75-
assertEq(keyperSetManager.getKeyperSetIndexBySlot(1250), 1);
88+
assertEq(keyperSetManager.getKeyperSetIndexByBlock(1100), 1);
89+
assertEq(keyperSetManager.getKeyperSetIndexByBlock(1250), 1);
7690
}
7791

78-
function testGetKeyperSetActivationSlot() public {
92+
function testGetKeyperSetActivationBlock() public {
7993
keyperSetManager.addKeyperSet(1000, address(members0));
8094
keyperSetManager.addKeyperSet(1100, address(members1));
81-
assertEq(keyperSetManager.getKeyperSetActivationSlot(0), 1000);
82-
assertEq(keyperSetManager.getKeyperSetActivationSlot(1), 1100);
95+
assertEq(keyperSetManager.getKeyperSetActivationBlock(0), 1000);
96+
assertEq(keyperSetManager.getKeyperSetActivationBlock(1), 1100);
8397
}
8498

8599
function testGetKeyperSetAddress() public {

gnosh_orig/test/Sequencer.t.sol renamed to test/Sequencer.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
pragma solidity ^0.8.20;
33

44
import "forge-std/Test.sol";
5-
import "../src/ISequencer.sol";
6-
import "../src/Sequencer.sol";
5+
import "../src/common/intf/ISequencer.sol";
6+
import "../src/gnosh/Sequencer.sol";
77

88
contract SequencerTest is Test {
99
Sequencer public sequencer;

gnosh_orig/test/ValidatorRegistry.t.sol renamed to test/ValidatorRegistry.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
pragma solidity ^0.8.20;
33

44
import "forge-std/Test.sol";
5-
import "../src/IValidatorRegistry.sol";
6-
import "../src/ValidatorRegistry.sol";
5+
import "../src/common/intf/IValidatorRegistry.sol";
6+
import "../src/gnosh/ValidatorRegistry.sol";
77

88
contract ValidatorRegistryTest is Test {
99
event Updated(bytes message, bytes signature);

0 commit comments

Comments
 (0)