From 2a052035190081c51d561e4e431ffca2b68987ec Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:46:30 -0300 Subject: [PATCH 1/3] Remove dead code --- .../src/main/java/bisq/apitest/linux/AbstractLinuxProcess.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/apitest/src/main/java/bisq/apitest/linux/AbstractLinuxProcess.java b/apitest/src/main/java/bisq/apitest/linux/AbstractLinuxProcess.java index 4687477e956..770df37ede2 100644 --- a/apitest/src/main/java/bisq/apitest/linux/AbstractLinuxProcess.java +++ b/apitest/src/main/java/bisq/apitest/linux/AbstractLinuxProcess.java @@ -70,10 +70,8 @@ public boolean hasShutdownExceptions() { @Override public void logExceptions(List exceptions, org.slf4j.Logger log) { - StringBuilder errorBuilder = new StringBuilder(); for (Throwable t : exceptions) { log.error("", t); - errorBuilder.append(t.getMessage()).append("\n"); } } From f61f148db194f38b16b299027a82289eea6d78ca Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:59:15 -0300 Subject: [PATCH 2/3] Refactor api test fixture setup - Remove dead code from AbstractLinuxProcess. - Make default dummy accts static in MethodTest. - Simplify gRPC stub creation, btc block generation, dispute agent registration, and dummy acct initialization in test case startup. - Make ExpectedProtocolStatus visible to scenario test pkg. --- .../java/bisq/apitest/method/MethodTest.java | 47 ++++++++--- .../method/offer/AbstractOfferTest.java | 30 ++----- .../method/trade/AbstractTradeTest.java | 79 +------------------ .../method/trade/ExpectedProtocolStatus.java | 69 ++++++++++++++++ 4 files changed, 115 insertions(+), 110 deletions(-) create mode 100644 apitest/src/test/java/bisq/apitest/method/trade/ExpectedProtocolStatus.java diff --git a/apitest/src/test/java/bisq/apitest/method/MethodTest.java b/apitest/src/test/java/bisq/apitest/method/MethodTest.java index dcf438f245e..6b21d76fb4a 100644 --- a/apitest/src/test/java/bisq/apitest/method/MethodTest.java +++ b/apitest/src/test/java/bisq/apitest/method/MethodTest.java @@ -43,11 +43,14 @@ import java.util.stream.Collectors; import static bisq.apitest.config.BisqAppConfig.alicedaemon; +import static bisq.apitest.config.BisqAppConfig.arbdaemon; import static bisq.apitest.config.BisqAppConfig.bobdaemon; import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY; import static bisq.core.payment.payload.PaymentMethod.PERFECT_MONEY; +import static java.util.Arrays.stream; import static java.util.Comparator.comparing; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; @@ -64,15 +67,39 @@ public class MethodTest extends ApiTestCase { protected static GrpcStubs aliceStubs; protected static GrpcStubs bobStubs; - protected PaymentAccount alicesDummyAcct; - protected PaymentAccount bobsDummyAcct; - - protected final void initAlicesDummyPaymentAccount() { - alicesDummyAcct = getDefaultPerfectDummyPaymentAccount(alicedaemon); - } - - protected final void initBobsDummyPaymentAccount() { - bobsDummyAcct = getDefaultPerfectDummyPaymentAccount(bobdaemon); + protected static PaymentAccount alicesDummyAcct; + protected static PaymentAccount bobsDummyAcct; + + public static void startSupportingApps(boolean registerDisputeAgents, + boolean generateBtcBlock, + Enum... supportingApps) { + try { + // To run Bisq apps in debug mode, use the other setUpScaffold method: + // setUpScaffold(new String[]{"--supportingApps", "bitcoind,seednode,arbdaemon,alicedaemon,bobdaemon", + // "--enableBisqDebugging", "true"}); + setUpScaffold(supportingApps); + if (registerDisputeAgents) { + registerDisputeAgents(arbdaemon); + } + + if (stream(supportingApps).map(Enum::name).anyMatch(name -> name.equals(alicedaemon.name()))) { + aliceStubs = grpcStubs(alicedaemon); + alicesDummyAcct = getDefaultPerfectDummyPaymentAccount(alicedaemon); + } + + if (stream(supportingApps).map(Enum::name).anyMatch(name -> name.equals(bobdaemon.name()))) { + bobStubs = grpcStubs(bobdaemon); + bobsDummyAcct = getDefaultPerfectDummyPaymentAccount(bobdaemon); + } + + // Generate 1 regtest block for alice's and/or bob's wallet to + // show 10 BTC balance, and allow time for daemons parse the new block. + if (generateBtcBlock) + genBtcBlocksThenWait(1, 1500); + + } catch (Exception ex) { + fail(ex); + } } // Convenience methods for building gRPC request objects @@ -185,7 +212,7 @@ protected final CreatePaymentAccountRequest createCreatePerfectMoneyPaymentAccou .build(); } - protected final PaymentAccount getDefaultPerfectDummyPaymentAccount(BisqAppConfig bisqAppConfig) { + protected static PaymentAccount getDefaultPerfectDummyPaymentAccount(BisqAppConfig bisqAppConfig) { var req = GetPaymentAccountsRequest.newBuilder().build(); var paymentAccountsService = grpcStubs(bisqAppConfig).paymentAccountsService; PaymentAccount paymentAccount = paymentAccountsService.getPaymentAccounts(req) diff --git a/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java index b1bae6fbd86..fe9a98aaaae 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java @@ -36,7 +36,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; import static bisq.apitest.config.BisqAppConfig.alicedaemon; @@ -62,28 +61,13 @@ public abstract class AbstractOfferTest extends MethodTest { @BeforeAll public static void setUp() { - startSupportingApps(); - } - - @BeforeEach - public void initDummyPaymentAccount() { - super.initAlicesDummyPaymentAccount(); - } - - static void startSupportingApps() { - try { - // setUpScaffold(new String[]{"--supportingApps", "bitcoind,seednode,arbdaemon,alicedaemon,bobdaemon", "--enableBisqDebugging", "true"}); - setUpScaffold(bitcoind, seednode, arbdaemon, alicedaemon, bobdaemon); - registerDisputeAgents(arbdaemon); - aliceStubs = grpcStubs(alicedaemon); - bobStubs = grpcStubs(bobdaemon); - - // Generate 1 regtest block for alice's wallet to show 10 BTC balance, - // and give alicedaemon time to parse the new block. - genBtcBlocksThenWait(1, 1500); - } catch (Exception ex) { - fail(ex); - } + startSupportingApps(true, + true, + bitcoind, + seednode, + arbdaemon, + alicedaemon, + bobdaemon); } protected final OfferInfo createAliceOffer(PaymentAccount paymentAccount, diff --git a/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java b/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java index 22aee1d70dd..e8537206dbf 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java @@ -1,13 +1,10 @@ package bisq.apitest.method.trade; -import bisq.core.trade.Trade; - import bisq.proto.grpc.TradeInfo; import org.slf4j.Logger; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; import static bisq.cli.TradeFormat.format; @@ -20,24 +17,16 @@ public class AbstractTradeTest extends AbstractOfferTest { - // A test fixture encapsulating expected trade protocol status. - // ExpectedProtocolStatus.init should be called before any @Test begins. - protected static final ExpectedProtocolStatus EXPECTED_PROTOCOL_STATUS = new ExpectedProtocolStatus(); + public static final ExpectedProtocolStatus EXPECTED_PROTOCOL_STATUS = new ExpectedProtocolStatus(); // A Trade ID cache for use in @Test sequences. protected static String tradeId; @BeforeAll - public static void clearExpectedPaymentStatusFlags() { + public static void initStaticFixtures() { EXPECTED_PROTOCOL_STATUS.init(); } - @BeforeEach - public void initDummyPaymentAccounts() { - super.initAlicesDummyPaymentAccount(); - super.initBobsDummyPaymentAccount(); - } - protected final TradeInfo takeAlicesOffer(String offerId, String paymentAccountId) { return bobStubs.tradesService.takeOffer(createTakeOfferRequest(offerId, paymentAccountId)).getTrade(); } @@ -68,68 +57,4 @@ protected final void logTrade(Logger log, description.toUpperCase(), format(trade))); } - - @SuppressWarnings("UnusedReturnValue") - static class ExpectedProtocolStatus { - Trade.State state; - Trade.Phase phase; - boolean isDepositPublished; - boolean isDepositConfirmed; - boolean isFiatSent; - boolean isFiatReceived; - boolean isPayoutPublished; - boolean isWithdrawn; - - ExpectedProtocolStatus setState(Trade.State state) { - this.state = state; - return this; - } - - ExpectedProtocolStatus setPhase(Trade.Phase phase) { - this.phase = phase; - return this; - } - - ExpectedProtocolStatus setDepositPublished(boolean depositPublished) { - isDepositPublished = depositPublished; - return this; - } - - ExpectedProtocolStatus setDepositConfirmed(boolean depositConfirmed) { - isDepositConfirmed = depositConfirmed; - return this; - } - - ExpectedProtocolStatus setFiatSent(boolean fiatSent) { - isFiatSent = fiatSent; - return this; - } - - ExpectedProtocolStatus setFiatReceived(boolean fiatReceived) { - isFiatReceived = fiatReceived; - return this; - } - - ExpectedProtocolStatus setPayoutPublished(boolean payoutPublished) { - isPayoutPublished = payoutPublished; - return this; - } - - ExpectedProtocolStatus setWithdrawn(boolean withdrawn) { - isWithdrawn = withdrawn; - return this; - } - - @SuppressWarnings("unused") - void init() { - state = null; - phase = null; - isDepositPublished = false; - isDepositConfirmed = false; - isFiatSent = false; - isFiatReceived = false; - isPayoutPublished = false; - isWithdrawn = false; - } - } } diff --git a/apitest/src/test/java/bisq/apitest/method/trade/ExpectedProtocolStatus.java b/apitest/src/test/java/bisq/apitest/method/trade/ExpectedProtocolStatus.java new file mode 100644 index 00000000000..63655585947 --- /dev/null +++ b/apitest/src/test/java/bisq/apitest/method/trade/ExpectedProtocolStatus.java @@ -0,0 +1,69 @@ +package bisq.apitest.method.trade; + +import bisq.core.trade.Trade; + +/** + * A test fixture encapsulating expected trade protocol status. + * Status flags should be cleared via init() before starting a new trade protocol. + */ +public class ExpectedProtocolStatus { + Trade.State state; + Trade.Phase phase; + boolean isDepositPublished; + boolean isDepositConfirmed; + boolean isFiatSent; + boolean isFiatReceived; + boolean isPayoutPublished; + boolean isWithdrawn; + + public ExpectedProtocolStatus setState(Trade.State state) { + this.state = state; + return this; + } + + public ExpectedProtocolStatus setPhase(Trade.Phase phase) { + this.phase = phase; + return this; + } + + public ExpectedProtocolStatus setDepositPublished(boolean depositPublished) { + isDepositPublished = depositPublished; + return this; + } + + public ExpectedProtocolStatus setDepositConfirmed(boolean depositConfirmed) { + isDepositConfirmed = depositConfirmed; + return this; + } + + public ExpectedProtocolStatus setFiatSent(boolean fiatSent) { + isFiatSent = fiatSent; + return this; + } + + public ExpectedProtocolStatus setFiatReceived(boolean fiatReceived) { + isFiatReceived = fiatReceived; + return this; + } + + public ExpectedProtocolStatus setPayoutPublished(boolean payoutPublished) { + isPayoutPublished = payoutPublished; + return this; + } + + public ExpectedProtocolStatus setWithdrawn(boolean withdrawn) { + isWithdrawn = withdrawn; + return this; + } + + public void init() { + state = null; + phase = null; + isDepositPublished = false; + isDepositConfirmed = false; + isFiatSent = false; + isFiatReceived = false; + isPayoutPublished = false; + isWithdrawn = false; + } +} From e8e55d2286ec8063361c3ece281883648e6c6ba9 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:01:49 -0300 Subject: [PATCH 3/3] Remove redundant ScenarioTest superclass --- .../scenario/FundWalletScenarioTest.java | 6 +++- .../bisq/apitest/scenario/ScenarioTest.java | 28 ------------------- 2 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 apitest/src/test/java/bisq/apitest/scenario/ScenarioTest.java diff --git a/apitest/src/test/java/bisq/apitest/scenario/FundWalletScenarioTest.java b/apitest/src/test/java/bisq/apitest/scenario/FundWalletScenarioTest.java index 75977949c33..4b7d40f516c 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/FundWalletScenarioTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/FundWalletScenarioTest.java @@ -33,9 +33,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; + + +import bisq.apitest.method.MethodTest; + @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class FundWalletScenarioTest extends ScenarioTest { +public class FundWalletScenarioTest extends MethodTest { @BeforeAll public static void setUp() { diff --git a/apitest/src/test/java/bisq/apitest/scenario/ScenarioTest.java b/apitest/src/test/java/bisq/apitest/scenario/ScenarioTest.java deleted file mode 100644 index 9750b2ed9d6..00000000000 --- a/apitest/src/test/java/bisq/apitest/scenario/ScenarioTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.apitest.scenario; - -import lombok.extern.slf4j.Slf4j; - - - -import bisq.apitest.method.MethodTest; - -@Slf4j -public class ScenarioTest extends MethodTest { -}