mirror of https://github.com/hyperledger/besu
[PAN-2941] Refactor privacy acceptance tests (#1864)
* update web3j 4.5.0 + use pantheon module in favour of core * remove custom eea/privacy rpc calls -> use web3j instead * overhaul the conditions -> web3j does the polling for receipts for us * re-define a PrivacyNode - it is an object that holds a PantheonNode and an OrionTestHarness * do not start OrionTestHarness prematurely - calling PrivacyNode.start() will start an Orion node followed by it's accompanying Pantheon node * stop and close resources properly -> clean-up removes the created temporary directories correctly Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
402937a459
commit
c691f488e2
@ -1,30 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class EeaConditions { |
||||
|
||||
private final EeaTransactions transactions; |
||||
|
||||
public EeaConditions(final EeaTransactions transactions) { |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
public Condition expectSuccessfulTransactionReceipt(final String transactionHash) { |
||||
return new ExpectSuccessfulEeaGetTransactionReceipt( |
||||
transactions.getTransactionReceipt(transactionHash)); |
||||
} |
||||
} |
@ -1,35 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static org.junit.Assert.assertNull; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class ExpectNoPrivateContractDeployedReceipt extends GetValidPrivateTransactionReceipt { |
||||
|
||||
public ExpectNoPrivateContractDeployedReceipt( |
||||
final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
final PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
|
||||
assertNull(privateTxReceipt.getContractAddress()); |
||||
} |
||||
} |
@ -1,37 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static junit.framework.TestCase.assertTrue; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class ExpectNoValidPrivateContractEventsEmitted extends GetValidPrivateTransactionReceipt { |
||||
|
||||
public ExpectNoValidPrivateContractEventsEmitted( |
||||
final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
final PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
|
||||
if (privateTxReceipt.getLogs() != null) { |
||||
assertTrue(privateTxReceipt.getLogs().isEmpty()); |
||||
} |
||||
} |
||||
} |
@ -1,37 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class ExpectNoValidPrivateContractValuesReturned extends GetValidPrivateTransactionReceipt { |
||||
|
||||
public ExpectNoValidPrivateContractValuesReturned( |
||||
final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
final PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
|
||||
if (privateTxReceipt.getOutput() != null) { |
||||
assertEquals("0x", privateTxReceipt.getOutput()); |
||||
} |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright 2018 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.condition.eea; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaGetTransactionReceiptTransaction; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
|
||||
public class ExpectSuccessfulEeaGetTransactionReceipt implements Condition { |
||||
|
||||
private final EeaGetTransactionReceiptTransaction transaction; |
||||
|
||||
public ExpectSuccessfulEeaGetTransactionReceipt( |
||||
final EeaGetTransactionReceiptTransaction transaction) { |
||||
this.transaction = transaction; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
waitFor( |
||||
() -> { |
||||
final PrivateTransactionReceipt response = node.execute(transaction); |
||||
assertThat(response.getContractAddress()).isNotEqualTo("0x"); |
||||
}); |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNotEquals; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class ExpectValidPrivateContractDeployedReceipt extends GetValidPrivateTransactionReceipt { |
||||
|
||||
private final String contractAddress; |
||||
|
||||
public ExpectValidPrivateContractDeployedReceipt( |
||||
final String contractAddress, final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
this.contractAddress = contractAddress; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
final PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
|
||||
assertEquals(contractAddress, privateTxReceipt.getContractAddress()); |
||||
assertNotEquals("0x", privateTxReceipt.getOutput()); |
||||
} |
||||
} |
@ -1,44 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
import java.math.BigInteger; |
||||
|
||||
import org.web3j.utils.Numeric; |
||||
|
||||
public class ExpectValidPrivateContractEventsEmitted extends GetValidPrivateTransactionReceipt { |
||||
|
||||
private final String eventValue; |
||||
|
||||
public ExpectValidPrivateContractEventsEmitted( |
||||
final String eventValue, final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
this.eventValue = eventValue; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
|
||||
String event = privateTxReceipt.getLogs().get(0).getData().substring(66, 130); |
||||
assertEquals( |
||||
new BigInteger(eventValue), Numeric.decodeQuantity(Numeric.prependHexPrefix(event))); |
||||
} |
||||
} |
@ -1,44 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
import tech.pegasys.pantheon.util.bytes.BytesValue; |
||||
|
||||
import java.math.BigInteger; |
||||
|
||||
import org.web3j.utils.Numeric; |
||||
|
||||
public class ExpectValidPrivateContractValuesReturned extends GetValidPrivateTransactionReceipt { |
||||
|
||||
private final String returnValue; |
||||
|
||||
public ExpectValidPrivateContractValuesReturned( |
||||
final String returnValue, final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
this.returnValue = returnValue; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
final PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
|
||||
BytesValue output = BytesValue.fromHexString(privateTxReceipt.getOutput()); |
||||
assertEquals(new BigInteger(returnValue), Numeric.decodeQuantity(output.toString())); |
||||
} |
||||
} |
@ -1,36 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.junit.Assert.assertNotNull; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class ExpectValidPrivateTransactionReceipt extends GetValidPrivateTransactionReceipt { |
||||
|
||||
public ExpectValidPrivateTransactionReceipt( |
||||
final EeaConditions eea, final EeaTransactions transactions) { |
||||
super(eea, transactions); |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PantheonNode node, final String transactionHash) { |
||||
final PrivateTransactionReceipt privateTxReceipt = |
||||
getPrivateTransactionReceipt(node, transactionHash); |
||||
assertNotNull(privateTxReceipt); |
||||
assertThat(privateTxReceipt.getFrom()).isNotBlank(); |
||||
} |
||||
} |
@ -1,37 +0,0 @@ |
||||
/* |
||||
* 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.condition.eea; |
||||
|
||||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaRequestFactory.PrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public abstract class GetValidPrivateTransactionReceipt implements EeaCondition { |
||||
|
||||
private EeaConditions eea; |
||||
private EeaTransactions transactions; |
||||
|
||||
GetValidPrivateTransactionReceipt(final EeaConditions eea, final EeaTransactions transactions) { |
||||
this.eea = eea; |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
PrivateTransactionReceipt getPrivateTransactionReceipt( |
||||
final PantheonNode node, final String transactionHash) { |
||||
|
||||
waitFor(() -> node.verify(eea.expectSuccessfulTransactionReceipt(transactionHash))); |
||||
return node.execute(transactions.getPrivateTransactionReceipt(transactionHash)); |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
/* |
||||
* 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.node.configuration.privacy; |
||||
|
||||
import tech.pegasys.orion.testutil.OrionKeyConfiguration; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonNodeConfiguration; |
||||
|
||||
public class PrivacyNodeConfiguration { |
||||
|
||||
private final PantheonNodeConfiguration pantheonConfig; |
||||
private final OrionKeyConfiguration orionConfig; |
||||
|
||||
PrivacyNodeConfiguration( |
||||
final PantheonNodeConfiguration pantheonConfig, final OrionKeyConfiguration orionConfig) { |
||||
this.pantheonConfig = pantheonConfig; |
||||
this.orionConfig = orionConfig; |
||||
} |
||||
|
||||
public PantheonNodeConfiguration getPantheonConfig() { |
||||
return pantheonConfig; |
||||
} |
||||
|
||||
public OrionKeyConfiguration getOrionKeyConfig() { |
||||
return orionConfig; |
||||
} |
||||
} |
@ -0,0 +1,81 @@ |
||||
/* |
||||
* 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.node.configuration.privacy; |
||||
|
||||
import tech.pegasys.orion.testutil.OrionKeyConfiguration; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.NodeConfigurationFactory; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonNodeConfigurationBuilder; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationFactory; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.account.PrivacyAccount; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
public class PrivacyNodeFactory { |
||||
|
||||
private final GenesisConfigurationFactory genesis = new GenesisConfigurationFactory(); |
||||
private final NodeConfigurationFactory node = new NodeConfigurationFactory(); |
||||
|
||||
private PrivacyNode create(final PrivacyNodeConfiguration privacyNodeConfig) throws IOException { |
||||
return new PrivacyNode(privacyNodeConfig); |
||||
} |
||||
|
||||
public PrivacyNode createPrivateTransactionEnabledMinerNode( |
||||
final String name, final PrivacyAccount privacyAccount) throws IOException { |
||||
return create( |
||||
new PrivacyNodeConfiguration( |
||||
new PantheonNodeConfigurationBuilder() |
||||
.name(name) |
||||
.miningEnabled() |
||||
.jsonRpcEnabled() |
||||
.webSocketEnabled() |
||||
.enablePrivateTransactions() |
||||
.keyFilePath(privacyAccount.getPrivateKeyPath()) |
||||
.build(), |
||||
new OrionKeyConfiguration( |
||||
privacyAccount.getEnclaveKeyPath(), privacyAccount.getEnclavePrivateKeyPath()))); |
||||
} |
||||
|
||||
public PrivacyNode createPrivateTransactionEnabledNode( |
||||
final String name, final PrivacyAccount privacyAccount) throws IOException { |
||||
return create( |
||||
new PrivacyNodeConfiguration( |
||||
new PantheonNodeConfigurationBuilder() |
||||
.name(name) |
||||
.jsonRpcEnabled() |
||||
.keyFilePath(privacyAccount.getPrivateKeyPath()) |
||||
.enablePrivateTransactions() |
||||
.webSocketEnabled() |
||||
.build(), |
||||
new OrionKeyConfiguration( |
||||
privacyAccount.getEnclaveKeyPath(), privacyAccount.getEnclavePrivateKeyPath()))); |
||||
} |
||||
|
||||
public PrivacyNode createIbft2NodePrivacyEnabled( |
||||
final String name, final PrivacyAccount privacyAccount) throws IOException { |
||||
return create( |
||||
new PrivacyNodeConfiguration( |
||||
new PantheonNodeConfigurationBuilder() |
||||
.name(name) |
||||
.miningEnabled() |
||||
.jsonRpcConfiguration(node.createJsonRpcWithIbft2EnabledConfig()) |
||||
.webSocketConfiguration(node.createWebSocketEnabledConfig()) |
||||
.devMode(false) |
||||
.genesisConfigProvider(genesis::createPrivacyIbft2GenesisConfig) |
||||
.keyFilePath(privacyAccount.getPrivateKeyPath()) |
||||
.enablePrivateTransactions() |
||||
.build(), |
||||
new OrionKeyConfiguration( |
||||
privacyAccount.getEnclaveKeyPath(), privacyAccount.getEnclavePrivateKeyPath()))); |
||||
} |
||||
} |
@ -1,78 +0,0 @@ |
||||
/* |
||||
* Copyright 2018 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.node.configuration.privacy; |
||||
|
||||
import tech.pegasys.orion.testutil.OrionTestHarness; |
||||
import tech.pegasys.pantheon.ethereum.core.MiningParameters; |
||||
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; |
||||
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; |
||||
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; |
||||
import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; |
||||
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; |
||||
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonFactoryConfiguration; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfiguration { |
||||
|
||||
private final OrionTestHarness orion; |
||||
|
||||
PrivacyPantheonFactoryConfiguration( |
||||
final String name, |
||||
final MiningParameters miningParameters, |
||||
final PrivacyParameters privacyParameters, |
||||
final JsonRpcConfiguration jsonRpcConfiguration, |
||||
final WebSocketConfiguration webSocketConfiguration, |
||||
final MetricsConfiguration metricsConfiguration, |
||||
final Optional<PermissioningConfiguration> permissioningConfiguration, |
||||
final Optional<String> keyFilePath, |
||||
final boolean devMode, |
||||
final GenesisConfigurationProvider genesisConfigProvider, |
||||
final boolean p2pEnabled, |
||||
final NetworkingConfiguration networkingConfiguration, |
||||
final boolean discoveryEnabled, |
||||
final boolean bootnodeEligible, |
||||
final boolean revertReasonEnabled, |
||||
final List<String> plugins, |
||||
final List<String> extraCLIOptions, |
||||
final OrionTestHarness orion) { |
||||
super( |
||||
name, |
||||
miningParameters, |
||||
privacyParameters, |
||||
jsonRpcConfiguration, |
||||
webSocketConfiguration, |
||||
metricsConfiguration, |
||||
permissioningConfiguration, |
||||
keyFilePath, |
||||
devMode, |
||||
genesisConfigProvider, |
||||
p2pEnabled, |
||||
networkingConfiguration, |
||||
discoveryEnabled, |
||||
bootnodeEligible, |
||||
revertReasonEnabled, |
||||
plugins, |
||||
extraCLIOptions, |
||||
new ArrayList<>()); |
||||
this.orion = orion; |
||||
} |
||||
|
||||
public OrionTestHarness getOrion() { |
||||
return orion; |
||||
} |
||||
} |
@ -1,55 +0,0 @@ |
||||
/* |
||||
* Copyright 2018 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.node.configuration.privacy; |
||||
|
||||
import tech.pegasys.orion.testutil.OrionTestHarness; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonFactoryConfiguration; |
||||
|
||||
public class PrivacyPantheonFactoryConfigurationBuilder { |
||||
|
||||
protected PantheonFactoryConfiguration config; |
||||
protected OrionTestHarness orion; |
||||
|
||||
public PrivacyPantheonFactoryConfigurationBuilder setConfig( |
||||
final PantheonFactoryConfiguration config) { |
||||
this.config = config; |
||||
return this; |
||||
} |
||||
|
||||
public PrivacyPantheonFactoryConfigurationBuilder setOrion(final OrionTestHarness orion) { |
||||
this.orion = orion; |
||||
return this; |
||||
} |
||||
|
||||
public PrivacyPantheonFactoryConfiguration build() { |
||||
return new PrivacyPantheonFactoryConfiguration( |
||||
config.getName(), |
||||
config.getMiningParameters(), |
||||
config.getPrivacyParameters(), |
||||
config.getJsonRpcConfiguration(), |
||||
config.getWebSocketConfiguration(), |
||||
config.getMetricsConfiguration(), |
||||
config.getPermissioningConfiguration(), |
||||
config.getKeyFilePath(), |
||||
config.isDevMode(), |
||||
config.getGenesisConfigProvider(), |
||||
config.isP2pEnabled(), |
||||
config.getNetworkingConfiguration(), |
||||
config.isDiscoveryEnabled(), |
||||
config.isBootnodeEligible(), |
||||
config.isRevertReasonEnabled(), |
||||
config.getPlugins(), |
||||
config.getExtraCLIOptions(), |
||||
orion); |
||||
} |
||||
} |
@ -1,115 +0,0 @@ |
||||
/* |
||||
* 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.node.configuration.privacy; |
||||
|
||||
import tech.pegasys.orion.testutil.OrionTestHarness; |
||||
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.NodeConfigurationFactory; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonFactoryConfigurationBuilder; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationFactory; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
public class PrivacyPantheonNodeFactory { |
||||
|
||||
private final GenesisConfigurationFactory genesis = new GenesisConfigurationFactory(); |
||||
private final NodeConfigurationFactory node = new NodeConfigurationFactory(); |
||||
|
||||
private static PrivacyNode create(final PrivacyPantheonFactoryConfiguration config) |
||||
throws IOException { |
||||
return new PrivacyNode( |
||||
config.getName(), |
||||
config.getMiningParameters(), |
||||
config.getPrivacyParameters(), |
||||
config.getJsonRpcConfiguration(), |
||||
config.getWebSocketConfiguration(), |
||||
config.getMetricsConfiguration(), |
||||
config.getPermissioningConfiguration(), |
||||
config.getKeyFilePath(), |
||||
config.isDevMode(), |
||||
config.getGenesisConfigProvider(), |
||||
config.isP2pEnabled(), |
||||
config.getNetworkingConfiguration(), |
||||
config.isDiscoveryEnabled(), |
||||
config.isBootnodeEligible(), |
||||
config.isRevertReasonEnabled(), |
||||
config.getPlugins(), |
||||
config.getExtraCLIOptions(), |
||||
config.getOrion()); |
||||
} |
||||
|
||||
public PrivacyNode createPrivateTransactionEnabledMinerNode( |
||||
final String name, |
||||
final PrivacyParameters privacyParameters, |
||||
final String keyFilePath, |
||||
final OrionTestHarness orionTestHarness) |
||||
throws IOException { |
||||
return create( |
||||
new PrivacyPantheonFactoryConfigurationBuilder() |
||||
.setConfig( |
||||
new PantheonFactoryConfigurationBuilder() |
||||
.name(name) |
||||
.miningEnabled() |
||||
.jsonRpcEnabled() |
||||
.keyFilePath(keyFilePath) |
||||
.enablePrivateTransactions(privacyParameters) |
||||
.webSocketEnabled() |
||||
.build()) |
||||
.setOrion(orionTestHarness) |
||||
.build()); |
||||
} |
||||
|
||||
public PrivacyNode createPrivateTransactionEnabledNode( |
||||
final String name, |
||||
final PrivacyParameters privacyParameters, |
||||
final String keyFilePath, |
||||
final OrionTestHarness orionTestHarness) |
||||
throws IOException { |
||||
return create( |
||||
new PrivacyPantheonFactoryConfigurationBuilder() |
||||
.setConfig( |
||||
new PantheonFactoryConfigurationBuilder() |
||||
.name(name) |
||||
.jsonRpcEnabled() |
||||
.keyFilePath(keyFilePath) |
||||
.enablePrivateTransactions(privacyParameters) |
||||
.webSocketEnabled() |
||||
.build()) |
||||
.setOrion(orionTestHarness) |
||||
.build()); |
||||
} |
||||
|
||||
public PrivacyNode createIbft2NodePrivacyEnabled( |
||||
final String name, |
||||
final PrivacyParameters privacyParameters, |
||||
final String keyFilePath, |
||||
final OrionTestHarness orionTestHarness) |
||||
throws IOException { |
||||
return create( |
||||
new PrivacyPantheonFactoryConfigurationBuilder() |
||||
.setConfig( |
||||
new PantheonFactoryConfigurationBuilder() |
||||
.name(name) |
||||
.miningEnabled() |
||||
.jsonRpcConfiguration(node.createJsonRpcWithIbft2EnabledConfig()) |
||||
.webSocketConfiguration(node.createWebSocketEnabledConfig()) |
||||
.devMode(false) |
||||
.genesisConfigProvider(genesis::createIbft2GenesisConfig) |
||||
.keyFilePath(keyFilePath) |
||||
.enablePrivateTransactions(privacyParameters) |
||||
.build()) |
||||
.setOrion(orionTestHarness) |
||||
.build()); |
||||
} |
||||
} |
@ -0,0 +1,141 @@ |
||||
/* |
||||
* 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.privacy; |
||||
|
||||
import static java.util.Collections.emptyList; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.NetConditions; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeRunner; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import org.apache.logging.log4j.LogManager; |
||||
import org.apache.logging.log4j.Logger; |
||||
|
||||
public class PrivacyCluster { |
||||
private static final Logger LOG = LogManager.getLogger(); |
||||
private final NetConditions net; |
||||
private final PantheonNodeRunner pantheonNodeRunner; |
||||
|
||||
private List<PrivacyNode> nodes = emptyList(); |
||||
private List<RunnableNode> runnableNodes = emptyList(); |
||||
private PrivacyNode bootNode; |
||||
|
||||
public PrivacyCluster(final NetConditions net) { |
||||
this.net = net; |
||||
this.pantheonNodeRunner = PantheonNodeRunner.instance(); |
||||
} |
||||
|
||||
public void start(final PrivacyNode... nodes) { |
||||
start(Arrays.asList(nodes)); |
||||
} |
||||
|
||||
public void start(final List<PrivacyNode> nodes) { |
||||
if (nodes.isEmpty()) { |
||||
throw new IllegalArgumentException("Can't start a cluster with no nodes"); |
||||
} |
||||
this.nodes = nodes; |
||||
this.runnableNodes = nodes.stream().map(n -> n.getPantheon()).collect(Collectors.toList()); |
||||
|
||||
final Optional<PrivacyNode> bootNode = selectAndStartBootnode(nodes); |
||||
|
||||
nodes.stream() |
||||
.filter(node -> bootNode.map(boot -> boot != node).orElse(true)) |
||||
.forEach(this::startNode); |
||||
|
||||
for (final PrivacyNode node : nodes) { |
||||
LOG.info("Awaiting peer discovery for node {}", node.getName()); |
||||
node.awaitPeerDiscovery(net.awaitPeerCount(nodes.size() - 1)); |
||||
} |
||||
|
||||
verifyAllOrionNetworkConnections(); |
||||
} |
||||
|
||||
public List<PrivacyNode> getNodes() { |
||||
return nodes; |
||||
} |
||||
|
||||
/** Verify that each Orion node has connected to every other Orion */ |
||||
public void verifyAllOrionNetworkConnections() { |
||||
for (int i = 0; i < nodes.size() - 1; i++) { |
||||
nodes.get(i).testOrionConnection(nodes.subList(i + 1, nodes.size())); |
||||
} |
||||
} |
||||
|
||||
public void stop() { |
||||
for (final PrivacyNode node : nodes) { |
||||
pantheonNodeRunner.stopNode(node.getPantheon()); |
||||
} |
||||
} |
||||
|
||||
public void stopNode(final PrivacyNode node) { |
||||
node.getOrion().stop(); |
||||
pantheonNodeRunner.stopNode(node.getPantheon()); |
||||
} |
||||
|
||||
public void close() { |
||||
stop(); |
||||
for (final PrivacyNode node : nodes) { |
||||
node.close(); |
||||
} |
||||
pantheonNodeRunner.shutdown(); |
||||
} |
||||
|
||||
private Optional<PrivacyNode> selectAndStartBootnode(final List<PrivacyNode> nodes) { |
||||
final Optional<PrivacyNode> bootNode = |
||||
nodes.stream() |
||||
.filter(node -> node.getConfiguration().isBootnodeEligible()) |
||||
.filter(node -> node.getConfiguration().isP2pEnabled()) |
||||
.filter(node -> node.getConfiguration().isDiscoveryEnabled()) |
||||
.findFirst(); |
||||
|
||||
bootNode.ifPresent( |
||||
b -> { |
||||
LOG.info("Selected node {} as bootnode", b.getName()); |
||||
startNode(b, true); |
||||
this.bootNode = b; |
||||
}); |
||||
|
||||
return bootNode; |
||||
} |
||||
|
||||
private void startNode(final PrivacyNode node) { |
||||
startNode(node, false); |
||||
} |
||||
|
||||
private void startNode(final PrivacyNode node, final boolean isBootNode) { |
||||
node.getConfiguration() |
||||
.setBootnodes(isBootNode ? emptyList() : Collections.singletonList(bootNode.enodeUrl())); |
||||
|
||||
node.getConfiguration() |
||||
.getGenesisConfigProvider() |
||||
.create(runnableNodes) |
||||
.ifPresent(node.getConfiguration()::setGenesisConfig); |
||||
|
||||
if (!isBootNode) { |
||||
node.addOtherEnclaveNode(bootNode.getOrion().nodeUrl()); |
||||
} |
||||
|
||||
LOG.info( |
||||
"Starting node {} (id = {}...{})", |
||||
node.getName(), |
||||
node.getNodeId().substring(0, 4), |
||||
node.getNodeId().substring(124)); |
||||
node.start(pantheonNodeRunner); |
||||
} |
||||
} |
@ -1,278 +0,0 @@ |
||||
/* |
||||
* 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.privacy; |
||||
|
||||
import tech.pegasys.orion.testutil.OrionTestHarness; |
||||
import tech.pegasys.orion.testutil.OrionTestHarnessFactory; |
||||
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.Cluster; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.privacy.PrivacyPantheonNodeFactory; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Path; |
||||
import java.util.Base64; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
|
||||
import com.google.common.base.Preconditions; |
||||
import org.apache.logging.log4j.LogManager; |
||||
import org.apache.logging.log4j.Logger; |
||||
import org.junit.rules.TemporaryFolder; |
||||
|
||||
public class PrivacyNet { |
||||
private static final Logger LOG = LogManager.getLogger(); |
||||
|
||||
private static final String PANTHEON_KEYPAIR_NODE_1 = "key"; |
||||
private static final String PANTHEON_KEYPAIR_NODE_2 = "key1"; |
||||
private static final String PANTHEON_KEYPAIR_NODE_3 = "key2"; |
||||
|
||||
private static final Map<String, String> KNOWN_PANTHEON_KEYPAIRS = new HashMap<>(); |
||||
|
||||
private final TemporaryFolder temporaryFolder; |
||||
private Cluster cluster; |
||||
|
||||
private Map<String, PrivacyNode> nodes; |
||||
|
||||
static { |
||||
KNOWN_PANTHEON_KEYPAIRS.put("Alice", PANTHEON_KEYPAIR_NODE_1); |
||||
KNOWN_PANTHEON_KEYPAIRS.put("Bob", PANTHEON_KEYPAIR_NODE_2); |
||||
KNOWN_PANTHEON_KEYPAIRS.put("Charlie", PANTHEON_KEYPAIR_NODE_3); |
||||
} |
||||
|
||||
private PrivacyNet( |
||||
final TemporaryFolder temporaryFolder, |
||||
final Map<String, PrivacyNode> privacyNodes, |
||||
final Cluster cluster) { |
||||
this.temporaryFolder = temporaryFolder; |
||||
this.nodes = privacyNodes; |
||||
this.cluster = cluster; |
||||
} |
||||
|
||||
public static PrivacyNet.Builder builder( |
||||
final TemporaryFolder temporaryFolder, |
||||
final PrivacyPantheonNodeFactory pantheonNodeFactory, |
||||
final Cluster cluster, |
||||
final boolean ibft) { |
||||
return new Builder(temporaryFolder, pantheonNodeFactory, cluster, ibft); |
||||
} |
||||
|
||||
public Map<String, PrivacyNode> getNodes() { |
||||
return nodes; |
||||
} |
||||
|
||||
public PrivacyNode getNode(final String name) { |
||||
return nodes.get(name); |
||||
} |
||||
|
||||
public OrionTestHarness getEnclave(final String name) { |
||||
return nodes.get(name).orion; |
||||
} |
||||
|
||||
public void startPrivacyNet() { |
||||
if (nodes == null) |
||||
throw new IllegalStateException( |
||||
"Cannot start network nodes. init method was never called to initialize the nodes"); |
||||
cluster.start(nodes.values().toArray(new PrivacyNode[0])); |
||||
verifyAllOrionNetworkConnections(); |
||||
} |
||||
|
||||
public void stopPrivacyNet() { |
||||
try { |
||||
cluster.stop(); |
||||
} catch (RuntimeException e) { |
||||
LOG.error("Error stopping Pantheon nodes. Logging and continuing.", e); |
||||
} |
||||
try { |
||||
stopOrionNodes(); |
||||
} catch (RuntimeException e) { |
||||
LOG.error("Error stopping Orion nodes. Logging and continuing.", e); |
||||
} |
||||
} |
||||
|
||||
private void stopOrionNodes() { |
||||
if (nodes == null) return; // Never started
|
||||
for (PrivacyNode node : nodes.values()) { |
||||
try { |
||||
node.orion.getOrion().stop(); |
||||
} catch (RuntimeException e) { |
||||
LOG.error( |
||||
String.format( |
||||
"Error stopping Orion node %s. Logging and continuing to shutdown other nodes.", |
||||
node.orion.nodeUrl()), |
||||
e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** Verify that each Orion node has connected to every other Orion */ |
||||
public void verifyAllOrionNetworkConnections() { |
||||
PrivacyNode[] nodeList = nodes.values().toArray(new PrivacyNode[0]); |
||||
for (int i = 0; i < nodeList.length; i++) { |
||||
for (int j = i + 1; j < nodeList.length; j++) { |
||||
nodeList[i].testOrionConnection(nodeList[j]); |
||||
} |
||||
for (int j = i + 2; j < nodeList.length; j = j + 2) { |
||||
nodeList[i].testOrionConnection(nodeList[j]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.append(String.format("temporaryFolder = %s\n", temporaryFolder.getRoot())); |
||||
for (PrivacyNode privacyNode : nodes.values()) { |
||||
sb.append(String.format("Pantheon Node Name = %s\n", privacyNode.getName())); |
||||
sb.append(String.format("Pantheon Address = %s\n", privacyNode.getAddress())); |
||||
sb.append( |
||||
String.format("Pantheon Private Key = %s\n", privacyNode.keyPair().getPrivateKey())); |
||||
sb.append(String.format("Pantheon Public Key = %s\n", privacyNode.keyPair().getPublicKey())); |
||||
sb.append(String.format("Orion Pub Key = %s\n", privacyNode.getOrionPubKeyBytes())); |
||||
sb.append( |
||||
String.format( |
||||
"Orion Pub Key Base64 = %s\n", |
||||
Base64.getEncoder() |
||||
.encodeToString(privacyNode.getOrionPubKeyBytes().extractArray()))); |
||||
|
||||
sb.append(String.format("Pantheon = %s\n", privacyNode)); |
||||
sb.append(String.format("Orion Config = %s\n", privacyNode.orion.getConfig())); |
||||
sb.append(String.format("Orion Pub Key = %s\n", privacyNode.getOrionPubKeyBytes())); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public static class Builder { |
||||
private TemporaryFolder temporaryFolder; |
||||
private PrivacyPantheonNodeFactory pantheonNodeFactory; |
||||
private Cluster cluster; |
||||
private final boolean ibft; |
||||
|
||||
private String otherOrionNode = null; |
||||
|
||||
private Map<String, PrivacyNode> nodes; |
||||
|
||||
private Builder( |
||||
final TemporaryFolder temporaryFolder, |
||||
final PrivacyPantheonNodeFactory pantheonNodeFactory, |
||||
final Cluster cluster, |
||||
final boolean ibft) { |
||||
this.temporaryFolder = temporaryFolder; |
||||
this.pantheonNodeFactory = pantheonNodeFactory; |
||||
this.cluster = cluster; |
||||
this.ibft = ibft; |
||||
} |
||||
|
||||
public Builder addMinerNode(final String name) throws IOException { |
||||
return addNode(name, true); |
||||
} |
||||
|
||||
public Builder addNode(final String name) throws IOException { |
||||
return addNode(name, false); |
||||
} |
||||
|
||||
public Builder addNode(final String name, final Optional<String> keyPath) throws IOException { |
||||
return addNode(name, false, keyPath); |
||||
} |
||||
|
||||
public Builder addNode(final String name, final boolean isMiningEnabled) throws IOException { |
||||
return addNode(name, isMiningEnabled, Optional.empty()); |
||||
} |
||||
|
||||
public Builder addNode( |
||||
final String name, final boolean isMiningEnabled, final Optional<String> keyPath) |
||||
throws IOException { |
||||
final PrivacyNode node = makeNode(name, isMiningEnabled, otherOrionNode, keyPath); |
||||
if (nodes == null) { |
||||
nodes = new HashMap<>(); |
||||
otherOrionNode = node.orion.nodeUrl(); // All nodes use first added node for discovery
|
||||
} |
||||
nodes.put(name, node); |
||||
return this; |
||||
} |
||||
|
||||
public PrivacyNode makeNode( |
||||
final String name, |
||||
final boolean isMiningEnabled, |
||||
final String otherOrionNodes, |
||||
final Optional<String> orionKeyPath) |
||||
throws IOException { |
||||
|
||||
final OrionTestHarness orion; |
||||
if (otherOrionNodes == null) { |
||||
// Need conditional because createEnclave will choke if passing in null
|
||||
orion = createEnclave(temporaryFolder, orionKeyPath); |
||||
} else { |
||||
orion = createEnclave(temporaryFolder, orionKeyPath, otherOrionNodes); |
||||
} |
||||
|
||||
final PrivacyNode node; |
||||
final String keyFilePath = KNOWN_PANTHEON_KEYPAIRS.get(name); |
||||
if (isMiningEnabled && !ibft) { |
||||
node = |
||||
pantheonNodeFactory.createPrivateTransactionEnabledMinerNode( |
||||
name, generatePrivacyParameters(orion), keyFilePath, orion); |
||||
} else if (!isMiningEnabled && !ibft) { |
||||
node = |
||||
pantheonNodeFactory.createPrivateTransactionEnabledNode( |
||||
name, generatePrivacyParameters(orion), keyFilePath, orion); |
||||
} else { |
||||
node = |
||||
pantheonNodeFactory.createIbft2NodePrivacyEnabled( |
||||
name, generatePrivacyParameters(orion), keyFilePath, orion); |
||||
} |
||||
|
||||
return node; |
||||
} |
||||
|
||||
protected OrionTestHarness createEnclave( |
||||
final TemporaryFolder temporaryFolder, |
||||
final Optional<String> pubKeyPath, |
||||
final String... othernode) |
||||
throws IOException { |
||||
final Path tmpPath = temporaryFolder.newFolder().toPath(); |
||||
final String orionPublicKeyFileName = pubKeyPath.orElse(provideNextKnownOrionKey()); |
||||
final String orionPrivateKeyFileName = privaKeyPathFromPubKeyPath(orionPublicKeyFileName); |
||||
return OrionTestHarnessFactory.create( |
||||
tmpPath, orionPublicKeyFileName, orionPrivateKeyFileName, othernode); |
||||
} |
||||
|
||||
private String privaKeyPathFromPubKeyPath(final String orionPublicKeyFileName) { |
||||
return orionPublicKeyFileName.substring(0, orionPublicKeyFileName.length() - 3) + "key"; |
||||
} |
||||
|
||||
private Integer nextKnownOrionKey = 0; |
||||
|
||||
private String provideNextKnownOrionKey() { |
||||
if (nextKnownOrionKey < 4) { |
||||
return String.format("orion_key_%d.pub", nextKnownOrionKey++); |
||||
} |
||||
throw new RuntimeException("Limit of known nodes reached"); |
||||
} |
||||
|
||||
private PrivacyParameters generatePrivacyParameters(final OrionTestHarness testHarness) |
||||
throws IOException { |
||||
return new PrivacyParameters.Builder() |
||||
.setEnabled(true) |
||||
.setEnclaveUrl(testHarness.clientUrl()) |
||||
.setEnclavePublicKeyUsingFile(testHarness.getConfig().publicKeys().get(0).toFile()) |
||||
.setDataDir(temporaryFolder.newFolder().toPath()) |
||||
.build(); |
||||
} |
||||
|
||||
public PrivacyNet build() { |
||||
Preconditions.checkNotNull(nodes); |
||||
return new PrivacyNet(temporaryFolder, nodes, cluster); |
||||
} |
||||
} |
||||
} |
@ -1,63 +0,0 @@ |
||||
/* |
||||
* 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.privacy; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.EeaConditions; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectNoPrivateContractDeployedReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectNoValidPrivateContractEventsEmitted; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectNoValidPrivateContractValuesReturned; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectValidPrivateContractDeployedReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectValidPrivateContractEventsEmitted; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectValidPrivateContractValuesReturned; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectValidPrivateTransactionReceipt; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; |
||||
|
||||
public class PrivateTransactionVerifier { |
||||
|
||||
private final EeaTransactions transactions; |
||||
private final EeaConditions eea; |
||||
|
||||
public PrivateTransactionVerifier(final EeaConditions eea, final EeaTransactions transactions) { |
||||
this.eea = eea; |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
public ExpectValidPrivateTransactionReceipt validPrivateTransactionReceipt() { |
||||
return new ExpectValidPrivateTransactionReceipt(eea, transactions); |
||||
} |
||||
|
||||
public ExpectValidPrivateContractDeployedReceipt validPrivateContractDeployed( |
||||
final String contractAddress) { |
||||
return new ExpectValidPrivateContractDeployedReceipt(contractAddress, eea, transactions); |
||||
} |
||||
|
||||
public ExpectNoPrivateContractDeployedReceipt noPrivateContractDeployed() { |
||||
return new ExpectNoPrivateContractDeployedReceipt(eea, transactions); |
||||
} |
||||
|
||||
public ExpectValidPrivateContractEventsEmitted validEventReturned(final String eventValue) { |
||||
return new ExpectValidPrivateContractEventsEmitted(eventValue, eea, transactions); |
||||
} |
||||
|
||||
public ExpectNoValidPrivateContractEventsEmitted noValidEventReturned() { |
||||
return new ExpectNoValidPrivateContractEventsEmitted(eea, transactions); |
||||
} |
||||
|
||||
public ExpectValidPrivateContractValuesReturned validOutputReturned(final String returnValue) { |
||||
return new ExpectValidPrivateContractValuesReturned(returnValue, eea, transactions); |
||||
} |
||||
|
||||
public ExpectNoValidPrivateContractValuesReturned noValidOutputReturned() { |
||||
return new ExpectNoValidPrivateContractValuesReturned(eea, transactions); |
||||
} |
||||
} |
@ -1,67 +0,0 @@ |
||||
/* |
||||
* 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.privacy; |
||||
|
||||
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; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class PrivateTransactions { |
||||
|
||||
public PrivateTransactions() {} |
||||
|
||||
public EeaSendRawTransactionTransaction deployPrivateSmartContract( |
||||
final String signedRawPrivateTransaction) { |
||||
return new EeaSendRawTransactionTransaction(signedRawPrivateTransaction); |
||||
} |
||||
|
||||
public EeaSendRawTransactionTransaction createPrivateRawTransaction( |
||||
final String signedRawPrivateTransaction) { |
||||
return new EeaSendRawTransactionTransaction(signedRawPrivateTransaction); |
||||
} |
||||
|
||||
public PrivGetTransactionCountTransaction getTransactionCount( |
||||
final String address, final String privacyGroupId) { |
||||
return new PrivGetTransactionCountTransaction(address, privacyGroupId); |
||||
} |
||||
|
||||
public PrivCreatePrivacyGroupTransaction createPrivacyGroup( |
||||
final List<String> addresses, final String name, final String description) { |
||||
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); |
||||
} |
||||
|
||||
public PrivFindPrivacyGroupTransaction findPrivacyGroup(final List<String> addresses) { |
||||
return new PrivFindPrivacyGroupTransaction(addresses); |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
/* |
||||
* 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.privacy.account; |
||||
|
||||
import java.io.File; |
||||
import java.net.URL; |
||||
|
||||
public class PrivacyAccount { |
||||
|
||||
private final URL privateKeyPath; |
||||
private final URL enclaveKeyPath; |
||||
private final URL enclavePrivateKeyPath; |
||||
|
||||
private PrivacyAccount( |
||||
final URL privateKeyPath, final URL enclavePublicKeyPath, final URL enclavePrivateKeyPath) { |
||||
this.privateKeyPath = privateKeyPath; |
||||
this.enclaveKeyPath = enclavePublicKeyPath; |
||||
this.enclavePrivateKeyPath = enclavePrivateKeyPath; |
||||
} |
||||
|
||||
public static PrivacyAccount create( |
||||
final URL privateKeyPath, final URL enclavePublicKeyPath, final URL enclavePrivateKeyPath) { |
||||
return new PrivacyAccount(privateKeyPath, enclavePublicKeyPath, enclavePrivateKeyPath); |
||||
} |
||||
|
||||
public String getPrivateKeyPath() { |
||||
return toStringResource(privateKeyPath); |
||||
} |
||||
|
||||
public String getEnclaveKeyPath() { |
||||
return toStringResource(enclaveKeyPath); |
||||
} |
||||
|
||||
public String getEnclavePrivateKeyPath() { |
||||
return toStringResource(enclavePrivateKeyPath); |
||||
} |
||||
|
||||
private String toStringResource(final URL path) { |
||||
return path.getPath().substring(path.getPath().lastIndexOf(File.separator) + 1); |
||||
} |
||||
} |
@ -0,0 +1,56 @@ |
||||
/* |
||||
* Copyright 2018 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.privacy.account; |
||||
|
||||
import java.net.URL; |
||||
|
||||
/** Supplier of known funded accounts defined in dev.json */ |
||||
public class PrivacyAccountResolver { |
||||
|
||||
public static final PrivacyAccount ALICE = |
||||
PrivacyAccount.create( |
||||
resolveResource("key"), |
||||
resolveResource("orion_key_0.pub"), |
||||
resolveResource("orion_key_0.key")); |
||||
|
||||
public static final PrivacyAccount BOB = |
||||
PrivacyAccount.create( |
||||
resolveResource("key1"), |
||||
resolveResource("orion_key_1.pub"), |
||||
resolveResource("orion_key_1.key")); |
||||
|
||||
public static final PrivacyAccount CHARLIE = |
||||
PrivacyAccount.create( |
||||
resolveResource("key2"), |
||||
resolveResource("orion_key_2.pub"), |
||||
resolveResource("orion_key_2.key")); |
||||
|
||||
private static URL resolveResource(final String resource) { |
||||
return PrivacyAccountResolver.class.getClassLoader().getResource(resource); |
||||
} |
||||
|
||||
public PrivacyAccountResolver() {} |
||||
|
||||
public PrivacyAccount resolve(final Integer account) { |
||||
switch (account) { |
||||
case 0: |
||||
return ALICE; |
||||
case 1: |
||||
return BOB; |
||||
case 2: |
||||
return CHARLIE; |
||||
default: |
||||
throw new RuntimeException("Unknown privacy account"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
/* |
||||
* 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.privacy.condition; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.transaction.PrivacyTransactions; |
||||
|
||||
public class ExpectNoPrivateTransactionReceipt implements PrivateCondition { |
||||
private final PrivacyTransactions transactions; |
||||
private final String transactionHash; |
||||
|
||||
public ExpectNoPrivateTransactionReceipt( |
||||
final PrivacyTransactions transactions, final String transactionHash) { |
||||
this.transactions = transactions; |
||||
this.transactionHash = transactionHash; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PrivacyNode node) { |
||||
assertThat(node.execute(transactions.getPrivateTransactionReceipt(transactionHash))).isNull(); |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
/* |
||||
* 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.privacy.condition; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.transaction.PrivacyTransactions; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.awaitility.Awaitility; |
||||
import org.web3j.protocol.pantheon.response.privacy.PrivacyGroup; |
||||
import org.web3j.utils.Base64String; |
||||
|
||||
public class ExpectValidPrivacyGroupCreated implements PrivateCondition { |
||||
|
||||
private final PrivacyTransactions transactions; |
||||
private final PrivacyGroup expected; |
||||
|
||||
public ExpectValidPrivacyGroupCreated( |
||||
final PrivacyTransactions transactions, final PrivacyGroup expected) { |
||||
this.transactions = transactions; |
||||
this.expected = expected; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PrivacyNode node) { |
||||
Awaitility.await() |
||||
.untilAsserted( |
||||
() -> { |
||||
final List<PrivacyGroup> groups = |
||||
node.execute( |
||||
transactions.findPrivacyGroup( |
||||
Base64String.unwrapList(expected.getMembers()))); |
||||
assertThat(groups).contains(expected); |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
/* |
||||
* 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.privacy.condition; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
import org.web3j.protocol.core.methods.response.TransactionReceipt; |
||||
import org.web3j.tx.Contract; |
||||
|
||||
public class ExpectValidPrivateContractDeployedReceipt implements PrivateContractCondition { |
||||
|
||||
private final String contractAddress; |
||||
private final String senderAddress; |
||||
|
||||
public ExpectValidPrivateContractDeployedReceipt( |
||||
final String contractAddress, final String senderAddress) { |
||||
this.contractAddress = contractAddress; |
||||
this.senderAddress = senderAddress; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Contract contract) { |
||||
|
||||
assertThat(contract).isNotNull(); |
||||
final Optional<TransactionReceipt> receipt = contract.getTransactionReceipt(); |
||||
|
||||
// We're expecting a receipt
|
||||
assertThat(receipt).isNotNull(); |
||||
assertThat(receipt.isPresent()).isTrue(); |
||||
final TransactionReceipt transactionReceipt = receipt.get(); |
||||
|
||||
// Contract transaction has no 'to' address or contract address
|
||||
assertThat(transactionReceipt.getTo()).isNull(); |
||||
|
||||
// Address generation is deterministic, based on the sender address and the transaction nonce
|
||||
assertThat(transactionReceipt.getContractAddress()).isEqualTo(contractAddress); |
||||
|
||||
// Address for the account that signed (and paid) for the contract deployment transaction
|
||||
assertThat(transactionReceipt.getFrom()).isEqualTo(senderAddress); |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
/* |
||||
* 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.privacy.condition; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.transaction.PrivacyTransactions; |
||||
|
||||
import org.web3j.protocol.eea.response.PrivateTransactionReceipt; |
||||
|
||||
public class ExpectValidPrivateTransactionReceipt implements PrivateCondition { |
||||
private final PrivacyTransactions transactions; |
||||
private final String transactionHash; |
||||
private final PrivateTransactionReceipt receipt; |
||||
|
||||
public ExpectValidPrivateTransactionReceipt( |
||||
final PrivacyTransactions transactions, |
||||
final String transactionHash, |
||||
final PrivateTransactionReceipt receipt) { |
||||
|
||||
this.transactions = transactions; |
||||
this.transactionHash = transactionHash; |
||||
this.receipt = receipt; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final PrivacyNode node) { |
||||
assertThat(node.execute(transactions.getPrivateTransactionReceipt(transactionHash))) |
||||
.isEqualTo(receipt); |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
/* |
||||
* 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.privacy.condition; |
||||
|
||||
import org.web3j.tx.Contract; |
||||
|
||||
public interface PrivateContractCondition { |
||||
void verify(final Contract contract); |
||||
} |
@ -0,0 +1,23 @@ |
||||
/* |
||||
* Copyright 2018 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.privacy.condition; |
||||
|
||||
public class PrivateContractVerifier { |
||||
|
||||
public PrivateContractVerifier() {} |
||||
|
||||
public ExpectValidPrivateContractDeployedReceipt validPrivateContractDeployed( |
||||
final String contractAddress, final String senderAddress) { |
||||
return new ExpectValidPrivateContractDeployedReceipt(contractAddress, senderAddress); |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
/* |
||||
* 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.privacy.condition; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.transaction.PrivacyTransactions; |
||||
|
||||
import org.web3j.protocol.eea.response.PrivateTransactionReceipt; |
||||
import org.web3j.protocol.pantheon.response.privacy.PrivacyGroup; |
||||
|
||||
public class PrivateTransactionVerifier { |
||||
|
||||
private final PrivacyTransactions transactions; |
||||
|
||||
public PrivateTransactionVerifier(final PrivacyTransactions transactions) { |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
public ExpectValidPrivateTransactionReceipt validPrivateTransactionReceipt( |
||||
final String transactionHash, final PrivateTransactionReceipt receipt) { |
||||
return new ExpectValidPrivateTransactionReceipt(transactions, transactionHash, receipt); |
||||
} |
||||
|
||||
public ExpectNoPrivateTransactionReceipt noPrivateTransactionReceipt( |
||||
final String transactionHash) { |
||||
return new ExpectNoPrivateTransactionReceipt(transactions, transactionHash); |
||||
} |
||||
|
||||
public ExpectValidPrivacyGroupCreated validPrivacyGroupCreated(final PrivacyGroup expected) { |
||||
return new ExpectValidPrivacyGroupCreated(transactions, expected); |
||||
} |
||||
} |
@ -0,0 +1,77 @@ |
||||
/* |
||||
* 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.privacy.contract; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; |
||||
|
||||
import java.io.IOException; |
||||
import java.math.BigInteger; |
||||
import java.util.List; |
||||
|
||||
import org.web3j.crypto.Credentials; |
||||
import org.web3j.protocol.pantheon.Pantheon; |
||||
import org.web3j.tx.LegacyPrivateTransactionManager; |
||||
import org.web3j.tx.PrivateTransactionManager; |
||||
import org.web3j.tx.gas.PantheonPrivacyGasProvider; |
||||
import org.web3j.utils.Base64String; |
||||
|
||||
public class CallPrivateSmartContractFunction implements Transaction<String> { |
||||
|
||||
private static final PantheonPrivacyGasProvider GAS_PROVIDER = |
||||
new PantheonPrivacyGasProvider(BigInteger.valueOf(1000)); |
||||
private final String contractAddress; |
||||
private final String encodedFunction; |
||||
private final Credentials senderCredentials; |
||||
private final long chainId; |
||||
private final Base64String privateFrom; |
||||
private final List<Base64String> privateFor; |
||||
|
||||
public CallPrivateSmartContractFunction( |
||||
final String contractAddress, |
||||
final String encodedFunction, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final List<String> privateFor) { |
||||
|
||||
this.contractAddress = contractAddress; |
||||
this.encodedFunction = encodedFunction; |
||||
this.senderCredentials = Credentials.create(transactionSigningKey); |
||||
this.chainId = chainId; |
||||
this.privateFrom = Base64String.wrap(privateFrom); |
||||
this.privateFor = Base64String.wrapList(privateFor); |
||||
} |
||||
|
||||
@Override |
||||
public String execute(final NodeRequests node) { |
||||
final Pantheon pantheon = node.privacy().getPantheonClient(); |
||||
|
||||
final PrivateTransactionManager privateTransactionManager = |
||||
new LegacyPrivateTransactionManager( |
||||
pantheon, GAS_PROVIDER, senderCredentials, chainId, privateFrom, privateFor); |
||||
|
||||
try { |
||||
return privateTransactionManager |
||||
.sendTransaction( |
||||
GAS_PROVIDER.getGasPrice(), |
||||
GAS_PROVIDER.getGasLimit(), |
||||
contractAddress, |
||||
encodedFunction, |
||||
null) |
||||
.getTransactionHash(); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
/* |
||||
* 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.privacy.contract; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.math.BigInteger; |
||||
import java.util.List; |
||||
|
||||
import org.web3j.crypto.Credentials; |
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.RemoteCall; |
||||
import org.web3j.tx.Contract; |
||||
import org.web3j.tx.LegacyPrivateTransactionManager; |
||||
import org.web3j.tx.PrivateTransactionManager; |
||||
import org.web3j.tx.TransactionManager; |
||||
import org.web3j.tx.gas.ContractGasProvider; |
||||
import org.web3j.tx.gas.PantheonPrivacyGasProvider; |
||||
import org.web3j.utils.Base64String; |
||||
|
||||
public class DeployPrivateSmartContractTransaction<T extends Contract> implements Transaction<T> { |
||||
|
||||
private static final PantheonPrivacyGasProvider GAS_PROVIDER = |
||||
new PantheonPrivacyGasProvider(BigInteger.valueOf(1000)); |
||||
private static final Object METHOD_IS_STATIC = null; |
||||
|
||||
private final Class<T> clazz; |
||||
private final Credentials senderCredentials; |
||||
private final long chainId; |
||||
private final Base64String privateFrom; |
||||
private final List<Base64String> privateFor; |
||||
|
||||
public DeployPrivateSmartContractTransaction( |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final List<String> privateFor) { |
||||
this.clazz = clazz; |
||||
this.senderCredentials = Credentials.create(transactionSigningKey); |
||||
this.chainId = chainId; |
||||
this.privateFrom = Base64String.wrap(privateFrom); |
||||
this.privateFor = Base64String.wrapList(privateFor); |
||||
} |
||||
|
||||
@Override |
||||
public T execute(final NodeRequests node) { |
||||
final PrivateTransactionManager privateTransactionManager = |
||||
new LegacyPrivateTransactionManager( |
||||
node.privacy().getPantheonClient(), |
||||
GAS_PROVIDER, |
||||
senderCredentials, |
||||
chainId, |
||||
privateFrom, |
||||
privateFor); |
||||
try { |
||||
final Method method = |
||||
clazz.getMethod( |
||||
"deploy", Web3j.class, TransactionManager.class, ContractGasProvider.class); |
||||
|
||||
final Object invoked = |
||||
method.invoke( |
||||
METHOD_IS_STATIC, |
||||
node.privacy().getPantheonClient(), |
||||
privateTransactionManager, |
||||
GAS_PROVIDER); |
||||
|
||||
return cast(invoked).send(); |
||||
} catch (final Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
private RemoteCall<T> cast(final Object invokedMethod) { |
||||
return (RemoteCall<T>) invokedMethod; |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
/* |
||||
* 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.privacy.contract; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.math.BigInteger; |
||||
|
||||
import org.web3j.crypto.Credentials; |
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.RemoteCall; |
||||
import org.web3j.tx.Contract; |
||||
import org.web3j.tx.PantheonPrivateTransactionManager; |
||||
import org.web3j.tx.PrivateTransactionManager; |
||||
import org.web3j.tx.TransactionManager; |
||||
import org.web3j.tx.gas.ContractGasProvider; |
||||
import org.web3j.tx.gas.PantheonPrivacyGasProvider; |
||||
import org.web3j.utils.Base64String; |
||||
|
||||
public class DeployPrivateSmartContractWithPrivacyGroupIdTransaction<T extends Contract> |
||||
implements Transaction<T> { |
||||
|
||||
private static final PantheonPrivacyGasProvider GAS_PROVIDER = |
||||
new PantheonPrivacyGasProvider(BigInteger.valueOf(1000)); |
||||
private static final Object METHOD_IS_STATIC = null; |
||||
|
||||
private final Class<T> clazz; |
||||
private final Credentials senderCredentials; |
||||
private final long chainId; |
||||
private final Base64String privateFrom; |
||||
private final Base64String privacyGroupId; |
||||
|
||||
public DeployPrivateSmartContractWithPrivacyGroupIdTransaction( |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final String privacyGroupId) { |
||||
this.clazz = clazz; |
||||
this.senderCredentials = Credentials.create(transactionSigningKey); |
||||
this.chainId = chainId; |
||||
this.privateFrom = Base64String.wrap(privateFrom); |
||||
this.privacyGroupId = Base64String.wrap(privacyGroupId); |
||||
} |
||||
|
||||
@Override |
||||
public T execute(final NodeRequests node) { |
||||
final PrivateTransactionManager privateTransactionManager = |
||||
new PantheonPrivateTransactionManager( |
||||
node.privacy().getPantheonClient(), |
||||
GAS_PROVIDER, |
||||
senderCredentials, |
||||
chainId, |
||||
privateFrom, |
||||
privacyGroupId); |
||||
try { |
||||
final Method method = |
||||
clazz.getMethod( |
||||
"deploy", Web3j.class, TransactionManager.class, ContractGasProvider.class); |
||||
|
||||
final Object invoked = |
||||
method.invoke( |
||||
METHOD_IS_STATIC, |
||||
node.privacy().getPantheonClient(), |
||||
privateTransactionManager, |
||||
GAS_PROVIDER); |
||||
|
||||
return cast(invoked).send(); |
||||
} catch (final Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
private RemoteCall<T> cast(final Object invokedMethod) { |
||||
return (RemoteCall<T>) invokedMethod; |
||||
} |
||||
} |
@ -0,0 +1,91 @@ |
||||
/* |
||||
* 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.privacy.contract; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.math.BigInteger; |
||||
import java.util.List; |
||||
|
||||
import org.web3j.crypto.Credentials; |
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.tx.Contract; |
||||
import org.web3j.tx.LegacyPrivateTransactionManager; |
||||
import org.web3j.tx.PrivateTransactionManager; |
||||
import org.web3j.tx.TransactionManager; |
||||
import org.web3j.tx.gas.ContractGasProvider; |
||||
import org.web3j.tx.gas.PantheonPrivacyGasProvider; |
||||
import org.web3j.utils.Base64String; |
||||
|
||||
public class LoadPrivateSmartContractTransaction<T extends Contract> implements Transaction<T> { |
||||
private static final PantheonPrivacyGasProvider GAS_PROVIDER = |
||||
new PantheonPrivacyGasProvider(BigInteger.valueOf(1000)); |
||||
private static final Object METHOD_IS_STATIC = null; |
||||
|
||||
private final Class<T> clazz; |
||||
private final Credentials senderCredentials; |
||||
private final long chainId; |
||||
private final Base64String privateFrom; |
||||
private final List<Base64String> privateFor; |
||||
private String contractAddress; |
||||
|
||||
public LoadPrivateSmartContractTransaction( |
||||
final String contractAddress, |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final List<String> privateFor) { |
||||
|
||||
this.contractAddress = contractAddress; |
||||
this.clazz = clazz; |
||||
this.senderCredentials = Credentials.create(transactionSigningKey); |
||||
this.chainId = chainId; |
||||
this.privateFrom = Base64String.wrap(privateFrom); |
||||
this.privateFor = Base64String.wrapList(privateFor); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
@Override |
||||
public T execute(final NodeRequests node) { |
||||
final PrivateTransactionManager privateTransactionManager = |
||||
new LegacyPrivateTransactionManager( |
||||
node.privacy().getPantheonClient(), |
||||
GAS_PROVIDER, |
||||
senderCredentials, |
||||
chainId, |
||||
privateFrom, |
||||
privateFor); |
||||
try { |
||||
final Method method = |
||||
clazz.getMethod( |
||||
"load", |
||||
String.class, |
||||
Web3j.class, |
||||
TransactionManager.class, |
||||
ContractGasProvider.class); |
||||
|
||||
return (T) |
||||
method.invoke( |
||||
METHOD_IS_STATIC, |
||||
contractAddress, |
||||
node.privacy().getPantheonClient(), |
||||
privateTransactionManager, |
||||
GAS_PROVIDER); |
||||
} catch (final Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,107 @@ |
||||
/* |
||||
* 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.privacy.contract; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
import org.web3j.tx.Contract; |
||||
|
||||
public class PrivateContractTransactions { |
||||
|
||||
public <T extends Contract> |
||||
DeployPrivateSmartContractWithPrivacyGroupIdTransaction<T> |
||||
createSmartContractWithPrivacyGroupId( |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final String privacyGroupId) { |
||||
return new DeployPrivateSmartContractWithPrivacyGroupIdTransaction<>( |
||||
clazz, transactionSigningKey, chainId, privateFrom, privacyGroupId); |
||||
} |
||||
|
||||
public <T extends Contract> DeployPrivateSmartContractTransaction<T> createSmartContract( |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final String... privateFor) { |
||||
return createSmartContract( |
||||
clazz, transactionSigningKey, chainId, privateFrom, Arrays.asList(privateFor)); |
||||
} |
||||
|
||||
public <T extends Contract> DeployPrivateSmartContractTransaction<T> createSmartContract( |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final List<String> privateFor) { |
||||
return new DeployPrivateSmartContractTransaction<>( |
||||
clazz, transactionSigningKey, chainId, privateFrom, privateFor); |
||||
} |
||||
|
||||
public CallPrivateSmartContractFunction callSmartContract( |
||||
final String contractAddress, |
||||
final String encodedFunction, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final String... privateFor) { |
||||
return callSmartContract( |
||||
contractAddress, |
||||
encodedFunction, |
||||
transactionSigningKey, |
||||
chainId, |
||||
privateFrom, |
||||
Arrays.asList(privateFor)); |
||||
} |
||||
|
||||
public CallPrivateSmartContractFunction callSmartContract( |
||||
final String contractAddress, |
||||
final String encodedFunction, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final List<String> privateFor) { |
||||
return new CallPrivateSmartContractFunction( |
||||
contractAddress, encodedFunction, transactionSigningKey, chainId, privateFrom, privateFor); |
||||
} |
||||
|
||||
public <T extends Contract> LoadPrivateSmartContractTransaction<T> loadSmartContract( |
||||
final String contractAddress, |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final String... privateFor) { |
||||
return loadSmartContract( |
||||
contractAddress, |
||||
clazz, |
||||
transactionSigningKey, |
||||
chainId, |
||||
privateFrom, |
||||
Arrays.asList(privateFor)); |
||||
} |
||||
|
||||
private <T extends Contract> LoadPrivateSmartContractTransaction<T> loadSmartContract( |
||||
final String contractAddress, |
||||
final Class<T> clazz, |
||||
final String transactionSigningKey, |
||||
final long chainId, |
||||
final String privateFrom, |
||||
final List<String> privateFor) { |
||||
return new LoadPrivateSmartContractTransaction<>( |
||||
contractAddress, clazz, transactionSigningKey, chainId, privateFrom, privateFor); |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
/* |
||||
* 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.privacy.transaction; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.core.Address; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; |
||||
|
||||
import java.io.IOException; |
||||
import java.math.BigInteger; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.web3j.protocol.core.DefaultBlockParameter; |
||||
import org.web3j.protocol.core.methods.response.EthBlock; |
||||
import org.web3j.protocol.pantheon.Pantheon; |
||||
|
||||
public class GetAllPrivacyMarkerTransactionHashes implements Transaction<List<String>> { |
||||
@Override |
||||
public List<String> execute(final NodeRequests node) { |
||||
final Pantheon pantheon = node.privacy().getPantheonClient(); |
||||
final List<String> toReturn = new ArrayList<>(); |
||||
try { |
||||
final long blockchainHeight = |
||||
pantheon.ethBlockNumber().send().getBlockNumber().longValueExact(); |
||||
for (int i = 0; i <= blockchainHeight; i++) { |
||||
pantheon |
||||
.ethGetBlockByNumber(DefaultBlockParameter.valueOf(BigInteger.valueOf(i)), true) |
||||
.send() |
||||
.getBlock() |
||||
.getTransactions() |
||||
.forEach( |
||||
t -> { |
||||
if (((EthBlock.TransactionObject) t) |
||||
.getTo() |
||||
.equals(Address.DEFAULT_PRIVACY.toString())) { |
||||
toReturn.add(((EthBlock.TransactionObject) t).getHash()); |
||||
} |
||||
}); |
||||
} |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
return toReturn; |
||||
} |
||||
} |
@ -1,101 +0,0 @@ |
||||
/* |
||||
* 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.eea; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
import org.assertj.core.util.Lists; |
||||
import org.web3j.protocol.Web3jService; |
||||
import org.web3j.protocol.core.Request; |
||||
import org.web3j.protocol.core.Response; |
||||
import org.web3j.protocol.core.methods.response.Log; |
||||
|
||||
public class EeaRequestFactory { |
||||
|
||||
public static class PrivateTransactionReceiptResponse |
||||
extends Response<PrivateTransactionReceipt> {} |
||||
|
||||
public static class PrivateTransactionReceipt { |
||||
private String contractAddress; |
||||
private String from; |
||||
private String to; |
||||
private String output; |
||||
private List<Log> logs; |
||||
|
||||
public PrivateTransactionReceipt() {} |
||||
|
||||
public String getContractAddress() { |
||||
return contractAddress; |
||||
} |
||||
|
||||
public void setContractAddress(final String contractAddress) { |
||||
this.contractAddress = contractAddress; |
||||
} |
||||
|
||||
public String getFrom() { |
||||
return from; |
||||
} |
||||
|
||||
public void setFrom(final String from) { |
||||
this.from = from; |
||||
} |
||||
|
||||
public String getTo() { |
||||
return to; |
||||
} |
||||
|
||||
public void setTo(final String to) { |
||||
this.to = to; |
||||
} |
||||
|
||||
public List<Log> getLogs() { |
||||
return logs; |
||||
} |
||||
|
||||
public void setLogs(final List<Log> logs) { |
||||
this.logs = logs; |
||||
} |
||||
|
||||
public String getOutput() { |
||||
return output; |
||||
} |
||||
|
||||
public void setOutput(final String output) { |
||||
this.output = output; |
||||
} |
||||
} |
||||
|
||||
private final Web3jService web3jService; |
||||
|
||||
public EeaRequestFactory(final Web3jService web3jService) { |
||||
this.web3jService = web3jService; |
||||
} |
||||
|
||||
Request<?, org.web3j.protocol.core.methods.response.EthSendTransaction> eeaSendRawTransaction( |
||||
final String signedTransactionData) { |
||||
return new Request<>( |
||||
"eea_sendRawTransaction", |
||||
Collections.singletonList(signedTransactionData), |
||||
web3jService, |
||||
org.web3j.protocol.core.methods.response.EthSendTransaction.class); |
||||
} |
||||
|
||||
Request<?, PrivateTransactionReceiptResponse> eeaGetTransactionReceipt(final String txHash) { |
||||
return new Request<>( |
||||
"eea_getTransactionReceipt", |
||||
Lists.newArrayList(txHash), |
||||
web3jService, |
||||
PrivateTransactionReceiptResponse.class); |
||||
} |
||||
} |
@ -1,42 +0,0 @@ |
||||
/* |
||||
* Copyright 2018 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.eea; |
||||
|
||||
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 org.web3j.protocol.core.methods.response.EthSendTransaction; |
||||
|
||||
public class EeaSendRawTransactionTransaction implements Transaction<String> { |
||||
|
||||
private final String transactionData; |
||||
|
||||
public EeaSendRawTransactionTransaction(final String transactionData) { |
||||
this.transactionData = transactionData; |
||||
} |
||||
|
||||
@Override |
||||
public String execute(final NodeRequests node) { |
||||
try { |
||||
EthSendTransaction response = node.eea().eeaSendRawTransaction(transactionData).send(); |
||||
assertThat(response.getTransactionHash()).isNotNull(); |
||||
return response.getTransactionHash(); |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -1,149 +0,0 @@ |
||||
/* |
||||
* 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.eea; |
||||
|
||||
import tech.pegasys.pantheon.crypto.SECP256K1; |
||||
import tech.pegasys.pantheon.ethereum.core.Address; |
||||
import tech.pegasys.pantheon.ethereum.core.Wei; |
||||
import tech.pegasys.pantheon.ethereum.privacy.PrivateTransaction; |
||||
import tech.pegasys.pantheon.ethereum.privacy.Restriction; |
||||
import tech.pegasys.pantheon.ethereum.rlp.RLP; |
||||
import tech.pegasys.pantheon.util.bytes.BytesValue; |
||||
|
||||
import java.math.BigInteger; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
public class PrivateTransactionBuilder { |
||||
|
||||
public static BytesValue EVENT_EMITTER_CONSTRUCTOR = |
||||
BytesValue.fromHexString( |
||||
"0x608060405234801561001057600080fd5b5060008054600160a06" |
||||
+ "0020a03191633179055610199806100326000396000f3fe6080" |
||||
+ "604052600436106100565763ffffffff7c01000000000000000" |
||||
+ "000000000000000000000000000000000000000006000350416" |
||||
+ "633fa4f245811461005b5780636057361d1461008257806367e" |
||||
+ "404ce146100ae575b600080fd5b34801561006757600080fd5b" |
||||
+ "506100706100ec565b60408051918252519081900360200190f" |
||||
+ "35b34801561008e57600080fd5b506100ac6004803603602081" |
||||
+ "10156100a557600080fd5b50356100f2565b005b3480156100b" |
||||
+ "a57600080fd5b506100c3610151565b6040805173ffffffffff" |
||||
+ "ffffffffffffffffffffffffffffff909216825251908190036" |
||||
+ "0200190f35b60025490565b6040805133815260208101839052" |
||||
+ "81517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb1" |
||||
+ "2b753f3d1aaa2d8f9f5929181900390910190a1600255600180" |
||||
+ "5473ffffffffffffffffffffffffffffffffffffffff1916331" |
||||
+ "79055565b60015473ffffffffffffffffffffffffffffffffff" |
||||
+ "ffffff169056fea165627a7a72305820c7f729cb24e05c221f5" |
||||
+ "aa913700793994656f233fe2ce3b9fd9a505ea17e8d8a0029"); |
||||
|
||||
private static BytesValue SET_FUNCTION_CALL = |
||||
BytesValue.fromHexString( |
||||
"0x6057361d00000000000000000000000000000000000000000000000000000000000003e8"); |
||||
|
||||
private static BytesValue GET_FUNCTION_CALL = BytesValue.fromHexString("0x3fa4f245"); |
||||
|
||||
public enum TransactionType { |
||||
CREATE_CONTRACT, |
||||
STORE, |
||||
GET |
||||
} |
||||
|
||||
public static PrivateTransactionBuilder.Builder builder() { |
||||
return new PrivateTransactionBuilder.Builder(); |
||||
} |
||||
|
||||
public static class Builder { |
||||
long nonce; |
||||
Address from; |
||||
Address to; |
||||
BytesValue privateFrom; |
||||
Optional<BytesValue> privacyGroupId = Optional.empty(); |
||||
Optional<List<BytesValue>> privateFor = Optional.of(new ArrayList<>()); |
||||
SECP256K1.KeyPair keyPair; |
||||
|
||||
public Builder nonce(final long nonce) { |
||||
this.nonce = nonce; |
||||
return this; |
||||
} |
||||
|
||||
public Builder from(final Address from) { |
||||
this.from = from; |
||||
return this; |
||||
} |
||||
|
||||
public Builder to(final Address to) { |
||||
this.to = to; |
||||
return this; |
||||
} |
||||
|
||||
public Builder privateFrom(final BytesValue privateFrom) { |
||||
this.privateFrom = privateFrom; |
||||
return this; |
||||
} |
||||
|
||||
public Builder privacyGroupId(final BytesValue privacyGroupId) { |
||||
this.privacyGroupId = Optional.of(privacyGroupId); |
||||
return this; |
||||
} |
||||
|
||||
public Builder privateFor(final List<BytesValue> privateFor) { |
||||
this.privateFor = Optional.of(privateFor); |
||||
return this; |
||||
} |
||||
|
||||
public Builder keyPair(final SECP256K1.KeyPair keyPair) { |
||||
this.keyPair = keyPair; |
||||
return this; |
||||
} |
||||
|
||||
public String build(final TransactionType type) { |
||||
BytesValue payload; |
||||
switch (type) { |
||||
case CREATE_CONTRACT: |
||||
payload = EVENT_EMITTER_CONSTRUCTOR; |
||||
break; |
||||
case STORE: |
||||
payload = SET_FUNCTION_CALL; |
||||
break; |
||||
case GET: |
||||
payload = GET_FUNCTION_CALL; |
||||
break; |
||||
default: |
||||
throw new IllegalStateException("Unexpected value: " + type); |
||||
} |
||||
|
||||
var builder = |
||||
PrivateTransaction.builder() |
||||
.nonce(nonce) |
||||
.gasPrice(Wei.of(1000)) |
||||
.gasLimit(63992) |
||||
.to(to) |
||||
.value(Wei.ZERO) |
||||
.payload(payload) |
||||
.sender(from) |
||||
.chainId(BigInteger.valueOf(2018)) |
||||
.privateFrom(privateFrom) |
||||
.restriction(Restriction.RESTRICTED); |
||||
|
||||
if (privacyGroupId.isPresent()) { |
||||
builder = builder.privacyGroupId(privacyGroupId.get()); |
||||
} else { |
||||
builder = builder.privateFor(privateFor.get()); |
||||
} |
||||
|
||||
return RLP.encode(builder.signAndBuild(keyPair)::writeTo).toString(); |
||||
} |
||||
} |
||||
} |
@ -1,44 +0,0 @@ |
||||
/* |
||||
* 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); |
||||
} |
||||
} |
||||
} |
@ -1,44 +0,0 @@ |
||||
/* |
||||
* 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); |
||||
} |
||||
} |
||||
} |
@ -1,43 +0,0 @@ |
||||
/* |
||||
* 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 PrivCreatePrivacyGroupWithoutOptionalParamsTransaction implements Transaction<String> { |
||||
|
||||
private final List<String> addresses; |
||||
|
||||
public PrivCreatePrivacyGroupWithoutOptionalParamsTransaction(final List<String> addresses) { |
||||
|
||||
this.addresses = addresses; |
||||
} |
||||
|
||||
@Override |
||||
public String execute(final NodeRequests node) { |
||||
try { |
||||
PrivRequestFactory.PrivCreatePrivacyGroupResponse result = |
||||
node.priv().privCreatePrivacyGroupWithoutOptionalParams(addresses).send(); |
||||
assertThat(result).isNotNull(); |
||||
return result.getResult(); |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -1,47 +0,0 @@ |
||||
/* |
||||
* 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.math.BigInteger; |
||||
|
||||
import org.web3j.protocol.core.methods.response.EthGetTransactionCount; |
||||
|
||||
public class PrivGetTransactionCountTransaction implements Transaction<BigInteger> { |
||||
|
||||
private final String accountAddress; |
||||
private String privacyGroupId; |
||||
|
||||
public PrivGetTransactionCountTransaction( |
||||
final String accountAddress, final String privacyGroupId) { |
||||
this.accountAddress = accountAddress; |
||||
this.privacyGroupId = privacyGroupId; |
||||
} |
||||
|
||||
@Override |
||||
public BigInteger execute(final NodeRequests node) { |
||||
try { |
||||
EthGetTransactionCount result = |
||||
node.priv().privGetTransactionCount(accountAddress, privacyGroupId).send(); |
||||
assertThat(result).isNotNull(); |
||||
return result.getTransactionCount(); |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -1,96 +0,0 @@ |
||||
/* |
||||
* 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 tech.pegasys.pantheon.enclave.types.PrivacyGroup; |
||||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
import org.assertj.core.util.Lists; |
||||
import org.web3j.protocol.Web3jService; |
||||
import org.web3j.protocol.core.Request; |
||||
import org.web3j.protocol.core.Response; |
||||
import org.web3j.protocol.core.methods.response.EthGetTransactionCount; |
||||
|
||||
public class PrivRequestFactory { |
||||
|
||||
public static class PrivCreatePrivacyGroupResponse extends Response<String> {} |
||||
|
||||
public static class PrivFindPrivacyGroupResponse extends Response<List<PrivacyGroup>> {} |
||||
|
||||
private final Web3jService web3jService; |
||||
|
||||
public PrivRequestFactory(final Web3jService web3jService) { |
||||
this.web3jService = web3jService; |
||||
} |
||||
|
||||
public Request<?, EthGetTransactionCount> privGetTransactionCount( |
||||
final String accountAddress, final String privacyGroupId) { |
||||
return new Request<>( |
||||
"priv_getTransactionCount", |
||||
Lists.newArrayList(accountAddress, privacyGroupId), |
||||
web3jService, |
||||
EthGetTransactionCount.class); |
||||
} |
||||
|
||||
public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroup( |
||||
final List<String> addresses, final String name, final String description) { |
||||
return new Request<>( |
||||
"priv_createPrivacyGroup", |
||||
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); |
||||
} |
||||
|
||||
public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroupWithoutOptionalParams( |
||||
final List<String> addresses) { |
||||
return new Request<>( |
||||
"priv_createPrivacyGroup", |
||||
Collections.singletonList( |
||||
new CreatePrivacyGroupParameter(addresses.toArray(new String[] {}), null, null)), |
||||
web3jService, |
||||
PrivCreatePrivacyGroupResponse.class); |
||||
} |
||||
|
||||
public Request<?, PrivFindPrivacyGroupResponse> privFindPrivacyGroup( |
||||
final List<String> addresses) { |
||||
return new Request<>( |
||||
"priv_findPrivacyGroup", |
||||
Collections.singletonList(addresses), |
||||
web3jService, |
||||
PrivFindPrivacyGroupResponse.class); |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
/* |
||||
* 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.privacy; |
||||
|
||||
import org.web3j.protocol.Web3jService; |
||||
import org.web3j.protocol.pantheon.Pantheon; |
||||
|
||||
public class PrivacyRequestFactory { |
||||
private final Pantheon pantheonClient; |
||||
|
||||
public PrivacyRequestFactory(final Web3jService web3jService) { |
||||
this.pantheonClient = Pantheon.build(web3jService); |
||||
} |
||||
|
||||
public Pantheon getPantheonClient() { |
||||
return pantheonClient; |
||||
} |
||||
} |
@ -1,305 +0,0 @@ |
||||
/* |
||||
* 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.web3j.privacy; |
||||
|
||||
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor; |
||||
import static tech.pegasys.pantheon.tests.web3j.privacy.PrivacyGroup.generatePrivacyGroup; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.core.Address; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.EeaCondition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.EeaConditions; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNet; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivateTransactionVerifier; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivateTransactions; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.PrivateTransactionBuilder; |
||||
import tech.pegasys.pantheon.util.bytes.BytesValue; |
||||
import tech.pegasys.pantheon.util.bytes.BytesValues; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
public class EventEmitterHarness { |
||||
|
||||
private PrivateTransactionBuilder.Builder privateTransactionBuilder; |
||||
private PrivacyNet privacyNet; |
||||
private PrivateTransactions privateTransactions; |
||||
private PrivateTransactionVerifier privateTransactionVerifier; |
||||
private EeaConditions eea; |
||||
|
||||
private Map<String, String> contracts; |
||||
|
||||
public EventEmitterHarness( |
||||
final PrivateTransactionBuilder.Builder privateTransactionBuilder, |
||||
final PrivacyNet privacyNet, |
||||
final PrivateTransactions privateTransactions, |
||||
final PrivateTransactionVerifier privateTransactionVerifier, |
||||
final EeaConditions eea) { |
||||
|
||||
this.privateTransactionBuilder = privateTransactionBuilder; |
||||
this.privacyNet = privacyNet; |
||||
this.privateTransactions = privateTransactions; |
||||
this.privateTransactionVerifier = privateTransactionVerifier; |
||||
this.eea = eea; |
||||
|
||||
this.contracts = new HashMap<>(); |
||||
} |
||||
|
||||
public String resolveContractAddress(final String contractName) { |
||||
return contracts.get(contractName); |
||||
} |
||||
|
||||
public void deploy(final String contractName, final String sender, final String... receivers) { |
||||
final BytesValue privacyGroupId = generatePrivacyGroup(privacyNet, sender, receivers); |
||||
final long nonce = nextNonce(sender, privacyGroupId); |
||||
final String contractAddress = |
||||
generateContractAddress(sender, nonce, privacyGroupId).toString(); |
||||
deploy( |
||||
contractName, |
||||
privateTransactionVerifier.validPrivateContractDeployed(contractAddress), |
||||
privateTransactionVerifier.noPrivateContractDeployed(), |
||||
sender, |
||||
receivers); |
||||
} |
||||
|
||||
public void deployWithPrivacyGroup( |
||||
final String contractName, |
||||
final String sender, |
||||
final String mPrivacyGroupId, |
||||
final String... groupMembers) { |
||||
deployWithPrivacyGroup( |
||||
contractName, |
||||
"Test", |
||||
nextNonce(sender, BytesValues.fromBase64(mPrivacyGroupId)), |
||||
sender, |
||||
mPrivacyGroupId, |
||||
groupMembers); |
||||
} |
||||
|
||||
public void deploy( |
||||
final String contractName, |
||||
final EeaCondition forParticipants, |
||||
final EeaCondition forNonParticipants, |
||||
final String sender, |
||||
final String... receivers) { |
||||
final BytesValue privacyGroupId = generatePrivacyGroup(privacyNet, sender, receivers); |
||||
final long nonce = nextNonce(sender, privacyGroupId); |
||||
final String contractAddress = |
||||
generateContractAddress(sender, nonce, privacyGroupId).toString(); |
||||
deploy( |
||||
contractAddress, |
||||
contractName, |
||||
nonce, |
||||
forParticipants, |
||||
forNonParticipants, |
||||
sender, |
||||
receivers); |
||||
} |
||||
|
||||
public void store(final String contractName, final String sender, final String... receivers) { |
||||
store( |
||||
contractName, |
||||
privateTransactionVerifier.validEventReturned("1000"), |
||||
privateTransactionVerifier.noValidEventReturned(), |
||||
sender, |
||||
receivers); |
||||
} |
||||
|
||||
public void store( |
||||
final String contractName, |
||||
final EeaCondition forParticipants, |
||||
final EeaCondition forNonParticipants, |
||||
final String sender, |
||||
final String... receivers) { |
||||
final String contractAddress = resolveContractAddress(contractName); |
||||
final BytesValue privacyGroupId = generatePrivacyGroup(privacyNet, sender, receivers); |
||||
final long nonce = nextNonce(sender, privacyGroupId); |
||||
final String storeValue = |
||||
privateTransactionBuilder |
||||
.nonce(nonce) |
||||
.from(privacyNet.getNode(sender).getAddress()) |
||||
.to(Address.fromHexString(contractAddress)) |
||||
.privateFrom( |
||||
BytesValues.fromBase64(privacyNet.getEnclave(sender).getPublicKeys().get(0))) |
||||
.privateFor(convertNamesToOrionPublicKeys(receivers)) |
||||
.keyPair(privacyNet.getNode(sender).keyPair()) |
||||
.build(PrivateTransactionBuilder.TransactionType.STORE); |
||||
final String transactionHash = |
||||
privacyNet |
||||
.getNode(sender) |
||||
.execute(privateTransactions.createPrivateRawTransaction(storeValue)); |
||||
|
||||
waitForTransactionToBeMined(transactionHash); |
||||
|
||||
verifyForParticipants(forParticipants, transactionHash, sender, receivers); |
||||
|
||||
verifyForNonParticipants(forNonParticipants, transactionHash, sender, receivers); |
||||
} |
||||
|
||||
public void get(final String contractName, final String sender, final String... receivers) { |
||||
get( |
||||
contractName, |
||||
privateTransactionVerifier.validOutputReturned("1000"), |
||||
privateTransactionVerifier.noValidOutputReturned(), |
||||
sender, |
||||
receivers); |
||||
} |
||||
|
||||
public void get( |
||||
final String contractName, |
||||
final EeaCondition forParticipants, |
||||
final EeaCondition forNonParticipants, |
||||
final String sender, |
||||
final String... receivers) { |
||||
final String contractAddress = resolveContractAddress(contractName); |
||||
final BytesValue privacyGroupId = generatePrivacyGroup(privacyNet, sender, receivers); |
||||
final long nonce = nextNonce(sender, privacyGroupId); |
||||
final String getValue = |
||||
privateTransactionBuilder |
||||
.nonce(nonce) |
||||
.from(privacyNet.getNode(sender).getAddress()) |
||||
.to(Address.fromHexString(contractAddress)) |
||||
.privateFrom( |
||||
BytesValues.fromBase64(privacyNet.getEnclave(sender).getPublicKeys().get(0))) |
||||
.privateFor(convertNamesToOrionPublicKeys(receivers)) |
||||
.keyPair(privacyNet.getNode(sender).keyPair()) |
||||
.build(PrivateTransactionBuilder.TransactionType.GET); |
||||
final String transactionHash = |
||||
privacyNet |
||||
.getNode(sender) |
||||
.execute(privateTransactions.createPrivateRawTransaction(getValue)); |
||||
|
||||
waitForTransactionToBeMined(transactionHash); |
||||
|
||||
verifyForParticipants(forParticipants, transactionHash, sender, receivers); |
||||
|
||||
verifyForNonParticipants(forNonParticipants, transactionHash, sender, receivers); |
||||
} |
||||
|
||||
private void deployWithPrivacyGroup( |
||||
final String contractAddress, |
||||
final String contractName, |
||||
final long nonce, |
||||
final String sender, |
||||
final String privacyGroupId, |
||||
final String... groupMembers) { |
||||
|
||||
final String deployContract = |
||||
privateTransactionBuilder |
||||
.nonce(nonce) |
||||
.from(privacyNet.getNode(sender).getAddress()) |
||||
.to(null) |
||||
.privateFrom( |
||||
BytesValues.fromBase64(privacyNet.getEnclave(sender).getPublicKeys().get(0))) |
||||
.privacyGroupId(BytesValues.fromBase64(privacyGroupId)) |
||||
.keyPair(privacyNet.getNode(sender).keyPair()) |
||||
.build(PrivateTransactionBuilder.TransactionType.CREATE_CONTRACT); |
||||
final String transactionHash = |
||||
privacyNet |
||||
.getNode(sender) |
||||
.execute(privateTransactions.deployPrivateSmartContract(deployContract)); |
||||
|
||||
waitForTransactionToBeMined(transactionHash); |
||||
|
||||
verifyForParticipants( |
||||
privateTransactionVerifier.validPrivateTransactionReceipt(), |
||||
transactionHash, |
||||
sender, |
||||
groupMembers); |
||||
|
||||
contracts.put(contractName, contractAddress); |
||||
} |
||||
|
||||
private void deploy( |
||||
final String contractAddress, |
||||
final String contractName, |
||||
final long nonce, |
||||
final EeaCondition forParticipants, |
||||
final EeaCondition forNonParticipants, |
||||
final String sender, |
||||
final String... receivers) { |
||||
final String deployContract = |
||||
privateTransactionBuilder |
||||
.nonce(nonce) |
||||
.from(privacyNet.getNode(sender).getAddress()) |
||||
.to(null) |
||||
.privateFrom( |
||||
BytesValues.fromBase64(privacyNet.getEnclave(sender).getPublicKeys().get(0))) |
||||
.privateFor(convertNamesToOrionPublicKeys(receivers)) |
||||
.keyPair(privacyNet.getNode(sender).keyPair()) |
||||
.build(PrivateTransactionBuilder.TransactionType.CREATE_CONTRACT); |
||||
final String transactionHash = |
||||
privacyNet |
||||
.getNode(sender) |
||||
.execute(privateTransactions.deployPrivateSmartContract(deployContract)); |
||||
|
||||
waitForTransactionToBeMined(transactionHash); |
||||
|
||||
verifyForParticipants(forParticipants, transactionHash, sender, receivers); |
||||
|
||||
verifyForNonParticipants(forNonParticipants, transactionHash, sender, receivers); |
||||
|
||||
contracts.put(contractName, contractAddress); |
||||
} |
||||
|
||||
private Address generateContractAddress( |
||||
final String sender, final long nonce, final BytesValue privacyGroupId) { |
||||
return Address.privateContractAddress( |
||||
privacyNet.getNode(sender).getAddress(), nonce, privacyGroupId); |
||||
} |
||||
|
||||
private long nextNonce(final String sender, final BytesValue privacyGroupId) { |
||||
return privacyNet.getNode(sender).nextNonce(privacyGroupId); |
||||
} |
||||
|
||||
private void waitForTransactionToBeMined(final String transactionHash) { |
||||
waitFor( |
||||
() -> |
||||
privacyNet |
||||
.getNode("Alice") |
||||
.verify(eea.expectSuccessfulTransactionReceipt(transactionHash))); |
||||
} |
||||
|
||||
private List<BytesValue> convertNamesToOrionPublicKeys(final String... toNodeNames) { |
||||
return Arrays.stream(toNodeNames) |
||||
.map(name -> BytesValues.fromBase64(privacyNet.getEnclave(name).getPublicKeys().get(0))) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
private void verifyForNonParticipants( |
||||
final EeaCondition condition, |
||||
final String transactionHash, |
||||
final String sender, |
||||
final String[] receivers) { |
||||
privacyNet.getNodes().keySet().stream() |
||||
.filter(key -> !sender.equals(key) && !Arrays.asList(receivers).contains(key)) |
||||
.forEach(node -> verifyForParticipant(condition, transactionHash, node)); |
||||
} |
||||
|
||||
private void verifyForParticipants( |
||||
final EeaCondition condition, |
||||
final String transactionHash, |
||||
final String fromNodeName, |
||||
final String[] toNodeNames) { |
||||
verifyForParticipant(condition, transactionHash, fromNodeName); |
||||
Arrays.stream(toNodeNames) |
||||
.forEach(node -> verifyForParticipant(condition, transactionHash, node)); |
||||
} |
||||
|
||||
private void verifyForParticipant( |
||||
final EeaCondition condition, final String transactionHash, final String nodeName) { |
||||
condition.verify(privacyNet.getNode(nodeName), transactionHash); |
||||
} |
||||
} |
@ -1,53 +0,0 @@ |
||||
/* |
||||
* 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.web3j.privacy; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNet; |
||||
import tech.pegasys.pantheon.util.bytes.BytesValue; |
||||
import tech.pegasys.pantheon.util.bytes.BytesValues; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Base64; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import org.web3j.crypto.Hash; |
||||
import org.web3j.rlp.RlpEncoder; |
||||
import org.web3j.rlp.RlpList; |
||||
import org.web3j.rlp.RlpString; |
||||
import org.web3j.rlp.RlpType; |
||||
|
||||
public class PrivacyGroup { |
||||
public static BytesValue generatePrivacyGroup( |
||||
final PrivacyNet privacyNet, final String sender, final String... receivers) { |
||||
final List<byte[]> stringList = new ArrayList<>(); |
||||
stringList.add( |
||||
Base64.getDecoder().decode(privacyNet.getEnclave(sender).getPublicKeys().get(0))); |
||||
Arrays.stream(receivers) |
||||
.forEach( |
||||
(receiver) -> |
||||
stringList.add( |
||||
Base64.getDecoder() |
||||
.decode(privacyNet.getEnclave(receiver).getPublicKeys().get(0)))); |
||||
List<RlpType> rlpList = |
||||
stringList.stream() |
||||
.distinct() |
||||
.sorted(Comparator.comparing(Arrays::hashCode)) |
||||
.map(RlpString::create) |
||||
.collect(Collectors.toList()); |
||||
return BytesValues.fromBase64( |
||||
Base64.getEncoder().encode(Hash.sha3(RlpEncoder.encode(new RlpList(rlpList))))); |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
{ |
||||
"config": { |
||||
"chainId": 4, |
||||
"byzantiumBlock": 0, |
||||
"ibft2": { |
||||
"blockperiodseconds": 1, |
||||
"epochlength": 30000, |
||||
"requesttimeoutseconds": 5 |
||||
} |
||||
}, |
||||
"nonce": "0x0", |
||||
"timestamp": "0x58ee40ba", |
||||
"extraData": "%extraData%", |
||||
"gasLimit": "0x47b760", |
||||
"difficulty": "0x1", |
||||
"mixHash": "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365", |
||||
"coinbase": "0x0000000000000000000000000000000000000000", |
||||
"alloc": { |
||||
"fe3b557e8fb62b89f4916b721be55ceb828dbd73": { |
||||
"privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63", |
||||
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", |
||||
"balance": "0xad78ebc5ac6200000" |
||||
}, |
||||
"627306090abaB3A6e1400e9345bC60c78a8BEf57": { |
||||
"privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3", |
||||
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", |
||||
"balance": "90000000000000000000000" |
||||
}, |
||||
"f17f52151EbEF6C7334FAD080c5704D77216b732": { |
||||
"privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f", |
||||
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", |
||||
"balance": "90000000000000000000000" |
||||
} |
||||
}, |
||||
"number": "0x0", |
||||
"gasUsed": "0x0", |
||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" |
||||
} |
@ -0,0 +1,57 @@ |
||||
/* |
||||
* 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.orion.testutil; |
||||
|
||||
import java.nio.file.Path; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class OrionConfiguration { |
||||
|
||||
private final Path publicKey; |
||||
private final Path privateKey; |
||||
private final Path tempDir; |
||||
private final List<String> otherNodes = new ArrayList<>(); |
||||
|
||||
public OrionConfiguration( |
||||
final Path publicKey, |
||||
final Path privateKey, |
||||
final Path tempDir, |
||||
final List<String> otherNodes) { |
||||
|
||||
this.publicKey = publicKey; |
||||
this.privateKey = privateKey; |
||||
this.tempDir = tempDir; |
||||
this.otherNodes.addAll(otherNodes); |
||||
} |
||||
|
||||
public Path getPublicKey() { |
||||
return publicKey; |
||||
} |
||||
|
||||
public Path getPrivateKey() { |
||||
return privateKey; |
||||
} |
||||
|
||||
public Path getTempDir() { |
||||
return tempDir; |
||||
} |
||||
|
||||
public List<String> getOtherNodes() { |
||||
return otherNodes; |
||||
} |
||||
|
||||
public void addOtherNode(final String otherNode) { |
||||
otherNodes.add(otherNode); |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
/* |
||||
* 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.orion.testutil; |
||||
|
||||
public class OrionKeyConfiguration { |
||||
private final String pubKeyPath; |
||||
private final String privKeyPath; |
||||
|
||||
public OrionKeyConfiguration(final String pubKeyPath, final String privKeyPath) { |
||||
this.pubKeyPath = pubKeyPath; |
||||
this.privKeyPath = privKeyPath; |
||||
} |
||||
|
||||
public String getPubKeyPath() { |
||||
return pubKeyPath; |
||||
} |
||||
|
||||
public String getPrivKeyPath() { |
||||
return privKeyPath; |
||||
} |
||||
} |
Loading…
Reference in new issue