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

[PRIV] Get Internal logs and output #1022

Merged
merged 12 commits into from
Mar 13, 2019
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 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.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaGetTransactionReceiptTransaction;

public class ExpectSuccessfulEeaGetTransactionReceipt implements Condition {

private final EeaGetTransactionReceiptTransaction transaction;

public ExpectSuccessfulEeaGetTransactionReceipt(
final EeaGetTransactionReceiptTransaction transaction) {
this.transaction = transaction;
}

@Override
public void verify(final Node node) {
final ResponseTypes.PrivateTransactionReceipt response = node.execute(transaction);
assertThat(response.getContractAddress()).isNotEqualTo("0x");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.jsonrpc;

import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectSuccessfulEeaGetTransactionReceipt;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions;

public class Eea {

EeaTransactions transactions;

public Eea(final EeaTransactions transactions) {
this.transactions = transactions;
}

public Condition expectSuccessfulTransactionReceipt(
final String transactionHash, final String publicKey) {
return new ExpectSuccessfulEeaGetTransactionReceipt(
transactions.getTransactionReceipt(transactionHash, publicKey));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ public String toString() {
.add("keyPair", keyPair)
.add("p2pEnabled", p2pEnabled)
.add("discoveryEnabled", discoveryEnabled)
.add("privacyEnabled", privacyParameters.isEnabled())
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 org.junit.Assert.assertEquals;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public class ExpectValidPrivateContractDeployedReceipt
extends ExpectValidPrivateTransactionReceipt {

private final String contractAddress;

public ExpectValidPrivateContractDeployedReceipt(
final String contractAddress, final Eea eea, final Transactions transactions) {
super(eea, transactions);
this.contractAddress = contractAddress;
}

public void verify(
final PantheonNode node, final String transactionHash, final String publicKey) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, publicKey);

assertEquals(contractAddress, privateTxReceipt.getContractAddress());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.privacy;

import static org.junit.Assert.assertEquals;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

import java.math.BigInteger;

import org.web3j.utils.Numeric;

public class ExpectValidPrivateContractEventsEmitted extends ExpectValidPrivateTransactionReceipt {
private final String eventValue;

public ExpectValidPrivateContractEventsEmitted(
final String eventValue, final Eea eea, final Transactions transactions) {
super(eea, transactions);
this.eventValue = eventValue;
}

public void verify(
final PantheonNode node, final String transactionHash, final String PUBLIC_KEY) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, PUBLIC_KEY);

String event = privateTxReceipt.getLogs().get(0).getData().substring(66, 130);
assertEquals(
Numeric.decodeQuantity(Numeric.prependHexPrefix(event)), new BigInteger(eventValue));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.privacy;

import static org.junit.Assert.assertEquals;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.math.BigInteger;

import org.web3j.utils.Numeric;

public class ExpectValidPrivateContractValuesReturned extends ExpectValidPrivateTransactionReceipt {
private final String returnValue;

public ExpectValidPrivateContractValuesReturned(
final String returnValue, final Eea eea, final Transactions transactions) {
super(eea, transactions);
this.returnValue = returnValue;
}

public void verify(
final PantheonNode node, final String transactionHash, final String PUBLIC_KEY) {
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
getPrivateTransactionReceipt(node, transactionHash, PUBLIC_KEY);

BytesValue output = BytesValue.fromHexString(privateTxReceipt.getOutput());
assertEquals(Numeric.decodeQuantity(output.toString()), new BigInteger(returnValue));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public abstract class ExpectValidPrivateTransactionReceipt {

private Eea eea;
private Transactions transactions;

ExpectValidPrivateTransactionReceipt(final Eea eea, final Transactions transactions) {
this.eea = eea;
this.transactions = transactions;
}

ResponseTypes.PrivateTransactionReceipt getPrivateTransactionReceipt(
final PantheonNode node, final String transactionHash, final String publicKey) {

waitFor(() -> node.verify(eea.expectSuccessfulTransactionReceipt(transactionHash, publicKey)));
ResponseTypes.PrivateTransactionReceipt privateTxReceipt =
node.execute(transactions.getPrivateTransactionReceipt(transactionHash, publicKey));
return privateTxReceipt;
}
}
Original file line number Diff line number Diff line change
@@ -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;

import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions;

public class PrivateContractVerifier {

private final Transactions transactions;
private final Eea eea;

public PrivateContractVerifier(final Eea eea, final Transactions transactions) {
this.eea = eea;
this.transactions = transactions;
}

public ExpectValidPrivateContractDeployedReceipt validPrivateTransactionReceipt(
final String contractAddress) {
return new ExpectValidPrivateContractDeployedReceipt(contractAddress, eea, transactions);
}

public ExpectValidPrivateContractEventsEmitted validPrivateTransactionReceiptReturnsEvents(
final String eventValue) {
return new ExpectValidPrivateContractEventsEmitted(eventValue, eea, transactions);
}

public ExpectValidPrivateContractValuesReturned validPrivateTransactionReceiptReturnsValues(
final String returnValue) {
return new ExpectValidPrivateContractValuesReturned(returnValue, eea, transactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;

import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.response.Log;

public class ResponseTypes {
public static class ProposeResponse extends Response<Boolean> {}
Expand Down Expand Up @@ -47,6 +48,8 @@ public static class PrivateTransactionReceipt {
private String contractAddress;
private String from;
private String to;
private String output;
private List<Log> logs;

public PrivateTransactionReceipt() {}

Expand All @@ -73,5 +76,21 @@ public String getTo() {
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public TransferTransaction createTransfer(
.build();
}

public EeaSendRawTransactionTransaction deployPrivateSmartContract(
final String signedRawPrivateTransaction) {
return new EeaSendRawTransactionTransaction(signedRawPrivateTransaction);
}

public EeaSendRawTransactionTransaction createPrivateRawTransaction(
final String signedRawPrivateTransaction) {
return new EeaSendRawTransactionTransaction(signedRawPrivateTransaction);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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;

public class EeaTransactions {

public EeaGetTransactionReceiptTransaction getTransactionReceipt(
final String transactionHash, final String pubKey) {
return new EeaGetTransactionReceiptTransaction(transactionHash, pubKey);
}
}
Loading