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

Add BTC/BSQ pair offer & trading tests #5359

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c3f5669
Add api method createcryptopaymentacct
ghubstan Mar 25, 2021
27b0900
Add cli side help for createcryptopaymentacct
ghubstan Mar 25, 2021
9e035e5
Provide more offer & contract detail available to CLI.
ghubstan Mar 25, 2021
55f157f
Add BTC/BSQ pair offer & trading tests
ghubstan Mar 25, 2021
45db3cb
Remove debugging code blocks
ghubstan Mar 25, 2021
780be1a
Adjust maker gettrade output checks to new column
ghubstan Mar 26, 2021
152f459
Remove unused parameter
ghubstan Mar 26, 2021
872834a
Merge branch '02-api-trade-contract-details' into 03-add-btc-bsq-pair…
ghubstan Mar 26, 2021
aad998c
Fix maker/taker fee format bug, rename methods
ghubstan Mar 28, 2021
20d02eb
Merge branch '02-api-trade-contract-details' into 03-add-btc-bsq-pair…
ghubstan Mar 28, 2021
2d66a59
Merge branch 'master' into 01-api-add-createcryptopaymentacct
ghubstan Apr 1, 2021
58c885e
Add support for creating instant altcoin payment accounts in api
ghubstan Apr 1, 2021
4fbdc32
Remove space char
ghubstan Apr 1, 2021
6299dc3
Merge branch '01-api-add-createcryptopaymentacct' into 02-api-trade-c…
ghubstan Apr 1, 2021
6bde12b
Improve takeoffer output and failure reason messaging
ghubstan Apr 1, 2021
a1deb1d
Merge branch '02-api-trade-contract-details' into 03-add-btc-bsq-pair…
ghubstan Apr 1, 2021
b838e59
Make test dispute agent registration a test harness opt.
ghubstan Apr 1, 2021
4424deb
Implement api VerifyBsqSentToAddressReply service
ghubstan Apr 1, 2021
b2634aa
Define grpc call rate meter for CreateCryptoCurrencyPaymentAccount
ghubstan Apr 1, 2021
da99feb
Refactor apitest's bot related classes
ghubstan Apr 1, 2021
6fa4f1a
Make codacy happy
ghubstan Apr 1, 2021
10f8a91
Fix loop & log
ghubstan Apr 2, 2021
a2c9eae
Return from method, not break loop
ghubstan Apr 2, 2021
2a7e39b
Add whitespace
ghubstan Apr 2, 2021
6981990
Remove example mm bot
ghubstan Apr 2, 2021
bddc273
Fix spelling
ghubstan Apr 2, 2021
8b156db
Merge branch '02-api-trade-contract-details' into 03-add-btc-bsq-pair…
ghubstan Apr 2, 2021
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
58 changes: 13 additions & 45 deletions apitest/scripts/trade-simulation-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,65 +238,35 @@ gettradedetail() {

istradedepositpublished() {
TRADE_DETAIL="$1"
MAKER_OR_TAKER="$2"
if [ "$MAKER_OR_TAKER" = "MAKER" ]
then
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $9}')
else
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $10}')
fi
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $10}')
commandalert $? "Could not parse istradedepositpublished from trade detail."
echo "$ANSWER"
}

istradedepositconfirmed() {
TRADE_DETAIL="$1"
MAKER_OR_TAKER="$2"
if [ "$MAKER_OR_TAKER" = "MAKER" ]
then
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $10}')
else
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $11}')
fi
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $11}')
commandalert $? "Could not parse istradedepositconfirmed from trade detail."
echo "$ANSWER"
}

istradepaymentsent() {
TRADE_DETAIL="$1"
MAKER_OR_TAKER="$2"
if [ "$MAKER_OR_TAKER" = "MAKER" ]
then
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $12}')
else
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $13}')
fi
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $13}')
commandalert $? "Could not parse istradepaymentsent from trade detail."
echo "$ANSWER"
}

istradepaymentreceived() {
TRADE_DETAIL="$1"
MAKER_OR_TAKER="$2"
if [ "$MAKER_OR_TAKER" = "MAKER" ]
then
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $13}')
else
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $14}')
fi
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $14}')
commandalert $? "Could not parse istradepaymentreceived from trade detail."
echo "$ANSWER"
}

istradepayoutpublished() {
TRADE_DETAIL="$1"
MAKER_OR_TAKER="$2"
if [ "$MAKER_OR_TAKER" = "MAKER" ]
then
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $14}')
else
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $15}')
fi
ANSWER=$(echo "$TRADE_DETAIL" | awk '{print $15}')
commandalert $? "Could not parse istradepayoutpublished from trade detail."
echo "$ANSWER"
}
Expand All @@ -321,7 +291,7 @@ waitfortradedepositpublished() {
TRADE_DETAIL=$(gettradedetail "$GETTRADE_CMD_OUTPUT")
exitoncommandalert $?

IS_TRADE_DEPOSIT_PUBLISHED=$(istradedepositpublished "$TRADE_DETAIL" "TAKER")
IS_TRADE_DEPOSIT_PUBLISHED=$(istradedepositpublished "$TRADE_DETAIL")
exitoncommandalert $?

printdate "BOB $BOB_ROLE: Has taker's trade deposit been published? $IS_TRADE_DEPOSIT_PUBLISHED"
Expand Down Expand Up @@ -356,7 +326,7 @@ waitfortradedepositconfirmed() {
TRADE_DETAIL=$(gettradedetail "$GETTRADE_CMD_OUTPUT")
exitoncommandalert $?

IS_TRADE_DEPOSIT_CONFIRMED=$(istradedepositconfirmed "$TRADE_DETAIL" "TAKER")
IS_TRADE_DEPOSIT_CONFIRMED=$(istradedepositconfirmed "$TRADE_DETAIL")
exitoncommandalert $?
printdate "BOB $BOB_ROLE: Has taker's trade deposit been confirmed? $IS_TRADE_DEPOSIT_CONFIRMED"
printbreak
Expand All @@ -379,7 +349,6 @@ waitfortradepaymentsent() {
PORT="$1"
SELLER="$2"
OFFER_ID="$3"
MAKER_OR_TAKER="$4"
DONE=0
while : ; do
if [ "$DONE" -ne 0 ]; then
Expand All @@ -397,7 +366,7 @@ waitfortradepaymentsent() {
TRADE_DETAIL=$(gettradedetail "$GETTRADE_CMD_OUTPUT")
exitoncommandalert $?

IS_TRADE_PAYMENT_SENT=$(istradepaymentsent "$TRADE_DETAIL" "$MAKER_OR_TAKER")
IS_TRADE_PAYMENT_SENT=$(istradepaymentsent "$TRADE_DETAIL")
exitoncommandalert $?
printdate "$SELLER: Has buyer's fiat payment been initiated? $IS_TRADE_PAYMENT_SENT"
if [ "$IS_TRADE_PAYMENT_SENT" = "YES" ]
Expand All @@ -416,7 +385,6 @@ waitfortradepaymentreceived() {
PORT="$1"
SELLER="$2"
OFFER_ID="$3"
MAKER_OR_TAKER="$4"
DONE=0
while : ; do
if [ "$DONE" -ne 0 ]; then
Expand All @@ -437,7 +405,7 @@ waitfortradepaymentreceived() {
# When the seller receives a 'payment sent' message, it is assumed funds (fiat) have already been deposited.
# In a real trade, there is usually a delay between receipt of a 'payment sent' message, and the funds deposit,
# but we do not need to simulate that in this regtest script.
IS_TRADE_PAYMENT_SENT=$(istradepaymentreceived "$TRADE_DETAIL" "$MAKER_OR_TAKER")
IS_TRADE_PAYMENT_SENT=$(istradepaymentreceived "$TRADE_DETAIL")
exitoncommandalert $?
printdate "$SELLER: Has buyer's payment been transferred to seller's fiat account? $IS_TRADE_PAYMENT_SENT"
if [ "$IS_TRADE_PAYMENT_SENT" = "YES" ]
Expand Down Expand Up @@ -544,10 +512,10 @@ executetrade() {
if [ "$DIRECTION" = "BUY" ]
then
# Bob waits for payment, polling status in taker specific trade detail.
waitfortradepaymentsent "$PAYEE_PORT" "$PAYEE" "$OFFER_ID" "TAKER"
waitfortradepaymentsent "$PAYEE_PORT" "$PAYEE" "$OFFER_ID"
else
# Alice waits for payment, polling status in maker specific trade detail.
waitfortradepaymentsent "$PAYEE_PORT" "$PAYEE" "$OFFER_ID" "MAKER"
waitfortradepaymentsent "$PAYEE_PORT" "$PAYEE" "$OFFER_ID"
fi


Expand All @@ -557,10 +525,10 @@ executetrade() {
if [ "$DIRECTION" = "BUY" ]
then
# Alice waits for payment rcvd confirm from Bob, polling status in maker specific trade detail.
waitfortradepaymentreceived "$PAYER_PORT" "$PAYER" "$OFFER_ID" "MAKER"
waitfortradepaymentreceived "$PAYER_PORT" "$PAYER" "$OFFER_ID"
else
# Bob waits for payment rcvd confirm from Alice, polling status in taker specific trade detail.
waitfortradepaymentreceived "$PAYER_PORT" "$PAYER" "$OFFER_ID" "TAKER"
waitfortradepaymentreceived "$PAYER_PORT" "$PAYER" "$OFFER_ID"
fi

# Generate some btc blocks
Expand Down
18 changes: 18 additions & 0 deletions apitest/src/main/java/bisq/apitest/Scaffold.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@
import javax.annotation.Nullable;

import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.ApiTestConfig.MEDIATOR;
import static bisq.apitest.config.ApiTestConfig.REFUND_AGENT;
import static bisq.apitest.config.BisqAppConfig.*;
import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY;
import static java.lang.String.format;
import static java.lang.System.exit;
import static java.lang.System.out;
import static java.net.InetAddress.getLoopbackAddress;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
Expand All @@ -58,6 +62,7 @@
import bisq.apitest.linux.BisqProcess;
import bisq.apitest.linux.BitcoinDaemon;
import bisq.apitest.linux.LinuxProcess;
import bisq.cli.GrpcClient;

@Slf4j
public class Scaffold {
Expand Down Expand Up @@ -146,6 +151,8 @@ public Scaffold setUp() throws IOException, InterruptedException, ExecutionExcep

// Verify each startup task's future is done.
verifyStartupCompleted();

maybeRegisterDisputeAgents();
return this;
}

Expand Down Expand Up @@ -448,4 +455,15 @@ private void verifyNotWindows() {
if (Utilities.isWindows())
throw new IllegalStateException("ApiTest not supported on Windows");
}

private void maybeRegisterDisputeAgents() {
if (config.hasSupportingApp(arbdaemon.name()) && config.registerDisputeAgents) {
log.info("Option --registerDisputeAgents=true, registering dispute agents in arbdaemon ...");
GrpcClient arbClient = new GrpcClient(getLoopbackAddress().getHostAddress(),
arbdaemon.apiPort,
config.apiPassword);
arbClient.registerDisputeAgent(MEDIATOR, DEV_PRIVILEGE_PRIV_KEY);
arbClient.registerDisputeAgent(REFUND_AGENT, DEV_PRIVILEGE_PRIV_KEY);
}
}
}
17 changes: 17 additions & 0 deletions apitest/src/main/java/bisq/apitest/config/ApiTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
@Slf4j
public class ApiTestConfig {

// Global constants
public static final String BSQ = "BSQ";
public static final String BTC = "BTC";
public static final String ARBITRATOR = "arbitrator";
public static final String MEDIATOR = "mediator";
public static final String REFUND_AGENT = "refundagent";

// Option name constants
static final String HELP = "help";
static final String BASH_PATH = "bashPath";
Expand All @@ -73,6 +80,7 @@ public class ApiTestConfig {
static final String SUPPORTING_APPS = "supportingApps";
static final String CALL_RATE_METERING_CONFIG_PATH = "callRateMeteringConfigPath";
static final String ENABLE_BISQ_DEBUGGING = "enableBisqDebugging";
static final String REGISTER_DISPUTE_AGENTS = "registerDisputeAgents";

// Default values for certain options
static final String DEFAULT_CONFIG_FILE_NAME = "apitest.properties";
Expand Down Expand Up @@ -105,6 +113,7 @@ public class ApiTestConfig {
public final List<String> supportingApps;
public final String callRateMeteringConfigPath;
public final boolean enableBisqDebugging;
public final boolean registerDisputeAgents;

// Immutable system configurations set in the constructor.
public final String bitcoinDatadir;
Expand Down Expand Up @@ -242,6 +251,13 @@ public ApiTestConfig(String... args) {
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(false);

ArgumentAcceptingOptionSpec<Boolean> registerDisputeAgentsOpt =
parser.accepts(REGISTER_DISPUTE_AGENTS,
"Register dispute agents in arbitration daemon")
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(true);
try {
CompositeOptionSet options = new CompositeOptionSet();

Expand Down Expand Up @@ -299,6 +315,7 @@ public ApiTestConfig(String... args) {
this.supportingApps = asList(options.valueOf(supportingAppsOpt).split(","));
this.callRateMeteringConfigPath = options.valueOf(callRateMeteringConfigPathOpt);
this.enableBisqDebugging = options.valueOf(enableBisqDebuggingOpt);
this.registerDisputeAgents = options.valueOf(registerDisputeAgentsOpt);

// Assign values to special-case static fields.
BASH_PATH_VALUE = bashPath;
Expand Down
Loading