forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print warning for deprecated testnets (hyperledger#4173)
* print warning for deprecated testnets Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
- Loading branch information
1 parent
93da04c
commit 3913174
Showing
8 changed files
with
206 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
besu/src/main/java/org/hyperledger/besu/cli/NetworkDeprecationMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.cli; | ||
|
||
import org.hyperledger.besu.cli.config.NetworkName; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class NetworkDeprecationMessage { | ||
private static final int MAX_LINE_LENGTH = 80; | ||
|
||
public static String generate(final NetworkName network) { | ||
if (network.getDeprecationDate().isEmpty()) { | ||
throw new AssertionError("Deprecation date is not set. Cannot print a deprecation message"); | ||
} | ||
|
||
final StringBuilder messageBuilder = new StringBuilder("\n"); | ||
messageBuilder | ||
.append("#".repeat(MAX_LINE_LENGTH)) | ||
.append(emptyLine()) | ||
.append( | ||
String.format( | ||
"#%s#", | ||
StringUtils.center( | ||
deprecationDetails( | ||
network.humanReadableNetworkName(), network.getDeprecationDate().get()), | ||
MAX_LINE_LENGTH - 2))) | ||
.append(emptyLine()) | ||
.append( | ||
String.format( | ||
"#%s#\n", StringUtils.center("For more details please go to", MAX_LINE_LENGTH - 2))) | ||
.append( | ||
String.format( | ||
"#%s#", | ||
StringUtils.center( | ||
"https://blog.ethereum.org/2022/06/21/testnet-deprecation/", | ||
MAX_LINE_LENGTH - 2))) | ||
.append(emptyLine()) | ||
.append("#".repeat(MAX_LINE_LENGTH)); | ||
|
||
return messageBuilder.toString(); | ||
} | ||
|
||
private static String deprecationDetails(final String networkName, final String deprecationDate) { | ||
return networkName + " is deprecated and will be shutdown " + deprecationDate; | ||
} | ||
|
||
private static String emptyLine() { | ||
return String.format("\n#%s#\n", StringUtils.center("", MAX_LINE_LENGTH - 2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
besu/src/test/java/org/hyperledger/besu/cli/NetworkDeprecationMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.cli; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.hyperledger.besu.cli.config.NetworkName; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
|
||
class NetworkDeprecationMessageTest { | ||
|
||
@ParameterizedTest | ||
@EnumSource( | ||
value = NetworkName.class, | ||
names = {"RINKEBY", "ROPSTEN", "KILN"}) | ||
void shouldGenerateDeprecationMessageForDeprecatedNetworks(final NetworkName network) { | ||
assertThat(NetworkDeprecationMessage.generate(network)) | ||
.contains(network.humanReadableNetworkName() + " is deprecated and will be shutdown"); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource( | ||
value = NetworkName.class, | ||
names = { | ||
"MAINNET", | ||
"SEPOLIA", | ||
"GOERLI", | ||
"DEV", | ||
"CLASSIC", | ||
"KOTTI", | ||
"MORDOR", | ||
"ECIP1049_DEV", | ||
"ASTOR" | ||
}) | ||
void shouldThrowErrorForNonDeprecatedNetworks(final NetworkName network) { | ||
assertThatThrownBy(() -> NetworkDeprecationMessage.generate(network)) | ||
.isInstanceOf(AssertionError.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters