mirror of https://github.com/hyperledger/besu
Acceptance test refactoring - DSL - Node interface (#170)
* Conditions to remove the getters from Node interface Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
cb93cbdfd9
commit
8fa45725f2
@ -0,0 +1,31 @@ |
||||
/* |
||||
* 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.blockchain; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.ExpectMinimumBlockNumber; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; |
||||
|
||||
public class Blockchain { |
||||
|
||||
private final EthTransactions eth; |
||||
|
||||
public Blockchain(final EthTransactions eth) { |
||||
this.eth = eth; |
||||
} |
||||
|
||||
public Condition blockNumberMustBeLatest(final Node node) { |
||||
return new ExpectMinimumBlockNumber(eth, node.execute(eth.blockNumber())); |
||||
} |
||||
} |
@ -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; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.EthTransactions; |
||||
|
||||
import java.math.BigInteger; |
||||
|
||||
public class ExpectMinimumBlockNumber implements Condition { |
||||
|
||||
private final EthTransactions eth; |
||||
private final BigInteger blockNumber; |
||||
|
||||
public ExpectMinimumBlockNumber(final EthTransactions eth, final BigInteger blockNumber) { |
||||
this.blockNumber = blockNumber; |
||||
this.eth = eth; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
assertThat(node.execute(eth.blockNumber())).isGreaterThanOrEqualTo(blockNumber); |
||||
} |
||||
} |
@ -1,48 +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; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import java.io.IOException; |
||||
import java.math.BigInteger; |
||||
|
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.methods.response.EthBlockNumber; |
||||
import org.web3j.protocol.core.methods.response.EthGetWork; |
||||
|
||||
public class Eth { |
||||
|
||||
private final Web3j web3j; |
||||
|
||||
public Eth(final Web3j web3) { |
||||
this.web3j = web3; |
||||
} |
||||
|
||||
public BigInteger blockNumber() throws IOException { |
||||
final EthBlockNumber result = web3j.ethBlockNumber().send(); |
||||
assertThat(result).isNotNull(); |
||||
assertThat(result.hasError()).isFalse(); |
||||
return result.getBlockNumber(); |
||||
} |
||||
|
||||
public String[] getWork() throws IOException { |
||||
final EthGetWork result = web3j.ethGetWork().send(); |
||||
assertThat(result).isNotNull(); |
||||
return new String[] { |
||||
result.getCurrentBlockHeaderPowHash(), |
||||
result.getSeedHashForDag(), |
||||
result.getBoundaryCondition() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import java.io.IOException; |
||||
import java.math.BigInteger; |
||||
|
||||
import org.web3j.protocol.Web3j; |
||||
|
||||
public class EthBlockNumberTransaction implements Transaction<BigInteger> { |
||||
|
||||
EthBlockNumberTransaction() {} |
||||
|
||||
@Override |
||||
public BigInteger execute(final Web3j node) { |
||||
try { |
||||
final org.web3j.protocol.core.methods.response.EthBlockNumber result = |
||||
node.ethBlockNumber().send(); |
||||
assertThat(result).isNotNull(); |
||||
assertThat(result.hasError()).isFalse(); |
||||
return result.getBlockNumber(); |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.web3j.protocol.core.DefaultBlockParameterName.LATEST; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; |
||||
|
||||
import java.io.IOException; |
||||
import java.math.BigInteger; |
||||
|
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.methods.response.EthGetBalance; |
||||
|
||||
public class EthGetBalanceTransaction implements Transaction<BigInteger> { |
||||
|
||||
private final Account account; |
||||
|
||||
EthGetBalanceTransaction(final Account account) { |
||||
this.account = account; |
||||
} |
||||
|
||||
@Override |
||||
public BigInteger execute(final Web3j node) { |
||||
try { |
||||
final EthGetBalance result = node.ethGetBalance(account.getAddress(), LATEST).send(); |
||||
assertThat(result).isNotNull(); |
||||
assertThat(result.hasError()).isFalse(); |
||||
|
||||
return result.getBalance(); |
||||
|
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.methods.response.EthGetWork; |
||||
|
||||
public class EthGetWorkTransaction implements Transaction<String[]> { |
||||
|
||||
EthGetWorkTransaction() {} |
||||
|
||||
@Override |
||||
public String[] execute(final Web3j node) { |
||||
try { |
||||
final EthGetWork result = node.ethGetWork().send(); |
||||
assertThat(result).isNotNull(); |
||||
return new String[] { |
||||
result.getCurrentBlockHeaderPowHash(), |
||||
result.getSeedHashForDag(), |
||||
result.getBoundaryCondition() |
||||
}; |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; |
||||
|
||||
public class EthTransactions { |
||||
|
||||
public EthGetWorkTransaction getWork() { |
||||
return new EthGetWorkTransaction(); |
||||
} |
||||
|
||||
public EthBlockNumberTransaction blockNumber() { |
||||
return new EthBlockNumberTransaction(); |
||||
} |
||||
|
||||
public EthGetBalanceTransaction getBalance(final Account account) { |
||||
return new EthGetBalanceTransaction(account); |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.methods.response.Web3Sha3; |
||||
|
||||
public class Web3Sha3Transaction implements Transaction<String> { |
||||
|
||||
private final String input; |
||||
|
||||
Web3Sha3Transaction(final String input) { |
||||
this.input = input; |
||||
} |
||||
|
||||
@Override |
||||
public String execute(final Web3j node) { |
||||
try { |
||||
final Web3Sha3 result = node.web3Sha3(input).send(); |
||||
assertThat(result).isNotNull(); |
||||
assertThat(result.hasError()).isFalse(); |
||||
return result.getResult(); |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
/* |
||||
* 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; |
||||
|
||||
public class Web3Transactions { |
||||
|
||||
public Web3Sha3Transaction sha3(final String input) { |
||||
return new Web3Sha3Transaction(input); |
||||
} |
||||
} |
Loading…
Reference in new issue