diff --git a/drongo b/drongo index e8d8fa61..747bfa91 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit e8d8fa61268ec8ac4dd5c14e6715d4a4bde2fe49 +Subproject commit 747bfa915f1ecf743b5e8876b9a4c54062e57c94 diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java index f8faec83..1229d3fe 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java @@ -1,10 +1,7 @@ package com.sparrowwallet.sparrow.wallet; import com.google.common.eventbus.Subscribe; -import com.sparrowwallet.drongo.ExtendedKey; -import com.sparrowwallet.drongo.KeyDerivation; -import com.sparrowwallet.drongo.SecureString; -import com.sparrowwallet.drongo.Utils; +import com.sparrowwallet.drongo.*; import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.KeystoreSource; import com.sparrowwallet.drongo.wallet.Wallet; @@ -148,7 +145,7 @@ public class KeystoreController extends WalletFormController implements Initiali contextMenu.getItems().add(copyXPub); ExtendedKey.Header header = ExtendedKey.Header.fromScriptType(walletForm.getWallet().getScriptType(), false); - if(header != ExtendedKey.Header.xpub) { + if(header != Network.get().getXpubHeader()) { String otherPub = extendedKey.getExtendedKey(header); MenuItem copyOtherPub = new MenuItem("Copy " + header.getName().replace('p', 'P')); diff --git a/src/test/java/com/sparrowwallet/sparrow/io/ColdcardMultisigTest.java b/src/test/java/com/sparrowwallet/sparrow/io/ColdcardMultisigTest.java index be105554..d42adafb 100644 --- a/src/test/java/com/sparrowwallet/sparrow/io/ColdcardMultisigTest.java +++ b/src/test/java/com/sparrowwallet/sparrow/io/ColdcardMultisigTest.java @@ -2,10 +2,12 @@ package com.sparrowwallet.sparrow.io; import com.google.common.io.ByteStreams; import com.sparrowwallet.drongo.ExtendedKey; +import com.sparrowwallet.drongo.Network; import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.Wallet; +import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -14,6 +16,7 @@ import java.io.*; public class ColdcardMultisigTest extends IoTest { @Test public void importKeystore1() throws ImportException { + Network.set(Network.TESTNET); ColdcardMultisig ccMultisig = new ColdcardMultisig(); Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WSH, getInputStream("cc-multisig-keystore-1.json"), null); Assert.assertEquals("Coldcard", keystore.getLabel()); @@ -31,6 +34,7 @@ public class ColdcardMultisigTest extends IoTest { @Test public void importKeystore2() throws ImportException { + Network.set(Network.TESTNET); ColdcardMultisig ccMultisig = new ColdcardMultisig(); Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH, getInputStream("cc-multisig-keystore-2.json"), null); Assert.assertEquals("Coldcard", keystore.getLabel()); @@ -42,6 +46,7 @@ public class ColdcardMultisigTest extends IoTest { @Test public void importKeystore2b() throws ImportException { + Network.set(Network.TESTNET); ColdcardMultisig ccMultisig = new ColdcardMultisig(); Keystore keystore = ccMultisig.getKeystore(ScriptType.P2WSH, getInputStream("cc-multisig-keystore-2.json"), null); Assert.assertEquals("Coldcard", keystore.getLabel()); @@ -65,6 +70,7 @@ public class ColdcardMultisigTest extends IoTest { @Test public void importWallet2() throws ImportException { + Network.set(Network.TESTNET); ColdcardMultisig ccMultisig = new ColdcardMultisig(); Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-2.txt"), null); Assert.assertEquals("CC-2-of-4", wallet.getName()); @@ -117,4 +123,9 @@ public class ColdcardMultisigTest extends IoTest { String exported = new String(exportedBytes); Assert.assertEquals(original.replaceAll("Exported from Electrum", ""), exported.replace("Coldcard Multisig setup file (created by Sparrow)\n#", "")); } + + @After + public void tearDown() throws Exception { + Network.set(null); + } } diff --git a/src/test/java/com/sparrowwallet/sparrow/io/ColdcardSinglesigTest.java b/src/test/java/com/sparrowwallet/sparrow/io/ColdcardSinglesigTest.java index 4c0b9b5c..dad65931 100644 --- a/src/test/java/com/sparrowwallet/sparrow/io/ColdcardSinglesigTest.java +++ b/src/test/java/com/sparrowwallet/sparrow/io/ColdcardSinglesigTest.java @@ -1,14 +1,17 @@ package com.sparrowwallet.sparrow.io; import com.sparrowwallet.drongo.ExtendedKey; +import com.sparrowwallet.drongo.Network; import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.wallet.Keystore; +import org.junit.After; import org.junit.Assert; import org.junit.Test; public class ColdcardSinglesigTest extends IoTest { @Test public void testImport() throws ImportException { + Network.set(Network.TESTNET); ColdcardSinglesig ccSingleSig = new ColdcardSinglesig(); Keystore keystore = ccSingleSig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-singlesig-keystore-1.json"), null); @@ -21,6 +24,7 @@ public class ColdcardSinglesigTest extends IoTest { @Test public void testImportWitness() throws ImportException { + Network.set(Network.TESTNET); ColdcardSinglesig ccSingleSig = new ColdcardSinglesig(); Keystore keystore = ccSingleSig.getKeystore(ScriptType.P2WPKH, getInputStream("cc-singlesig-keystore-1.json"), null); @@ -30,4 +34,9 @@ public class ColdcardSinglesigTest extends IoTest { Assert.assertEquals(ExtendedKey.fromDescriptor("tpubDC7jGaaSE66VDB6VhEDFYQSCAyugXmfnMnrMVyHNzW9wryyTxvha7TmfAHd7GRXrr2TaAn2HXn9T8ep4gyNX1bzGiieqcTUNcu2poyntrET"), keystore.getExtendedPublicKey()); Assert.assertTrue(keystore.isValid()); } + + @After + public void tearDown() throws Exception { + Network.set(null); + } } diff --git a/src/test/java/com/sparrowwallet/sparrow/io/ElectrumTest.java b/src/test/java/com/sparrowwallet/sparrow/io/ElectrumTest.java index 0536d7f3..63e4a800 100644 --- a/src/test/java/com/sparrowwallet/sparrow/io/ElectrumTest.java +++ b/src/test/java/com/sparrowwallet/sparrow/io/ElectrumTest.java @@ -1,11 +1,13 @@ package com.sparrowwallet.sparrow.io; import com.google.common.io.ByteStreams; +import com.sparrowwallet.drongo.Network; import com.sparrowwallet.drongo.Utils; import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.wallet.MnemonicException; import com.sparrowwallet.drongo.wallet.Wallet; +import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -50,6 +52,7 @@ public class ElectrumTest extends IoTest { @Test public void testMultisigImport() throws ImportException { + Network.set(Network.TESTNET); Electrum electrum = new Electrum(); Wallet wallet = electrum.importWallet(getInputStream("electrum-multisig-wallet.json"), null); @@ -59,7 +62,7 @@ public class ElectrumTest extends IoTest { Assert.assertEquals("sh(wsh(sortedmulti(2,coldcard6ba6cfd0,coldcard747b698e,coldcard7bb026be,coldcard0f056943)))", wallet.getDefaultPolicy().getMiniscript().getScript()); Assert.assertEquals("6ba6cfd0", wallet.getKeystores().get(0).getKeyDerivation().getMasterFingerprint()); Assert.assertEquals("m/48'/1'/0'/1'", wallet.getKeystores().get(0).getKeyDerivation().getDerivationPath()); - Assert.assertEquals("xpub6FFEQVG6QR28chQzgSJ7Gjx5j5BGLkCMgZ9bc41YJCXfwYiCKUQdcwm4Fe1stvzRjosz5udMedYZFRL56AeZXCsiVmnVUysio4jkAKTukmN", wallet.getKeystores().get(0).getExtendedPublicKey().toString()); + Assert.assertEquals("tpubDFcrvj5n7gyatVbr8dHCUfHT4CGvL8hREBjtxc4ge7HZgqNuPhFimPRtVg6fRRwfXiQthV9EBjNbwbpgV2VoQeL1ZNXoAWXxP2L9vMtRjax", wallet.getKeystores().get(0).getExtendedPublicKey().toString()); Assert.assertEquals("7bb026be", wallet.getKeystores().get(2).getKeyDerivation().getMasterFingerprint()); Assert.assertEquals("m/48'/1'/0'/1'", wallet.getKeystores().get(2).getKeyDerivation().getDerivationPath()); Assert.assertTrue(wallet.isValid()); @@ -67,6 +70,7 @@ public class ElectrumTest extends IoTest { @Test public void testMultisigExport() throws ImportException, ExportException, IOException { + Network.set(Network.TESTNET); Electrum electrum = new Electrum(); byte[] walletBytes = ByteStreams.toByteArray(getInputStream("electrum-multisig-wallet.json")); Wallet wallet = electrum.importWallet(new ByteArrayInputStream(walletBytes), null); @@ -81,7 +85,7 @@ public class ElectrumTest extends IoTest { Assert.assertEquals("sh(wsh(sortedmulti(2,coldcard6ba6cfd0,coldcard747b698e,coldcard7bb026be,coldcard0f056943)))", wallet.getDefaultPolicy().getMiniscript().getScript()); Assert.assertEquals("6ba6cfd0", wallet.getKeystores().get(0).getKeyDerivation().getMasterFingerprint()); Assert.assertEquals("m/48'/1'/0'/1'", wallet.getKeystores().get(0).getKeyDerivation().getDerivationPath()); - Assert.assertEquals("xpub6FFEQVG6QR28chQzgSJ7Gjx5j5BGLkCMgZ9bc41YJCXfwYiCKUQdcwm4Fe1stvzRjosz5udMedYZFRL56AeZXCsiVmnVUysio4jkAKTukmN", wallet.getKeystores().get(0).getExtendedPublicKey().toString()); + Assert.assertEquals("tpubDFcrvj5n7gyatVbr8dHCUfHT4CGvL8hREBjtxc4ge7HZgqNuPhFimPRtVg6fRRwfXiQthV9EBjNbwbpgV2VoQeL1ZNXoAWXxP2L9vMtRjax", wallet.getKeystores().get(0).getExtendedPublicKey().toString()); Assert.assertEquals("7bb026be", wallet.getKeystores().get(2).getKeyDerivation().getMasterFingerprint()); Assert.assertEquals("m/48'/1'/0'/1'", wallet.getKeystores().get(2).getKeyDerivation().getDerivationPath()); } @@ -123,4 +127,9 @@ public class ElectrumTest extends IoTest { Assert.assertEquals(wallet.getKeystores().get(0).getSeed().getMnemonicString().asString(), "coach fan denial rifle frost rival join install one wasp cool antique"); Assert.assertEquals("e14c40c638e2c83d1f20e5ee9cd744bc2ba1ef64fa939926f3778fc8735e891f56852f687b32bbd044f272d2831137e3eeba61fd1f285fa73dcc97d9f2be3cd1", Utils.bytesToHex(wallet.getKeystores().get(0).getSeed().getSeedBytes())); } + + @After + public void tearDown() throws Exception { + Network.set(null); + } } \ No newline at end of file