From a9e505fbca823515672bd41b18b310deeae3c9e8 Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Sun, 24 Sep 2023 18:23:43 -0700 Subject: [PATCH] Move BTCTestSupport from Groovy to Java Move from cj-btc-jsonrpc-gvy to cj-btc-jsonrpc module --- .../test/JTransactionTestSupport.groovy | 1 + .../bitcoin/test/BaseMainNetTestSpec.groovy | 2 +- .../bitcoin/test/BaseRegTestSpec.groovy | 2 +- .../bitcoin/jsonrpc/test/BTCTestSupport.java | 19 +++++++++---------- 4 files changed, 12 insertions(+), 12 deletions(-) rename cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/BTCTestSupport.groovy => cj-btc-jsonrpc/src/main/java/org/consensusj/bitcoin/jsonrpc/test/BTCTestSupport.java (51%) diff --git a/cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/JTransactionTestSupport.groovy b/cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/JTransactionTestSupport.groovy index 914114bd9..3c13ec58a 100644 --- a/cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/JTransactionTestSupport.groovy +++ b/cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/JTransactionTestSupport.groovy @@ -1,6 +1,7 @@ package org.consensusj.bitcoin.jsonrpc.groovy.test import org.consensusj.bitcoin.json.pojo.RawTransactionInfo +import org.consensusj.bitcoin.jsonrpc.test.BTCTestSupport import org.consensusj.bitcoin.jsonrpc.test.RegTestFundingSource import org.consensusj.bitcoin.jsonrpc.test.TransactionIngredients import org.consensusj.jsonrpc.JsonRpcStatusException diff --git a/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseMainNetTestSpec.groovy b/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseMainNetTestSpec.groovy index 68c555274..5bee84044 100644 --- a/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseMainNetTestSpec.groovy +++ b/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseMainNetTestSpec.groovy @@ -3,7 +3,7 @@ package org.consensusj.bitcoin.test import groovy.util.logging.Slf4j import org.bitcoinj.base.BitcoinNetwork import org.consensusj.bitcoin.jsonrpc.BitcoinExtendedClient -import org.consensusj.bitcoin.jsonrpc.groovy.test.BTCTestSupport +import org.consensusj.bitcoin.jsonrpc.test.BTCTestSupport import org.consensusj.bitcoin.jsonrpc.RpcURI import org.consensusj.bitcoin.jsonrpc.test.TestServers import spock.lang.Specification diff --git a/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseRegTestSpec.groovy b/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseRegTestSpec.groovy index eb12aa8a0..6ae1d4a1e 100644 --- a/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseRegTestSpec.groovy +++ b/cj-btc-jsonrpc-integ-test/src/integ/groovy/org/consensusj/bitcoin/test/BaseRegTestSpec.groovy @@ -3,7 +3,7 @@ package org.consensusj.bitcoin.test import groovy.util.logging.Slf4j import org.bitcoinj.base.BitcoinNetwork import org.consensusj.bitcoin.jsonrpc.BitcoinExtendedClient -import org.consensusj.bitcoin.jsonrpc.groovy.test.BTCTestSupport +import org.consensusj.bitcoin.jsonrpc.test.BTCTestSupport import org.consensusj.bitcoin.jsonrpc.test.FundingSource import org.consensusj.bitcoin.jsonrpc.test.FundingSourceAccessor import org.consensusj.bitcoin.jsonrpc.test.RegTestFundingSource diff --git a/cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/BTCTestSupport.groovy b/cj-btc-jsonrpc/src/main/java/org/consensusj/bitcoin/jsonrpc/test/BTCTestSupport.java similarity index 51% rename from cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/BTCTestSupport.groovy rename to cj-btc-jsonrpc/src/main/java/org/consensusj/bitcoin/jsonrpc/test/BTCTestSupport.java index b829db4df..9323203d0 100644 --- a/cj-btc-jsonrpc-gvy/src/main/groovy/org/consensusj/bitcoin/jsonrpc/groovy/test/BTCTestSupport.groovy +++ b/cj-btc-jsonrpc/src/main/java/org/consensusj/bitcoin/jsonrpc/test/BTCTestSupport.java @@ -1,27 +1,26 @@ -package org.consensusj.bitcoin.jsonrpc.groovy.test +package org.consensusj.bitcoin.jsonrpc.test; -import groovy.transform.CompileStatic -import org.bitcoinj.base.Network -import org.consensusj.bitcoin.jsonrpc.test.BitcoinClientAccessor +import org.bitcoinj.base.Network; +import org.consensusj.jsonrpc.JsonRpcException; -// TODO: Migrate to Java /** * Test support functions intended to be mixed-in to Spock test specs */ -@CompileStatic -interface BTCTestSupport extends BitcoinClientAccessor { +public interface BTCTestSupport extends BitcoinClientAccessor { /** * Wait for the server to become ready and validate the Bitcoin network it is running on - * @param expectedNetworkParams The network the server is expected to be running on + * @param expectedNetwork The network the server is expected to be running on */ - default void serverReady(Network expectedNetwork) { + default void serverReady(Network expectedNetwork) throws JsonRpcException { Boolean ready = client().waitForServer(60); // Wait up to 1 minute if (!ready) { throw new RuntimeException("Timeout waiting for server"); } // As soon as the server is ready we must initialize network parameters in the client (by querying them) Network network = client().getNetwork(); - assert network.equals(expectedNetwork); + if (!network.equals(expectedNetwork)) { + throw new IllegalStateException("Server reports unexpected Bitcoin network."); + } } }