-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4554 from ghubstan/create-offer
Change 'createoffer' api method return type
- Loading branch information
Showing
13 changed files
with
427 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# Bats helper script for parsing current version from Version.java. | ||
|
||
export CURRENT_VERSION=$(grep "String VERSION =" common/src/main/java/bisq/common/app/Version.java | sed 's/[^0-9.]*//g') |
112 changes: 112 additions & 0 deletions
112
apitest/src/test/java/bisq/apitest/method/CreateOfferTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.apitest.method; | ||
|
||
import bisq.core.btc.wallet.Restrictions; | ||
|
||
import bisq.proto.grpc.CreateOfferRequest; | ||
import bisq.proto.grpc.GetOffersRequest; | ||
import bisq.proto.grpc.OfferInfo; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; | ||
import static bisq.apitest.config.BisqAppConfig.alicedaemon; | ||
import static bisq.apitest.config.BisqAppConfig.arbdaemon; | ||
import static bisq.apitest.config.BisqAppConfig.seednode; | ||
import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
|
||
|
||
@Slf4j | ||
@TestMethodOrder(OrderAnnotation.class) | ||
public class CreateOfferTest extends MethodTest { | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
try { | ||
// setUpScaffold(new String[]{"--supportingApps", "bitcoind,seednode,arbdaemon,alicedaemon", "--enableBisqDebugging", "true"}); | ||
setUpScaffold(bitcoind, seednode, arbdaemon, alicedaemon); | ||
|
||
// Generate 1 regtest block for alice's wallet to show 10 BTC balance, | ||
// and give alicedaemon time to parse the new block. | ||
bitcoinCli.generateBlocks(1); | ||
MILLISECONDS.sleep(1500); | ||
} catch (Exception ex) { | ||
fail(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
public void testCreateBuyOffer() { | ||
var paymentAccount = getDefaultPerfectDummyPaymentAccount(alicedaemon); | ||
var req = CreateOfferRequest.newBuilder() | ||
.setCurrencyCode("USD") | ||
.setDirection("BUY") | ||
.setPrice(0) | ||
.setUseMarketBasedPrice(true) | ||
.setMarketPriceMargin(0.00) | ||
.setAmount(10000000) | ||
.setMinAmount(10000000) | ||
.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent()) | ||
.setPaymentAccountId(paymentAccount.getId()) | ||
.build(); | ||
var newOffer = grpcStubs(alicedaemon).offersService.createOffer(req).getOffer(); | ||
assertEquals("BUY", newOffer.getDirection()); | ||
assertTrue(newOffer.getUseMarketBasedPrice()); | ||
assertEquals(10000000, newOffer.getAmount()); | ||
assertEquals(10000000, newOffer.getMinAmount()); | ||
assertEquals(1500000, newOffer.getBuyerSecurityDeposit()); | ||
assertEquals(paymentAccount.getId(), newOffer.getPaymentAccountId()); | ||
assertEquals("BTC", newOffer.getBaseCurrencyCode()); | ||
assertEquals("USD", newOffer.getCounterCurrencyCode()); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void testGetNewBuyOffer() { | ||
var req = GetOffersRequest.newBuilder().setDirection("BUY").setCurrencyCode("USD").build(); | ||
var reply = grpcStubs(alicedaemon).offersService.getOffers(req); | ||
|
||
assertEquals(1, reply.getOffersCount()); | ||
OfferInfo offer = reply.getOffersList().get(0); | ||
assertEquals("BUY", offer.getDirection()); | ||
assertTrue(offer.getUseMarketBasedPrice()); | ||
assertEquals(10000000, offer.getAmount()); | ||
assertEquals(10000000, offer.getMinAmount()); | ||
assertEquals(1500000, offer.getBuyerSecurityDeposit()); | ||
assertEquals("", offer.getPaymentAccountId()); | ||
assertEquals("BTC", offer.getBaseCurrencyCode()); | ||
assertEquals("USD", offer.getCounterCurrencyCode()); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() { | ||
tearDownScaffold(); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
apitest/src/test/java/bisq/apitest/method/CreatePaymentAccountTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.apitest.method; | ||
|
||
import bisq.proto.grpc.GetPaymentAccountsRequest; | ||
|
||
import protobuf.PaymentAccount; | ||
import protobuf.PerfectMoneyAccountPayload; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; | ||
import static bisq.apitest.config.BisqAppConfig.alicedaemon; | ||
import static java.util.Comparator.comparing; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
|
||
|
||
@Slf4j | ||
@TestMethodOrder(OrderAnnotation.class) | ||
public class CreatePaymentAccountTest extends MethodTest { | ||
|
||
static final String PERFECT_MONEY_ACCT_NAME = "Perfect Money USD"; | ||
static final String PERFECT_MONEY_ACCT_NUMBER = "0123456789"; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
try { | ||
setUpScaffold(bitcoind, alicedaemon); | ||
} catch (Exception ex) { | ||
fail(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
public void testCreatePerfectMoneyUSDPaymentAccount() { | ||
var perfectMoneyPaymentAccountRequest = createCreatePerfectMoneyPaymentAccountRequest( | ||
PERFECT_MONEY_ACCT_NAME, | ||
PERFECT_MONEY_ACCT_NUMBER, | ||
"USD"); | ||
//noinspection ResultOfMethodCallIgnored | ||
grpcStubs(alicedaemon).paymentAccountsService.createPaymentAccount(perfectMoneyPaymentAccountRequest); | ||
|
||
var getPaymentAccountsRequest = GetPaymentAccountsRequest.newBuilder().build(); | ||
var reply = grpcStubs(alicedaemon).paymentAccountsService.getPaymentAccounts(getPaymentAccountsRequest); | ||
|
||
// The daemon is running against the regtest/dao setup files, and was set up with | ||
// two dummy accounts ("PerfectMoney dummy", "ETH dummy") before any tests ran. | ||
// We just added 1 test account, making 3 total. | ||
assertEquals(3, reply.getPaymentAccountsCount()); | ||
|
||
// Sort the returned list by creation date; the last item in the sorted | ||
// list will be the payment acct we just created. | ||
List<PaymentAccount> paymentAccountList = reply.getPaymentAccountsList().stream() | ||
.sorted(comparing(PaymentAccount::getCreationDate)) | ||
.collect(Collectors.toList()); | ||
PaymentAccount paymentAccount = paymentAccountList.get(2); | ||
PerfectMoneyAccountPayload perfectMoneyAccount = paymentAccount | ||
.getPaymentAccountPayload() | ||
.getPerfectMoneyAccountPayload(); | ||
|
||
assertEquals(PERFECT_MONEY_ACCT_NAME, paymentAccount.getAccountName()); | ||
assertEquals("USD", | ||
paymentAccount.getSelectedTradeCurrency().getFiatCurrency().getCurrency().getCurrencyCode()); | ||
assertEquals(PERFECT_MONEY_ACCT_NUMBER, perfectMoneyAccount.getAccountNr()); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() { | ||
tearDownScaffold(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.