-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fabio Di Fabio <[email protected]>
- Loading branch information
Showing
5 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/SetExtraDataTest.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,168 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* 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 linea.plugin.acc.test.rpc.linea; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.List; | ||
|
||
import linea.plugin.acc.test.LineaPluginTestBase; | ||
import linea.plugin.acc.test.TestCommandLineOptionsBuilder; | ||
import net.consensys.linea.config.LineaProfitabilityCliOptions; | ||
import net.consensys.linea.config.LineaProfitabilityConfiguration; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.web3j.protocol.core.Request; | ||
import org.web3j.protocol.http.HttpService; | ||
|
||
public class SetExtraDataTest extends LineaPluginTestBase { | ||
protected static final int FIXED_GAS_COST_WEI = 0; | ||
protected static final int VARIABLE_GAS_COST_WEI = 1_000_000_000; | ||
protected static final double MIN_MARGIN = 1.0; | ||
protected static final double ESTIMATE_GAS_MIN_MARGIN = 1.0; | ||
protected static final Wei MIN_GAS_PRICE = Wei.of(1_000_000_000); | ||
protected static final int MAX_TRANSACTION_GAS_LIMIT = 30_000_000; | ||
protected LineaProfitabilityConfiguration profitabilityConf; | ||
|
||
@Override | ||
public List<String> getTestCliOptions() { | ||
return getTestCommandLineOptionsBuilder().build(); | ||
} | ||
|
||
protected TestCommandLineOptionsBuilder getTestCommandLineOptionsBuilder() { | ||
return new TestCommandLineOptionsBuilder() | ||
.set("--plugin-linea-fixed-gas-cost-wei=", String.valueOf(FIXED_GAS_COST_WEI)) | ||
.set("--plugin-linea-variable-gas-cost-wei=", String.valueOf(VARIABLE_GAS_COST_WEI)) | ||
.set("--plugin-linea-min-margin=", String.valueOf(MIN_MARGIN)) | ||
.set("--plugin-linea-estimate-gas-min-margin=", String.valueOf(ESTIMATE_GAS_MIN_MARGIN)) | ||
.set("--plugin-linea-max-tx-gas-limit=", String.valueOf(MAX_TRANSACTION_GAS_LIMIT)); | ||
} | ||
|
||
@BeforeEach | ||
public void setMinGasPrice() { | ||
minerNode.getMiningParameters().setMinTransactionGasPrice(MIN_GAS_PRICE); | ||
} | ||
|
||
@BeforeEach | ||
public void createDefaultConfigurations() { | ||
profitabilityConf = | ||
LineaProfitabilityCliOptions.create().toDomainObject().toBuilder() | ||
.fixedCostWei(FIXED_GAS_COST_WEI) | ||
.variableCostWei(VARIABLE_GAS_COST_WEI) | ||
.minMargin(MIN_MARGIN) | ||
.estimateGasMinMargin(ESTIMATE_GAS_MIN_MARGIN) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void setUnsupportedExtraDataReturnsError() { | ||
final var unsupportedExtraData = Bytes32.ZERO; | ||
|
||
final var reqLinea = new FailingLineaSetExtraDataRequest(unsupportedExtraData); | ||
final var respLinea = reqLinea.execute(minerNode.nodeRequests()); | ||
assertThat(respLinea.getMessage()) | ||
.isEqualTo( | ||
"Unsupported extra data field 0x0000000000000000000000000000000000000000000000000000000000000000"); | ||
} | ||
|
||
@Test | ||
public void successfulSetExtraData() { | ||
final var extraData = | ||
Bytes32.fromHexString("0x0100000000000000000000000000000000000000000000000000000000000000"); | ||
|
||
final var reqLinea = new LineaSetExtraDataRequest(extraData); | ||
final var respLinea = reqLinea.execute(minerNode.nodeRequests()); | ||
assertThat(respLinea).isTrue(); | ||
} | ||
|
||
@Test | ||
public void parseErrorLineaEstimateGasRequestReturnErrorResponse() | ||
throws IOException, InterruptedException { | ||
final var httpService = (HttpService) minerNode.nodeRequests().getWeb3jService(); | ||
final var httpClient = HttpClient.newHttpClient(); | ||
final var badJsonRequest = | ||
HttpRequest.newBuilder(URI.create(httpService.getUrl())) | ||
.headers("Content-Type", "application/json") | ||
.POST( | ||
HttpRequest.BodyPublishers.ofString( | ||
""" | ||
{"jsonrpc":"2.0","method":"linea_setExtraData","params":[malformed json],"id":53} | ||
""")) | ||
.build(); | ||
final var errorResponse = httpClient.send(badJsonRequest, HttpResponse.BodyHandlers.ofString()); | ||
assertThat(errorResponse.body()) | ||
.isEqualTo( | ||
""" | ||
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}"""); | ||
} | ||
|
||
static class LineaSetExtraDataRequest implements Transaction<Boolean> { | ||
private final Bytes32 extraData; | ||
|
||
public LineaSetExtraDataRequest(final Bytes32 extraData) { | ||
this.extraData = extraData; | ||
} | ||
|
||
@Override | ||
public Boolean execute(final NodeRequests nodeRequests) { | ||
try { | ||
return new Request<>( | ||
"linea_setExtraData", | ||
List.of(extraData.toHexString()), | ||
nodeRequests.getWeb3jService(), | ||
LineaSetExtraDataResponse.class) | ||
.send() | ||
.getResult(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
static class FailingLineaSetExtraDataRequest | ||
implements Transaction<org.web3j.protocol.core.Response.Error> { | ||
private final Bytes32 extraData; | ||
|
||
public FailingLineaSetExtraDataRequest(final Bytes32 extraData) { | ||
this.extraData = extraData; | ||
} | ||
|
||
@Override | ||
public org.web3j.protocol.core.Response.Error execute(final NodeRequests nodeRequests) { | ||
try { | ||
return new Request<>( | ||
"linea_setExtraData", | ||
List.of(extraData.toHexString()), | ||
nodeRequests.getWeb3jService(), | ||
LineaSetExtraDataResponse.class) | ||
.send() | ||
.getError(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
static class LineaSetExtraDataResponse extends org.web3j.protocol.core.Response<Boolean> {} | ||
} |
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
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