From 9ee3d34aa9292779d4e2a9c0895b4ec6fa105fa9 Mon Sep 17 00:00:00 2001 From: Android-X13 <76814540+Android-X13@users.noreply.github.com> Date: Wed, 10 Aug 2022 20:10:36 +0300 Subject: [PATCH] Add tests for blockchain URLs --- .../java/bisq/desktop/util/GUIUtilTest.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java b/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java index 1cab68540c..72eae547ab 100644 --- a/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java +++ b/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java @@ -23,6 +23,7 @@ import bisq.core.locale.TradeCurrency; import bisq.core.monetary.Price; import bisq.core.provider.price.MarketPrice; import bisq.core.provider.price.PriceFeedService; +import bisq.core.user.BlockChainExplorer; import bisq.core.user.DontShowAgainLookup; import bisq.core.user.Preferences; import bisq.core.util.coin.BsqFormatter; @@ -53,12 +54,27 @@ import static org.mockito.Mockito.when; public class GUIUtilTest { + private Preferences preferences; + private String explorerName; + private String bsqExplorerName; + private String txUrlPrefix; + private String bsqTxUrlPrefix; + private String addressUrlPrefix; + private String bsqAddressUrlPrefix; + @Before public void setup() { Locale.setDefault(new Locale("en", "US")); GlobalSettings.setLocale(new Locale("en", "US")); Res.setBaseCurrencyCode("BTC"); Res.setBaseCurrencyName("Bitcoin"); + preferences = mock(Preferences.class); + explorerName = "Blockstream.info"; + bsqExplorerName = "mempool.space (@wiz)"; + txUrlPrefix = "https://blockstream.info/tx/"; + bsqTxUrlPrefix = "https://mempool.space/bisq/tx/"; + addressUrlPrefix = "https://blockstream.info/address/"; + bsqAddressUrlPrefix = "https://mempool.space/bisq/address/"; } @Test @@ -79,7 +95,6 @@ public class GUIUtilTest { @Test public void testOpenURLWithCampaignParameters() { - Preferences preferences = mock(Preferences.class); DontShowAgainLookup.setPreferences(preferences); GUIUtil.setPreferences(preferences); when(preferences.showAgain("warnOpenURLWhenTorEnabled")).thenReturn(false); @@ -100,7 +115,6 @@ public class GUIUtilTest { @Test public void testOpenURLWithoutCampaignParameters() { - Preferences preferences = mock(Preferences.class); DontShowAgainLookup.setPreferences(preferences); GUIUtil.setPreferences(preferences); when(preferences.showAgain("warnOpenURLWhenTorEnabled")).thenReturn(false); @@ -114,6 +128,38 @@ public class GUIUtilTest { */ } + @Test + public void testGetAddressUrl() { + GUIUtil.setPreferences(preferences); + when(preferences.getBlockChainExplorer()).thenReturn(new BlockChainExplorer( + explorerName, txUrlPrefix, addressUrlPrefix)); + when(preferences.getBsqBlockChainExplorer()).thenReturn(new BlockChainExplorer( + bsqExplorerName, bsqTxUrlPrefix, bsqAddressUrlPrefix)); + + String address = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"; + assertEquals(addressUrlPrefix + address, GUIUtil.getAddressUrl(address)); + assertEquals(addressUrlPrefix + address, GUIUtil.getAddressUrl(address, false)); + + String bsqAddress = "B17Q6zA7LbEt5je4mtkBtYBfvDfvEwkzde"; + assertEquals(bsqAddressUrlPrefix + bsqAddress, GUIUtil.getAddressUrl(bsqAddress, true)); + } + + @Test + public void testGetTxUrl() { + GUIUtil.setPreferences(preferences); + when(preferences.getBlockChainExplorer()).thenReturn(new BlockChainExplorer( + explorerName, txUrlPrefix, addressUrlPrefix)); + when(preferences.getBsqBlockChainExplorer()).thenReturn(new BlockChainExplorer( + bsqExplorerName, bsqTxUrlPrefix, bsqAddressUrlPrefix)); + + String txId = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"; + assertEquals(txUrlPrefix + txId, GUIUtil.getTxUrl(txId)); + assertEquals(txUrlPrefix + txId, GUIUtil.getTxUrl(txId, false)); + + String bsqTxId = "4b5417ec5ab6112bedf539c3b4f5a806ed539542d8b717e1c4470aa3180edce5"; + assertEquals(bsqTxUrlPrefix + bsqTxId, GUIUtil.getTxUrl(bsqTxId, true)); + } + @Test public void testGetBsqInUsd() { PriceFeedService priceFeedService = mock(PriceFeedService.class);