Skip to content

Commit

Permalink
upgrade junit tests from 4 to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
craigraw committed Feb 15, 2024
1 parent 22310cd commit 1d50b4f
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 208 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ dependencies {
implementation('com.github.hervegirod:fxsvgimage:1.0b2')
implementation('com.sparrowwallet:toucan:0.9.0')
testImplementation('org.junit.jupiter:junit-jupiter-api:5.10.0')
testImplementation('org.junit.vintage:junit-vintage-engine:5.10.0')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.10.0')
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
}

compileJava {
Expand All @@ -156,6 +157,7 @@ processResources {
}

test {
useJUnitPlatform()
jvmArgs '--add-opens=java.base/java.io=ALL-UNNAMED'
}

Expand Down Expand Up @@ -701,5 +703,4 @@ extraJavaModuleInfo {
module('jcommander-1.81.jar', 'com.beust.jcommander', '1.81') {
exports('com.beust.jcommander')
}
module('hamcrest-core-1.3.jar', 'org.hamcrest.core', '1.3')
}
26 changes: 13 additions & 13 deletions src/test/java/com/sparrowwallet/sparrow/io/CaravanMultisigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletModel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -18,16 +18,16 @@ public class CaravanMultisigTest extends IoTest {
public void importWallet1() throws ImportException {
CaravanMultisig ccMultisig = new CaravanMultisig();
Wallet wallet = ccMultisig.importWallet(getInputStream("caravan-multisig-export-1.json"), null);
Assert.assertEquals("Test Wallet", wallet.getName());
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType());
Assert.assertEquals(2, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assert.assertEquals("wsh(sortedmulti(2,mercury,venus,earth))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assert.assertTrue(wallet.isValid());
Assert.assertEquals("8188029f", wallet.getKeystores().get(0).getKeyDerivation().getMasterFingerprint());
Assert.assertEquals("m/48'/0'/0'/2'", wallet.getKeystores().get(0).getKeyDerivation().getDerivationPath());
Assert.assertEquals(WalletModel.TREZOR_1, wallet.getKeystores().get(0).getWalletModel());
Assert.assertEquals("xpub6EMVvcTUbaABdaPLaVWE72CjcN72URa5pKK1knrKLz1hKaDwUkgddc3832a8MHEpLyuow7MfjMRomt2iMtwPH4pWrFLft4JsquHjeZfKsYp", wallet.getKeystores().get(0).getExtendedPublicKey().toString());
Assertions.assertEquals("Test Wallet", wallet.getName());
Assertions.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assertions.assertEquals(ScriptType.P2WSH, wallet.getScriptType());
Assertions.assertEquals(2, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assertions.assertEquals("wsh(sortedmulti(2,mercury,venus,earth))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assertions.assertTrue(wallet.isValid());
Assertions.assertEquals("8188029f", wallet.getKeystores().get(0).getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals("m/48'/0'/0'/2'", wallet.getKeystores().get(0).getKeyDerivation().getDerivationPath());
Assertions.assertEquals(WalletModel.TREZOR_1, wallet.getKeystores().get(0).getWalletModel());
Assertions.assertEquals("xpub6EMVvcTUbaABdaPLaVWE72CjcN72URa5pKK1knrKLz1hKaDwUkgddc3832a8MHEpLyuow7MfjMRomt2iMtwPH4pWrFLft4JsquHjeZfKsYp", wallet.getKeystores().get(0).getExtendedPublicKey().toString());
}

@Test
Expand All @@ -40,6 +40,6 @@ public void exportWallet1() throws ImportException, ExportException, IOException
byte[] exportedBytes = baos.toByteArray();
String original = new String(walletBytes);
String exported = new String(exportedBytes);
Assert.assertEquals(original, exported);
Assertions.assertEquals(original, exported);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@
import com.sparrowwallet.drongo.ExtendedKey;
import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Keystore;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CoboVaultSinglesigTest extends IoTest {
@Test
public void testImport() throws ImportException {
CoboVaultSinglesig coboSingleSig = new CoboVaultSinglesig();
Keystore keystore = coboSingleSig.getKeystore(ScriptType.P2WPKH, getInputStream("cobo-singlesig-keystore-1.json"), null);

Assert.assertEquals("Cobo Vault", keystore.getLabel());
Assert.assertEquals("m/84'/0'/0'", keystore.getKeyDerivation().getDerivationPath());
Assert.assertEquals("73c5da0a", keystore.getKeyDerivation().getMasterFingerprint());
Assert.assertEquals(ExtendedKey.fromDescriptor("zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"), keystore.getExtendedPublicKey());
Assert.assertTrue(keystore.isValid());
Assertions.assertEquals("Cobo Vault", keystore.getLabel());
Assertions.assertEquals("m/84'/0'/0'", keystore.getKeyDerivation().getDerivationPath());
Assertions.assertEquals("73c5da0a", keystore.getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals(ExtendedKey.fromDescriptor("zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"), keystore.getExtendedPublicKey());
Assertions.assertTrue(keystore.isValid());
}

@Test(expected = ImportException.class)
@Test
public void testIncorrectScriptType() throws ImportException {
CoboVaultSinglesig coboSingleSig = new CoboVaultSinglesig();
Keystore keystore = coboSingleSig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cobo-singlesig-keystore-1.json"), null);

Assert.assertEquals("Cobo Vault", keystore.getLabel());
Assert.assertEquals("m/84'/0'/0'", keystore.getKeyDerivation().getDerivationPath());
Assert.assertEquals("73c5da0a", keystore.getKeyDerivation().getMasterFingerprint());
Assert.assertEquals(ExtendedKey.fromDescriptor("zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"), keystore.getExtendedPublicKey());
Assert.assertTrue(keystore.isValid());
Assertions.assertThrows(ImportException.class, () -> coboSingleSig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cobo-singlesig-keystore-1.json"), null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
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;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.util.Locale;
Expand All @@ -20,83 +20,83 @@ 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());
Assert.assertEquals("m/48'/1'/0'/1'", keystore.getKeyDerivation().getDerivationPath());
Assert.assertEquals("0f056943", keystore.getKeyDerivation().getMasterFingerprint());
Assert.assertEquals(ExtendedKey.fromDescriptor("Upub5T4XUooQzDXL58NCHk8ZCw9BsRSLCtnyHeZEExAq1XdnBFXiXVrHFuvvmh3TnCR7XmKHxkwqdACv68z7QKT1vwru9L1SZSsw8B2fuBvtSa6"), keystore.getExtendedPublicKey());
Assert.assertTrue(keystore.isValid());
Assertions.assertEquals("Coldcard", keystore.getLabel());
Assertions.assertEquals("m/48'/1'/0'/1'", keystore.getKeyDerivation().getDerivationPath());
Assertions.assertEquals("0f056943", keystore.getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals(ExtendedKey.fromDescriptor("Upub5T4XUooQzDXL58NCHk8ZCw9BsRSLCtnyHeZEExAq1XdnBFXiXVrHFuvvmh3TnCR7XmKHxkwqdACv68z7QKT1vwru9L1SZSsw8B2fuBvtSa6"), keystore.getExtendedPublicKey());
Assertions.assertTrue(keystore.isValid());
}

@Test(expected = ImportException.class)
@Test
public void importKeystore1IncorrectScriptType() throws ImportException {
ColdcardMultisig ccMultisig = new ColdcardMultisig();
Keystore keystore = ccMultisig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-multisig-keystore-1.json"), null);
Assertions.assertThrows(ImportException.class, () -> ccMultisig.getKeystore(ScriptType.P2SH_P2WPKH, getInputStream("cc-multisig-keystore-1.json"), null));
}

@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());
Assert.assertEquals("m/45'", keystore.getKeyDerivation().getDerivationPath());
Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint());
Assert.assertEquals(ExtendedKey.fromDescriptor("tpubD9429UXFGCTKJ9NdiNK4rC5ygqSUkginycYHccqSg5gkmyQ7PZRHNjk99M6a6Y3NY8ctEUUJvCu6iCCui8Ju3xrHRu3Ez1CKB4ZFoRZDdP9"), keystore.getExtendedPublicKey());
Assert.assertTrue(keystore.isValid());
Assertions.assertEquals("Coldcard", keystore.getLabel());
Assertions.assertEquals("m/45'", keystore.getKeyDerivation().getDerivationPath());
Assertions.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals(ExtendedKey.fromDescriptor("tpubD9429UXFGCTKJ9NdiNK4rC5ygqSUkginycYHccqSg5gkmyQ7PZRHNjk99M6a6Y3NY8ctEUUJvCu6iCCui8Ju3xrHRu3Ez1CKB4ZFoRZDdP9"), keystore.getExtendedPublicKey());
Assertions.assertTrue(keystore.isValid());
}

@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());
Assert.assertEquals("m/48'/1'/0'/2'", keystore.getKeyDerivation().getDerivationPath());
Assert.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint());
Assert.assertEquals(ExtendedKey.fromDescriptor("Vpub5nUnvPehg1VYQh13dGznx1P9moac3SNUrn3qhU9r85RhXabYbSSBNsNNwyR7akozAZJw1SZmRRjry1zY8PWMuw8Ga1vQZ5qzPjKyTDQwtzs"), keystore.getExtendedPublicKey());
Assert.assertTrue(keystore.isValid());
Assertions.assertEquals("Coldcard", keystore.getLabel());
Assertions.assertEquals("m/48'/1'/0'/2'", keystore.getKeyDerivation().getDerivationPath());
Assertions.assertEquals("6ba6cfd0", keystore.getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals(ExtendedKey.fromDescriptor("Vpub5nUnvPehg1VYQh13dGznx1P9moac3SNUrn3qhU9r85RhXabYbSSBNsNNwyR7akozAZJw1SZmRRjry1zY8PWMuw8Ga1vQZ5qzPjKyTDQwtzs"), keystore.getExtendedPublicKey());
Assertions.assertTrue(keystore.isValid());
}

@Test
public void importWallet1() throws ImportException {
ColdcardMultisig ccMultisig = new ColdcardMultisig();
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-1.txt"), null);
Assert.assertEquals("CC-2-of-4", wallet.getName());
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType());
Assert.assertEquals(2, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assert.assertEquals("wsh(sortedmulti(2,coldcard1,coldcard2,coldcard3,coldcard4))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assert.assertTrue(wallet.isValid());
Assertions.assertEquals("CC-2-of-4", wallet.getName());
Assertions.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assertions.assertEquals(ScriptType.P2WSH, wallet.getScriptType());
Assertions.assertEquals(2, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assertions.assertEquals("wsh(sortedmulti(2,coldcard1,coldcard2,coldcard3,coldcard4))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assertions.assertTrue(wallet.isValid());
}

@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());
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assert.assertEquals(ScriptType.P2SH_P2WSH, wallet.getScriptType());
Assert.assertEquals(2, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assert.assertEquals("sh(wsh(sortedmulti(2,coldcard1,coldcard2,coldcard3,coldcard4)))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assert.assertTrue(wallet.isValid());
Assertions.assertEquals("CC-2-of-4", wallet.getName());
Assertions.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assertions.assertEquals(ScriptType.P2SH_P2WSH, wallet.getScriptType());
Assertions.assertEquals(2, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assertions.assertEquals("sh(wsh(sortedmulti(2,coldcard1,coldcard2,coldcard3,coldcard4)))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assertions.assertTrue(wallet.isValid());
}

@Test
public void importWalletMultiDeriv() throws ImportException {
ColdcardMultisig ccMultisig = new ColdcardMultisig();
Wallet wallet = ccMultisig.importWallet(getInputStream("cc-multisig-export-multideriv.txt"), null);
Assert.assertEquals("el-CC-3-of-3-sb-2", wallet.getName());
Assert.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assert.assertEquals(ScriptType.P2WSH, wallet.getScriptType());
Assert.assertEquals(3, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assert.assertEquals("wsh(sortedmulti(3,coldcard1,coldcard2,coldcard3))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assert.assertEquals("06b57041", wallet.getKeystores().get(0).getKeyDerivation().getMasterFingerprint());
Assert.assertEquals("m/48'/0'/0'/2'", wallet.getKeystores().get(0).getKeyDerivation().getDerivationPath());
Assert.assertEquals("xpub6EfEGa5isJbQFSswM5Uptw5BSq2Td1ZDJr3QUNUcMySpC7itZ3ccypVHtLPnvMzKQ2qxrAgH49vhVxRcaQLFbixAVRR8RACrYTp88Uv9h8Z", wallet.getKeystores().get(0).getExtendedPublicKey().toString());
Assert.assertEquals("ca9a2b19", wallet.getKeystores().get(2).getKeyDerivation().getMasterFingerprint());
Assert.assertEquals("m/47'/0'/0'/1'", wallet.getKeystores().get(2).getKeyDerivation().getDerivationPath());
Assert.assertTrue(wallet.isValid());
Assertions.assertEquals("el-CC-3-of-3-sb-2", wallet.getName());
Assertions.assertEquals(PolicyType.MULTI, wallet.getPolicyType());
Assertions.assertEquals(ScriptType.P2WSH, wallet.getScriptType());
Assertions.assertEquals(3, wallet.getDefaultPolicy().getNumSignaturesRequired());
Assertions.assertEquals("wsh(sortedmulti(3,coldcard1,coldcard2,coldcard3))", wallet.getDefaultPolicy().getMiniscript().getScript().toLowerCase(Locale.ROOT));
Assertions.assertEquals("06b57041", wallet.getKeystores().get(0).getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals("m/48'/0'/0'/2'", wallet.getKeystores().get(0).getKeyDerivation().getDerivationPath());
Assertions.assertEquals("xpub6EfEGa5isJbQFSswM5Uptw5BSq2Td1ZDJr3QUNUcMySpC7itZ3ccypVHtLPnvMzKQ2qxrAgH49vhVxRcaQLFbixAVRR8RACrYTp88Uv9h8Z", wallet.getKeystores().get(0).getExtendedPublicKey().toString());
Assertions.assertEquals("ca9a2b19", wallet.getKeystores().get(2).getKeyDerivation().getMasterFingerprint());
Assertions.assertEquals("m/47'/0'/0'/1'", wallet.getKeystores().get(2).getKeyDerivation().getDerivationPath());
Assertions.assertTrue(wallet.isValid());
}

@Test
Expand All @@ -109,7 +109,7 @@ public void exportWallet1() throws ImportException, ExportException, IOException
byte[] exportedBytes = baos.toByteArray();
String original = new String(walletBytes);
String exported = new String(exportedBytes);
Assert.assertEquals(original.replaceAll("created on [0-9A-F]+", ""), exported.replace("created by Sparrow", ""));
Assertions.assertEquals(original.replaceAll("created on [0-9A-F]+", ""), exported.replace("created by Sparrow", ""));
}

@Test
Expand All @@ -122,10 +122,10 @@ public void exportWalletMultiDeriv() throws ImportException, ExportException, IO
byte[] exportedBytes = baos.toByteArray();
String original = new String(walletBytes);
String exported = new String(exportedBytes);
Assert.assertEquals(original.replaceAll("Exported from Electrum", ""), exported.replace("Coldcard Multisig setup file (created by Sparrow)\n#", ""));
Assertions.assertEquals(original.replaceAll("Exported from Electrum", ""), exported.replace("Coldcard Multisig setup file (created by Sparrow)\n#", ""));
}

@After
@AfterEach
public void tearDown() throws Exception {
Network.set(null);
}
Expand Down
Loading

0 comments on commit 1d50b4f

Please sign in to comment.