-
Notifications
You must be signed in to change notification settings - Fork 34
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: Gabriel-Trintinalia <[email protected]>
- v0.8.0-rc8
- v0.8.0-rc7
- v0.8.0-rc6
- v0.8.0-rc5
- v0.8.0-rc4
- v0.8.0-rc3
- v0.8.0-rc2
- v0.8.0-rc1
- v0.7.0-rc1
- v0.6.0-rc8
- v0.6.0-rc7
- v0.6.0-rc6
- v0.6.0-rc5
- v0.6.0-rc4
- v0.6.0-rc3
- v0.6.0-rc2
- v0.6.0-rc1
- v0.5.3-beta
- v0.5.2-beta
- v0.5.1-beta
- v0.5.0-beta
- v0.4.0-rc2
- v0.4.0-rc1
- v0.3.0-rc2
- v0.3.0-rc1
- v0.2.0-rc5
- v0.2.0-rc4
- v0.2.0-rc3
- v0.2.0-rc2
- v0.2.0-rc1
- v0.1.5-rc6
- v0.1.5-rc5
- v0.1.5-rc4
- v0.1.5-rc3
- v0.1.5-rc2
- v0.1.4-test25
- v0.1.4-test24
- v0.1.4-test23
- v0.1.4-test22
- v0.1.4-test21
- v0.1.4-test20
- v0.1.4-test19
- v0.1.4-test18
- v0.1.4-test18-RC3
- v0.1.4-test18-RC2
- v0.1.4-test18-RC1
- v0.1.4-test17
- v0.1.4-test16
- v0.1.4-test15
- v0.1.4-test14
- v0.1.4-test13
- v0.1.4-test12
- v0.1.4-test11
- v0.1.4-test10
- v0.1.4-test9
- v0.1.4-test8
- v0.1.4-test7
- v0.1.4-test6
- v0.1.4-test5
- v0.1.4-test4
- v0.1.4-test3
- v0.1.4-test2
- v0.1.4-test
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.1.0-prover-integration
- mmu_mmio_v1
- 0.0.1
1 parent
8f0b5a1
commit 7def985
Showing
7 changed files
with
587 additions
and
419 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.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,163 @@ | ||
/* | ||
* 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; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.assertj.core.api.Assertions; | ||
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; | ||
import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.web3j.crypto.Credentials; | ||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.core.RemoteCall; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
import org.web3j.protocol.exceptions.TransactionException; | ||
import org.web3j.tx.RawTransactionManager; | ||
import org.web3j.tx.TransactionManager; | ||
import org.web3j.tx.gas.DefaultGasProvider; | ||
import org.web3j.tx.response.PollingTransactionReceiptProcessor; | ||
import org.web3j.tx.response.TransactionReceiptProcessor; | ||
|
||
/** Base class for plugin tests. */ | ||
public class LineaPluginTestBase extends AcceptanceTestBase { | ||
public static final int MAX_CALLDATA_SIZE = 1188; // contract has a call data size of 1160 | ||
public static final long CHAIN_ID = 1337L; | ||
protected BesuNode minerNode; | ||
|
||
@BeforeEach | ||
public void setup() throws Exception { | ||
minerNode = besu.createMinerNodeWithExtraCliOptions("miner1", getTestCliOptions()); | ||
cluster.start(minerNode); | ||
} | ||
|
||
public List<String> getTestCliOptions() { | ||
return new TestCommandLineOptionsBuilder().build(); | ||
} | ||
|
||
@AfterEach | ||
public void stop() { | ||
cluster.stop(); | ||
cluster.close(); | ||
} | ||
|
||
protected void sendTransactionsWithGivenLengthPayload( | ||
final SimpleStorage simpleStorage, | ||
final List<String> accounts, | ||
final Web3j web3j, | ||
final int num) { | ||
final String contractAddress = simpleStorage.getContractAddress(); | ||
final String txData = | ||
simpleStorage.set(RandomStringUtils.randomAlphabetic(num)).encodeFunctionCall(); | ||
final List<String> hashes = new ArrayList<>(); | ||
accounts.forEach( | ||
a -> { | ||
final Credentials credentials = Credentials.create(a); | ||
TransactionManager txManager = new RawTransactionManager(web3j, credentials, CHAIN_ID); | ||
for (int i = 0; i < 5; i++) { | ||
try { | ||
hashes.add( | ||
txManager | ||
.sendTransaction( | ||
DefaultGasProvider.GAS_PRICE, | ||
DefaultGasProvider.GAS_LIMIT, | ||
contractAddress, | ||
txData, | ||
BigInteger.ZERO) | ||
.getTransactionHash()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
|
||
assertTransactionsInCorrectBlocks(web3j, hashes, num); | ||
} | ||
|
||
private void assertTransactionsInCorrectBlocks(Web3j web3j, List<String> hashes, int num) { | ||
final HashMap<Long, Integer> txMap = new HashMap<>(); | ||
TransactionReceiptProcessor receiptProcessor = | ||
new PollingTransactionReceiptProcessor( | ||
web3j, | ||
TransactionManager.DEFAULT_POLLING_FREQUENCY, | ||
TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH); | ||
// CallData for the transaction for empty String is 68 and grows in steps of 32 with (String | ||
// size / 32) | ||
final int maxTxs = MAX_CALLDATA_SIZE / (68 + ((num + 31) / 32) * 32); | ||
|
||
// Wait for transaction to be mined and check that there are no more than maxTxs per block | ||
hashes.forEach( | ||
h -> { | ||
final TransactionReceipt transactionReceipt; | ||
try { | ||
transactionReceipt = receiptProcessor.waitForTransactionReceipt(h); | ||
} catch (IOException | TransactionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
final long blockNumber = transactionReceipt.getBlockNumber().longValue(); | ||
txMap.compute(blockNumber, (b, n) -> n == null ? 1 : n + 1); | ||
|
||
// make sure that no block contained more than maxTxs | ||
assertThat(txMap.get(blockNumber)).isLessThanOrEqualTo(maxTxs); | ||
}); | ||
// make sure that at least one block has maxTxs | ||
assertThat(txMap).containsValue(maxTxs); | ||
} | ||
|
||
protected SimpleStorage deploySimpleStorage() throws Exception { | ||
final Web3j web3j = minerNode.nodeRequests().eth(); | ||
final Credentials credentials = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY); | ||
TransactionManager txManager = new RawTransactionManager(web3j, credentials, CHAIN_ID); | ||
|
||
final RemoteCall<SimpleStorage> deploy = | ||
SimpleStorage.deploy(web3j, txManager, new DefaultGasProvider()); | ||
return deploy.send(); | ||
} | ||
|
||
public static String getResourcePath(String resource) { | ||
return Objects.requireNonNull(LineaPluginTestBase.class.getResource(resource)).getPath(); | ||
} | ||
|
||
protected void assertTransactionsInSeparateBlocks(Web3j web3j, ArrayList<String> hashes) | ||
throws Exception { | ||
TransactionReceiptProcessor receiptProcessor = | ||
new PollingTransactionReceiptProcessor( | ||
web3j, | ||
TransactionManager.DEFAULT_POLLING_FREQUENCY, | ||
TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH); | ||
|
||
final HashSet<Long> blockNumbers = new HashSet<>(); | ||
for (String h : hashes) { | ||
Assertions.assertThat( | ||
blockNumbers.add( | ||
receiptProcessor.waitForTransactionReceipt(h).getBlockNumber().longValue())) | ||
.isEqualTo(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.