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

Commit

Permalink
Added in a fixed difficulty acceptance test.
Browse files Browse the repository at this point in the history
  • Loading branch information
rojotek committed Jan 27, 2019
1 parent 5b53754 commit 700edf4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode;

Expand Down Expand Up @@ -119,6 +120,24 @@ public PantheonNode createArchiveNodeWithP2pDisabled(final String name) throws I
.webSocketEnabled()
.build());
}
public Node createFixedDifficultyMinerNode(final String name) throws IOException {
return create(
new PantheonFactoryConfigurationBuilder()
.setName(name)
.miningEnabled()
.setDevMode(false)
.jsonRpcEnabled()
.webSocketEnabled()
.setGenesisConfigProvider(this::createFixedDifficultyGenesisConfig)
.build());

}

private Optional<String> createFixedDifficultyGenesisConfig(
final Collection<? extends RunnableNode> runnableNodes) {
final String template = genesisTemplateConfig("fixed/fixed.json");
return Optional.of(template);
}

public PantheonNode createArchiveNodeWithCustomRefreshDelay(
final String name, final Long refreshDelay) throws IOException {
Expand Down Expand Up @@ -346,4 +365,5 @@ private JsonRpcConfiguration createJsonRpcConfigWithRpcApiEnabled(final RpcApi r
jsonRpcConfig.setRpcApis(rpcApis);
return jsonRpcConfig;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tech.pegasys.pantheon.tests.acceptance.mining;

import static org.web3j.utils.Convert.Unit.ETHER;

import org.junit.Before;
import org.junit.Test;
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.Node;

public class FixedMiningDifficultyAcceptanceTest extends AcceptanceTestBase {
private Node minerNode;

@Before
public void setUp() throws Exception {
minerNode = pantheon.createFixedDifficultyMinerNode("node1");
cluster.start(minerNode);
}

@Test
public void shouldMineTransactions() {
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));

minerNode.execute(transactions.createIncrementalTransfers(sender, receiver, 3));
cluster.verify(receiver.balanceEquals(6));

minerNode.execute(transactions.createIncrementalTransfers(sender, receiver, 4));
cluster.verify(receiver.balanceEquals(10));

minerNode.execute(transactions.createIncrementalTransfers(sender, receiver, 5));
cluster.verify(receiver.balanceEquals(15));
}
}
40 changes: 40 additions & 0 deletions acceptance-tests/src/test/resources/fixed/fixed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"config": {
"chainId": 4,
"homesteadBlock": 1,
"eip150Block": 2,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 3,
"eip158Block": 3,
"byzantiumBlock": 1035301,
"ethash": {
"fixeddifficulty": 100
}
},
"nonce": "0x0",
"timestamp": "0x58ee40ba",
"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 comments on commit 700edf4

Please sign in to comment.