Skip to content

Commit

Permalink
Adjust trade apitest cases, anticipating offerFilter.canTakeOffer
Browse files Browse the repository at this point in the history
Refering to PR bisq-network#5053.

Test cases need to explicitly use a matching fiat payment account
type when calling 'getoffers'.
  • Loading branch information
ghubstan committed Jan 5, 2021
1 parent 18de222 commit 03a814f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
package bisq.apitest.method.offer;

import bisq.core.monetary.Altcoin;
import bisq.core.payment.PaymentAccount;

import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.GetMyOffersRequest;
import bisq.proto.grpc.GetOffersRequest;
import bisq.proto.grpc.OfferInfo;

import protobuf.PaymentAccount;

import org.bitcoinj.utils.Fiat;

import java.math.BigDecimal;
Expand Down Expand Up @@ -139,10 +138,6 @@ protected final OfferInfo getMostRecentOffer(GrpcStubs grpcStubs, String directi
return offerInfoList.get(offerInfoList.size() - 1);
}

protected final int getOpenOffersCount(GrpcStubs grpcStubs, String direction, String currencyCode) {
return getOffersSortedByDate(grpcStubs, direction, currencyCode).size();
}

protected final List<OfferInfo> getOffersSortedByDate(GrpcStubs grpcStubs,
String direction,
String currencyCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.apitest.method.trade;

import bisq.core.payment.PaymentAccount;

import bisq.proto.grpc.BtcBalanceInfo;

import io.grpc.StatusRuntimeException;
Expand Down Expand Up @@ -59,7 +61,8 @@ public class TakeBuyBTCOfferTest extends AbstractTradeTest {
@Order(1)
public void testTakeAlicesBuyOffer(final TestInfo testInfo) {
try {
var alicesOffer = createAliceOffer(alicesDummyAcct,
PaymentAccount alicesUsdAccount = createDummyF2FAccount(alicedaemon, "US");
var alicesOffer = createAliceOffer(alicesUsdAccount,
"buy",
"usd",
12500000,
Expand All @@ -70,17 +73,20 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) {
// Wait for Alice's AddToOfferBook task.
// Wait times vary; my logs show >= 2 second delay.
sleep(3000); // TODO loop instead of hard code wait time
assertEquals(1, getOpenOffersCount(aliceStubs, "buy", "usd"));
var alicesUsdOffers = getMyOffersSortedByDate(aliceStubs, "buy", "usd");
assertEquals(1, alicesUsdOffers.size());

var trade = takeAlicesOffer(offerId, bobsDummyAcct.getId(), TRADE_FEE_CURRENCY_CODE);
PaymentAccount bobsUsdAccount = createDummyF2FAccount(bobdaemon, "US");
var trade = takeAlicesOffer(offerId, bobsUsdAccount.getId(), TRADE_FEE_CURRENCY_CODE);
assertNotNull(trade);
assertEquals(offerId, trade.getTradeId());
assertFalse(trade.getIsCurrencyForTakerFeeBtc());
// Cache the trade id for the other tests.
tradeId = trade.getTradeId();

genBtcBlocksThenWait(1, 1000);
assertEquals(0, getOpenOffersCount(aliceStubs, "buy", "usd"));
alicesUsdOffers = getMyOffersSortedByDate(aliceStubs, "buy", "usd");
assertEquals(0, alicesUsdOffers.size());

trade = getTrade(bobdaemon, trade.getTradeId());
EXPECTED_PROTOCOL_STATUS.setState(SELLER_PUBLISHED_DEPOSIT_TX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.apitest.method.trade;

import bisq.core.payment.PaymentAccount;

import bisq.proto.grpc.BtcBalanceInfo;

import io.grpc.StatusRuntimeException;
Expand Down Expand Up @@ -58,7 +60,8 @@ public class TakeSellBTCOfferTest extends AbstractTradeTest {
@Order(1)
public void testTakeAlicesSellOffer(final TestInfo testInfo) {
try {
var alicesOffer = createAliceOffer(alicesDummyAcct,
PaymentAccount alicesUsdAccount = createDummyF2FAccount(alicedaemon, "US");
var alicesOffer = createAliceOffer(alicesUsdAccount,
"sell",
"usd",
12500000,
Expand All @@ -70,17 +73,20 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) {
// Wait times vary; my logs show >= 2 second delay, but taking sell offers
// seems to require more time to prepare.
sleep(3000); // TODO loop instead of hard code wait time
assertEquals(1, getOpenOffersCount(bobStubs, "sell", "usd"));
var alicesUsdOffers = getMyOffersSortedByDate(aliceStubs, "sell", "usd");
assertEquals(1, alicesUsdOffers.size());

var trade = takeAlicesOffer(offerId, bobsDummyAcct.getId(), TRADE_FEE_CURRENCY_CODE);
PaymentAccount bobsUsdAccount = createDummyF2FAccount(bobdaemon, "US");
var trade = takeAlicesOffer(offerId, bobsUsdAccount.getId(), TRADE_FEE_CURRENCY_CODE);
assertNotNull(trade);
assertEquals(offerId, trade.getTradeId());
assertTrue(trade.getIsCurrencyForTakerFeeBtc());
// Cache the trade id for the other tests.
tradeId = trade.getTradeId();

genBtcBlocksThenWait(1, 4000);
assertEquals(0, getOpenOffersCount(bobStubs, "sell", "usd"));
var takeableUsdOffers = getOffersSortedByDate(bobStubs, "sell", "usd");
assertEquals(0, takeableUsdOffers.size());

trade = getTrade(bobdaemon, trade.getTradeId());
EXPECTED_PROTOCOL_STATUS.setState(BUYER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG)
Expand Down

0 comments on commit 03a814f

Please sign in to comment.