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

Adjust to changing minimum tx fee rates #5420

Merged
merged 6 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 20 additions & 2 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 @@ -287,7 +294,7 @@ private void installBitcoinBlocknotify() {
Files.copy(srcPath, destPath, REPLACE_EXISTING);
String chmod700Perms = "rwx------";
Files.setPosixFilePermissions(destPath, PosixFilePermissions.fromString(chmod700Perms));
log.info("Installed {} with perms {}.", destPath.toString(), chmod700Perms);
log.info("Installed {} with perms {}.", destPath, chmod700Perms);
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -309,7 +316,7 @@ private void installCallRateMeteringConfiguration(String dataDir) throws IOExcep
Path destPath = Paths.get(dataDir, testRateMeteringFile.getName());
String chmod700Perms = "rwx------";
Files.setPosixFilePermissions(destPath, PosixFilePermissions.fromString(chmod700Perms));
log.info("Installed {} with perms {}.", destPath.toString(), chmod700Perms);
log.info("Installed {} with perms {}.", destPath, chmod700Perms);
}

private void installShutdownHook() {
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
33 changes: 6 additions & 27 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.stream;
import static org.junit.jupiter.api.Assertions.fail;
Expand All @@ -42,28 +41,21 @@

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 final CoreProtoResolver CORE_PROTO_RESOLVER = new CoreProtoResolver();

private static final Function<Enum<?>[], String> toNameList = (enums) ->
stream(enums).map(Enum::name).collect(Collectors.joining(","));

public static void startSupportingApps(File callRateMeteringConfigFile,
boolean registerDisputeAgents,
boolean generateBtcBlock,
Enum<?>... supportingApps) {
startSupportingApps(callRateMeteringConfigFile,
registerDisputeAgents,
generateBtcBlock,
false,
supportingApps);
}

public static void startSupportingApps(File callRateMeteringConfigFile,
boolean registerDisputeAgents,
boolean generateBtcBlock,
boolean startSupportingAppsInDebugMode,
Enum<?>... supportingApps) {
Expand All @@ -73,23 +65,20 @@ public static void startSupportingApps(File callRateMeteringConfigFile,
"--callRateMeteringConfigPath", callRateMeteringConfigFile.getAbsolutePath(),
"--enableBisqDebugging", startSupportingAppsInDebugMode ? "true" : "false"
});
doPostStartup(registerDisputeAgents, generateBtcBlock);
doPostStartup(generateBtcBlock);
} catch (Exception ex) {
fail(ex);
}
}

public static void startSupportingApps(boolean registerDisputeAgents,
boolean generateBtcBlock,
public static void startSupportingApps(boolean generateBtcBlock,
Enum<?>... supportingApps) {
startSupportingApps(registerDisputeAgents,
generateBtcBlock,
startSupportingApps(generateBtcBlock,
false,
supportingApps);
}

public static void startSupportingApps(boolean registerDisputeAgents,
boolean generateBtcBlock,
public static void startSupportingApps(boolean generateBtcBlock,
boolean startSupportingAppsInDebugMode,
Enum<?>... supportingApps) {
try {
Expand All @@ -100,18 +89,13 @@ public static void startSupportingApps(boolean registerDisputeAgents,
"--callRateMeteringConfigPath", callRateMeteringConfigFile.getAbsolutePath(),
"--enableBisqDebugging", startSupportingAppsInDebugMode ? "true" : "false"
});
doPostStartup(registerDisputeAgents, generateBtcBlock);
doPostStartup(generateBtcBlock);
} catch (Exception ex) {
fail(ex);
}
}

protected static void doPostStartup(boolean registerDisputeAgents,
boolean generateBtcBlock) {
if (registerDisputeAgents) {
registerDisputeAgents();
}

protected static void doPostStartup(boolean generateBtcBlock) {
// Generate 1 regtest block for alice's and/or bob's wallet to
// show 10 BTC balance, and allow time for daemons parse the new block.
if (generateBtcBlock)
Expand Down Expand Up @@ -159,11 +143,6 @@ protected final bisq.core.payment.PaymentAccount createPaymentAccount(GrpcClient

// Static conveniences for test methods and test case fixture setups.

protected static void registerDisputeAgents() {
arbClient.registerDisputeAgent(MEDIATOR, DEV_PRIVILEGE_PRIV_KEY);
arbClient.registerDisputeAgent(REFUND_AGENT, DEV_PRIVILEGE_PRIV_KEY);
}

protected static String encodeToHex(String s) {
return Utilities.bytesAsHexString(s.getBytes(UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import org.junit.jupiter.api.TestMethodOrder;

import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.ApiTestConfig.ARBITRATOR;
import static bisq.apitest.config.ApiTestConfig.MEDIATOR;
import static bisq.apitest.config.ApiTestConfig.REFUND_AGENT;
import static bisq.apitest.config.BisqAppConfig.arbdaemon;
import static bisq.apitest.config.BisqAppConfig.seednode;
import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import bisq.core.monetary.Altcoin;

import protobuf.PaymentAccount;

import org.bitcoinj.utils.Fiat;

import java.math.BigDecimal;
Expand All @@ -30,6 +32,7 @@
import org.junit.jupiter.api.BeforeAll;

import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.ApiTestConfig.BSQ;
import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.arbdaemon;
import static bisq.apitest.config.BisqAppConfig.bobdaemon;
Expand All @@ -49,17 +52,32 @@ public abstract class AbstractOfferTest extends MethodTest {
@Setter
protected static boolean isLongRunningTest;

protected static PaymentAccount alicesBsqAcct;
protected static PaymentAccount bobsBsqAcct;

@BeforeAll
public static void setUp() {
startSupportingApps(true,
true,
false,
bitcoind,
seednode,
arbdaemon,
alicedaemon,
bobdaemon);
}


public static void createBsqPaymentAccounts() {
alicesBsqAcct = aliceClient.createCryptoCurrencyPaymentAccount("Alice's BSQ Account",
BSQ,
aliceClient.getUnusedBsqAddress(),
false);
bobsBsqAcct = bobClient.createCryptoCurrencyPaymentAccount("Bob's BSQ Account",
BSQ,
bobClient.getUnusedBsqAddress(),
false);
}

protected double getScaledOfferPrice(double offerPrice, String currencyCode) {
int precision = isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
return scaleDownByPowerOf10(offerPrice, precision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static bisq.apitest.config.ApiTestConfig.BSQ;
import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static protobuf.OfferPayload.Direction.BUY;

@Disabled
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CancelOfferTest extends AbstractOfferTest {

private static final String DIRECTION = "buy";
private static final String DIRECTION = BUY.name();
private static final String CURRENCY_CODE = "cad";
private static final int MAX_OFFERS = 3;

Expand All @@ -52,7 +54,7 @@ public class CancelOfferTest extends AbstractOfferTest {
0.00,
getDefaultBuyerSecurityDepositAsPercent(),
paymentAccountId,
"bsq");
BSQ);
};

@Test
Expand Down
Loading