use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class SendWithRemoteEnclaveReconnectIT method beforeTest.
@Before
public void beforeTest() throws IOException {
EncryptorConfig encryptorConfig = new EncryptorConfig() {
{
setType(EncryptorType.NACL);
}
};
ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EnclaveType.REMOTE).with(encryptorConfig.getType()).with(ClientMode.TESSERA).buildAndStoreContext();
final PortUtil portGenerator = new PortUtil(50100);
final String serverUriTemplate = "http://localhost:%d";
KeyEncryptorFactory.newFactory().create(encryptorConfig);
final Config nodeConfig = new Config();
nodeConfig.setEncryptor(encryptorConfig);
JdbcConfig jdbcConfig = new JdbcConfig();
jdbcConfig.setUrl("jdbc:h2:mem:junit");
jdbcConfig.setUsername("sa");
jdbcConfig.setPassword("");
jdbcConfig.setAutoCreateTables(true);
nodeConfig.setJdbcConfig(jdbcConfig);
ServerConfig p2pServerConfig = new ServerConfig();
p2pServerConfig.setApp(AppType.P2P);
p2pServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
p2pServerConfig.setCommunicationType(CommunicationType.REST);
final ServerConfig q2tServerConfig = new ServerConfig();
q2tServerConfig.setApp(AppType.Q2T);
q2tServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
q2tServerConfig.setCommunicationType(CommunicationType.REST);
final Config enclaveConfig = new Config();
enclaveConfig.setEncryptor(nodeConfig.getEncryptor());
final ServerConfig enclaveServerConfig = new ServerConfig();
enclaveServerConfig.setApp(AppType.ENCLAVE);
enclaveServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
enclaveServerConfig.setCommunicationType(CommunicationType.REST);
nodeConfig.setServerConfigs(Arrays.asList(p2pServerConfig, q2tServerConfig, enclaveServerConfig));
KeyData keyPair = new KeyData();
keyPair.setPublicKey("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
keyPair.setPrivateKey("yAWAJjwPqUtNVlqGjSrBmr1/iIkghuOh1803Yzx9jLM=");
enclaveConfig.setKeys(new KeyConfiguration());
enclaveConfig.getKeys().setKeyData(Arrays.asList(keyPair));
nodeConfig.setPeers(Arrays.asList(new Peer(p2pServerConfig.getServerAddress())));
enclaveConfig.setServerConfigs(Arrays.asList(enclaveServerConfig));
Path configPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
configPath.toFile().deleteOnExit();
Path enclaveConfigPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
enclaveConfigPath.toFile().deleteOnExit();
try (OutputStream out = Files.newOutputStream(configPath)) {
JaxbUtil.marshalWithNoValidation(nodeConfig, out);
out.flush();
}
JaxbUtil.marshalWithNoValidation(enclaveConfig, System.out);
try (OutputStream out = Files.newOutputStream(enclaveConfigPath)) {
JaxbUtil.marshalWithNoValidation(enclaveConfig, out);
out.flush();
}
ConfigDescriptor configDescriptor = new ConfigDescriptor(NodeAlias.A, configPath, nodeConfig, enclaveConfig, enclaveConfigPath);
String key = configDescriptor.getKey().getPublicKey();
URL file = Utils.toUrl(configDescriptor.getPath());
String alias = configDescriptor.getAlias().name();
this.party = new Party(key, file, alias);
nodeExecManager = new NodeExecManager(configDescriptor);
enclaveExecManager = new EnclaveExecManager(configDescriptor);
enclaveExecManager.start();
nodeExecManager.start();
client = party.getRestClient();
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class VersionIT method getSupportedVersions.
@Test
public void getSupportedVersions() {
Map<URI, Party> uriPartyPairs = partyHelper.getParties().map(p -> Map.of(p.getQ2TUri(), p, p.getP2PUri(), p)).flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
uriPartyPairs.entrySet().forEach(pair -> {
URI u = pair.getKey();
Party party = pair.getValue();
Response response = party.getRestClient().target(u).path("version").path("api").request().get();
assertThat(response.getStatus()).describedAs("%s should return status 200", u).isEqualTo(200);
JsonArray versions = response.readEntity(JsonArray.class);
assertThat(versions.stream().map(JsonString.class::cast).map(JsonString::getString).toArray(String[]::new)).describedAs("%s/version/api should return 1.0, 2.0, 2.1, 3.0, 4.0, 5.0", u).containsExactly("1.0", "2.0", "2.1", "3.0", "4.0", "5.0");
});
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class PrivacyIT method updateExistingContractByParticipant.
@Test
public void updateExistingContractByParticipant() {
final String originalHash = sendContractCreationTransaction(PrivacyMode.PARTY_PROTECTION);
Party sender = partyHelper.findByAlias(NodeAlias.B);
SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(new RestUtils().createTransactionData());
sendRequest.setFrom(sender.getPublicKey());
List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.A).getPublicKey());
sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
sendRequest.setPrivacyFlag(PrivacyMode.PARTY_PROTECTION.getPrivacyFlag());
sendRequest.setAffectedContractTransactions(originalHash);
Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
assertThat(response.getStatus()).isEqualTo(201);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class PrivacyIT method sendPSVTransactionWithoutExecHashWillBeRejected.
@Test
public void sendPSVTransactionWithoutExecHashWillBeRejected() {
Party sender = partyHelper.findByAlias(NodeAlias.A);
SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(new RestUtils().createTransactionData());
sendRequest.setFrom(sender.getPublicKey());
List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
sendRequest.setPrivacyFlag(PrivacyMode.PRIVATE_STATE_VALIDATION.getPrivacyFlag());
sendRequest.setAffectedContractTransactions(new String[0]);
Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
assertThat(response.getStatus()).isEqualTo(400);
}
use of com.quorum.tessera.test.Party in project tessera by ConsenSys.
the class PrivacyIT method updateExistingContractByNonParticipant.
@Test
public void updateExistingContractByNonParticipant() {
final String originalHash = sendContractCreationTransaction(PrivacyMode.PARTY_PROTECTION);
Party sender = partyHelper.findByAlias(NodeAlias.C);
SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(new RestUtils().createTransactionData());
sendRequest.setFrom(sender.getPublicKey());
List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
sendRequest.setPrivacyFlag(PrivacyMode.PARTY_PROTECTION.getPrivacyFlag());
sendRequest.setAffectedContractTransactions(originalHash);
Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
assertThat(response.getStatus()).isEqualTo(403);
}
Aggregations