This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smart contract acceptance test (#296)
* Upgrade Web3j to 3.6.0 * Correcting ErrorProne exclusion regex * Deploying the simple storage contract * Web3j to 4.0.1 * Verifying the transaction receipt
- Loading branch information
Showing
14 changed files
with
437 additions
and
75 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...h/pegasys/pantheon/tests/acceptance/dsl/condition/eth/EthGetTransactionReceiptEquals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.eth; | ||
|
||
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.eth.EthGetTransactionReceiptTransaction; | ||
|
||
import java.util.Optional; | ||
|
||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
|
||
public class EthGetTransactionReceiptEquals implements Condition { | ||
|
||
private final EthGetTransactionReceiptTransaction transaction; | ||
private final TransactionReceipt expectedReceipt; | ||
|
||
public EthGetTransactionReceiptEquals( | ||
final EthGetTransactionReceiptTransaction transaction, | ||
final TransactionReceipt expectedReceipt) { | ||
this.transaction = transaction; | ||
this.expectedReceipt = expectedReceipt; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
final Optional<TransactionReceipt> response = node.execute(transaction); | ||
|
||
assertThat(response.isPresent()).isTrue(); | ||
assertThat(response.get()).isEqualTo(expectedReceipt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ts/src/test/java/tech/pegasys/pantheon/tests/web3j/DeploySmartContractAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.web3j; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; | ||
import tech.pegasys.pantheon.tests.web3j.generated.SimpleStorage; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
|
||
public class DeploySmartContractAcceptanceTest extends AcceptanceTestBase { | ||
|
||
private PantheonNode minerNode; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
minerNode = pantheon.createMinerNode("miner-node"); | ||
cluster.start(minerNode); | ||
} | ||
|
||
@Test | ||
public void deployContractReceiptMustMatchEthGetTransactionReceipt() { | ||
final SimpleStorage contract = | ||
minerNode.execute(transactions.createSmartContract(SimpleStorage.class)); | ||
assertThat(contract).isNotNull(); | ||
|
||
final Optional<TransactionReceipt> receipt = contract.getTransactionReceipt(); | ||
assertThat(receipt).isNotNull(); | ||
assertThat(receipt.isPresent()).isTrue(); | ||
|
||
final TransactionReceipt transactionReceipt = receipt.get(); | ||
assertThat(transactionReceipt.getTransactionHash()).isNotNull(); | ||
|
||
// Contract transaction has no 'to' address or contract address | ||
assertThat(transactionReceipt.getTo()).isNull(); | ||
assertThat(transactionReceipt.getContractAddress()).isNotBlank(); | ||
|
||
minerNode.verify( | ||
eth.expectTransactionReceipt(transactionReceipt.getTransactionHash(), transactionReceipt)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/SimpleStorage.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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. | ||
*/ | ||
pragma solidity >=0.4.0 <0.6.0; | ||
|
||
// compile with: | ||
// solc SimpleStorage.sol --bin --abi --optimize --overwrite -o . | ||
// then create web3j wrappers with: | ||
// web3j solidity generate -b ./generated/SimpleStorage.bin -a ./generated/SimpleStorage.abi -o ../../../../../ -p tech.pegasys.pantheon.tests.web3j.generated | ||
contract SimpleStorage { | ||
uint data; | ||
|
||
function set(uint value) public { | ||
data = value; | ||
} | ||
|
||
function get() public view returns (uint) { | ||
return data; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/EventEmitter.bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
608060405234801561001057600080fd5b5060008054600160a060020a03191633179055610187806100326000396000f3006080604052600436106100565763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f245811461005b5780636057361d1461008257806367e404ce1461009c575b600080fd5b34801561006757600080fd5b506100706100da565b60408051918252519081900360200190f35b34801561008e57600080fd5b5061009a6004356100e0565b005b3480156100a857600080fd5b506100b161013f565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a16002556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a72305820f958aea7922a9538be4c34980ad3171806aad2d3fedb62682cef2ca4e1f1f3120029 | ||
608060405234801561001057600080fd5b5060008054600160a060020a03191633179055610199806100326000396000f3fe6080604052600436106100565763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f245811461005b5780636057361d1461008257806367e404ce146100ae575b600080fd5b34801561006757600080fd5b506100706100ec565b60408051918252519081900360200190f35b34801561008e57600080fd5b506100ac600480360360208110156100a557600080fd5b50356100f2565b005b3480156100ba57600080fd5b506100c3610151565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a16002556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff169056fea165627a7a72305820c7f729cb24e05c221f5aa913700793994656f233fe2ce3b9fd9a505ea17e8d8a0029 |
Oops, something went wrong.