@@ -101,6 +101,17 @@ protected int calculateGraffitiLength(Optional<Bytes32> graffiti) {
101
101
assertThat (graffitiBuilder .buildGraffiti (Optional .of (graffiti ))).isEqualTo (graffiti );
102
102
}
103
103
104
+ @ Test
105
+ public void buildGraffiti_shouldPreferCallInput () {
106
+ final Bytes32 defaultGraffiti = Bytes32Parser .toBytes32 (asciiGraffiti32 );
107
+ final Bytes32 userGraffiti = Bytes32Parser .toBytes32 (ASCII_GRAFFITI_20 );
108
+ final Bytes32 expectedGraffiti = Bytes32Parser .toBytes32 (ASCII_GRAFFITI_20 + " TK" );
109
+ this .graffitiBuilder = new GraffitiBuilder (CLIENT_CODES , Optional .of (defaultGraffiti ));
110
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
111
+ assertThat (graffitiBuilder .buildGraffiti (Optional .of (userGraffiti )))
112
+ .isEqualTo (expectedGraffiti );
113
+ }
114
+
104
115
@ ParameterizedTest (name = "format={0}, userGraffiti={1}" )
105
116
@ MethodSource ("getBuildGraffitiFixtures" )
106
117
public void buildGraffiti_shouldProvideCorrectOutput (
@@ -122,6 +133,27 @@ public void buildGraffiti_shouldProvideCorrectOutput(
122
133
.isEqualTo (expectedGraffitiBytes );
123
134
}
124
135
136
+ @ ParameterizedTest (name = "format={0}, userGraffiti={1}" )
137
+ @ MethodSource ("getBuildGraffitiFixturesElInfoNa" )
138
+ public void buildGraffiti_shouldProvideCorrectOutput_whenElInfoNa (
139
+ final ClientGraffitiAppendFormat clientGraffitiAppendFormat ,
140
+ final Optional <String > maybeUserGraffiti ,
141
+ final String expectedGraffiti ) {
142
+ this .graffitiBuilder = new GraffitiBuilder (clientGraffitiAppendFormat , userGraffiti );
143
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
144
+ final Bytes32 expectedGraffitiBytes = Bytes32Parser .toBytes32 (expectedGraffiti );
145
+ assertThat (
146
+ new String (
147
+ Arrays .copyOfRange (
148
+ expectedGraffitiBytes .toArray (),
149
+ 0 ,
150
+ 32 - expectedGraffitiBytes .numberOfTrailingZeroBytes ()),
151
+ StandardCharsets .UTF_8 ))
152
+ .isEqualTo (expectedGraffiti );
153
+ assertThat (graffitiBuilder .buildGraffiti (maybeUserGraffiti .map (Bytes32Parser ::toBytes32 )))
154
+ .isEqualTo (expectedGraffitiBytes );
155
+ }
156
+
125
157
@ Test
126
158
public void extractGraffiti_shouldReturnEmptyString () {
127
159
assertThat (graffitiBuilder .extractGraffiti (Optional .empty (), 0 )).isEqualTo ("" );
@@ -290,7 +322,7 @@ public void formatClientInfo_shouldRenderClientNames() {
290
322
}
291
323
292
324
@ Test
293
- public void formatClientInfo_shouldSkipClientsInfoWhenNotEnoughSpace () {
325
+ public void formatClientInfo_shouldSkipClientsInfo_whenNotEnoughSpace () {
294
326
graffitiBuilder .onExecutionClientVersion (BESU_CLIENT_VERSION );
295
327
296
328
// Empty
@@ -305,6 +337,84 @@ public void formatClientInfo_shouldSkipClientsInfoWhenNotEnoughSpace() {
305
337
.satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isEqualTo (0 ));
306
338
}
307
339
340
+ @ Test
341
+ public void formatClientInfo_shouldRenderClClientNameAndFullCommit_whenElInfoNotAvailable () {
342
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
343
+
344
+ // 20: LH1be52536BU0f91a674
345
+ assertThat (graffitiBuilder .formatClientsInfo (30 ))
346
+ .isEqualTo (
347
+ TEKU_CLIENT_VERSION .code () + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ())
348
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (20 ));
349
+ assertThat (graffitiBuilder .formatClientsInfo (20 ))
350
+ .isEqualTo (
351
+ TEKU_CLIENT_VERSION .code () + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ())
352
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (20 ));
353
+ }
354
+
355
+ @ Test
356
+ public void formatClientInfo_shouldRenderClClientNameAndHalfCommit_whenElInfoNotAvailable () {
357
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
358
+
359
+ // 12: LH1be5BU0f91
360
+ assertThat (graffitiBuilder .formatClientsInfo (19 ))
361
+ .isEqualTo (
362
+ TEKU_CLIENT_VERSION .code ()
363
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ().substring (0 , 4 ))
364
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (12 ));
365
+ assertThat (graffitiBuilder .formatClientsInfo (12 ))
366
+ .isEqualTo (
367
+ TEKU_CLIENT_VERSION .code ()
368
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ().substring (0 , 4 ))
369
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (12 ));
370
+ }
371
+
372
+ @ Test
373
+ public void formatClientInfo_shouldRenderClClientNameAnd1stCommitByte_whenElInfoNotAvailable () {
374
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
375
+
376
+ // 8: LH1bBU0f
377
+ assertThat (graffitiBuilder .formatClientsInfo (11 ))
378
+ .isEqualTo (
379
+ TEKU_CLIENT_VERSION .code ()
380
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ().substring (0 , 2 ))
381
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (8 ));
382
+ assertThat (graffitiBuilder .formatClientsInfo (8 ))
383
+ .isEqualTo (
384
+ TEKU_CLIENT_VERSION .code ()
385
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ().substring (0 , 2 ))
386
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (8 ));
387
+ }
388
+
389
+ @ Test
390
+ public void formatClientInfo_shouldRenderClClientName_whenElInfoNotAvailable () {
391
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
392
+
393
+ // 4: LHBU
394
+ assertThat (graffitiBuilder .formatClientsInfo (7 ))
395
+ .isEqualTo (TEKU_CLIENT_VERSION .code ())
396
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (4 ));
397
+ assertThat (graffitiBuilder .formatClientsInfo (4 ))
398
+ .isEqualTo (TEKU_CLIENT_VERSION .code ())
399
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isLessThan (4 ));
400
+ }
401
+
402
+ @ Test
403
+ public void formatClientInfo_shouldSkipClientsInfo_whenNotEnoughSpaceAndElInfoNotAvailable () {
404
+ graffitiBuilder .onExecutionClientVersion (ClientVersion .UNKNOWN );
405
+
406
+ // Empty
407
+ assertThat (graffitiBuilder .formatClientsInfo (3 ))
408
+ .isEqualTo ("" )
409
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isEqualTo (0 ));
410
+ assertThat (graffitiBuilder .formatClientsInfo (0 ))
411
+ .isEqualTo ("" )
412
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isEqualTo (0 ));
413
+ assertThat (graffitiBuilder .formatClientsInfo (-1 ))
414
+ .isEqualTo ("" )
415
+ .satisfies (s -> assertThat (s .getBytes (StandardCharsets .UTF_8 ).length ).isEqualTo (0 ));
416
+ }
417
+
308
418
@ ParameterizedTest (name = "code={0}" )
309
419
@ MethodSource ("getClientCodes" )
310
420
public void formatClientInfo_shouldHandleBadCodeOnClientNamesAndFullCommit (
@@ -452,4 +562,46 @@ private static Stream<Arguments> getBuildGraffitiFixtures() {
452
562
Arguments .of (DISABLED , Optional .of (UTF_8_GRAFFITI_4 ), UTF_8_GRAFFITI_4 ),
453
563
Arguments .of (DISABLED , Optional .of (ASCII_GRAFFITI_20 ), ASCII_GRAFFITI_20 ));
454
564
}
565
+
566
+ private static Stream <Arguments > getBuildGraffitiFixturesElInfoNa () {
567
+ return Stream .of (
568
+ Arguments .of (
569
+ AUTO ,
570
+ Optional .empty (),
571
+ TEKU_CLIENT_VERSION .code () + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ()),
572
+ Arguments .of (
573
+ AUTO ,
574
+ Optional .of ("small" ),
575
+ "small "
576
+ + TEKU_CLIENT_VERSION .code ()
577
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ()),
578
+ Arguments .of (
579
+ AUTO ,
580
+ Optional .of (UTF_8_GRAFFITI_4 ),
581
+ UTF_8_GRAFFITI_4
582
+ + " "
583
+ + TEKU_CLIENT_VERSION .code ()
584
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ()),
585
+ Arguments .of (
586
+ AUTO ,
587
+ Optional .of (ASCII_GRAFFITI_20 ),
588
+ ASCII_GRAFFITI_20
589
+ + " "
590
+ + TEKU_CLIENT_VERSION .code ()
591
+ + TEKU_CLIENT_VERSION .commit ().toUnprefixedHexString ().substring (0 , 2 )),
592
+ Arguments .of (CLIENT_CODES , Optional .empty (), TEKU_CLIENT_VERSION .code ()),
593
+ Arguments .of (CLIENT_CODES , Optional .of ("small" ), "small " + TEKU_CLIENT_VERSION .code ()),
594
+ Arguments .of (
595
+ CLIENT_CODES ,
596
+ Optional .of (UTF_8_GRAFFITI_4 ),
597
+ UTF_8_GRAFFITI_4 + " " + TEKU_CLIENT_VERSION .code ()),
598
+ Arguments .of (
599
+ CLIENT_CODES ,
600
+ Optional .of (ASCII_GRAFFITI_20 ),
601
+ ASCII_GRAFFITI_20 + " " + TEKU_CLIENT_VERSION .code ()),
602
+ Arguments .of (DISABLED , Optional .empty (), "" ),
603
+ Arguments .of (DISABLED , Optional .of ("small" ), "small" ),
604
+ Arguments .of (DISABLED , Optional .of (UTF_8_GRAFFITI_4 ), UTF_8_GRAFFITI_4 ),
605
+ Arguments .of (DISABLED , Optional .of (ASCII_GRAFFITI_20 ), ASCII_GRAFFITI_20 ));
606
+ }
455
607
}
0 commit comments