Skip to content

Commit

Permalink
Add new acceptance test to soak test BFT chains (#7023)
Browse files Browse the repository at this point in the history
* Add new acceptance test to soak test BFT chains

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless

Signed-off-by: Matthew Whitehead <[email protected]>

* Tidy up a little with re-usable start and stop functions with built in delays

Signed-off-by: Matthew Whitehead <[email protected]>

* Add shanghai version of Simple Storage contract

Signed-off-by: Matthew Whitehead <[email protected]>

* Put commented gradle code back in. Fix the web3j example commands in .sol files

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless

Signed-off-by: Matthew Whitehead <[email protected]>

* Set publication artifacts to avoid clash

Signed-off-by: Matthew Whitehead <[email protected]>

* Exclude from regular acceptance tests

Signed-off-by: Matthew Whitehead <[email protected]>

* Add shanghai fork to the test. Stall the chain for less time to reduce the time taken to mine new blocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Tidy up

Signed-off-by: Matthew Whitehead <[email protected]>

* Update acceptance-tests/tests/shanghai/build.gradle

Co-authored-by: Simon Dudley <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Tidy up var names

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix ports for IBFT2 as well as QBFT

Signed-off-by: Matthew Whitehead <[email protected]>

* Remove maven publish spec, disable jar building for shanghai contract project

Signed-off-by: Matthew Whitehead <[email protected]>

* web3j version

Signed-off-by: Matthew Whitehead <[email protected]>

* Make fixed port optional when creating a BFT node

Signed-off-by: Matthew Whitehead <[email protected]>

* Only check artifact coordinates for those starting 'org.*'

Signed-off-by: Matthew Whitehead <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Co-authored-by: Simon Dudley <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
3 people authored Jun 11, 2024
1 parent 04f304f commit b1ac5ac
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,30 @@ public BesuNode createIbft2Node(final String name, final String genesisFile) thr
.build());
}

public BesuNode createIbft2Node(final String name) throws IOException {
return create(
public BesuNode createIbft2Node(final String name, final boolean fixedPort) throws IOException {
JsonRpcConfiguration rpcConfig = node.createJsonRpcWithIbft2EnabledConfig(false);
rpcConfig.addRpcApi("ADMIN,TXPOOL");
if (fixedPort) {
rpcConfig.setPort(
Math.abs(name.hashCode() % 60000)
+ 1024); // Generate a consistent port for p2p based on node name
}
BesuNodeConfigurationBuilder builder =
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcConfiguration(node.createJsonRpcWithIbft2EnabledConfig(false))
.jsonRpcConfiguration(rpcConfig)
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.devMode(false)
.genesisConfigProvider(GenesisConfigurationFactory::createIbft2GenesisConfig)
.build());
.genesisConfigProvider(GenesisConfigurationFactory::createIbft2GenesisConfig);
if (fixedPort) {
builder.p2pPort(
Math.abs(name.hashCode() % 60000)
+ 1024
+ 500); // Generate a consistent port for p2p based on node name (+ 500 to avoid
// clashing with RPC port or other nodes with a similar name)
}
return create(builder.build());
}

public BesuNode createQbftNodeWithTLS(final String name, final String type) throws IOException {
Expand Down Expand Up @@ -498,16 +512,31 @@ public BesuNode createQbftNodeWithTLSPKCS11(final String name) throws IOExceptio
return createQbftNodeWithTLS(name, KeyStoreWrapper.KEYSTORE_TYPE_PKCS11);
}

public BesuNode createQbftNode(final String name) throws IOException {
return create(
public BesuNode createQbftNode(final String name, final boolean fixedPort) throws IOException {
JsonRpcConfiguration rpcConfig = node.createJsonRpcWithQbftEnabledConfig(false);
rpcConfig.addRpcApi("ADMIN,TXPOOL");
if (fixedPort) {
rpcConfig.setPort(
Math.abs(name.hashCode() % 60000)
+ 1024); // Generate a consistent port for p2p based on node name
}

BesuNodeConfigurationBuilder builder =
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcConfiguration(node.createJsonRpcWithQbftEnabledConfig(false))
.jsonRpcConfiguration(rpcConfig)
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.devMode(false)
.genesisConfigProvider(GenesisConfigurationFactory::createQbftGenesisConfig)
.build());
.genesisConfigProvider(GenesisConfigurationFactory::createQbftGenesisConfig);
if (fixedPort) {
builder.p2pPort(
Math.abs(name.hashCode() % 60000)
+ 1024
+ 500); // Generate a consistent port for p2p based on node name (+ 500 to avoid
// clashing with RPC port or other nodes with a similar name)
}
return create(builder.build());
}

public BesuNode createCustomGenesisNode(
Expand Down
32 changes: 32 additions & 0 deletions acceptance-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ solidity {
resolvePackages = false
// TODO: remove the forced version, when DEV network is upgraded to support latest forks
version '0.8.19'
evmVersion 'london'
}

dependencies {
Expand Down Expand Up @@ -79,6 +80,7 @@ dependencies {
testImplementation 'org.web3j:besu'
testImplementation 'org.web3j:core'
testImplementation 'org.wiremock:wiremock'
testImplementation project(path: ':acceptance-tests:tests:shanghai')

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
Expand Down Expand Up @@ -153,6 +155,7 @@ task acceptanceTestMainnet(type: Test) {
task acceptanceTestNotPrivacy(type: Test) {
inputs.property "integration.date", LocalTime.now() // so it runs at every invocation
exclude '**/privacy/**'
exclude '**/bftsoak/**'

useJUnitPlatform {}

Expand Down Expand Up @@ -205,6 +208,35 @@ task acceptanceTestCliqueBft(type: Test) {
doFirst { mkdir "${buildDir}/jvmErrorLogs" }
}

task acceptanceTestBftSoak(type: Test) {
inputs.property "integration.date", LocalTime.now() // so it runs at every invocation
include '**/bftsoak/**'

useJUnitPlatform {}

dependsOn(rootProject.installDist)
setSystemProperties(test.getSystemProperties())
systemProperty 'acctests.runBesuAsProcess', 'true'
// Set to any time > 60 minutes to run the soak test for longer
// systemProperty 'acctests.soakTimeMins', '120'
systemProperty 'java.security.properties', "${buildDir}/resources/test/acceptanceTesting.security"
mustRunAfter rootProject.subprojects*.test
description = 'Runs BFT soak test.'
group = 'verification'

jvmArgs "-XX:ErrorFile=${buildDir}/jvmErrorLogs/java_err_pid%p.log"

testLogging {
exceptionFormat = 'full'
showStackTraces = true
showStandardStreams = true
showExceptions = true
showCauses = true
}

doFirst { mkdir "${buildDir}/jvmErrorLogs" }
}

task acceptanceTestPrivacy(type: Test) {
inputs.property "integration.date", LocalTime.now() // so it runs at every invocation
include '**/privacy/**'
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/contracts/CrossContractReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "./EventEmitter.sol";
// compile with:
// solc CrossContractReader.sol --bin --abi --optimize --overwrite -o .
// then create web3j wrappers with:
// web3j solidity generate -b ./generated/CrossContractReader.bin -a ./generated/CrossContractReader.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
// web3j generate solidity -b ./generated/CrossContractReader.bin -a ./generated/CrossContractReader.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
contract CrossContractReader {
uint counter;

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/contracts/EventEmitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pragma solidity >=0.7.0 <0.9.0;
// compile with:
// solc EventEmitter.sol --bin --abi --optimize --overwrite -o .
// then create web3j wrappers with:
// web3j solidity generate -b ./generated/EventEmitter.bin -a ./generated/EventEmitter.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
// web3j generate solidity -b ./generated/EventEmitter.bin -a ./generated/EventEmitter.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
contract EventEmitter {
address owner;
event stored(address _to, uint _amount);
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/contracts/RemoteSimpleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "./SimpleStorage.sol";
// compile with:
// solc RemoteSimpleStorage.sol --bin --abi --optimize --overwrite -o .
// then create web3j wrappers with:
// web3j solidity generate -b ./generated/RemoteSimpleStorage.bin -a ./generated/RemoteSimpleStorage.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
// web3j generate solidity -b ./generated/RemoteSimpleStorage.bin -a ./generated/RemoteSimpleStorage.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
contract RemoteSimpleStorage {
SimpleStorage public simpleStorage;

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/contracts/RevertReason.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pragma solidity >=0.7.0 <0.9.0;
// compile with:
// solc RevertReason.sol --bin --abi --optimize --overwrite -o .
// then create web3j wrappers with:
// web3j solidity generate -b ./generated/RevertReason.bin -a ./generated/RevertReason.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
// web3j generate solidity -b ./generated/RevertReason.bin -a ./generated/RevertReason.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
contract RevertReason {

function revertWithRevertReason() public pure returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/contracts/SimpleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pragma solidity >=0.7.0 <0.8.20;
// compile with:
// solc SimpleStorage.sol --bin --abi --optimize --overwrite -o .
// then create web3j wrappers with:
// web3j solidity generate -b ./generated/SimpleStorage.bin -a ./generated/SimpleStorage.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
// web3j generate solidity -b ./generated/SimpleStorage.bin -a ./generated/SimpleStorage.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
contract SimpleStorage {
uint data;

Expand Down
21 changes: 21 additions & 0 deletions acceptance-tests/tests/shanghai/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

plugins {
id 'org.web3j' version '4.11.3'
id 'org.web3j.solidity' version '0.4.1'
}

jar { enabled = true }

web3j {
generatedPackageName = 'org.hyperledger.besu.tests.web3j.generated'
}

sourceSets.main.solidity.srcDirs = [
"$projectDir/shanghaicontracts"
]

solidity {
resolvePackages = false
version '0.8.25'
evmVersion 'shanghai'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* 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
*/
pragma solidity >=0.8.20;

// compile with:
// solc SimpleStorageShanghai.sol --bin --abi --optimize --overwrite -o .
// then create web3j wrappers with:
// web3j generate solidity -b ./SimpleStorageShanghai.bin -a ./SimpleStorageShanghai.abi -o ../../../../../ -p org.hyperledger.besu.tests.web3j.generated
contract SimpleStorageShanghai {
uint data;

function set(uint value) public {
data = value;
}

function get() public view returns (uint) {
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ public static Stream<Arguments> getFactories() {
@FunctionalInterface
public interface NodeCreator {

BesuNode create(BesuNodeFactory factory, String name) throws Exception;
BesuNode create(BesuNodeFactory factory, String name, boolean fixedPort) throws Exception;
}

@FunctionalInterface
public interface FixedPortNodeCreator {

BesuNode createFixedPort(BesuNodeFactory factory, String name, boolean fixedPort)
throws Exception;
}

@FunctionalInterface
Expand All @@ -57,7 +64,11 @@ public BftAcceptanceTestParameterization(
}

public BesuNode createNode(BesuNodeFactory factory, String name) throws Exception {
return creatorFn.create(factory, name);
return creatorFn.create(factory, name, false);
}

public BesuNode createNodeFixedPort(BesuNodeFactory factory, String name) throws Exception {
return creatorFn.create(factory, name, true);
}

public BesuNode createNodeWithValidators(
Expand Down
Loading

0 comments on commit b1ac5ac

Please sign in to comment.