Skip to content

Commit

Permalink
split MainnetEnvironment into Clio and Reporting mode variants
Browse files Browse the repository at this point in the history
  • Loading branch information
nkramer44 committed Jun 22, 2023
1 parent 43c2a79 commit fe430ea
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ jobs:
key: ${{ env.cache-name }}-${{ hashFiles('pom.xml') }}
restore-keys: ${{ env.cache-name }}-
- name: Build
run: mvn dependency:go-offline install -Dmaven.javadoc.skip=true -DuseClioTestnet
run: mvn dependency:go-offline install -Dmaven.javadoc.skip=true -DuseClioTestnet -DuseClioMainnet
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@
import org.xrpl.xrpl4j.model.client.ledger.LedgerResult;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.Hash256;
import org.xrpl.xrpl4j.tests.environment.MainnetEnvironment;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.xrpl.xrpl4j.tests.environment.ReportingMainnetEnvironment;
import org.xrpl.xrpl4j.tests.environment.XrplEnvironment;

/**
* An Integration Test to validate submission of Account transactions.
Expand All @@ -58,7 +55,7 @@ public class AccountTransactionsIT {
// an arbitrary address on xrpl mainnet that has a decent amount of transaction history
public static final Address MAINNET_ADDRESS = Address.of("r9m6MwViR4GnUNqoGXGa8eroBrZ9FAPHFS");

private final XrplClient mainnetClient = new MainnetEnvironment().getXrplClient();
private final XrplClient mainnetClient = XrplEnvironment.getConfiguredMainnetEnvironment().getXrplClient();

@Test
public void listTransactionsDefaultWithPagination() throws JsonRpcClientErrorException {
Expand All @@ -69,44 +66,49 @@ public void listTransactionsDefaultWithPagination() throws JsonRpcClientErrorExc
assertThat(results.marker()).isNotEmpty();
}

/**
* This test will fail if we hit a Clio node until <a href="https://github.com/XRPLF/clio/pull/687">CLIO-687</a> is deployed
* to mainnet. We expect 748 transactions across all pages of account_tx, however Clio duplicates the last
* transaction from each page in the next page, which results in more than 748 transactions returned.
*
* @throws JsonRpcClientErrorException If rippled/Clio returns an error or a request fails.
*/
@Test
@Timeout(30)
public void listTransactionsPagination() throws JsonRpcClientErrorException {
final int expectedTransactions = 748;
// known ledger index range for this account that is known to have exactly 748 transactions
LedgerIndexBound minLedger = LedgerIndexBound.of(61400000);
LedgerIndexBound maxLedger = LedgerIndexBound.of(61487000);
Set<Hash256> transactionHashes = new HashSet<>();

AccountTransactionsResult results = mainnetClient.accountTransactions(
AccountTransactionsRequestParams.builder(minLedger, maxLedger)
.account(MAINNET_ADDRESS)
.build()
);
assertThat(results.transactions()).isNotEmpty();
assertThat(results.marker()).isNotEmpty();
results.transactions().forEach(transaction -> transactionHashes.add(transaction.resultTransaction().hash()));

int transactionsFound = results.transactions().size();
int pages = 0;
while (results.marker().isPresent() &&
// Needed because clio is broken. See https://github.com/XRPLF/clio/issues/195#issuecomment-1247412892
results.transactions().size() > 0
) {
results = mainnetClient.accountTransactions(AccountTransactionsRequestParams.builder(minLedger, maxLedger)
.account(MAINNET_ADDRESS)
.limit(UnsignedInteger.valueOf(100L))
.limit(UnsignedInteger.valueOf(200L))
.marker(results.marker().get())
.build());
results.transactions().forEach(transaction -> transactionHashes.add(transaction.resultTransaction().hash()));
transactionsFound += results.transactions().size();
pages++;
logger.info("Retrieved {} transaction (marker={} page={})",
transactionHashes.size(),
logger.info("Retrieved {} ledgers (marker={} page={})",
transactionsFound,
results.marker().map($ -> $.value()).orElseGet(() -> "n/a"),
pages
);
}

assertThat(transactionHashes.size()).isEqualTo(expectedTransactions);
assertThat(transactionsFound).isEqualTo(expectedTransactions);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.xrpl.xrpl4j.tests.environment;

/*-
* ========================LICENSE_START=================================
* xrpl4j :: integration-tests
* %%
* Copyright (C) 2020 - 2022 XRPL Foundation and its contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/

import okhttp3.HttpUrl;
import org.xrpl.xrpl4j.client.XrplClient;
import org.xrpl.xrpl4j.model.transactions.Address;

/**
* XRPL mainnet environment that uses a Clio node. Integration tests can be run against a reporting mode mainnet
* node by using the {@link ReportingMainnetEnvironment}.
*/
public class ClioMainnetEnvironment extends MainnetEnvironment {

private final XrplClient xrplClient = new XrplClient(HttpUrl.parse("https://s2-clio.ripple.com:51234"));

@Override
public XrplClient getXrplClient() {
return xrplClient;
}

}
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
package org.xrpl.xrpl4j.tests.environment;

/*-
* ========================LICENSE_START=================================
* xrpl4j :: integration-tests
* %%
* Copyright (C) 2020 - 2022 XRPL Foundation and its contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/

import okhttp3.HttpUrl;
import org.xrpl.xrpl4j.client.XrplClient;
import org.xrpl.xrpl4j.model.transactions.Address;

/**
* XRPL mainnet environment.
*/
public class MainnetEnvironment implements XrplEnvironment {

// FIXME: At the time of writing this, Clio is powering some traffic to s1 and s2. Clio behaves differently
// than reporting mode servers/rippled p2p servers in responses to account_tx RPC calls with
// "ledger_index" = "validated", which breaks AccountTransactionsIT. xrplcluster.com is not powered by Clio, so
// this client is pointed at xrplcluster.com. However, once this bug in Clio is resolved, we should revert back to
// using s1/s2 here.
// See this github issue: https://github.com/XRPLF/clio/pull/694
private final XrplClient xrplClient = new XrplClient(HttpUrl.parse("https://xrplcluster.com"));
public abstract class MainnetEnvironment implements XrplEnvironment {

@Override
public XrplClient getXrplClient() {
return xrplClient;
}
public abstract XrplClient getXrplClient();

@Override
public void fundAccount(Address classicAddress) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.xrpl.xrpl4j.tests.environment;

/*-
* ========================LICENSE_START=================================
* xrpl4j :: integration-tests
* %%
* Copyright (C) 2020 - 2022 XRPL Foundation and its contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/

import okhttp3.HttpUrl;
import org.xrpl.xrpl4j.client.XrplClient;
import org.xrpl.xrpl4j.model.transactions.Address;

/**
* XRPL mainnet environment that uses a reporting mode only node. Integration tests can be run against a Clio mainnet
* node by using the {@link ClioMainnetEnvironment}.
*/
public class ReportingMainnetEnvironment extends MainnetEnvironment {

private final XrplClient xrplClient = new XrplClient(HttpUrl.parse("https://s2-reporting.ripple.com:51234"));

@Override
public XrplClient getXrplClient() {
return xrplClient;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ public interface XrplEnvironment {
Logger logger = LoggerFactory.getLogger(XrplEnvironment.class);

/**
* Gets the XRPL environment to use (based on existence of -DuseTestnet property).
* Gets the XRPL environment to use.
*
* <p>
* Uses local rippled container by default.
* Set -DuseTestnet to run against reporting mode testnet node
* Set -DuseClioTestnet to run against Clio testnet node
* Set -DuseDevnet to run against devnet
* </p>
*
* @return XRPL environment of the correct type.
*/
Expand Down Expand Up @@ -64,6 +71,32 @@ static XrplEnvironment getConfiguredEnvironment() {
}
}

/**
* Gets the configured {@link MainnetEnvironment} for integration tests that run against mainnet, such as
* {@link org.xrpl.xrpl4j.tests.AccountTransactionsIT}.
*
* <p>The default environment is a Reporting Mode only environment. Tests can be run against a Clio node
* by setting the {@code -DuseClioMainnet} system property.</p>
*
* @return A {@link MainnetEnvironment}.
*/
static MainnetEnvironment getConfiguredMainnetEnvironment() {
boolean isClioEnabled = System.getProperty("useClioMainnet") != null;
if (isClioEnabled) {
logger.info(
"System property 'useClioMainnet' detected; Using Clio mainnet node for integration tests that are run " +
"against mainnet."
);
return new ClioMainnetEnvironment();
} else {
logger.info(
"System property 'useClioMainnet' was not detected; Using Reporting Mode mainnet node for integration tests " +
"that are run against mainnet."
);
return new ReportingMainnetEnvironment();
}
}

XrplClient getXrplClient();

void fundAccount(Address classicAddress);
Expand Down

0 comments on commit fe430ea

Please sign in to comment.