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

Integration Test for RPC nodes #2984

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions app/src/androidTest/java/com/alphawallet/app/RPCNodesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.alphawallet.app;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static com.alphawallet.app.steps.Steps.createNewWallet;
import static com.alphawallet.app.steps.Steps.gotoSettingsPage;
import static com.alphawallet.app.steps.Steps.selectMenu;
import static com.alphawallet.app.steps.Steps.selectTestNet;
import static com.alphawallet.app.util.Helper.click;
import static com.alphawallet.app.util.Helper.hasBackgroundResource;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.core.IsNot.not;

import com.alphawallet.app.util.Helper;

import org.junit.Test;

public class RPCNodesTest extends BaseE2ETest
{

@Test
public void should_select_network()
{
createNewWallet();
selectTestNet("Mumbai");

gotoSettingsPage();
selectMenu("Select Active Networks");
Helper.wait(1);
click(withId(R.id.action_node_status));
Helper.wait(20);

onView(withId(R.id.main_list)).check(matches(not(hasDescendant(allOf(withId(R.id.image_status), hasBackgroundResource(R.drawable.ic_node_not_responding))))));
onView(withId(R.id.test_list)).check(matches(not(hasDescendant(allOf(withId(R.id.image_status), hasBackgroundResource(R.drawable.ic_node_not_responding))))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withSubstring;
import static androidx.test.espresso.matcher.ViewMatchers.withTagValue;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.alphawallet.app.util.Helper.waitUntil;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
Expand All @@ -30,6 +32,11 @@ public static void shouldNotSee(String text)
onView(isRoot()).perform(waitUntil(not(withSubstring(text)), TIMEOUT_IN_SECONDS));
}

public static void shouldNotSeeTag(int tagId)
{
onView(isRoot()).perform(waitUntil(not(withTagValue(equalTo(tagId))), TIMEOUT_IN_SECONDS));
}

public static void shouldNotSee(int id)
{
onView(isRoot()).perform(waitUntil(not(withId(id)), TIMEOUT_IN_SECONDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static void selectTestNet(String name)
clickStaticListItem(withSubstring("Ethereum")); //deactivate eth
onView(withId(R.id.network_scroller)).perform(swipeUp());
Helper.wait(1);
onView(withSubstring("Testnet")).perform(scrollToImproved());
onView(allOf(withId(R.id.switch_material), isDescendantOfA(withId(R.id.testnet_header)))).perform(ViewActions.click());

click(withText(R.string.action_enable_testnet));
Expand Down
29 changes: 26 additions & 3 deletions app/src/androidTest/java/com/alphawallet/app/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@
import static org.hamcrest.core.AllOf.allOf;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.View;

import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;
import androidx.test.espresso.PerformException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.matcher.BoundedMatcher;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.espresso.util.HumanReadables;
import androidx.test.espresso.util.TreeIterables;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

Expand Down Expand Up @@ -215,7 +220,7 @@ public static void clickListItem(int list, Matcher matcher)
{
try
{
click(matcher, 0);
click(matcher, 1);
return;
}
catch (Exception e)
Expand All @@ -229,11 +234,11 @@ public static void clickListItem(int list, Matcher matcher)
//This is an item inside a list that doesn't scroll (eg TestNet / Mainnet list)
public static void clickStaticListItem(Matcher matcher)
{
for (int i = 0; i < 50; i++)
for (int i = 0; i < 49; i++)
{
try
{
click(matcher, 0);
click(matcher, 1);
return;
}
catch (Exception e)
Expand Down Expand Up @@ -350,4 +355,22 @@ public static boolean hasView(String text)

return false;
}

public static Matcher<View> hasBackgroundResource(final int resourceId) {
return new BoundedMatcher<>(ImageView.class)
{
@Override
protected boolean matchesSafely(ImageView imageView)
{
Drawable expectedDrawable = ContextCompat.getDrawable(imageView.getContext(), resourceId);
return expectedDrawable != null && imageView.getBackground().getConstantState().equals(expectedDrawable.getConstantState());
}

@Override
public void describeTo(Description description)
{
description.appendText("has background resource with id " + resourceId);
}
};
}
}
5 changes: 0 additions & 5 deletions app/src/main/java/com/alphawallet/app/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public abstract class C {
public static final String CLASSIC_NETWORK_NAME = "Ethereum Classic";
public static final String XDAI_NETWORK_NAME = "Gnosis";
public static final String GOERLI_NETWORK_NAME = "Görli (Test)";
public static final String ARTIS_SIGMA1_NETWORK = "ARTIS sigma1";
public static final String ARTIS_TAU1_NETWORK = "ARTIS tau1 (Test)";
public static final String BINANCE_TEST_NETWORK = "BSC TestNet";
public static final String BINANCE_MAIN_NETWORK = "Binance (BSC)";
public static final String HECO_MAIN_NETWORK = "Heco";
Expand Down Expand Up @@ -58,7 +56,6 @@ public abstract class C {
public static final String ETHEREUM_TICKER_NAME = "ethereum";
public static final String CLASSIC_TICKER_NAME = "ethereum-classic";
public static final String XDAI_TICKER_NAME = "dai";
public static final String ARTIS_SIGMA_TICKER = "artis";
public static final String BINANCE_TICKER = "binance";

public static final String ETHEREUM_TICKER = "ethereum";
Expand All @@ -68,8 +65,6 @@ public abstract class C {
public static final String xDAI_SYMBOL = "xDai";
public static final String ETC_SYMBOL = "ETC";
public static final String GOERLI_SYMBOL = "GÖETH";
public static final String ARTIS_SIGMA1_SYMBOL = "ATS";
public static final String ARTIS_TAU1_SYMBOL = "ATS";
public static final String BINANCE_SYMBOL = "BNB";
public static final String HECO_SYMBOL = "HT";
public static final String FANTOM_SYMBOL = "FTM";
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/alphawallet/app/entity/EventSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ private void storeTransferData(Realm instance, String hash, String valueList, St
if (activityName.equals("receive"))
{
instance.where(RealmTransfer.class)
.equalTo("hash", hash)
.like("hash", RealmTransfer.databaseKey(token.tokenInfo.chainId, hash))
.findAll().deleteAllFromRealm();
}

RealmTransfer matchingEntry = instance.where(RealmTransfer.class)
.equalTo("hash", hash)
.equalTo("hash", RealmTransfer.databaseKey(token.tokenInfo.chainId, hash))
.equalTo("tokenAddress", token.tokenInfo.address)
.equalTo("eventName", activityName)
.equalTo("transferDetail", valueList)
Expand All @@ -662,7 +662,7 @@ private void storeTransferData(Realm instance, String hash, String valueList, St
if (matchingEntry == null) //prevent duplicates
{
matchingEntry = instance.createObject(RealmTransfer.class);
matchingEntry.setHash(hash);
matchingEntry.setHashKey(token.tokenInfo.chainId, hash);
matchingEntry.setTokenAddress(token.tokenInfo.address);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.alphawallet.app.repository.TokenRepositoryType;
import com.alphawallet.app.repository.TransactionRepositoryType;

import io.reactivex.Completable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -71,4 +72,9 @@ public void restartTransactionService()
{
transactionRepository.restartService();
}

public Single<Transaction> fetchFromNode(String walletAddress, long chainId, String hash)
{
return transactionRepository.fetchTransactionFromNode(walletAddress, chainId, hash);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import static com.alphawallet.ethereum.EthereumNetworkBase.ARBITRUM_GOERLI_TESTNET_FALLBACK_RPC_URL;
import static com.alphawallet.ethereum.EthereumNetworkBase.ARBITRUM_GOERLI_TEST_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.ARBITRUM_MAIN_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.ARTIS_SIGMA1_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.ARTIS_TAU1_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.AURORA_MAINNET_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.AURORA_MAINNET_RPC_URL;
import static com.alphawallet.ethereum.EthereumNetworkBase.AURORA_TESTNET_ID;
Expand Down Expand Up @@ -157,8 +155,6 @@ public abstract class EthereumNetworkBase implements EthereumNetworkRepositoryTy
//See the declaration of NetworkInfo - it has a member backupNodeUrl. Put your secondary node here.

public static final String CLASSIC_RPC_URL = "https://www.ethercluster.com/etc";
public static final String ARTIS_SIGMA1_RPC_URL = "https://rpc.sigma1.artis.network";
public static final String ARTIS_TAU1_RPC_URL = "https://rpc.tau1.artis.network";
public static final String BINANCE_TEST_RPC_URL = "https://data-seed-prebsc-1-s3.binance.org:8545";
public static final String BINANCE_TEST_FALLBACK_RPC_URL = "https://data-seed-prebsc-2-s1.binance.org:8545";
public static final String BINANCE_MAIN_RPC_URL = "https://bsc-dataseed.binance.org";
Expand All @@ -177,12 +173,12 @@ public abstract class EthereumNetworkBase implements EthereumNetworkRepositoryTy
//If your wallet prioritises xDai for example, you may want to move the XDAI_ID to the front of this list,
//Then xDai would appear as the first token at the top of the wallet
private static final List<Long> hasValue = new ArrayList<>(Arrays.asList(
MAINNET_ID, GNOSIS_ID, POLYGON_ID, CLASSIC_ID, ARTIS_SIGMA1_ID, BINANCE_MAIN_ID, HECO_ID, AVALANCHE_ID,
MAINNET_ID, GNOSIS_ID, POLYGON_ID, CLASSIC_ID, BINANCE_MAIN_ID, HECO_ID, AVALANCHE_ID,
FANTOM_ID, OPTIMISTIC_MAIN_ID, CRONOS_MAIN_ID, ARBITRUM_MAIN_ID, PALM_ID, KLAYTN_ID, IOTEX_MAINNET_ID, AURORA_MAINNET_ID, MILKOMEDA_C1_ID, OKX_ID));

private static final List<Long> testnetList = new ArrayList<>(Arrays.asList(
GOERLI_ID, BINANCE_TEST_ID, HECO_TEST_ID, CRONOS_TEST_ID, OPTIMISM_GOERLI_TEST_ID, ARBITRUM_GOERLI_TEST_ID, KLAYTN_BAOBAB_ID,
FANTOM_TEST_ID, IOTEX_TESTNET_ID, FUJI_TEST_ID, POLYGON_TEST_ID, MILKOMEDA_C1_TEST_ID, ARTIS_TAU1_ID,
FANTOM_TEST_ID, IOTEX_TESTNET_ID, FUJI_TEST_ID, POLYGON_TEST_ID, MILKOMEDA_C1_TEST_ID,
SEPOLIA_TESTNET_ID, AURORA_TESTNET_ID, PALM_TEST_ID));

private static final List<Long> deprecatedNetworkList = new ArrayList<>(Arrays.asList(
Expand Down Expand Up @@ -233,18 +229,10 @@ public static boolean isInfura(String rpcServerUrl)
XDAI_RPC_URL,
"https://blockscout.com/xdai/mainnet/tx/", GNOSIS_ID,
"https://rpc.ankr.com/gnosis", "https://blockscout.com/xdai/mainnet/api?"));
put(ARTIS_SIGMA1_ID, new NetworkInfo(C.ARTIS_SIGMA1_NETWORK, C.ARTIS_SIGMA1_SYMBOL,
ARTIS_SIGMA1_RPC_URL,
"https://explorer.sigma1.artis.network/tx/", ARTIS_SIGMA1_ID,
ARTIS_SIGMA1_RPC_URL, "https://explorer.sigma1.artis.network/api?"));
put(GOERLI_ID, new NetworkInfo(C.GOERLI_NETWORK_NAME, C.GOERLI_SYMBOL,
GOERLI_RPC_URL,
"https://goerli.etherscan.io/tx/", GOERLI_ID,
GOERLI_FALLBACK_RPC_URL, "https://api-goerli.etherscan.io/api?"));
put(ARTIS_TAU1_ID, new NetworkInfo(C.ARTIS_TAU1_NETWORK, C.ARTIS_TAU1_SYMBOL,
ARTIS_TAU1_RPC_URL,
"https://explorer.tau1.artis.network/tx/", ARTIS_TAU1_ID,
ARTIS_TAU1_RPC_URL, "https://explorer.tau1.artis.network/api?"));
put(BINANCE_TEST_ID, new NetworkInfo(C.BINANCE_TEST_NETWORK, C.BINANCE_SYMBOL,
BINANCE_TEST_RPC_URL,
"https://testnet.bscscan.com/tx/", BINANCE_TEST_ID,
Expand Down Expand Up @@ -370,8 +358,6 @@ public static boolean isInfura(String rpcServerUrl)
put(CLASSIC_ID, R.drawable.ic_icons_network_etc); //classic_logo
put(GNOSIS_ID, R.drawable.ic_icons_network_gnosis);
put(GOERLI_ID, R.drawable.ic_goerli);
put(ARTIS_SIGMA1_ID, R.drawable.ic_artis_sigma_logo);
put(ARTIS_TAU1_ID, R.drawable.ic_artis_tau_logo);
put(BINANCE_MAIN_ID, R.drawable.ic_binance_logo);
put(BINANCE_TEST_ID, R.drawable.ic_icons_tokens_bnb_testnet);
put(HECO_ID, R.drawable.ic_heco_logo);
Expand Down Expand Up @@ -410,8 +396,6 @@ public static boolean isInfura(String rpcServerUrl)
put(CLASSIC_ID, R.drawable.ic_icons_network_etc);
put(GNOSIS_ID, R.drawable.ic_icons_network_gnosis);
put(GOERLI_ID, R.drawable.ic_goerli);
put(ARTIS_SIGMA1_ID, R.drawable.ic_icons_network_artis);
put(ARTIS_TAU1_ID, R.drawable.ic_artis_tau_logo);
put(BINANCE_MAIN_ID, R.drawable.ic_icons_network_bsc);
put(BINANCE_TEST_ID, R.drawable.ic_icons_tokens_bnb_testnet);
put(HECO_ID, R.drawable.ic_icons_network_heco);
Expand Down Expand Up @@ -450,8 +434,6 @@ public static boolean isInfura(String rpcServerUrl)
put(CLASSIC_ID, R.color.classic);
put(GNOSIS_ID, R.color.xdai);
put(GOERLI_ID, R.color.goerli);
put(ARTIS_SIGMA1_ID, R.color.artis_sigma1);
put(ARTIS_TAU1_ID, R.color.artis_tau1);
put(BINANCE_MAIN_ID, R.color.binance_main);
put(BINANCE_TEST_ID, R.color.binance_test);
put(HECO_ID, R.color.heco_main);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public interface TransactionLocalSource {
Transaction fetchTransaction(Wallet wallet, String hash);
void putTransaction(Wallet wallet, Transaction tx);
Transaction putTransaction(Wallet wallet, Transaction tx);
Realm getRealmInstance(Wallet wallet);

Single<ActivityMeta[]> fetchActivityMetas(Wallet wallet, List<Long> networkFilters, long fetchTime, int fetchLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ public void restartService()
transactionsService.startUpdateCycle();
}

public Single<Transaction> fetchTransactionFromNode(String walletAddress, long chainId, String hash)
{
return transactionsService.fetchTransaction(walletAddress, chainId, hash)
.map(tx -> inDiskCache.putTransaction(new Wallet(walletAddress), tx));
}

private Single<BigInteger> getNonceForTransaction(Web3j web3j, String wallet, long nonce)
{
if (nonce != -1) //use supplied nonce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public interface TransactionRepositoryType
RawTransaction formatRawTransaction(Web3Transaction w3Tx, long nonce, long chainId);

Single<String> sendTransaction(Wallet from, RawTransaction rtx, SignatureFromKey sigData, long chainId);

Single<Transaction> fetchTransactionFromNode(String walletAddress, long chainId, String hash);
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public RealmAuxData fetchEvent(String walletAddress, String eventKey)
}

@Override
public void putTransaction(Wallet wallet, final Transaction tx)
public Transaction putTransaction(Wallet wallet, final Transaction tx)
{
try (Realm instance = realmManager.getRealmInstance(wallet))
{
Expand All @@ -258,6 +258,8 @@ public void putTransaction(Wallet wallet, final Transaction tx)
//do not record
Timber.w(e);
}

return tx;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,33 @@ public class RealmTransfer extends RealmObject

public String getHash()
{
return hash;
String[] split = hash.split("-");
if (split.length > 0)
{
return split[0];
}
else
{
return "";
}
}
public void setHashKey(long chainId, String hash)
{
this.hash = databaseKey(chainId, hash);
}

public long getChain()
{
String[] split = hash.split("-");
if (split.length > 1)
{
return Long.parseLong(split[1]);
}
else
{
return 0L;
}
}
public void setHash(String hash) { this.hash = hash; }

public String getTokenAddress()
{
Expand Down Expand Up @@ -47,4 +71,9 @@ public void setEventName(String eventName)
{
this.eventName = eventName;
}

public static String databaseKey(long chainId, String hash)
{
return hash + "-" + chainId;
}
}
Loading