mirror of https://github.com/hyperledger/besu
Acceptance test - refactor JsonRpc to use conditionals (#204)
parent
42d69d89ce
commit
697171d429
@ -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.condition.eth; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.catchThrowable; |
||||
|
||||
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.EthAccountsTransaction; |
||||
|
||||
import org.web3j.protocol.exceptions.ClientConnectionException; |
||||
|
||||
public class ExpectEthAccountsException implements Condition { |
||||
|
||||
private final String expectedMessage; |
||||
private final EthAccountsTransaction transaction; |
||||
|
||||
public ExpectEthAccountsException( |
||||
final EthAccountsTransaction transaction, final String expectedMessage) { |
||||
this.expectedMessage = expectedMessage; |
||||
this.transaction = transaction; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
final Throwable thrown = catchThrowable(() -> node.execute(transaction)); |
||||
assertThat(thrown).isInstanceOf(ClientConnectionException.class); |
||||
assertThat(thrown.getMessage()).contains(expectedMessage); |
||||
} |
||||
} |
@ -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.condition.eth; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.catchThrowable; |
||||
|
||||
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.EthGetWorkTransaction; |
||||
|
||||
import org.web3j.protocol.exceptions.ClientConnectionException; |
||||
|
||||
public class ExpectEthGetWorkException implements Condition { |
||||
|
||||
private final EthGetWorkTransaction transaction; |
||||
private final String expectedMessage; |
||||
|
||||
public ExpectEthGetWorkException( |
||||
final EthGetWorkTransaction transaction, final String expectedMessage) { |
||||
this.transaction = transaction; |
||||
this.expectedMessage = expectedMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
final Throwable thrown = catchThrowable(() -> node.execute(transaction)); |
||||
assertThat(thrown).isInstanceOf(ClientConnectionException.class); |
||||
assertThat(thrown.getMessage()).contains(expectedMessage); |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
/* |
||||
* 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.EthGetWorkTransaction; |
||||
|
||||
public class SanityCheckEthGetWorkValues implements Condition { |
||||
|
||||
private final EthGetWorkTransaction transaction; |
||||
|
||||
public SanityCheckEthGetWorkValues(final EthGetWorkTransaction transaction) { |
||||
this.transaction = transaction; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
final String[] response = node.execute(transaction); |
||||
assertThat(response).hasSize(3); |
||||
assertThat(response).doesNotContainNull(); |
||||
} |
||||
} |
@ -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.net; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.catchThrowable; |
||||
|
||||
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.net.NetVersionTransaction; |
||||
|
||||
import java.net.ConnectException; |
||||
|
||||
public class ExpectNetVersionConnectionException implements Condition { |
||||
|
||||
private final NetVersionTransaction transaction; |
||||
private final String expectedMessage; |
||||
|
||||
public ExpectNetVersionConnectionException( |
||||
final NetVersionTransaction transaction, final String expectedMessage) { |
||||
this.transaction = transaction; |
||||
this.expectedMessage = expectedMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
final Throwable thrown = catchThrowable(() -> node.execute(transaction)); |
||||
assertThat(thrown).isInstanceOf(RuntimeException.class); |
||||
|
||||
final Throwable cause = thrown.getCause(); |
||||
assertThat(cause).isInstanceOf(ConnectException.class); |
||||
assertThat(cause.getMessage()).contains(expectedMessage); |
||||
} |
||||
} |
@ -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.condition.net; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.catchThrowable; |
||||
|
||||
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.net.NetVersionTransaction; |
||||
|
||||
public class ExpectNetVersionConnectionExceptionWithCause implements Condition { |
||||
|
||||
private final NetVersionTransaction transaction; |
||||
private final Class<? extends Throwable> cause; |
||||
|
||||
public ExpectNetVersionConnectionExceptionWithCause( |
||||
final NetVersionTransaction transaction, final Class<? extends Throwable> cause) { |
||||
this.transaction = transaction; |
||||
this.cause = cause; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
final Throwable thrown = catchThrowable(() -> node.execute(transaction)); |
||||
assertThat(thrown).isInstanceOf(cause); |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
/* |
||||
* 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.net; |
||||
|
||||
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.net.NetVersionTransaction; |
||||
|
||||
public class ExpectNetVersionIsNotBlank implements Condition { |
||||
|
||||
private final NetVersionTransaction transaction; |
||||
|
||||
public ExpectNetVersionIsNotBlank(final NetVersionTransaction transaction) { |
||||
this.transaction = transaction; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
assertThat(node.execute(transaction)).isNotBlank(); |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
/* |
||||
* 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.web3; |
||||
|
||||
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.web3.Web3Sha3Transaction; |
||||
|
||||
public class ExpectWeb3Sha3Equals implements Condition { |
||||
|
||||
private final Web3Sha3Transaction input; |
||||
private final String hash; |
||||
|
||||
public ExpectWeb3Sha3Equals(final Web3Sha3Transaction input, final String expectedHash) { |
||||
this.hash = expectedHash; |
||||
this.input = input; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
assertThat(node.execute(input)).isEqualTo(hash); |
||||
} |
||||
} |
@ -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.jsonrpc; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectEthAccountsException; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.ExpectEthGetWorkException; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eth.SanityCheckEthGetWorkValues; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; |
||||
|
||||
public class Eth { |
||||
|
||||
private final EthTransactions transactions; |
||||
|
||||
public Eth(final EthTransactions transactions) { |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
public Condition getWork() { |
||||
return new SanityCheckEthGetWorkValues(transactions.getWork()); |
||||
} |
||||
|
||||
public Condition getWorkExceptional(final String expectedMessage) { |
||||
return new ExpectEthGetWorkException(transactions.getWork(), expectedMessage); |
||||
} |
||||
|
||||
public Condition accountsExceptional(final String expectedMessage) { |
||||
return new ExpectEthAccountsException(transactions.accounts(), expectedMessage); |
||||
} |
||||
} |
@ -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.jsonrpc; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionConnectionException; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionConnectionExceptionWithCause; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.ExpectNetVersionIsNotBlank; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions; |
||||
|
||||
public class Net { |
||||
|
||||
private final NetTransactions transactions; |
||||
|
||||
public Net(final NetTransactions transactions) { |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
public Condition netVersion() { |
||||
return new ExpectNetVersionIsNotBlank(transactions.netVersion()); |
||||
} |
||||
|
||||
public Condition netVersionExceptional(final String expectedMessage) { |
||||
return new ExpectNetVersionConnectionException(transactions.netVersion(), expectedMessage); |
||||
} |
||||
|
||||
public Condition netVersionExceptional(final Class<? extends Throwable> cause) { |
||||
return new ExpectNetVersionConnectionExceptionWithCause(transactions.netVersion(), cause); |
||||
} |
||||
} |
@ -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.jsonrpc; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.web3.ExpectWeb3Sha3Equals; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.web3.Web3Transactions; |
||||
|
||||
public class Web3 { |
||||
|
||||
private final Web3Transactions transactions; |
||||
|
||||
public Web3(final Web3Transactions transactions) { |
||||
this.transactions = transactions; |
||||
} |
||||
|
||||
public Condition sha3(final String input, final String expectedHash) { |
||||
return new ExpectWeb3Sha3Equals(transactions.sha3(input), expectedHash); |
||||
} |
||||
} |
@ -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.net; |
||||
|
||||
public class NetTransactions { |
||||
|
||||
public NetVersionTransaction netVersion() { |
||||
return new NetVersionTransaction(); |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
/* |
||||
* 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.net; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.web3j.protocol.Web3j; |
||||
import org.web3j.protocol.core.methods.response.NetVersion; |
||||
|
||||
public class NetVersionTransaction implements Transaction<String> { |
||||
|
||||
NetVersionTransaction() {} |
||||
|
||||
@Override |
||||
public String execute(final Web3j node) { |
||||
try { |
||||
final NetVersion result = node.netVersion().send(); |
||||
assertThat(result).isNotNull(); |
||||
assertThat(result.hasError()).isFalse(); |
||||
return result.getNetVersion(); |
||||
} catch (final IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue