27
27
import java .io .IOException ;
28
28
import java .util .Optional ;
29
29
import org .junit .jupiter .api .Test ;
30
- import tech .pegasys .teku .infrastructure .restapi .endpoints .RestApiRequest ;
30
+ import tech .pegasys .teku .infrastructure .restapi .StubRestApiRequest ;
31
+ import tech .pegasys .teku .spec .Spec ;
32
+ import tech .pegasys .teku .spec .TestSpecFactory ;
31
33
import tech .pegasys .teku .spec .datastructures .eth1 .Eth1Address ;
34
+ import tech .pegasys .teku .spec .util .DataStructureUtil ;
32
35
import tech .pegasys .teku .validator .client .BeaconProposerPreparer ;
33
36
34
37
public class SetFeeRecipientTest {
35
38
private final BeaconProposerPreparer beaconProposerPreparer = mock (BeaconProposerPreparer .class );
36
39
private final SetFeeRecipient handler = new SetFeeRecipient (Optional .of (beaconProposerPreparer ));
37
40
38
- private final RestApiRequest request = mock (RestApiRequest .class );
41
+ private final StubRestApiRequest request = new StubRestApiRequest (handler .getMetadata ());
42
+
43
+ private final Spec spec = TestSpecFactory .createMinimalAltair ();
44
+ private final DataStructureUtil dataStructureUtil = new DataStructureUtil (spec );
45
+
46
+ @ Test
47
+ void badPubkey_shouldGiveIllegalArgument () {
48
+ request .setPathParameter ("pubkey" , "pubkey" );
49
+ assertThatThrownBy (() -> handler .handleRequest (request ))
50
+ .isInstanceOf (IllegalArgumentException .class );
51
+ }
39
52
40
53
@ Test
41
54
void metadata_shouldHandle400 () throws JsonProcessingException {
@@ -49,6 +62,9 @@ void metadata_shouldHandle500() throws JsonProcessingException {
49
62
50
63
@ Test
51
64
void shouldShareContextIfBellatrixNotEnabled () {
65
+ request .setPathParameter ("pubkey" , dataStructureUtil .randomPublicKey ().toString ());
66
+ request .setRequestBody (
67
+ new SetFeeRecipient .SetFeeRecipientBody (dataStructureUtil .randomEth1Address ()));
52
68
assertThatThrownBy (
53
69
() -> {
54
70
SetFeeRecipient handler = new SetFeeRecipient (Optional .empty ());
@@ -73,4 +89,13 @@ void metadata_shouldReadRequestBody() throws IOException {
73
89
new SetFeeRecipient .SetFeeRecipientBody (
74
90
Eth1Address .fromHexString ("0xabcf8e0d4e9587369b2301d0790347320302cc09" )));
75
91
}
92
+
93
+ @ Test
94
+ void metadata_shoulThrowInvalidArgument () {
95
+ assertThatThrownBy (
96
+ () ->
97
+ getRequestBodyFromMetadata (
98
+ handler , "{\" ethaddress\" :\" 0xabcF8e0d4E9587369b2301d0790347320302CC09\" }" ))
99
+ .isInstanceOf (IllegalArgumentException .class );
100
+ }
76
101
}
0 commit comments