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

[PAN-3071] use object parameter instead of list of parameters for priv_createPrivacyGroup #1868

Merged
merged 12 commits into from
Aug 30, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaSendRawTransactionTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivCreatePrivacyGroupTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivCreatePrivacyGroupTransactionWithoutDescription;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivCreatePrivacyGroupTransactionWithoutName;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivCreatePrivacyGroupWithoutOptionalParamsTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivFindPrivacyGroupTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivGetTransactionCountTransaction;
Expand Down Expand Up @@ -44,6 +46,16 @@ public PrivCreatePrivacyGroupTransaction createPrivacyGroup(
return new PrivCreatePrivacyGroupTransaction(addresses, name, description);
}

public PrivCreatePrivacyGroupTransactionWithoutName createPrivacyGroupWithoutName(
final List<String> addresses, final String description) {
return new PrivCreatePrivacyGroupTransactionWithoutName(addresses, description);
}

public PrivCreatePrivacyGroupTransactionWithoutDescription createPrivacyGroupWithoutDescription(
final List<String> addresses, final String name) {
return new PrivCreatePrivacyGroupTransactionWithoutDescription(addresses, name);
}

public PrivCreatePrivacyGroupWithoutOptionalParamsTransaction
createPrivacyGroupWithoutOptionalParams(final List<String> addresses) {
return new PrivCreatePrivacyGroupWithoutOptionalParamsTransaction(addresses);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* 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.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv;

import static org.assertj.core.api.Assertions.assertThat;

import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;
import java.util.List;

public class PrivCreatePrivacyGroupTransactionWithoutDescription implements Transaction<String> {
private final List<String> addresses;
private final String name;

public PrivCreatePrivacyGroupTransactionWithoutDescription(
final List<String> addresses, final String name) {
this.addresses = addresses;
this.name = name;
}

@Override
public String execute(final NodeRequests node) {
try {
final PrivRequestFactory.PrivCreatePrivacyGroupResponse result =
node.priv().privCreatePrivacyGroupWithoutDescription(addresses, name).send();
assertThat(result).isNotNull();
return result.getResult();
} catch (final IOException e) {
throw new RuntimeException(e);
iikirilov marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* 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.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv;

import static org.assertj.core.api.Assertions.assertThat;

import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;
import java.util.List;

public class PrivCreatePrivacyGroupTransactionWithoutName implements Transaction<String> {
private final List<String> addresses;
private final String description;

public PrivCreatePrivacyGroupTransactionWithoutName(
final List<String> addresses, final String description) {
this.addresses = addresses;
this.description = description;
}

@Override
public String execute(final NodeRequests node) {
try {
final PrivRequestFactory.PrivCreatePrivacyGroupResponse result =
node.priv().privCreatePrivacyGroupWithoutName(addresses, description).send();
assertThat(result).isNotNull();
return result.getResult();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv;

import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -48,7 +49,28 @@ public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroup(
final List<String> addresses, final String name, final String description) {
return new Request<>(
"priv_createPrivacyGroup",
Lists.newArrayList(addresses, name, description),
Lists.newArrayList(
new CreatePrivacyGroupParameter(addresses.toArray(new String[] {}), name, description)),
web3jService,
PrivCreatePrivacyGroupResponse.class);
}

public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroupWithoutName(
final List<String> addresses, final String description) {
return new Request<>(
"priv_createPrivacyGroup",
Collections.singletonList(
new CreatePrivacyGroupParameter(addresses.toArray(new String[] {}), null, description)),
web3jService,
PrivCreatePrivacyGroupResponse.class);
}

public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroupWithoutDescription(
final List<String> addresses, final String name) {
return new Request<>(
"priv_createPrivacyGroup",
Collections.singletonList(
new CreatePrivacyGroupParameter(addresses.toArray(new String[] {}), name, null)),
web3jService,
PrivCreatePrivacyGroupResponse.class);
}
Expand All @@ -57,7 +79,8 @@ public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroupWithoutO
final List<String> addresses) {
return new Request<>(
"priv_createPrivacyGroup",
Collections.singletonList(addresses),
Collections.singletonList(
new CreatePrivacyGroupParameter(addresses.toArray(new String[] {}), null, null)),
web3jService,
PrivCreatePrivacyGroupResponse.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.List;

import org.awaitility.Awaitility;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -86,7 +87,7 @@ public void nodeCanCreatePrivacyGroup() {
"my group description"));

assertThat(privacyGroupId).isNotNull();

verifyGroupWasCreated();
final List<PrivacyGroup> privacyGroups =
privacyNet
.getNode("Alice")
Expand All @@ -103,6 +104,66 @@ public void nodeCanCreatePrivacyGroup() {
assertThat(privacyGroups.get(0).getMembers().length).isEqualTo(2);
}

@Test
public void nodeCanCreatePrivacyGroupWithoutName() {
final String privacyGroupId =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.createPrivacyGroupWithoutName(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0)),
"my group description"));

assertThat(privacyGroupId).isNotNull();
verifyGroupWasCreated();
final List<PrivacyGroup> privacyGroups =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.findPrivacyGroup(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0))));

assertThat(privacyGroups.size()).isEqualTo(1);
assertThat(privacyGroups.get(0).getPrivacyGroupId()).isEqualTo(privacyGroupId);
assertThat(privacyGroups.get(0).getName()).isEqualTo("Default Name");
rain-on marked this conversation as resolved.
Show resolved Hide resolved
assertThat(privacyGroups.get(0).getDescription()).isEqualTo("my group description");
assertThat(privacyGroups.get(0).getMembers().length).isEqualTo(2);
iikirilov marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void nodeCanCreatePrivacyGroupWithoutDescription() {
final String privacyGroupId =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.createPrivacyGroupWithoutDescription(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0)),
"myGroupName"));

assertThat(privacyGroupId).isNotNull();
verifyGroupWasCreated();
final List<PrivacyGroup> privacyGroups =
privacyNet
.getNode("Alice")
iikirilov marked this conversation as resolved.
Show resolved Hide resolved
.execute(
privateTransactions.findPrivacyGroup(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0))));

assertThat(privacyGroups.size()).isEqualTo(1);
assertThat(privacyGroups.get(0).getPrivacyGroupId()).isEqualTo(privacyGroupId);
assertThat(privacyGroups.get(0).getName()).isEqualTo("myGroupName");
assertThat(privacyGroups.get(0).getDescription()).isEqualTo("Default Description");
iikirilov marked this conversation as resolved.
Show resolved Hide resolved
assertThat(privacyGroups.get(0).getMembers().length).isEqualTo(2);
}

@Test
public void nodeCanCreatePrivacyGroupWithoutOptionalParams() {
final String privacyGroupId =
Expand All @@ -115,7 +176,7 @@ public void nodeCanCreatePrivacyGroupWithoutOptionalParams() {
privacyNet.getEnclave("Bob").getPublicKeys().get(0))));

assertThat(privacyGroupId).isNotNull();

verifyGroupWasCreated();
final List<PrivacyGroup> privacyGroups =
privacyNet
.getNode("Alice")
Expand All @@ -131,4 +192,27 @@ public void nodeCanCreatePrivacyGroupWithoutOptionalParams() {
assertThat(privacyGroups.get(0).getDescription()).isEqualTo("Default Description");
assertThat(privacyGroups.get(0).getMembers().length).isEqualTo(2);
}

private void verifyGroupWasCreated() {
privacyNet
.getNode("Alice")
iikirilov marked this conversation as resolved.
Show resolved Hide resolved
.verify(
node ->
Awaitility.await()
.until(
() ->
node.execute(
privateTransactions.findPrivacyGroup(
List.of(
privacyNet
.getEnclave("Alice")
.getPublicKeys()
.get(0),
privacyNet
.getEnclave("Bob")
.getPublicKeys()
.get(0))))
.size()
> 0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivGetPrivateTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.TransactionWithMetadata;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.permissioning.PermReloadPermissionsFromFile;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromWhitelist;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromWhitelist;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea.EeaGetTransactionCount;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea.EeaGetTransactionReceipt;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea.EeaPrivateNonceProvider;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea.EeaSendRawTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivCreatePrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivDeletePrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivFindPrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivGetPrivacyPrecompileAddress;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivGetPrivateTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivGetTransactionCount;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea.EeaGetTransactionCount;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea.EeaGetTransactionReceipt;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea.EeaPrivateNonceProvider;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea.EeaSendRawTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivCreatePrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivDeletePrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivFindPrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivGetPrivacyPrecompileAddress;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionCount;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockReplay;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTracer;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.TransactionTracer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea;
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea;

import static org.apache.logging.log4j.LogManager.getLogger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea;
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea;

import static org.apache.logging.log4j.LogManager.getLogger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea;
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea;

import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.FindPrivacyGroupRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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.
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.eea;
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.methods.eea;

import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason;
import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcErrorConverter.convertTransactionInvalidReason;
Expand Down
Loading