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
Next Next commit
init
Signed-off-by: Frank Li <b439988l@gmail.com>
  • Loading branch information
frankisawesome committed Nov 24, 2021
commit 910224cc922de9cb14b41b95863398ce0eb77998
20 changes: 17 additions & 3 deletions besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hyperledger.besu.enclave.Enclave;
import org.hyperledger.besu.enclave.EnclaveFactory;
import org.hyperledger.besu.enclave.types.PrivacyGroup;
import org.hyperledger.besu.enclave.types.ReceiveResponse;
import org.hyperledger.besu.enclave.types.SendResponse;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.ProtocolContext;
Expand Down Expand Up @@ -140,9 +141,12 @@ public class PrivacyReorgTest {
private PrivateStateRootResolver privateStateRootResolver;
private PrivacyParameters privacyParameters;
private RestrictedDefaultPrivacyController privacyController;
private Enclave mockEnclave;

@Before
public void setUp() throws IOException {
mockEnclave = mock(Enclave.class);

enclave =
OrionTestHarnessFactory.create(
"orion",
Expand All @@ -154,12 +158,15 @@ public void setUp() throws IOException {
final Path dataDir = folder.newFolder().toPath();

// Configure Privacy
EnclaveFactory enclaveFactory = mock(EnclaveFactory.class);
when(enclaveFactory.createVertxEnclave(any())).thenReturn(mockEnclave);

privacyParameters =
new PrivacyParameters.Builder()
.setEnabled(true)
.setStorageProvider(createKeyValueStorageProvider())
.setEnclaveUrl(enclave.clientUrl())
.setEnclaveFactory(new EnclaveFactory(Vertx.vertx()))
.setEnclaveUrl(URI.create("http//1.1.1.1:1234"))
.setEnclaveFactory(enclaveFactory)
.build();
privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
privacyController = mock(RestrictedDefaultPrivacyController.class);
Expand Down Expand Up @@ -204,8 +211,15 @@ public void privacyGroupHeadIsTracked() {
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();

when(mockEnclave.receive("AA=="))
.thenReturn(
new ReceiveResponse(
PRIVATE_TRANSACTION.getPayload().toArrayUnsafe(),
PRIVACY_GROUP_BYTES32.toBase64String(),
ENCLAVE_PUBLIC_KEY.toBase64String()));

final Transaction privateMarkerTransaction =
buildMarkerTransaction(getEnclaveKey(enclave.clientUrl()));
buildMarkerTransaction(Bytes.fromHexString("0x00"));
final Block firstBlock =
gen.block(
getBlockOptionsWithTransaction(
Expand Down