Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(internal) Refactor PrivacyReorgTest to use mock enclave #3103

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
working test
Signed-off-by: Frank Li <b439988l@gmail.com>
  • Loading branch information
frankisawesome committed Nov 25, 2021
commit 7a8923d7ad8037b5d80eb9bd735403a814df271a
31 changes: 19 additions & 12 deletions besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.io.IOException;
import java.math.BigInteger;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -168,6 +169,13 @@ public void setUp() throws IOException {
.setEnclaveUrl(URI.create("http//1.1.1.1:1234"))
.setEnclaveFactory(enclaveFactory)
.build();
// privacyParameters =
// new PrivacyParameters.Builder()
// .setEnabled(true)
// .setStorageProvider(createKeyValueStorageProvider())
// .setEnclaveUrl(enclave.clientUrl())
// .setEnclaveFactory(new EnclaveFactory(Vertx.vertx()))
// .build();
privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
privacyController = mock(RestrictedDefaultPrivacyController.class);
when(privacyController.findPrivacyGroupByGroupId(any(), any()))
Expand Down Expand Up @@ -210,16 +218,17 @@ public void privacyGroupHeadIsTracked() {
final ProtocolContext protocolContext = besuController.getProtocolContext();
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();
final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
PRIVATE_TRANSACTION.writeTo(rlpOutput);

when(mockEnclave.receive("AA=="))
when(mockEnclave.receive(any()))
.thenReturn(
new ReceiveResponse(
PRIVATE_TRANSACTION.getPayload().toArrayUnsafe(),
rlpOutput.encoded().toBase64String().getBytes(StandardCharsets.UTF_8),
PRIVACY_GROUP_BYTES32.toBase64String(),
ENCLAVE_PUBLIC_KEY.toBase64String()));

final Transaction privateMarkerTransaction =
buildMarkerTransaction(Bytes.fromHexString("0x00"));
final Transaction privateMarkerTransaction = buildMarkerTransaction();
final Block firstBlock =
gen.block(
getBlockOptionsWithTransaction(
Expand Down Expand Up @@ -263,7 +272,7 @@ public void reorgToChainAtEqualHeight() {
gen.block(
getBlockOptionsWithTransaction(
blockchain.getGenesisBlock(),
buildMarkerTransaction(getEnclaveKey(enclave.clientUrl())),
buildMarkerTransaction(),
FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT));

appendBlock(besuController, blockchain, protocolContext, firstBlock);
Expand Down Expand Up @@ -302,9 +311,7 @@ public void reorgToShorterChain() {
final Block secondBlock =
gen.block(
getBlockOptionsWithTransaction(
firstBlock,
buildMarkerTransaction(getEnclaveKey(enclave.clientUrl())),
secondBlockStateRoot));
firstBlock, buildMarkerTransaction(), secondBlockStateRoot));

appendBlock(besuController, blockchain, protocolContext, firstBlock);
appendBlock(besuController, blockchain, protocolContext, secondBlock);
Expand Down Expand Up @@ -351,7 +358,7 @@ public void reorgToLongerChain() {
gen.block(
getBlockOptionsWithTransaction(
blockchain.getGenesisBlock(),
buildMarkerTransaction(getEnclaveKey(enclave.clientUrl())),
buildMarkerTransaction(),
FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT));

appendBlock(besuController, blockchain, protocolContext, firstBlock);
Expand Down Expand Up @@ -398,7 +405,7 @@ public void reorgToLongerChain() {
gen.block(
getBlockOptionsWithTransactionAndDifficulty(
secondForkBlock,
buildMarkerTransaction(getEnclaveKey(enclave.clientUrl())),
buildMarkerTransaction(),
secondForkBlock.getHeader().getDifficulty().plus(10L),
thirdForkBlockStateRoot));

Expand Down Expand Up @@ -469,14 +476,14 @@ private SendResponse sendRequest(
}
}

private Transaction buildMarkerTransaction(final Bytes payload) {
private Transaction buildMarkerTransaction() {
return Transaction.builder()
.type(TransactionType.FRONTIER)
.chainId(BigInteger.valueOf(1337))
.gasLimit(60000)
.gasPrice(Wei.of(1000))
.nonce(0)
.payload(payload)
.payload(Bytes32.random())
.to(DEFAULT_PRIVACY)
.value(Wei.ZERO)
.signAndBuild(KEY_PAIR);
Expand Down