-
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.
Reject a tx, sent via eth_sendRawTransaction, if its simulation fails
Signed-off-by: Fabio Di Fabio <[email protected]>
- Loading branch information
Showing
13 changed files
with
555 additions
and
45 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
103 changes: 103 additions & 0 deletions
103
...c/test/java/linea/plugin/acc/test/rpc/linea/EthSendRawTransactionSimulationCheckTest.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,103 @@ | ||
/* | ||
* 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.math.BigInteger; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import linea.plugin.acc.test.LineaPluginTestBase; | ||
import linea.plugin.acc.test.TestCommandLineOptionsBuilder; | ||
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage; | ||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.tests.acceptance.dsl.account.Account; | ||
import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; | ||
import org.junit.jupiter.api.Test; | ||
import org.web3j.crypto.Credentials; | ||
import org.web3j.crypto.RawTransaction; | ||
import org.web3j.crypto.TransactionEncoder; | ||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.core.methods.response.EthSendTransaction; | ||
import org.web3j.tx.gas.DefaultGasProvider; | ||
import org.web3j.utils.Numeric; | ||
|
||
public class EthSendRawTransactionSimulationCheckTest extends LineaPluginTestBase { | ||
|
||
private static final BigInteger GAS_LIMIT = DefaultGasProvider.GAS_LIMIT; | ||
private static final BigInteger VALUE = BigInteger.ZERO; | ||
private static final BigInteger GAS_PRICE = BigInteger.TEN.pow(9); | ||
|
||
@Override | ||
public List<String> getTestCliOptions() { | ||
return new TestCommandLineOptionsBuilder() | ||
.set( | ||
"--plugin-linea-module-limit-file-path=", | ||
getResourcePath("/txOverflowModuleLimits.toml")) | ||
.set("--plugin-linea-tx-pool-simulation-check-api-enabled=", "true") | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void transactionOverModuleLineCountNotAccepted() throws Exception { | ||
final SimpleStorage simpleStorage = deploySimpleStorage(); | ||
final Web3j web3j = minerNode.nodeRequests().eth(); | ||
final String contractAddress = simpleStorage.getContractAddress(); | ||
final String txData = simpleStorage.add(BigInteger.valueOf(100)).encodeFunctionCall(); | ||
|
||
// this tx will not be accepted since it goes above the line count limit | ||
final RawTransaction txModuleLineCountTooBig = | ||
RawTransaction.createTransaction( | ||
CHAIN_ID, | ||
BigInteger.valueOf(1), | ||
GAS_LIMIT.divide(BigInteger.TEN), | ||
contractAddress, | ||
VALUE, | ||
txData, | ||
GAS_PRICE, | ||
GAS_PRICE.multiply(BigInteger.TEN).add(BigInteger.ONE)); | ||
final byte[] signedTxContractInteraction = | ||
TransactionEncoder.signMessage( | ||
txModuleLineCountTooBig, Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY)); | ||
|
||
final EthSendTransaction signedTxContractInteractionResp = | ||
web3j.ethSendRawTransaction(Numeric.toHexString(signedTxContractInteraction)).send(); | ||
|
||
assertThat(signedTxContractInteractionResp.hasError()).isTrue(); | ||
assertThat(signedTxContractInteractionResp.getError().getMessage()) | ||
.isEqualTo("Transaction line count for module ADD=2018 is above the limit 70"); | ||
|
||
assertThat(getTxPoolContent()).isEmpty(); | ||
|
||
// these are under the line count limit and should be accepted and selected | ||
final Account fewLinesSender = accounts.getSecondaryBenefactor(); | ||
final Account recipient = accounts.createAccount("recipient"); | ||
final List<Hash> expectedConfirmedTxs = new ArrayList<>(4); | ||
|
||
expectedConfirmedTxs.addAll( | ||
minerNode.execute( | ||
accountTransactions.createIncrementalTransfers(fewLinesSender, recipient, 4))); | ||
|
||
final var txPoolContentByHash = getTxPoolContent().stream().map(e -> e.get("hash")).toList(); | ||
assertThat(txPoolContentByHash) | ||
.containsExactlyInAnyOrderElementsOf( | ||
expectedConfirmedTxs.stream().map(Hash::toHexString).toList()); | ||
|
||
expectedConfirmedTxs.stream() | ||
.map(Hash::toHexString) | ||
.forEach(hash -> minerNode.verify(eth.expectSuccessfulTransactionReceipt(hash))); | ||
} | ||
} |
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
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
Oops, something went wrong.