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.
This commit is contained in:
ghubstan 2020-10-28 17:59:15 -03:00
parent 2a05203519
commit f61f148db1
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
4 changed files with 113 additions and 108 deletions

View File

@ -43,11 +43,14 @@ import protobuf.PaymentAccount;
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 static PaymentAccount alicesDummyAcct;
protected static PaymentAccount bobsDummyAcct;
protected final void initAlicesDummyPaymentAccount() {
alicesDummyAcct = getDefaultPerfectDummyPaymentAccount(alicedaemon);
}
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);
}
protected final void initBobsDummyPaymentAccount() {
bobsDummyAcct = getDefaultPerfectDummyPaymentAccount(bobdaemon);
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 @@ public class MethodTest extends ApiTestCase {
.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)

View File

@ -36,7 +36,6 @@ import lombok.extern.slf4j.Slf4j;
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,

View File

@ -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 @@ import bisq.apitest.method.offer.AbstractOfferTest;
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 @@ public class AbstractTradeTest extends AbstractOfferTest {
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;
}
}
}

View File

@ -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;
}
}