39
39
import tech .pegasys .teku .spec .TestSpecFactory ;
40
40
import tech .pegasys .teku .spec .util .DataStructureUtil ;
41
41
import tech .pegasys .teku .validator .api .Bytes32Parser ;
42
+ import tech .pegasys .teku .validator .api .GraffitiProvider ;
42
43
import tech .pegasys .teku .validator .client .OwnedKeyManager ;
43
44
import tech .pegasys .teku .validator .client .Validator ;
44
45
@@ -52,45 +53,14 @@ class GetGraffitiTest {
52
53
53
54
@ Test
54
55
void shouldGetGraffiti () throws JsonProcessingException {
55
- final BLSPublicKey publicKey = dataStructureUtil .randomPublicKey ();
56
56
final String stringGraffiti = "Test graffiti" ;
57
57
final Bytes32 graffiti = Bytes32Parser .toBytes32 (stringGraffiti );
58
-
59
- request =
60
- StubRestApiRequest .builder ()
61
- .metadata (handler .getMetadata ())
62
- .pathParameter ("pubkey" , publicKey .toHexString ())
63
- .build ();
64
-
65
- final Validator validator = new Validator (publicKey , NO_OP_SIGNER , () -> Optional .of (graffiti ));
66
- when (keyManager .getValidatorByPublicKey (eq (publicKey ))).thenReturn (Optional .of (validator ));
67
-
68
- handler .handleRequest (request );
69
-
70
- final GetGraffiti .GraffitiResponse expectedResponse =
71
- new GetGraffiti .GraffitiResponse (publicKey , stringGraffiti );
72
- assertThat (request .getResponseCode ()).isEqualTo (SC_OK );
73
- assertThat (request .getResponseBody ()).isEqualTo (expectedResponse );
58
+ checkGraffiti (() -> Optional .of (graffiti ), stringGraffiti );
74
59
}
75
60
76
61
@ Test
77
62
void shouldGetEmptyGraffiti () throws JsonProcessingException {
78
- final BLSPublicKey publicKey = dataStructureUtil .randomPublicKey ();
79
- request =
80
- StubRestApiRequest .builder ()
81
- .metadata (handler .getMetadata ())
82
- .pathParameter ("pubkey" , publicKey .toHexString ())
83
- .build ();
84
-
85
- final Validator validator = new Validator (publicKey , NO_OP_SIGNER , Optional ::empty );
86
- when (keyManager .getValidatorByPublicKey (eq (publicKey ))).thenReturn (Optional .of (validator ));
87
-
88
- handler .handleRequest (request );
89
-
90
- final GetGraffiti .GraffitiResponse expectedResponse =
91
- new GetGraffiti .GraffitiResponse (publicKey , "" );
92
- assertThat (request .getResponseCode ()).isEqualTo (SC_OK );
93
- assertThat (request .getResponseBody ()).isEqualTo (expectedResponse );
63
+ checkGraffiti (Optional ::empty , "" );
94
64
}
95
65
96
66
@ Test
@@ -140,4 +110,24 @@ void metadata_shouldHandle403() throws JsonProcessingException {
140
110
void metadata_shouldHandle500 () throws JsonProcessingException {
141
111
verifyMetadataErrorResponse (handler , SC_INTERNAL_SERVER_ERROR );
142
112
}
113
+
114
+ private void checkGraffiti (final GraffitiProvider graffitiProvider , final String expectedGraffiti )
115
+ throws JsonProcessingException {
116
+ final BLSPublicKey publicKey = dataStructureUtil .randomPublicKey ();
117
+ request =
118
+ StubRestApiRequest .builder ()
119
+ .metadata (handler .getMetadata ())
120
+ .pathParameter ("pubkey" , publicKey .toHexString ())
121
+ .build ();
122
+
123
+ final Validator validator = new Validator (publicKey , NO_OP_SIGNER , graffitiProvider );
124
+ when (keyManager .getValidatorByPublicKey (eq (publicKey ))).thenReturn (Optional .of (validator ));
125
+
126
+ handler .handleRequest (request );
127
+
128
+ final GetGraffiti .GraffitiResponse expectedResponse =
129
+ new GetGraffiti .GraffitiResponse (publicKey , expectedGraffiti );
130
+ assertThat (request .getResponseCode ()).isEqualTo (SC_OK );
131
+ assertThat (request .getResponseBody ()).isEqualTo (expectedResponse );
132
+ }
143
133
}
0 commit comments