Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Fix privacy precompiled contract unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneetha17 committed Jan 31, 2019
1 parent ea19f4e commit 518a098
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void setUpOnce() throws Exception {

testHarness = OrionTestHarness.create(folder.newFolder().toPath());

orion = new Orion(testHarness.getConfig().clientUrl().toString());
orion = new Orion(testHarness.clientUrl());
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public BytesValue compute(final BytesValue input) {
return BytesValue.wrap(receiveResponse.getPayload());
// pass it to private tx processor
} catch (IOException e) {
LOG.error("Orion threw an unhandled exception.", e);
LOG.fatal("Orion threw an unhandled exception.", e);
return BytesValue.EMPTY;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,36 @@

import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;

public class PrivacyPrecompiledContractTest {
private final String actual = "Test String";
private final String publicKey = "public key";
private final BytesValue key = BytesValue.wrap(actual.getBytes(UTF_8));
private PrivacyPrecompiledContract privacyPrecompiledContract;
private static final Logger LOG = LogManager.getLogger();
private PrivacyPrecompiledContract brokenPrivateTransactionHandler;

Orion mockOrion() {
Orion mockOrion() throws IOException {
Orion mockOrion = mock(Orion.class);
ReceiveResponse response = new ReceiveResponse(actual.getBytes(UTF_8));
try {
when(mockOrion.receive(any(ReceiveRequest.class))).thenReturn(response);
} catch (IOException e) {
LOG.error("Orion: failed to test");
}
when(mockOrion.receive(any(ReceiveRequest.class))).thenReturn(response);
return mockOrion;
}

Orion brokenMockOrion() throws IOException {
Orion mockOrion = mock(Orion.class);
when(mockOrion.receive(any(ReceiveRequest.class))).thenThrow(IOException.class);
return mockOrion;
}

@Before
public void setUp() {
Orion orion = mockOrion();
public void setUp() throws IOException {
privacyPrecompiledContract =
new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), "public key", orion);
new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), publicKey, mockOrion());
brokenPrivateTransactionHandler =
new PrivacyPrecompiledContract(
new SpuriousDragonGasCalculator(), publicKey, brokenMockOrion());
}

@Test
Expand All @@ -63,4 +66,11 @@ public void testPrivacyPrecompiledContract() {
String exp = new String(expected.extractArray(), UTF_8);
assertThat(exp).isEqualTo(actual);
}

@Test
public void enclaveIsDownWhileHandling() {
final BytesValue expected = brokenPrivateTransactionHandler.compute(key);

assertThat(expected).isEqualTo(BytesValue.EMPTY);
}
}

0 comments on commit 518a098

Please sign in to comment.