44
44
import tech .pegasys .teku .validator .client .Validator ;
45
45
46
46
class GetGraffitiTest {
47
- private final OwnedKeyManager keyManager = mock (OwnedKeyManager .class );
48
- private final GetGraffiti handler = new GetGraffiti (keyManager );
49
- private StubRestApiRequest request ;
50
-
51
- final String stringGraffiti = "Test graffiti" ;
52
- final Bytes32 bytesGraffiti = Bytes32Parser .toBytes32 (stringGraffiti );
53
-
54
47
private final DataStructureUtil dataStructureUtil =
55
48
new DataStructureUtil (TestSpecFactory .createDefault ());
49
+ private final String stringGraffiti = "Test graffiti" ;
50
+ private final Bytes32 bytesGraffiti = Bytes32Parser .toBytes32 (stringGraffiti );
51
+ private final BLSPublicKey publicKey = dataStructureUtil .randomPublicKey ();
52
+
53
+ private final OwnedKeyManager keyManager = mock (OwnedKeyManager .class );
54
+ private final GetGraffiti handler = new GetGraffiti (keyManager );
55
+ private final StubRestApiRequest request =
56
+ StubRestApiRequest .builder ()
57
+ .metadata (handler .getMetadata ())
58
+ .pathParameter ("pubkey" , publicKey .toHexString ())
59
+ .build ();
56
60
57
61
@ Test
58
62
void shouldGetGraffiti () throws JsonProcessingException {
@@ -66,15 +70,10 @@ void shouldGetEmptyGraffiti() throws JsonProcessingException {
66
70
67
71
@ Test
68
72
void shouldHandleValidatorNotFound () throws IOException {
69
- request =
70
- StubRestApiRequest .builder ()
71
- .metadata (handler .getMetadata ())
72
- .pathParameter ("pubkey" , dataStructureUtil .randomPublicKey ().toHexString ())
73
- .build ();
74
-
75
73
when (keyManager .getValidatorByPublicKey (any ())).thenReturn (Optional .empty ());
76
74
77
75
handler .handleRequest (request );
76
+
78
77
assertThat (request .getResponseCode ()).isEqualTo (SC_NOT_FOUND );
79
78
assertThat (request .getResponseBody ())
80
79
.isEqualTo (new HttpErrorResponse (SC_NOT_FOUND , "Validator not found" ));
@@ -83,13 +82,13 @@ void shouldHandleValidatorNotFound() throws IOException {
83
82
@ Test
84
83
void metadata_shouldHandle200 () throws JsonProcessingException {
85
84
final GetGraffiti .GraffitiResponse response =
86
- new GetGraffiti .GraffitiResponse (dataStructureUtil . randomPublicKey () , bytesGraffiti );
85
+ new GetGraffiti .GraffitiResponse (publicKey , bytesGraffiti );
87
86
final String responseData = getResponseStringFromMetadata (handler , SC_OK , response );
88
- assertThat ( responseData )
89
- . isEqualTo (
90
- "{\" data\" :{\" pubkey\" :"
91
- + " \" 0xa4654ac3105a58c7634031b5718c4880c87300f72091cfbc69fe490b71d93a671e00e80a388e1ceb8ea1de112003e976 \" ,"
92
- + " \" graffiti \" : \" Test graffiti \" }}" );
87
+ final String expectedResponse =
88
+ String . format (
89
+ "{\" data\" :{\" pubkey\" :\" %s \" , \" graffiti \" : \" %s \" }}" ,
90
+ publicKey . toHexString (), stringGraffiti );
91
+ assertThat ( responseData ). isEqualTo ( expectedResponse );
93
92
}
94
93
95
94
@ Test
@@ -114,13 +113,6 @@ void metadata_shouldHandle500() throws JsonProcessingException {
114
113
115
114
private void checkGraffiti (final Optional <Bytes32 > graffiti ) throws JsonProcessingException {
116
115
final GraffitiProvider provider = () -> graffiti ;
117
- final BLSPublicKey publicKey = dataStructureUtil .randomPublicKey ();
118
- request =
119
- StubRestApiRequest .builder ()
120
- .metadata (handler .getMetadata ())
121
- .pathParameter ("pubkey" , publicKey .toHexString ())
122
- .build ();
123
-
124
116
final Validator validator = new Validator (publicKey , NO_OP_SIGNER , provider );
125
117
when (keyManager .getValidatorByPublicKey (eq (publicKey ))).thenReturn (Optional .of (validator ));
126
118
0 commit comments