mirror of https://github.com/hyperledger/besu
ibft mining acceptance tests (#483)
parent
5e46d1b2ba
commit
ba3c2a500a
@ -0,0 +1,30 @@ |
|||||||
|
/* |
||||||
|
* 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.node.PantheonNode; |
||||||
|
|
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class Ibft { |
||||||
|
|
||||||
|
public List<PantheonNode> validators(final PantheonNode[] nodes) { |
||||||
|
final Comparator<PantheonNode> compareByAddress = |
||||||
|
Comparator.comparing(PantheonNode::getAddress); |
||||||
|
List<PantheonNode> pantheonNodes = Arrays.asList(nodes); |
||||||
|
pantheonNodes.sort(compareByAddress); |
||||||
|
return pantheonNodes; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,112 @@ |
|||||||
|
/* |
||||||
|
* 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.ibft; |
||||||
|
|
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.junit.Ignore; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
public class IbftMiningAcceptanceTest extends AcceptanceTestBase { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void shouldMineOnSingleNode() throws IOException { |
||||||
|
final PantheonNode minerNode = pantheon.createIbftNode("miner1"); |
||||||
|
cluster.start(minerNode); |
||||||
|
|
||||||
|
final Account sender = accounts.createAccount("account1"); |
||||||
|
final Account receiver = accounts.createAccount("account2"); |
||||||
|
|
||||||
|
minerNode.execute(transactions.createTransfer(sender, 50)); |
||||||
|
cluster.verify(sender.balanceEquals(50)); |
||||||
|
|
||||||
|
minerNode.execute(transactions.createIncrementalTransfers(sender, receiver, 1)); |
||||||
|
cluster.verify(receiver.balanceEquals(1)); |
||||||
|
|
||||||
|
minerNode.execute(transactions.createIncrementalTransfers(sender, receiver, 2)); |
||||||
|
cluster.verify(receiver.balanceEquals(3)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void shouldMineOnMultipleNodes() throws IOException { |
||||||
|
final PantheonNode minerNode1 = pantheon.createIbftNode("miner1"); |
||||||
|
final PantheonNode minerNode2 = pantheon.createIbftNode("miner2"); |
||||||
|
final PantheonNode minerNode3 = pantheon.createIbftNode("miner3"); |
||||||
|
final PantheonNode minerNode4 = pantheon.createIbftNode("miner4"); |
||||||
|
cluster.start(minerNode1, minerNode2, minerNode3, minerNode4); |
||||||
|
|
||||||
|
final Account sender = accounts.createAccount("account1"); |
||||||
|
final Account receiver = accounts.createAccount("account2"); |
||||||
|
|
||||||
|
minerNode1.execute(transactions.createTransfer(sender, 50)); |
||||||
|
cluster.verify(sender.balanceEquals(50)); |
||||||
|
|
||||||
|
minerNode2.execute(transactions.createIncrementalTransfers(sender, receiver, 1)); |
||||||
|
cluster.verify(receiver.balanceEquals(1)); |
||||||
|
|
||||||
|
minerNode3.execute(transactions.createIncrementalTransfers(sender, receiver, 2)); |
||||||
|
cluster.verify(receiver.balanceEquals(3)); |
||||||
|
|
||||||
|
minerNode4.execute(transactions.createIncrementalTransfers(sender, receiver, 3)); |
||||||
|
cluster.verify(receiver.balanceEquals(6)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
@Ignore("Temporarily disabled until ibft new block events are being sent") |
||||||
|
public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator() throws IOException { |
||||||
|
final String[] validators = {"validator1", "validator2", "validator3"}; |
||||||
|
final PantheonNode validator1 = pantheon.createIbftNodeWithValidators("validator1", validators); |
||||||
|
final PantheonNode validator2 = pantheon.createIbftNodeWithValidators("validator2", validators); |
||||||
|
final PantheonNode validator3 = pantheon.createIbftNodeWithValidators("validator3", validators); |
||||||
|
final PantheonNode nonValidatorNode = |
||||||
|
pantheon.createIbftNodeWithValidators("non-validator", validators); |
||||||
|
cluster.start(validator1, validator2, validator3, nonValidatorNode); |
||||||
|
|
||||||
|
final Account sender = accounts.createAccount("account1"); |
||||||
|
final Account receiver = accounts.createAccount("account2"); |
||||||
|
|
||||||
|
validator1.execute(transactions.createTransfer(sender, 50)); |
||||||
|
cluster.verify(sender.balanceEquals(50)); |
||||||
|
|
||||||
|
validator2.execute(transactions.createIncrementalTransfers(sender, receiver, 1)); |
||||||
|
cluster.verify(receiver.balanceEquals(1)); |
||||||
|
|
||||||
|
nonValidatorNode.execute(transactions.createIncrementalTransfers(sender, receiver, 2)); |
||||||
|
cluster.verify(receiver.balanceEquals(3)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void shouldStillMineWhenANonProposerNodeFailsAndHasSufficientValidators() |
||||||
|
throws IOException { |
||||||
|
final PantheonNode minerNode1 = pantheon.createIbftNode("miner1"); |
||||||
|
final PantheonNode minerNode2 = pantheon.createIbftNode("miner2"); |
||||||
|
final PantheonNode minerNode3 = pantheon.createIbftNode("miner3"); |
||||||
|
final PantheonNode minerNode4 = pantheon.createIbftNode("miner4"); |
||||||
|
final List<PantheonNode> validators = |
||||||
|
ibft.validators(new PantheonNode[] {minerNode1, minerNode2, minerNode3, minerNode4}); |
||||||
|
final PantheonNode nonProposerNode = validators.get(validators.size() - 1); |
||||||
|
cluster.start(validators); |
||||||
|
|
||||||
|
final Account receiver = accounts.createAccount("account2"); |
||||||
|
|
||||||
|
cluster.stopNode(nonProposerNode); |
||||||
|
validators.get(0).execute(transactions.createTransfer(receiver, 80)); |
||||||
|
|
||||||
|
cluster.verifyOnActiveNodes(receiver.balanceEquals(80)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
{ |
||||||
|
"config": { |
||||||
|
"chainId": 4, |
||||||
|
"homesteadBlock": 1, |
||||||
|
"eip150Block": 2, |
||||||
|
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||||
|
"eip155Block": 3, |
||||||
|
"eip158Block": 3, |
||||||
|
"byzantiumBlock": 1035301, |
||||||
|
"revisedibft": { |
||||||
|
"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" |
||||||
|
} |
Loading…
Reference in new issue