[PRIV] Generify orion to enclave (#745)

* Generify orion to enclave

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Vinicius Stevam 6 years ago committed by Sally MacFarlane
parent ad7c5fb54f
commit cd818814ff
  1. 0
      enclave/build.gradle
  2. 24
      enclave/src/integration-test/java/tech/pegasys/pantheon/enclave/EnclaveTest.java
  3. 24
      enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java
  4. 2
      enclave/src/main/java/tech/pegasys/pantheon/enclave/types/ReceiveRequest.java
  5. 2
      enclave/src/main/java/tech/pegasys/pantheon/enclave/types/ReceiveResponse.java
  6. 2
      enclave/src/main/java/tech/pegasys/pantheon/enclave/types/SendRequest.java
  7. 2
      enclave/src/main/java/tech/pegasys/pantheon/enclave/types/SendResponse.java
  8. 2
      ethereum/core/build.gradle
  9. 17
      ethereum/core/src/integration-test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractIntegrationTest.java
  10. 6
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java
  11. 24
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java
  12. 16
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java
  13. 26
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java
  14. 27
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandlerTest.java
  15. 2
      pantheon/build.gradle
  16. 6
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  17. 24
      pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java
  18. 2
      settings.gradle

@ -10,17 +10,17 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.orion; package tech.pegasys.pantheon.enclave;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import tech.pegasys.orion.testutil.OrionTestHarness; import tech.pegasys.orion.testutil.OrionTestHarness;
import tech.pegasys.pantheon.orion.types.ReceiveRequest; import tech.pegasys.pantheon.enclave.types.ReceiveRequest;
import tech.pegasys.pantheon.orion.types.ReceiveResponse; import tech.pegasys.pantheon.enclave.types.ReceiveResponse;
import tech.pegasys.pantheon.orion.types.SendRequest; import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse; import tech.pegasys.pantheon.enclave.types.SendResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -32,12 +32,12 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
public class OrionTest { public class EnclaveTest {
@ClassRule public static final TemporaryFolder folder = new TemporaryFolder(); @ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
private static final String PAYLOAD = "a wonderful transaction"; private static final String PAYLOAD = "a wonderful transaction";
private static Orion orion; private static Enclave enclave;
private static OrionTestHarness testHarness; private static OrionTestHarness testHarness;
@ -47,7 +47,7 @@ public class OrionTest {
testHarness = OrionTestHarness.create(folder.newFolder().toPath()); testHarness = OrionTestHarness.create(folder.newFolder().toPath());
orion = new Orion(testHarness.clientUrl()); enclave = new Enclave(testHarness.clientUrl());
} }
@AfterClass @AfterClass
@ -57,7 +57,7 @@ public class OrionTest {
@Test @Test
public void testUpCheck() throws IOException { public void testUpCheck() throws IOException {
assertTrue(orion.upCheck()); assertTrue(enclave.upCheck());
} }
@Test @Test
@ -66,17 +66,17 @@ public class OrionTest {
SendRequest sc = SendRequest sc =
new SendRequest(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(1))); new SendRequest(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(1)));
SendResponse sr = orion.send(sc); SendResponse sr = enclave.send(sc);
ReceiveRequest rc = new ReceiveRequest(sr.getKey(), publicKeys.get(1)); ReceiveRequest rc = new ReceiveRequest(sr.getKey(), publicKeys.get(1));
ReceiveResponse rr = orion.receive(rc); ReceiveResponse rr = enclave.receive(rc);
assertEquals(PAYLOAD, new String(rr.getPayload(), UTF_8)); assertEquals(PAYLOAD, new String(rr.getPayload(), UTF_8));
} }
@Test(expected = IOException.class) @Test(expected = IOException.class)
public void whenUpCheckFailsThrows() throws IOException { public void whenUpCheckFailsThrows() throws IOException {
Orion broken = new Orion("http:"); Enclave broken = new Enclave("http:");
broken.upCheck(); broken.upCheck();
} }

@ -10,12 +10,12 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.orion; package tech.pegasys.pantheon.enclave;
import tech.pegasys.pantheon.orion.types.ReceiveRequest; import tech.pegasys.pantheon.enclave.types.ReceiveRequest;
import tech.pegasys.pantheon.orion.types.ReceiveResponse; import tech.pegasys.pantheon.enclave.types.ReceiveResponse;
import tech.pegasys.pantheon.orion.types.SendRequest; import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse; import tech.pegasys.pantheon.enclave.types.SendResponse;
import java.io.IOException; import java.io.IOException;
@ -28,7 +28,7 @@ import okhttp3.Response;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
public class Orion { public class Enclave {
private static final MediaType JSON = MediaType.parse("application/json"); private static final MediaType JSON = MediaType.parse("application/json");
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
private static final Logger LOG = LogManager.getLogger(); private static final Logger LOG = LogManager.getLogger();
@ -36,12 +36,8 @@ public class Orion {
private String url; private String url;
private final OkHttpClient client; private final OkHttpClient client;
public Orion() { public Enclave(final String enclaveUrl) {
this.client = new OkHttpClient(); this.url = enclaveUrl;
}
public Orion(final String orionUrl) {
this.url = orionUrl;
this.client = new OkHttpClient(); this.client = new OkHttpClient();
} }
@ -51,7 +47,7 @@ public class Orion {
try (Response response = client.newCall(request).execute()) { try (Response response = client.newCall(request).execute()) {
return response.isSuccessful(); return response.isSuccessful();
} catch (IOException e) { } catch (IOException e) {
LOG.error("Orion failed to execute upcheck"); LOG.error("Enclave failed to execute upcheck");
throw new IOException("Failed to perform upcheck", e); throw new IOException("Failed to perform upcheck", e);
} }
} }
@ -74,7 +70,7 @@ public class Orion {
try (Response response = client.newCall(request).execute()) { try (Response response = client.newCall(request).execute()) {
return objectMapper.readValue(response.body().string(), responseType); return objectMapper.readValue(response.body().string(), responseType);
} catch (IOException e) { } catch (IOException e) {
LOG.error("Orion failed to execute ", path); LOG.error("Enclave failed to execute ", path);
throw new IOException("Failed to execute post", e); throw new IOException("Failed to execute post", e);
} }
} }

@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.orion.types; package tech.pegasys.pantheon.enclave.types;
public class ReceiveRequest { public class ReceiveRequest {
private String key; private String key;

@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.orion.types; package tech.pegasys.pantheon.enclave.types;
public class ReceiveResponse { public class ReceiveResponse {

@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.orion.types; package tech.pegasys.pantheon.enclave.types;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;

@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package tech.pegasys.pantheon.orion.types; package tech.pegasys.pantheon.enclave.types;
public class SendResponse { public class SendResponse {
String key; String key;

@ -32,7 +32,7 @@ dependencies {
implementation project(':ethereum:trie') implementation project(':ethereum:trie')
implementation project(':ethereum:permissioning') implementation project(':ethereum:permissioning')
implementation project(':metrics') implementation project(':metrics')
implementation project(':orion') implementation project(':enclave')
implementation project(':services:kvstore') implementation project(':services:kvstore')
implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-databind'

@ -17,10 +17,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import tech.pegasys.orion.testutil.OrionTestHarness; import tech.pegasys.orion.testutil.OrionTestHarness;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.enclave.types.SendResponse;
import tech.pegasys.pantheon.ethereum.mainnet.SpuriousDragonGasCalculator; import tech.pegasys.pantheon.ethereum.mainnet.SpuriousDragonGasCalculator;
import tech.pegasys.pantheon.orion.Orion;
import tech.pegasys.pantheon.orion.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException; import java.io.IOException;
@ -38,7 +38,7 @@ public class PrivacyPrecompiledContractIntegrationTest {
@ClassRule public static final TemporaryFolder folder = new TemporaryFolder(); @ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
private static final String PAYLOAD = "a wonderful transaction"; private static final String PAYLOAD = "a wonderful transaction";
private static Orion orion; private static Enclave enclave;
private static OrionTestHarness testHarness; private static OrionTestHarness testHarness;
@ -48,7 +48,7 @@ public class PrivacyPrecompiledContractIntegrationTest {
testHarness = OrionTestHarness.create(folder.newFolder().toPath()); testHarness = OrionTestHarness.create(folder.newFolder().toPath());
orion = new Orion(testHarness.clientUrl()); enclave = new Enclave(testHarness.clientUrl());
} }
@AfterClass @AfterClass
@ -58,7 +58,7 @@ public class PrivacyPrecompiledContractIntegrationTest {
@Test @Test
public void testUpCheck() throws IOException { public void testUpCheck() throws IOException {
assertTrue(orion.upCheck()); assertTrue(enclave.upCheck());
} }
@Test @Test
@ -67,10 +67,11 @@ public class PrivacyPrecompiledContractIntegrationTest {
SendRequest sc = SendRequest sc =
new SendRequest(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(1))); new SendRequest(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(1)));
SendResponse sr = orion.send(sc); SendResponse sr = enclave.send(sc);
PrivacyPrecompiledContract privacyPrecompiledContract = PrivacyPrecompiledContract privacyPrecompiledContract =
new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), publicKeys.get(0), orion); new PrivacyPrecompiledContract(
new SpuriousDragonGasCalculator(), publicKeys.get(0), enclave);
BytesValue result = BytesValue result =
privacyPrecompiledContract.compute(BytesValue.wrap(sr.getKey().getBytes(UTF_8))); privacyPrecompiledContract.compute(BytesValue.wrap(sr.getKey().getBytes(UTF_8)));

@ -21,8 +21,8 @@ import java.net.URI;
import com.google.common.io.Files; import com.google.common.io.Files;
public class PrivacyParameters { public class PrivacyParameters {
private static final String ORION_URL = "http://localhost:8888"; private static final String ENCLAVE_URL = "http://localhost:8888";
public static final URI DEFAULT_ORION_URL = URI.create(ORION_URL); public static final URI DEFAULT_ENCLAVE_URL = URI.create(ENCLAVE_URL);
private Integer privacyAddress; private Integer privacyAddress;
private boolean enabled; private boolean enabled;
@ -40,7 +40,7 @@ public class PrivacyParameters {
public static PrivacyParameters noPrivacy() { public static PrivacyParameters noPrivacy() {
final PrivacyParameters config = new PrivacyParameters(); final PrivacyParameters config = new PrivacyParameters();
config.setEnabled(false); config.setEnabled(false);
config.setUrl(ORION_URL); config.setUrl(ENCLAVE_URL);
config.setPrivacyAddress(Address.PRIVACY); config.setPrivacyAddress(Address.PRIVACY);
return config; return config;
} }

@ -14,13 +14,13 @@ package tech.pegasys.pantheon.ethereum.mainnet.precompiles.privacy;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.ReceiveRequest;
import tech.pegasys.pantheon.enclave.types.ReceiveResponse;
import tech.pegasys.pantheon.ethereum.core.Gas; import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.mainnet.AbstractPrecompiledContract; import tech.pegasys.pantheon.ethereum.mainnet.AbstractPrecompiledContract;
import tech.pegasys.pantheon.ethereum.vm.GasCalculator; import tech.pegasys.pantheon.ethereum.vm.GasCalculator;
import tech.pegasys.pantheon.orion.Orion;
import tech.pegasys.pantheon.orion.types.ReceiveRequest;
import tech.pegasys.pantheon.orion.types.ReceiveResponse;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException; import java.io.IOException;
@ -29,21 +29,21 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
public class PrivacyPrecompiledContract extends AbstractPrecompiledContract { public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
private final Orion orion; private final Enclave enclave;
private final String orionPublicKey; private final String enclavePublicKey;
private static final Logger LOG = LogManager.getLogger(); private static final Logger LOG = LogManager.getLogger();
public PrivacyPrecompiledContract( public PrivacyPrecompiledContract(
final GasCalculator gasCalculator, final PrivacyParameters privacyParameters) { final GasCalculator gasCalculator, final PrivacyParameters privacyParameters) {
this(gasCalculator, privacyParameters.getPublicKey(), new Orion(privacyParameters.getUrl())); this(gasCalculator, privacyParameters.getPublicKey(), new Enclave(privacyParameters.getUrl()));
} }
PrivacyPrecompiledContract( PrivacyPrecompiledContract(
final GasCalculator gasCalculator, final String publicKey, final Orion orion) { final GasCalculator gasCalculator, final String publicKey, final Enclave enclave) {
super("Privacy", gasCalculator); super("Privacy", gasCalculator);
this.orion = orion; this.enclave = enclave;
this.orionPublicKey = publicKey; this.enclavePublicKey = publicKey;
} }
@Override @Override
@ -55,13 +55,13 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
public BytesValue compute(final BytesValue input) { public BytesValue compute(final BytesValue input) {
try { try {
String key = new String(input.extractArray(), UTF_8); String key = new String(input.extractArray(), UTF_8);
ReceiveRequest receiveRequest = new ReceiveRequest(key, orionPublicKey); ReceiveRequest receiveRequest = new ReceiveRequest(key, enclavePublicKey);
ReceiveResponse receiveResponse = orion.receive(receiveRequest); ReceiveResponse receiveResponse = enclave.receive(receiveRequest);
LOG.info("Got the response as ", receiveResponse.getPayload()); LOG.info("Got the response as ", receiveResponse.getPayload());
return BytesValue.wrap(receiveResponse.getPayload()); return BytesValue.wrap(receiveResponse.getPayload());
// pass it to private tx processor // pass it to private tx processor
} catch (IOException e) { } catch (IOException e) {
LOG.fatal("Orion threw an unhandled exception.", e); LOG.fatal("Enclave threw an unhandled exception.", e);
return BytesValue.EMPTY; return BytesValue.EMPTY;
} }
} }

@ -12,13 +12,13 @@
*/ */
package tech.pegasys.pantheon.ethereum.privacy; package tech.pegasys.pantheon.ethereum.privacy;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.enclave.types.SendResponse;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput; import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.orion.Orion;
import tech.pegasys.pantheon.orion.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.bytes.BytesValues; import tech.pegasys.pantheon.util.bytes.BytesValues;
@ -31,17 +31,17 @@ import java.util.stream.Collectors;
public class PrivateTransactionHandler { public class PrivateTransactionHandler {
private final Orion orion; private final Enclave enclave;
private final Address privacyPrecompileAddress; private final Address privacyPrecompileAddress;
public PrivateTransactionHandler(final PrivacyParameters privacyParameters) { public PrivateTransactionHandler(final PrivacyParameters privacyParameters) {
this( this(
new Orion(privacyParameters.getUrl()), new Enclave(privacyParameters.getUrl()),
Address.privacyPrecompiled(privacyParameters.getPrivacyAddress())); Address.privacyPrecompiled(privacyParameters.getPrivacyAddress()));
} }
public PrivateTransactionHandler(final Orion orion, final Address privacyPrecompileAddress) { public PrivateTransactionHandler(final Enclave enclave, final Address privacyPrecompileAddress) {
this.orion = orion; this.enclave = enclave;
this.privacyPrecompileAddress = privacyPrecompileAddress; this.privacyPrecompileAddress = privacyPrecompileAddress;
} }
@ -49,7 +49,7 @@ public class PrivateTransactionHandler {
final SendRequest sendRequest = createSendRequest(privateTransaction); final SendRequest sendRequest = createSendRequest(privateTransaction);
final SendResponse sendResponse; final SendResponse sendResponse;
try { try {
sendResponse = orion.send(sendRequest); sendResponse = enclave.send(sendRequest);
} catch (IOException e) { } catch (IOException e) {
throw e; throw e;
} }

@ -18,10 +18,10 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.ReceiveRequest;
import tech.pegasys.pantheon.enclave.types.ReceiveResponse;
import tech.pegasys.pantheon.ethereum.mainnet.SpuriousDragonGasCalculator; import tech.pegasys.pantheon.ethereum.mainnet.SpuriousDragonGasCalculator;
import tech.pegasys.pantheon.orion.Orion;
import tech.pegasys.pantheon.orion.types.ReceiveRequest;
import tech.pegasys.pantheon.orion.types.ReceiveResponse;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException; import java.io.IOException;
@ -36,26 +36,26 @@ public class PrivacyPrecompiledContractTest {
private PrivacyPrecompiledContract privacyPrecompiledContract; private PrivacyPrecompiledContract privacyPrecompiledContract;
private PrivacyPrecompiledContract brokenPrivateTransactionHandler; private PrivacyPrecompiledContract brokenPrivateTransactionHandler;
Orion mockOrion() throws IOException { Enclave mockEnclave() throws IOException {
Orion mockOrion = mock(Orion.class); Enclave mockEnclave = mock(Enclave.class);
ReceiveResponse response = new ReceiveResponse(actual.getBytes(UTF_8)); ReceiveResponse response = new ReceiveResponse(actual.getBytes(UTF_8));
when(mockOrion.receive(any(ReceiveRequest.class))).thenReturn(response); when(mockEnclave.receive(any(ReceiveRequest.class))).thenReturn(response);
return mockOrion; return mockEnclave;
} }
Orion brokenMockOrion() throws IOException { Enclave brokenMockEnclave() throws IOException {
Orion mockOrion = mock(Orion.class); Enclave mockEnclave = mock(Enclave.class);
when(mockOrion.receive(any(ReceiveRequest.class))).thenThrow(IOException.class); when(mockEnclave.receive(any(ReceiveRequest.class))).thenThrow(IOException.class);
return mockOrion; return mockEnclave;
} }
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
privacyPrecompiledContract = privacyPrecompiledContract =
new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), publicKey, mockOrion()); new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), publicKey, mockEnclave());
brokenPrivateTransactionHandler = brokenPrivateTransactionHandler =
new PrivacyPrecompiledContract( new PrivacyPrecompiledContract(
new SpuriousDragonGasCalculator(), publicKey, brokenMockOrion()); new SpuriousDragonGasCalculator(), publicKey, brokenMockEnclave());
} }
@Test @Test

@ -19,12 +19,12 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.SendRequest;
import tech.pegasys.pantheon.enclave.types.SendResponse;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.orion.Orion;
import tech.pegasys.pantheon.orion.types.SendRequest;
import tech.pegasys.pantheon.orion.types.SendResponse;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException; import java.io.IOException;
@ -90,25 +90,26 @@ public class PrivateTransactionHandlerTest {
Address.wrap(BytesValue.fromHexString("0x8411b12666f68ef74cace3615c9d5a377729d03f")), Address.wrap(BytesValue.fromHexString("0x8411b12666f68ef74cace3615c9d5a377729d03f")),
1); 1);
Orion mockOrion() throws IOException { Enclave mockEnclave() throws IOException {
Orion mockOrion = mock(Orion.class); Enclave mockEnclave = mock(Enclave.class);
SendResponse response = new SendResponse(); SendResponse response = new SendResponse();
response.setKey(TRANSACTION_KEY); response.setKey(TRANSACTION_KEY);
when(mockOrion.send(any(SendRequest.class))).thenReturn(response); when(mockEnclave.send(any(SendRequest.class))).thenReturn(response);
return mockOrion; return mockEnclave;
} }
Orion brokenMockOrion() throws IOException { Enclave brokenMockEnclave() throws IOException {
Orion mockOrion = mock(Orion.class); Enclave mockEnclave = mock(Enclave.class);
when(mockOrion.send(any(SendRequest.class))).thenThrow(IOException.class); when(mockEnclave.send(any(SendRequest.class))).thenThrow(IOException.class);
return mockOrion; return mockEnclave;
} }
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
privateTransactionHandler = new PrivateTransactionHandler(mockOrion(), Address.DEFAULT_PRIVACY); privateTransactionHandler =
new PrivateTransactionHandler(mockEnclave(), Address.DEFAULT_PRIVACY);
brokenPrivateTransactionHandler = brokenPrivateTransactionHandler =
new PrivateTransactionHandler(brokenMockOrion(), Address.DEFAULT_PRIVACY); new PrivateTransactionHandler(brokenMockEnclave(), Address.DEFAULT_PRIVACY);
} }
@Test @Test

@ -40,7 +40,7 @@ dependencies {
implementation project(':ethereum:p2p') implementation project(':ethereum:p2p')
implementation project(':ethereum:rlp') implementation project(':ethereum:rlp')
implementation project(':metrics') implementation project(':metrics')
implementation project(':orion') implementation project(':enclave')
implementation project(':services:kvstore') implementation project(':services:kvstore')
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'

@ -479,7 +479,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
names = {"--privacy-url"}, names = {"--privacy-url"},
description = "The URL on which enclave is running " description = "The URL on which enclave is running "
) )
private final URI privacyUrl = PrivacyParameters.DEFAULT_ORION_URL; private final URI privacyUrl = PrivacyParameters.DEFAULT_ENCLAVE_URL;
@Option( @Option(
names = {"--privacy-public-key-file"}, names = {"--privacy-public-key-file"},
@ -634,7 +634,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
.devMode(NetworkName.DEV.equals(getNetwork())) .devMode(NetworkName.DEV.equals(getNetwork()))
.nodePrivateKeyFile(nodePrivateKeyFile()) .nodePrivateKeyFile(nodePrivateKeyFile())
.metricsSystem(metricsSystem) .metricsSystem(metricsSystem)
.privacyParameters(orionConfiguration()) .privacyParameters(privacyParameters())
.build(); .build();
} catch (final InvalidConfigurationException e) { } catch (final InvalidConfigurationException e) {
throw new ExecutionException(new CommandLine(this), e.getMessage()); throw new ExecutionException(new CommandLine(this), e.getMessage());
@ -750,7 +750,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
return Optional.of(permissioningConfiguration); return Optional.of(permissioningConfiguration);
} }
private PrivacyParameters orionConfiguration() throws IOException { private PrivacyParameters privacyParameters() throws IOException {
CommandLineUtils.checkOptionDependencies( CommandLineUtils.checkOptionDependencies(
logger, logger,

@ -71,8 +71,8 @@ import picocli.CommandLine;
public class PantheonCommandTest extends CommandTestAbstract { public class PantheonCommandTest extends CommandTestAbstract {
private final String ORION_URI = "http://1.2.3.4:5555"; private final String ENCLAVE_URI = "http://1.2.3.4:5555";
private final String ORION_PUBLIC_KEY = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; private final String ENCLAVE_PUBLIC_KEY = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
private final String VALID_NODE_ID = private final String VALID_NODE_ID =
"6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"; "6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0";
static final String PERMISSIONING_CONFIG_TOML = "permissioning_config.toml"; static final String PERMISSIONING_CONFIG_TOML = "permissioning_config.toml";
@ -1822,24 +1822,24 @@ public class PantheonCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void mustUseOrionUriAndOptions() throws IOException { public void mustUseEnclaveUriAndOptions() throws IOException {
final URL configFile = Resources.getResource("orion_publickey.pub"); final URL configFile = Resources.getResource("orion_publickey.pub");
parseCommand( parseCommand(
"--privacy-enabled", "--privacy-enabled",
"--privacy-url", "--privacy-url",
ORION_URI, ENCLAVE_URI,
"--privacy-public-key-file", "--privacy-public-key-file",
configFile.getPath()); configFile.getPath());
final ArgumentCaptor<PrivacyParameters> orionArg = final ArgumentCaptor<PrivacyParameters> enclaveArg =
ArgumentCaptor.forClass(PrivacyParameters.class); ArgumentCaptor.forClass(PrivacyParameters.class);
verify(mockControllerBuilder).privacyParameters(orionArg.capture()); verify(mockControllerBuilder).privacyParameters(enclaveArg.capture());
verify(mockControllerBuilder).build(); verify(mockControllerBuilder).build();
assertThat(orionArg.getValue().getUrl()).isEqualTo(ORION_URI); assertThat(enclaveArg.getValue().getUrl()).isEqualTo(ENCLAVE_URI);
assertThat(orionArg.getValue().getPublicKey()).isEqualTo(ORION_PUBLIC_KEY); assertThat(enclaveArg.getValue().getPublicKey()).isEqualTo(ENCLAVE_PUBLIC_KEY);
assertThat(commandOutput.toString()).isEmpty(); assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
@ -1852,7 +1852,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
parseCommand( parseCommand(
"--privacy-url", "--privacy-url",
ORION_URI, ENCLAVE_URI,
"--privacy-public-key-file", "--privacy-public-key-file",
file.getPath(), file.getPath(),
"--privacy-precompiled-address", "--privacy-precompiled-address",
@ -1870,15 +1870,15 @@ public class PantheonCommandTest extends CommandTestAbstract {
public void mustVerifyPrivacyIsDisabled() throws IOException { public void mustVerifyPrivacyIsDisabled() throws IOException {
parseCommand(); parseCommand();
final ArgumentCaptor<PrivacyParameters> orionArg = final ArgumentCaptor<PrivacyParameters> enclaveArg =
ArgumentCaptor.forClass(PrivacyParameters.class); ArgumentCaptor.forClass(PrivacyParameters.class);
verify(mockControllerBuilder).privacyParameters(orionArg.capture()); verify(mockControllerBuilder).privacyParameters(enclaveArg.capture());
verify(mockControllerBuilder).build(); verify(mockControllerBuilder).build();
assertThat(commandOutput.toString()).isEmpty(); assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(orionArg.getValue().isEnabled()).isEqualTo(false); assertThat(enclaveArg.getValue().isEnabled()).isEqualTo(false);
} }
private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException { private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException {

@ -20,6 +20,7 @@ include 'consensus:common'
include 'consensus:ibft' include 'consensus:ibft'
include 'consensus:ibftlegacy' include 'consensus:ibftlegacy'
include 'crypto' include 'crypto'
include 'enclave'
include 'errorprone-checks' include 'errorprone-checks'
include 'ethereum:blockcreation' include 'ethereum:blockcreation'
include 'ethereum:core' include 'ethereum:core'
@ -32,7 +33,6 @@ include 'ethereum:referencetests'
include 'ethereum:rlp' include 'ethereum:rlp'
include 'ethereum:trie' include 'ethereum:trie'
include 'metrics' include 'metrics'
include 'orion'
include 'pantheon' include 'pantheon'
include 'services:kvstore' include 'services:kvstore'
include 'services:queue' include 'services:queue'

Loading…
Cancel
Save