Skip to content

Commit e9b72a7

Browse files
committed
test: add test for delegation on a non existing provision
Signed-off-by: Tomás Migone <[email protected]>
1 parent 25376af commit e9b72a7

File tree

1 file changed

+52
-20
lines changed

1 file changed

+52
-20
lines changed

packages/horizon/test/staking/delegation/delegate.t.sol

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
1515
function testDelegate_Tokens(
1616
uint256 amount,
1717
uint256 delegationAmount
18-
) public useIndexer useProvision(amount, 0, 0) useDelegation(delegationAmount) {
19-
}
18+
) public useIndexer useProvision(amount, 0, 0) useDelegation(delegationAmount) {}
2019

2120
function testDelegate_Tokens_WhenThawing(
2221
uint256 amount,
@@ -30,7 +29,12 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
3029
vm.startPrank(users.delegator);
3130
_delegate(users.indexer, subgraphDataServiceAddress, delegationAmount, 0);
3231

33-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
32+
DelegationInternal memory delegation = _getStorage_Delegation(
33+
users.indexer,
34+
subgraphDataServiceAddress,
35+
users.delegator,
36+
false
37+
);
3438
undelegateAmount = bound(undelegateAmount, 1 wei, delegation.shares - 1 ether);
3539
_undelegate(users.indexer, subgraphDataServiceAddress, undelegateAmount);
3640

@@ -46,10 +50,15 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
4650
vm.startPrank(users.delegator);
4751
_delegate(users.indexer, subgraphDataServiceAddress, delegationAmount, 0);
4852

49-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
53+
DelegationInternal memory delegation = _getStorage_Delegation(
54+
users.indexer,
55+
subgraphDataServiceAddress,
56+
users.delegator,
57+
false
58+
);
5059
_undelegate(users.indexer, subgraphDataServiceAddress, delegation.shares);
5160

52-
_delegate(users.indexer, subgraphDataServiceAddress, delegationAmount, 0);
61+
_delegate(users.indexer, subgraphDataServiceAddress, delegationAmount, 0);
5362
}
5463

5564
function testDelegate_RevertWhen_ZeroTokens(uint256 amount) public useIndexer useProvision(amount, 0, 0) {
@@ -87,7 +96,7 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
8796
function testDelegate_RevertWhen_InvalidPool(
8897
uint256 tokens,
8998
uint256 delegationTokens
90-
) public useIndexer useProvision(tokens, 0, 0) useDelegationSlashing() {
99+
) public useIndexer useProvision(tokens, 0, 0) useDelegationSlashing {
91100
delegationTokens = bound(delegationTokens, MIN_DELEGATION, MAX_STAKING_TOKENS);
92101

93102
resetPrank(users.delegator);
@@ -96,29 +105,36 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
96105
// slash entire provision + pool
97106
resetPrank(subgraphDataServiceAddress);
98107
_slash(users.indexer, subgraphDataServiceAddress, tokens + delegationTokens, 0);
99-
108+
100109
// attempt to delegate to a pool on invalid state, should revert
101110
resetPrank(users.delegator);
102111
token.approve(address(staking), delegationTokens);
103-
vm.expectRevert(abi.encodeWithSelector(
104-
IHorizonStakingMain.HorizonStakingInvalidDelegationPoolState.selector,
105-
users.indexer,
106-
subgraphDataServiceAddress
107-
));
112+
vm.expectRevert(
113+
abi.encodeWithSelector(
114+
IHorizonStakingMain.HorizonStakingInvalidDelegationPoolState.selector,
115+
users.indexer,
116+
subgraphDataServiceAddress
117+
)
118+
);
108119
staking.delegate(users.indexer, subgraphDataServiceAddress, delegationTokens, 0);
109120
}
110121

111122
function testDelegate_RevertWhen_ThawingShares_InvalidPool(
112123
uint256 tokens,
113124
uint256 delegationTokens
114-
) public useIndexer useProvision(tokens, 0, 0) useDelegationSlashing() {
125+
) public useIndexer useProvision(tokens, 0, 0) useDelegationSlashing {
115126
delegationTokens = bound(delegationTokens, MIN_DELEGATION * 2, MAX_STAKING_TOKENS);
116127

117128
resetPrank(users.delegator);
118129
_delegate(users.indexer, subgraphDataServiceAddress, delegationTokens, 0);
119130

120131
// undelegate some shares but not all
121-
DelegationInternal memory delegation = _getStorage_Delegation(users.indexer, subgraphDataServiceAddress, users.delegator, false);
132+
DelegationInternal memory delegation = _getStorage_Delegation(
133+
users.indexer,
134+
subgraphDataServiceAddress,
135+
users.delegator,
136+
false
137+
);
122138
_undelegate(users.indexer, subgraphDataServiceAddress, delegation.shares / 2);
123139

124140
// slash entire provision + pool
@@ -128,19 +144,21 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
128144
// attempt to delegate to a pool on invalid state, should revert
129145
resetPrank(users.delegator);
130146
token.approve(address(staking), delegationTokens);
131-
vm.expectRevert(abi.encodeWithSelector(
132-
IHorizonStakingMain.HorizonStakingInvalidDelegationPoolState.selector,
133-
users.indexer,
134-
subgraphDataServiceAddress
135-
));
147+
vm.expectRevert(
148+
abi.encodeWithSelector(
149+
IHorizonStakingMain.HorizonStakingInvalidDelegationPoolState.selector,
150+
users.indexer,
151+
subgraphDataServiceAddress
152+
)
153+
);
136154
staking.delegate(users.indexer, subgraphDataServiceAddress, delegationTokens, 0);
137155
}
138156

139157
function testDelegate_AfterRecoveringPool(
140158
uint256 tokens,
141159
uint256 delegationTokens,
142160
uint256 recoverAmount
143-
) public useIndexer useProvision(tokens, 0, 0) useDelegationSlashing() {
161+
) public useIndexer useProvision(tokens, 0, 0) useDelegationSlashing {
144162
recoverAmount = bound(recoverAmount, 1, MAX_STAKING_TOKENS);
145163
delegationTokens = bound(delegationTokens, MIN_DELEGATION, MAX_STAKING_TOKENS);
146164

@@ -162,4 +180,18 @@ contract HorizonStakingDelegateTest is HorizonStakingTest {
162180
resetPrank(users.delegator);
163181
_delegate(users.indexer, subgraphDataServiceAddress, delegationTokens, 0);
164182
}
183+
184+
function testDelegate_RevertWhen_ProvisionNotCreated(uint256 delegationAmount) public {
185+
delegationAmount = bound(delegationAmount, MIN_DELEGATION, MAX_STAKING_TOKENS);
186+
187+
vm.startPrank(users.delegator);
188+
token.approve(address(staking), delegationAmount);
189+
bytes memory expectedError = abi.encodeWithSelector(
190+
IHorizonStakingMain.HorizonStakingInvalidProvision.selector,
191+
users.indexer,
192+
subgraphDataServiceAddress
193+
);
194+
vm.expectRevert(expectedError);
195+
staking.delegate(users.indexer, subgraphDataServiceAddress, delegationAmount, 0);
196+
}
165197
}

0 commit comments

Comments
 (0)