Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stub out 'canceloffer offer-id' api method #4713

Merged
merged 23 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cb65de6
Block on tx-fee-request in core TakeOfferModel init
ghubstan Oct 23, 2020
ab20225
Add compiler warning suppression, remove comment
ghubstan Oct 24, 2020
63cf436
Add fields to grpc TradeInfo proto & wrapper
ghubstan Oct 24, 2020
296e4f9
Replace static TradeUtil with singleton TradeUtil
ghubstan Oct 24, 2020
ccd3c99
Fix comment typos
ghubstan Oct 24, 2020
24ba921
Refactor PendingTradesViewModel methods -> TradeUtil & OfferUtil
ghubstan Oct 25, 2020
36ad137
Remove trailing spaces for codacy
ghubstan Oct 25, 2020
95bcb1e
Refactor PendingTradesDataModel methods -> TradeUtil
ghubstan Oct 25, 2020
bbd7a31
Remove unused import
ghubstan Oct 25, 2020
161dbad
Add getRole(tradeId) to core api
ghubstan Oct 25, 2020
3379376
Refactor CLI output formatting code & add trade formatter
ghubstan Oct 25, 2020
d8bc265
Add license comment
ghubstan Oct 25, 2020
31435bb
Move semicolon up from blank line
ghubstan Oct 25, 2020
2b23704
Add 'gettrade' to api method CLI
ghubstan Oct 25, 2020
a2b2923
Add boolean 'showcontract' argument to api's 'gettrade'
ghubstan Oct 25, 2020
a8decaf
Stub out api methods 'keepfunds', 'withdrawfunds'
ghubstan Oct 26, 2020
a3631a0
Implement api methods 'keepfunds', 'withdrawfunds'
ghubstan Oct 26, 2020
f1db254
Make formatSatoshis visible for testing
ghubstan Oct 27, 2020
b8ae566
Add method for printing current jupiter test name
ghubstan Oct 27, 2020
1e25be5
Test trade closing api methods 'keepfunds' withdrawfunds'
ghubstan Oct 27, 2020
2746b27
Fix apitest dummy payment acct init bug
ghubstan Oct 27, 2020
027a7d5
Stub out canceloffer api method
ghubstan Oct 27, 2020
0f1d4f8
Fix typo
ghubstan Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apitest/src/test/java/bisq/apitest/ApiTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import org.junit.jupiter.api.TestInfo;

import static java.util.Arrays.stream;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

Expand Down Expand Up @@ -117,4 +119,10 @@ protected static void sleep(long ms) {
// empty
}
}

protected final String testName(TestInfo testInfo) {
return testInfo.getTestMethod().isPresent()
? testInfo.getTestMethod().get().getName()
: "unknown test name";
}
}
45 changes: 45 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.proto.grpc.GetOfferRequest;
import bisq.proto.grpc.GetPaymentAccountsRequest;
import bisq.proto.grpc.GetTradeRequest;
import bisq.proto.grpc.KeepFundsRequest;
import bisq.proto.grpc.LockWalletRequest;
import bisq.proto.grpc.MarketPriceRequest;
import bisq.proto.grpc.OfferInfo;
Expand All @@ -34,11 +35,14 @@
import bisq.proto.grpc.TakeOfferRequest;
import bisq.proto.grpc.TradeInfo;
import bisq.proto.grpc.UnlockWalletRequest;
import bisq.proto.grpc.WithdrawFundsRequest;

import protobuf.PaymentAccount;

import java.util.stream.Collectors;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
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.Comparator.comparing;
Expand All @@ -48,13 +52,28 @@

import bisq.apitest.ApiTestCase;
import bisq.apitest.config.BisqAppConfig;
import bisq.cli.GrpcStubs;

public class MethodTest extends ApiTestCase {

protected static final String ARBITRATOR = "arbitrator";
protected static final String MEDIATOR = "mediator";
protected static final String REFUND_AGENT = "refundagent";

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

// Convenience methods for building gRPC request objects

protected final GetBalanceRequest createBalanceRequest() {
Expand Down Expand Up @@ -109,6 +128,19 @@ protected final ConfirmPaymentReceivedRequest createConfirmPaymentReceivedReques
return ConfirmPaymentReceivedRequest.newBuilder().setTradeId(tradeId).build();
}

protected final KeepFundsRequest createKeepFundsRequest(String tradeId) {
return KeepFundsRequest.newBuilder()
.setTradeId(tradeId)
.build();
}

protected final WithdrawFundsRequest createWithdrawFundsRequest(String tradeId, String address) {
return WithdrawFundsRequest.newBuilder()
.setTradeId(tradeId)
.setAddress(address)
.build();
}

// Convenience methods for calling frequently used & thoroughly tested gRPC services.

protected final long getBalance(BisqAppConfig bisqAppConfig) {
Expand Down Expand Up @@ -175,16 +207,29 @@ protected final TradeInfo getTrade(BisqAppConfig bisqAppConfig, String tradeId)
return grpcStubs(bisqAppConfig).tradesService.getTrade(req).getTrade();
}

@SuppressWarnings("ResultOfMethodCallIgnored")
protected final void confirmPaymentStarted(BisqAppConfig bisqAppConfig, String tradeId) {
var req = createConfirmPaymentStartedRequest(tradeId);
grpcStubs(bisqAppConfig).tradesService.confirmPaymentStarted(req);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
protected final void confirmPaymentReceived(BisqAppConfig bisqAppConfig, String tradeId) {
var req = createConfirmPaymentReceivedRequest(tradeId);
grpcStubs(bisqAppConfig).tradesService.confirmPaymentReceived(req);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
protected final void keepFunds(BisqAppConfig bisqAppConfig, String tradeId) {
var req = createKeepFundsRequest(tradeId);
grpcStubs(bisqAppConfig).tradesService.keepFunds(req);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
protected final void withdrawFunds(BisqAppConfig bisqAppConfig, String tradeId, String address) {
var req = createWithdrawFundsRequest(tradeId, address);
grpcStubs(bisqAppConfig).tradesService.withdrawFunds(req);
}
// Static conveniences for test methods and test case fixture setups.

protected static RegisterDisputeAgentRequest createRegisterDisputeAgentRequest(String disputeAgentType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public static void setUp() {
@Test
@Order(1)
public void testRegisterArbitratorShouldThrowException() {
var req =
createRegisterDisputeAgentRequest(ARBITRATOR);
var req = createRegisterDisputeAgentRequest(ARBITRATOR);
Throwable exception = assertThrows(StatusRuntimeException.class, () ->
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req));
assertEquals("INVALID_ARGUMENT: arbitrators must be registered in a Bisq UI",
Expand All @@ -67,8 +66,7 @@ public void testRegisterArbitratorShouldThrowException() {
@Test
@Order(2)
public void testInvalidDisputeAgentTypeArgShouldThrowException() {
var req =
createRegisterDisputeAgentRequest("badagent");
var req = createRegisterDisputeAgentRequest("badagent");
Throwable exception = assertThrows(StatusRuntimeException.class, () ->
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req));
assertEquals("INVALID_ARGUMENT: unknown dispute agent type 'badagent'",
Expand All @@ -90,16 +88,14 @@ public void testInvalidRegistrationKeyArgShouldThrowException() {
@Test
@Order(4)
public void testRegisterMediator() {
var req =
createRegisterDisputeAgentRequest(MEDIATOR);
var req = createRegisterDisputeAgentRequest(MEDIATOR);
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req);
}

@Test
@Order(5)
public void testRegisterRefundAgent() {
var req =
createRegisterDisputeAgentRequest(REFUND_AGENT);
var req = createRegisterDisputeAgentRequest(REFUND_AGENT);
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

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;
Expand All @@ -59,14 +60,16 @@
@Slf4j
public abstract class AbstractOfferTest extends MethodTest {

protected static GrpcStubs aliceStubs;
protected static GrpcStubs bobStubs;

@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"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand All @@ -37,12 +36,12 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CreateOfferUsingFixedPriceTest extends AbstractOfferTest {


@Test
@Order(1)
public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("buy")
.setCurrencyCode("aud")
.setAmount(10000000)
Expand All @@ -61,7 +60,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
assertEquals(10000000, newOffer.getAmount());
assertEquals(10000000, newOffer.getMinAmount());
assertEquals(1500000, newOffer.getBuyerSecurityDeposit());
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("AUD", newOffer.getCounterCurrencyCode());

Expand All @@ -73,17 +72,16 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
assertEquals(10000000, newOffer.getAmount());
assertEquals(10000000, newOffer.getMinAmount());
assertEquals(1500000, newOffer.getBuyerSecurityDeposit());
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("AUD", newOffer.getCounterCurrencyCode());
}

@Test
@Order(2)
public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("buy")
.setCurrencyCode("usd")
.setAmount(10000000)
Expand All @@ -102,7 +100,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
assertEquals(10000000, newOffer.getAmount());
assertEquals(10000000, newOffer.getMinAmount());
assertEquals(1500000, newOffer.getBuyerSecurityDeposit());
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("USD", newOffer.getCounterCurrencyCode());

Expand All @@ -114,17 +112,16 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
assertEquals(10000000, newOffer.getAmount());
assertEquals(10000000, newOffer.getMinAmount());
assertEquals(1500000, newOffer.getBuyerSecurityDeposit());
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("USD", newOffer.getCounterCurrencyCode());
}

@Test
@Order(3)
public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("sell")
.setCurrencyCode("eur")
.setAmount(10000000)
Expand All @@ -143,7 +140,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
assertEquals(10000000, newOffer.getAmount());
assertEquals(10000000, newOffer.getMinAmount());
assertEquals(1500000, newOffer.getBuyerSecurityDeposit());
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("EUR", newOffer.getCounterCurrencyCode());

Expand All @@ -155,7 +152,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
assertEquals(10000000, newOffer.getAmount());
assertEquals(10000000, newOffer.getMinAmount());
assertEquals(1500000, newOffer.getBuyerSecurityDeposit());
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("EUR", newOffer.getCounterCurrencyCode());
}
Expand Down
Loading