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

Test trade closing api methods 'keepfunds' and 'withdrawfunds' #4712

Merged
merged 21 commits into from Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 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
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Expand Up @@ -41,8 +41,6 @@

import java.util.stream.Collectors;

import org.junit.jupiter.api.BeforeEach;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.bobdaemon;
import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY;
Expand All @@ -68,9 +66,11 @@ public class MethodTest extends ApiTestCase {
protected PaymentAccount alicesDummyAcct;
protected PaymentAccount bobsDummyAcct;

@BeforeEach
public void initDummyPaymentAccounts() {
protected final void initAlicesDummyPaymentAccount() {
alicesDummyAcct = getDefaultPerfectDummyPaymentAccount(alicedaemon);
}

protected final void initBobsDummyPaymentAccount() {
bobsDummyAcct = getDefaultPerfectDummyPaymentAccount(bobdaemon);
}

Expand Down
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
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 Down Expand Up @@ -64,6 +65,11 @@ 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
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
Expand Up @@ -31,7 +31,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.common.util.MathUtils.scaleDownByPowerOf10;
import static bisq.common.util.MathUtils.scaleUpByPowerOf10;
import static java.lang.Math.abs;
Expand All @@ -52,10 +51,9 @@ public class CreateOfferUsingMarketPriceMarginTest extends AbstractOfferTest {
@Test
@Order(1)
public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
double priceMarginPctInput = 5.00;
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("buy")
.setCurrencyCode("usd")
.setAmount(10000000)
Expand All @@ -73,7 +71,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
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 @@ -84,7 +82,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
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 @@ -94,10 +92,9 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
@Test
@Order(2)
public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
double priceMarginPctInput = -2.00;
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("buy")
.setCurrencyCode("nzd")
.setAmount(10000000)
Expand All @@ -115,7 +112,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
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("NZD", newOffer.getCounterCurrencyCode());

Expand All @@ -126,7 +123,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
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("NZD", newOffer.getCounterCurrencyCode());

Expand All @@ -136,10 +133,9 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
@Test
@Order(3)
public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
double priceMarginPctInput = -1.5;
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("sell")
.setCurrencyCode("gbp")
.setAmount(10000000)
Expand All @@ -158,7 +154,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
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("GBP", newOffer.getCounterCurrencyCode());

Expand All @@ -169,7 +165,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
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("GBP", newOffer.getCounterCurrencyCode());

Expand All @@ -179,10 +175,9 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
@Test
@Order(4)
public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
double priceMarginPctInput = 6.55;
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("sell")
.setCurrencyCode("brl")
.setAmount(10000000)
Expand All @@ -201,7 +196,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
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("BRL", newOffer.getCounterCurrencyCode());

Expand All @@ -212,7 +207,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
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("BRL", newOffer.getCounterCurrencyCode());

Expand Down
Expand Up @@ -30,7 +30,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.assertThrows;

Expand All @@ -41,9 +40,8 @@ public class ValidateCreateOfferTest extends AbstractOfferTest {
@Test
@Order(1)
public void testAmtTooLargeShouldThrowException() {
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon);
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setPaymentAccountId(alicesDummyAcct.getId())
.setDirection("buy")
.setCurrencyCode("usd")
.setAmount(100000000000L)
Expand Down
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -31,6 +32,12 @@ public static void clearExpectedPaymentStatusFlags() {
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();
}
Expand Down