forked from Qortal/qortal
Merge pull request #127 from kennycud/master
consolidated shared functionality into BitcoinyTests.java
This commit is contained in:
commit
9f4a0b7957
@ -1,121 +1,59 @@
|
|||||||
package org.qortal.test.crosschain;
|
package org.qortal.test.crosschain;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bitcoinj.core.Transaction;
|
|
||||||
import org.bitcoinj.store.BlockStoreException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.crosschain.Bitcoin;
|
import org.qortal.crosschain.Bitcoin;
|
||||||
import org.qortal.crosschain.ForeignBlockchainException;
|
import org.qortal.crosschain.Bitcoiny;
|
||||||
import org.qortal.crosschain.BitcoinyHTLC;
|
|
||||||
import org.qortal.repository.DataException;
|
|
||||||
import org.qortal.test.common.Common;
|
|
||||||
|
|
||||||
public class BitcoinTests extends Common {
|
public class BitcoinTests extends BitcoinyTests {
|
||||||
|
|
||||||
private Bitcoin bitcoin;
|
@Override
|
||||||
|
protected String getCoinName() {
|
||||||
@Before
|
return "Bitcoin";
|
||||||
public void beforeTest() throws DataException {
|
|
||||||
Common.useDefaultSettings(); // TestNet3
|
|
||||||
bitcoin = Bitcoin.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected String getCoinSymbol() {
|
||||||
|
return "BTC";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Bitcoiny getCoin() {
|
||||||
|
return Bitcoin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetCoinForTesting() {
|
||||||
Bitcoin.resetForTesting();
|
Bitcoin.resetForTesting();
|
||||||
bitcoin = null;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getDeterministicKey58() {
|
||||||
|
return "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getRecipient() {
|
||||||
|
return "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
||||||
public void testGetMedianBlockTime() throws BlockStoreException, ForeignBlockchainException {
|
public void testGetMedianBlockTime() {}
|
||||||
System.out.println(String.format("Starting BTC instance..."));
|
|
||||||
System.out.println(String.format("BTC instance started"));
|
|
||||||
|
|
||||||
long before = System.currentTimeMillis();
|
|
||||||
System.out.println(String.format("Bitcoin median blocktime: %d", bitcoin.getMedianBlockTime()));
|
|
||||||
long afterFirst = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println(String.format("Bitcoin median blocktime: %d", bitcoin.getMedianBlockTime()));
|
|
||||||
long afterSecond = System.currentTimeMillis();
|
|
||||||
|
|
||||||
long firstPeriod = afterFirst - before;
|
|
||||||
long secondPeriod = afterSecond - afterFirst;
|
|
||||||
|
|
||||||
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
|
||||||
|
|
||||||
assertTrue("2nd call should be quicker than 1st", secondPeriod < firstPeriod);
|
|
||||||
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
||||||
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
public void testFindHtlcSecret() {}
|
||||||
// This actually exists on TEST3 but can take a while to fetch
|
|
||||||
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
|
|
||||||
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
|
||||||
byte[] secret = BitcoinyHTLC.findHtlcSecret(bitcoin, p2shAddress);
|
|
||||||
|
|
||||||
assertNotNull(secret);
|
|
||||||
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
||||||
public void testBuildSpend() {
|
public void testBuildSpend() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String recipient = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
long amount = 1000L;
|
|
||||||
|
|
||||||
Transaction transaction = bitcoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull(transaction);
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
transaction = bitcoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull(transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
||||||
public void testGetWalletBalance() throws ForeignBlockchainException {
|
public void testGetWalletBalance() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
Long balance = bitcoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(balance);
|
|
||||||
|
|
||||||
System.out.println(bitcoin.format(balance));
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
Long repeatBalance = bitcoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(repeatBalance);
|
|
||||||
|
|
||||||
System.out.println(bitcoin.format(repeatBalance));
|
|
||||||
|
|
||||||
assertEquals(balance, repeatBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
@Ignore("Often fails due to unreliable BTC testnet ElectrumX servers")
|
||||||
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
public void testGetUnusedReceiveAddress() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String address = bitcoin.getUnusedReceiveAddress(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(address);
|
|
||||||
|
|
||||||
System.out.println(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
130
src/test/java/org/qortal/test/crosschain/BitcoinyTests.java
Normal file
130
src/test/java/org/qortal/test/crosschain/BitcoinyTests.java
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
package org.qortal.test.crosschain;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.Transaction;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.qortal.crosschain.Bitcoiny;
|
||||||
|
import org.qortal.crosschain.BitcoinyHTLC;
|
||||||
|
import org.qortal.crosschain.ForeignBlockchainException;
|
||||||
|
import org.qortal.repository.DataException;
|
||||||
|
import org.qortal.test.common.Common;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public abstract class BitcoinyTests extends Common {
|
||||||
|
|
||||||
|
protected Bitcoiny bitcoiny;
|
||||||
|
|
||||||
|
protected abstract String getCoinName();
|
||||||
|
|
||||||
|
protected abstract String getCoinSymbol();
|
||||||
|
|
||||||
|
protected abstract Bitcoiny getCoin();
|
||||||
|
|
||||||
|
protected abstract void resetCoinForTesting();
|
||||||
|
|
||||||
|
protected abstract String getDeterministicKey58();
|
||||||
|
|
||||||
|
protected abstract String getRecipient();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void beforeTest() throws DataException {
|
||||||
|
Common.useDefaultSettings(); // TestNet3
|
||||||
|
bitcoiny = getCoin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void afterTest() {
|
||||||
|
resetCoinForTesting();
|
||||||
|
bitcoiny = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMedianBlockTime() throws ForeignBlockchainException {
|
||||||
|
System.out.println(String.format("Starting " + getCoinSymbol() + " instance..."));
|
||||||
|
System.out.println(String.format(getCoinSymbol() + " instance started"));
|
||||||
|
|
||||||
|
long before = System.currentTimeMillis();
|
||||||
|
System.out.println(String.format(getCoinName() + " median blocktime: %d", bitcoiny.getMedianBlockTime()));
|
||||||
|
long afterFirst = System.currentTimeMillis();
|
||||||
|
|
||||||
|
System.out.println(String.format(getCoinName() + " median blocktime: %d", bitcoiny.getMedianBlockTime()));
|
||||||
|
long afterSecond = System.currentTimeMillis();
|
||||||
|
|
||||||
|
long firstPeriod = afterFirst - before;
|
||||||
|
long secondPeriod = afterSecond - afterFirst;
|
||||||
|
|
||||||
|
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
||||||
|
|
||||||
|
makeGetMedianBlockTimeAssertions(firstPeriod, secondPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void makeGetMedianBlockTimeAssertions(long firstPeriod, long secondPeriod) {
|
||||||
|
assertTrue("2nd call should be quicker than 1st", secondPeriod < firstPeriod);
|
||||||
|
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
||||||
|
// This actually exists on TEST3 but can take a while to fetch
|
||||||
|
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
||||||
|
|
||||||
|
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
||||||
|
byte[] secret = BitcoinyHTLC.findHtlcSecret(bitcoiny, p2shAddress);
|
||||||
|
|
||||||
|
assertNotNull(secret);
|
||||||
|
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildSpend() {
|
||||||
|
String xprv58 = getDeterministicKey58();
|
||||||
|
|
||||||
|
String recipient = getRecipient();
|
||||||
|
long amount = 1000L;
|
||||||
|
|
||||||
|
Transaction transaction = bitcoiny.buildSpend(xprv58, recipient, amount);
|
||||||
|
assertNotNull(transaction);
|
||||||
|
|
||||||
|
// Check spent key caching doesn't affect outcome
|
||||||
|
|
||||||
|
transaction = bitcoiny.buildSpend(xprv58, recipient, amount);
|
||||||
|
assertNotNull(transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetWalletBalance() throws ForeignBlockchainException {
|
||||||
|
String xprv58 = getDeterministicKey58();
|
||||||
|
|
||||||
|
Long balance = bitcoiny.getWalletBalance(xprv58);
|
||||||
|
|
||||||
|
assertNotNull(balance);
|
||||||
|
|
||||||
|
System.out.println(bitcoiny.format(balance));
|
||||||
|
|
||||||
|
// Check spent key caching doesn't affect outcome
|
||||||
|
|
||||||
|
Long repeatBalance = bitcoiny.getWalletBalance(xprv58);
|
||||||
|
|
||||||
|
assertNotNull(repeatBalance);
|
||||||
|
|
||||||
|
System.out.println(bitcoiny.format(repeatBalance));
|
||||||
|
|
||||||
|
assertEquals(balance, repeatBalance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
||||||
|
String xprv58 = getDeterministicKey58();
|
||||||
|
|
||||||
|
String address = bitcoiny.getUnusedReceiveAddress(xprv58);
|
||||||
|
|
||||||
|
assertNotNull(address);
|
||||||
|
|
||||||
|
System.out.println(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,115 +1,48 @@
|
|||||||
package org.qortal.test.crosschain;
|
package org.qortal.test.crosschain;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bitcoinj.core.Transaction;
|
|
||||||
import org.bitcoinj.store.BlockStoreException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.crosschain.ForeignBlockchainException;
|
import org.qortal.crosschain.Bitcoiny;
|
||||||
import org.qortal.crosschain.Digibyte;
|
import org.qortal.crosschain.Digibyte;
|
||||||
import org.qortal.crosschain.BitcoinyHTLC;
|
|
||||||
import org.qortal.repository.DataException;
|
|
||||||
import org.qortal.test.common.Common;
|
|
||||||
|
|
||||||
public class DigibyteTests extends Common {
|
public class DigibyteTests extends BitcoinyTests {
|
||||||
|
|
||||||
private Digibyte digibyte;
|
@Override
|
||||||
|
protected String getCoinName() {
|
||||||
@Before
|
return "Digibyte";
|
||||||
public void beforeTest() throws DataException {
|
|
||||||
Common.useDefaultSettings(); // TestNet3
|
|
||||||
digibyte = Digibyte.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected String getCoinSymbol() {
|
||||||
|
return "DGB";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Bitcoiny getCoin() {
|
||||||
|
return Digibyte.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetCoinForTesting() {
|
||||||
Digibyte.resetForTesting();
|
Digibyte.resetForTesting();
|
||||||
digibyte = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void testGetMedianBlockTime() throws BlockStoreException, ForeignBlockchainException {
|
protected String getDeterministicKey58() {
|
||||||
long before = System.currentTimeMillis();
|
return "xpub661MyMwAqRbcEnabTLX5uebYcsE3uG5y7ve9jn1VK8iY1MaU3YLoLJEe8sTu2YVav5Zka5qf2dmMssfxmXJTqZnazZL2kL7M2tNKwEoC34R";
|
||||||
System.out.println(String.format("Digibyte median blocktime: %d", digibyte.getMedianBlockTime()));
|
}
|
||||||
long afterFirst = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println(String.format("Digibyte median blocktime: %d", digibyte.getMedianBlockTime()));
|
@Override
|
||||||
long afterSecond = System.currentTimeMillis();
|
protected String getRecipient() {
|
||||||
|
return "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
||||||
long firstPeriod = afterFirst - before;
|
|
||||||
long secondPeriod = afterSecond - afterFirst;
|
|
||||||
|
|
||||||
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
|
||||||
|
|
||||||
assertTrue("2nd call should be quicker than 1st", secondPeriod < firstPeriod);
|
|
||||||
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Doesn't work, to be fixed later")
|
@Ignore(value = "Doesn't work, to be fixed later")
|
||||||
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
public void testFindHtlcSecret() {}
|
||||||
// This actually exists on TEST3 but can take a while to fetch
|
|
||||||
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
|
|
||||||
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
|
||||||
byte[] secret = BitcoinyHTLC.findHtlcSecret(digibyte, p2shAddress);
|
|
||||||
|
|
||||||
assertNotNull("secret not found", secret);
|
|
||||||
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "No testnet nodes available, so we can't regularly test buildSpend yet")
|
@Ignore(value = "No testnet nodes available, so we can't regularly test buildSpend yet")
|
||||||
public void testBuildSpend() {
|
public void testBuildSpend() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String recipient = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
long amount = 1000L;
|
|
||||||
|
|
||||||
Transaction transaction = digibyte.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
transaction = digibyte.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetWalletBalance() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "xpub661MyMwAqRbcEnabTLX5uebYcsE3uG5y7ve9jn1VK8iY1MaU3YLoLJEe8sTu2YVav5Zka5qf2dmMssfxmXJTqZnazZL2kL7M2tNKwEoC34R";
|
|
||||||
|
|
||||||
Long balance = digibyte.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(balance);
|
|
||||||
|
|
||||||
System.out.println(digibyte.format(balance));
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
Long repeatBalance = digibyte.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(repeatBalance);
|
|
||||||
|
|
||||||
System.out.println(digibyte.format(repeatBalance));
|
|
||||||
|
|
||||||
assertEquals(balance, repeatBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "xpub661MyMwAqRbcEnabTLX5uebYcsE3uG5y7ve9jn1VK8iY1MaU3YLoLJEe8sTu2YVav5Zka5qf2dmMssfxmXJTqZnazZL2kL7M2tNKwEoC34R";
|
|
||||||
|
|
||||||
String address = digibyte.getUnusedReceiveAddress(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(address);
|
|
||||||
|
|
||||||
System.out.println(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,115 +1,47 @@
|
|||||||
package org.qortal.test.crosschain;
|
package org.qortal.test.crosschain;
|
||||||
|
|
||||||
import org.bitcoinj.core.Transaction;
|
|
||||||
import org.bitcoinj.store.BlockStoreException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.crosschain.BitcoinyHTLC;
|
import org.qortal.crosschain.Bitcoiny;
|
||||||
import org.qortal.crosschain.ForeignBlockchainException;
|
|
||||||
import org.qortal.crosschain.Dogecoin;
|
import org.qortal.crosschain.Dogecoin;
|
||||||
import org.qortal.repository.DataException;
|
|
||||||
import org.qortal.test.common.Common;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
public class DogecoinTests extends BitcoinyTests {
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
@Override
|
||||||
|
protected String getCoinName() {
|
||||||
public class DogecoinTests extends Common {
|
return "Dogecoin";
|
||||||
|
|
||||||
private Dogecoin dogecoin;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void beforeTest() throws DataException {
|
|
||||||
Common.useDefaultSettings(); // TestNet3
|
|
||||||
dogecoin = Dogecoin.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected String getCoinSymbol() {
|
||||||
|
return "DOGE";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Bitcoiny getCoin() {
|
||||||
|
return Dogecoin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetCoinForTesting() {
|
||||||
Dogecoin.resetForTesting();
|
Dogecoin.resetForTesting();
|
||||||
dogecoin = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void testGetMedianBlockTime() throws BlockStoreException, ForeignBlockchainException {
|
protected String getDeterministicKey58() {
|
||||||
long before = System.currentTimeMillis();
|
return "dgpv51eADS3spNJh9drNeW1Tc1P9z2LyaQRXPBortsq6yice1k47C2u2Prvgxycr2ihNBWzKZ2LthcBBGiYkWZ69KUTVkcLVbnjq7pD8mnApEru";
|
||||||
System.out.println(String.format("Dogecoin median blocktime: %d", dogecoin.getMedianBlockTime()));
|
}
|
||||||
long afterFirst = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println(String.format("Dogecoin median blocktime: %d", dogecoin.getMedianBlockTime()));
|
@Override
|
||||||
long afterSecond = System.currentTimeMillis();
|
protected String getRecipient() {
|
||||||
|
return null;
|
||||||
long firstPeriod = afterFirst - before;
|
|
||||||
long secondPeriod = afterSecond - afterFirst;
|
|
||||||
|
|
||||||
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
|
||||||
|
|
||||||
assertTrue("2nd call should be quicker than 1st", secondPeriod < firstPeriod);
|
|
||||||
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Doesn't work, to be fixed later")
|
@Ignore(value = "Doesn't work, to be fixed later")
|
||||||
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
public void testFindHtlcSecret() {}
|
||||||
// This actually exists on TEST3 but can take a while to fetch
|
|
||||||
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
|
|
||||||
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
|
||||||
byte[] secret = BitcoinyHTLC.findHtlcSecret(dogecoin, p2shAddress);
|
|
||||||
|
|
||||||
assertNotNull("secret not found", secret);
|
|
||||||
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "No testnet nodes available, so we can't regularly test buildSpend yet")
|
@Ignore(value = "No testnet nodes available, so we can't regularly test buildSpend yet")
|
||||||
public void testBuildSpend() {
|
public void testBuildSpend() {}
|
||||||
String xprv58 = "dgpv51eADS3spNJh9drNeW1Tc1P9z2LyaQRXPBortsq6yice1k47C2u2Prvgxycr2ihNBWzKZ2LthcBBGiYkWZ69KUTVkcLVbnjq7pD8mnApEru";
|
|
||||||
|
|
||||||
String recipient = "DP1iFao33xdEPa5vaArpj7sykfzKNeiJeX";
|
|
||||||
long amount = 1000L;
|
|
||||||
|
|
||||||
Transaction transaction = dogecoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
transaction = dogecoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetWalletBalance() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "dgpv51eADS3spNJh9drNeW1Tc1P9z2LyaQRXPBortsq6yice1k47C2u2Prvgxycr2ihNBWzKZ2LthcBBGiYkWZ69KUTVkcLVbnjq7pD8mnApEru";
|
|
||||||
|
|
||||||
Long balance = dogecoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(balance);
|
|
||||||
|
|
||||||
System.out.println(dogecoin.format(balance));
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
Long repeatBalance = dogecoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(repeatBalance);
|
|
||||||
|
|
||||||
System.out.println(dogecoin.format(repeatBalance));
|
|
||||||
|
|
||||||
assertEquals(balance, repeatBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "dgpv51eADS3spNJh9drNeW1Tc1P9z2LyaQRXPBortsq6yice1k47C2u2Prvgxycr2ihNBWzKZ2LthcBBGiYkWZ69KUTVkcLVbnjq7pD8mnApEru";
|
|
||||||
|
|
||||||
String address = dogecoin.getUnusedReceiveAddress(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(address);
|
|
||||||
|
|
||||||
System.out.println(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,113 +1,43 @@
|
|||||||
package org.qortal.test.crosschain;
|
package org.qortal.test.crosschain;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bitcoinj.core.Transaction;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.crosschain.ForeignBlockchainException;
|
import org.qortal.crosschain.Bitcoiny;
|
||||||
import org.qortal.crosschain.Litecoin;
|
import org.qortal.crosschain.Litecoin;
|
||||||
import org.qortal.crosschain.BitcoinyHTLC;
|
|
||||||
import org.qortal.repository.DataException;
|
|
||||||
import org.qortal.test.common.Common;
|
|
||||||
|
|
||||||
public class LitecoinTests extends Common {
|
public class LitecoinTests extends BitcoinyTests {
|
||||||
|
|
||||||
private Litecoin litecoin;
|
@Override
|
||||||
|
protected String getCoinName() {
|
||||||
@Before
|
return "Litecoin";
|
||||||
public void beforeTest() throws DataException {
|
|
||||||
Common.useDefaultSettings(); // TestNet3
|
|
||||||
litecoin = Litecoin.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected String getCoinSymbol() {
|
||||||
|
return "LTC";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Bitcoiny getCoin() {
|
||||||
|
return Litecoin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetCoinForTesting() {
|
||||||
Litecoin.resetForTesting();
|
Litecoin.resetForTesting();
|
||||||
litecoin = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void testGetMedianBlockTime() throws ForeignBlockchainException {
|
protected String getDeterministicKey58() {
|
||||||
long before = System.currentTimeMillis();
|
return "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
||||||
System.out.println(String.format("Litecoin median blocktime: %d", litecoin.getMedianBlockTime()));
|
}
|
||||||
long afterFirst = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println(String.format("Litecoin median blocktime: %d", litecoin.getMedianBlockTime()));
|
@Override
|
||||||
long afterSecond = System.currentTimeMillis();
|
protected String getRecipient() {
|
||||||
|
return "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
||||||
long firstPeriod = afterFirst - before;
|
|
||||||
long secondPeriod = afterSecond - afterFirst;
|
|
||||||
|
|
||||||
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
|
||||||
|
|
||||||
assertTrue("2nd call should be quicker than 1st", secondPeriod < firstPeriod);
|
|
||||||
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Doesn't work, to be fixed later")
|
@Ignore(value = "Doesn't work, to be fixed later")
|
||||||
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
public void testFindHtlcSecret() {}
|
||||||
// This actually exists on TEST3 but can take a while to fetch
|
|
||||||
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
|
|
||||||
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
|
||||||
byte[] secret = BitcoinyHTLC.findHtlcSecret(litecoin, p2shAddress);
|
|
||||||
|
|
||||||
assertNotNull("secret not found", secret);
|
|
||||||
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBuildSpend() {
|
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String recipient = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
long amount = 1000L;
|
|
||||||
|
|
||||||
Transaction transaction = litecoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
transaction = litecoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetWalletBalance() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
Long balance = litecoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(balance);
|
|
||||||
|
|
||||||
System.out.println(litecoin.format(balance));
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
Long repeatBalance = litecoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(repeatBalance);
|
|
||||||
|
|
||||||
System.out.println(litecoin.format(repeatBalance));
|
|
||||||
|
|
||||||
assertEquals(balance, repeatBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String address = litecoin.getUnusedReceiveAddress(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(address);
|
|
||||||
|
|
||||||
System.out.println(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,57 +3,53 @@ package org.qortal.test.crosschain;
|
|||||||
import cash.z.wallet.sdk.rpc.CompactFormats.*;
|
import cash.z.wallet.sdk.rpc.CompactFormats.*;
|
||||||
import com.google.common.hash.HashCode;
|
import com.google.common.hash.HashCode;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import org.bitcoinj.core.Transaction;
|
|
||||||
import org.bitcoinj.store.BlockStoreException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.controller.tradebot.TradeBot;
|
import org.qortal.controller.tradebot.TradeBot;
|
||||||
import org.qortal.crosschain.*;
|
import org.qortal.crosschain.*;
|
||||||
import org.qortal.crypto.Crypto;
|
import org.qortal.crypto.Crypto;
|
||||||
import org.qortal.repository.DataException;
|
|
||||||
import org.qortal.test.common.Common;
|
|
||||||
import org.qortal.transform.TransformationException;
|
import org.qortal.transform.TransformationException;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.qortal.crosschain.BitcoinyHTLC.Status.*;
|
import static org.qortal.crosschain.BitcoinyHTLC.Status.*;
|
||||||
|
|
||||||
public class PirateChainTests extends Common {
|
public class PirateChainTests extends BitcoinyTests {
|
||||||
|
|
||||||
private PirateChain pirateChain;
|
@Override
|
||||||
|
protected String getCoinName() {
|
||||||
@Before
|
return "PirateChain";
|
||||||
public void beforeTest() throws DataException {
|
|
||||||
Common.useDefaultSettings();
|
|
||||||
pirateChain = PirateChain.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected String getCoinSymbol() {
|
||||||
|
return "ARRR";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Bitcoiny getCoin() {
|
||||||
|
return PirateChain.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetCoinForTesting() {
|
||||||
Litecoin.resetForTesting();
|
Litecoin.resetForTesting();
|
||||||
pirateChain = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void testGetMedianBlockTime() throws BlockStoreException, ForeignBlockchainException {
|
protected String getDeterministicKey58() {
|
||||||
long before = System.currentTimeMillis();
|
return null;
|
||||||
System.out.println(String.format("Pirate Chain median blocktime: %d", pirateChain.getMedianBlockTime()));
|
}
|
||||||
long afterFirst = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println(String.format("Pirate Chain median blocktime: %d", pirateChain.getMedianBlockTime()));
|
@Override
|
||||||
long afterSecond = System.currentTimeMillis();
|
protected String getRecipient() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
long firstPeriod = afterFirst - before;
|
public void makeGetMedianBlockTimeAssertions(long firstPeriod, long secondPeriod) {
|
||||||
long secondPeriod = afterSecond - afterFirst;
|
assertTrue("1st call should take less than 5 seconds", firstPeriod < 5000L);
|
||||||
|
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
||||||
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
|
||||||
|
|
||||||
assertTrue("1st call should take less than 5 seconds", firstPeriod < 5000L);
|
|
||||||
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -62,7 +58,7 @@ public class PirateChainTests extends Common {
|
|||||||
int count = 20;
|
int count = 20;
|
||||||
|
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
List<CompactBlock> compactBlocks = pirateChain.getCompactBlocks(startHeight, count);
|
List<CompactBlock> compactBlocks = ((PirateChain) bitcoiny).getCompactBlocks(startHeight, count);
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
|
|
||||||
System.out.println(String.format("Retrieval took: %d ms", after-before));
|
System.out.println(String.format("Retrieval took: %d ms", after-before));
|
||||||
@ -82,7 +78,7 @@ public class PirateChainTests extends Common {
|
|||||||
Bytes.reverse(txBytes);
|
Bytes.reverse(txBytes);
|
||||||
String txHashBE = HashCode.fromBytes(txBytes).toString();
|
String txHashBE = HashCode.fromBytes(txBytes).toString();
|
||||||
|
|
||||||
byte[] rawTransaction = pirateChain.getBlockchainProvider().getRawTransaction(txHashBE);
|
byte[] rawTransaction = bitcoiny.getBlockchainProvider().getRawTransaction(txHashBE);
|
||||||
assertNotNull(rawTransaction);
|
assertNotNull(rawTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +117,7 @@ public class PirateChainTests extends Common {
|
|||||||
String p2shAddress = "ba6Q5HWrWtmfU2WZqQbrFdRYsafA45cUAt";
|
String p2shAddress = "ba6Q5HWrWtmfU2WZqQbrFdRYsafA45cUAt";
|
||||||
long p2shFee = 10000;
|
long p2shFee = 10000;
|
||||||
final long minimumAmount = 10000 + p2shFee;
|
final long minimumAmount = 10000 + p2shFee;
|
||||||
BitcoinyHTLC.Status htlcStatus = PirateChainHTLC.determineHtlcStatus(pirateChain.getBlockchainProvider(), p2shAddress, minimumAmount);
|
BitcoinyHTLC.Status htlcStatus = PirateChainHTLC.determineHtlcStatus(bitcoiny.getBlockchainProvider(), p2shAddress, minimumAmount);
|
||||||
assertEquals(FUNDED, htlcStatus);
|
assertEquals(FUNDED, htlcStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +126,7 @@ public class PirateChainTests extends Common {
|
|||||||
String p2shAddress = "bYZrzSSgGp8aEGvihukoMGU8sXYrx19Wka";
|
String p2shAddress = "bYZrzSSgGp8aEGvihukoMGU8sXYrx19Wka";
|
||||||
long p2shFee = 10000;
|
long p2shFee = 10000;
|
||||||
final long minimumAmount = 10000 + p2shFee;
|
final long minimumAmount = 10000 + p2shFee;
|
||||||
BitcoinyHTLC.Status htlcStatus = PirateChainHTLC.determineHtlcStatus(pirateChain.getBlockchainProvider(), p2shAddress, minimumAmount);
|
BitcoinyHTLC.Status htlcStatus = PirateChainHTLC.determineHtlcStatus(bitcoiny.getBlockchainProvider(), p2shAddress, minimumAmount);
|
||||||
assertEquals(REDEEMED, htlcStatus);
|
assertEquals(REDEEMED, htlcStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,14 +135,14 @@ public class PirateChainTests extends Common {
|
|||||||
String p2shAddress = "bE49izfVxz8odhu8c2BcUaVFUnt7NLFRgv";
|
String p2shAddress = "bE49izfVxz8odhu8c2BcUaVFUnt7NLFRgv";
|
||||||
long p2shFee = 10000;
|
long p2shFee = 10000;
|
||||||
final long minimumAmount = 10000 + p2shFee;
|
final long minimumAmount = 10000 + p2shFee;
|
||||||
BitcoinyHTLC.Status htlcStatus = PirateChainHTLC.determineHtlcStatus(pirateChain.getBlockchainProvider(), p2shAddress, minimumAmount);
|
BitcoinyHTLC.Status htlcStatus = PirateChainHTLC.determineHtlcStatus(bitcoiny.getBlockchainProvider(), p2shAddress, minimumAmount);
|
||||||
assertEquals(REFUNDED, htlcStatus);
|
assertEquals(REFUNDED, htlcStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetTxidForUnspentAddress() throws ForeignBlockchainException {
|
public void testGetTxidForUnspentAddress() throws ForeignBlockchainException {
|
||||||
String p2shAddress = "ba6Q5HWrWtmfU2WZqQbrFdRYsafA45cUAt";
|
String p2shAddress = "ba6Q5HWrWtmfU2WZqQbrFdRYsafA45cUAt";
|
||||||
String txid = PirateChainHTLC.getFundingTxid(pirateChain.getBlockchainProvider(), p2shAddress);
|
String txid = PirateChainHTLC.getFundingTxid(bitcoiny.getBlockchainProvider(), p2shAddress);
|
||||||
|
|
||||||
// Reverse the byte order of the txid used by block explorers, to get to big-endian form
|
// Reverse the byte order of the txid used by block explorers, to get to big-endian form
|
||||||
byte[] expectedTxidLE = HashCode.fromString("fea4b0c1abcf8f0f3ddc2fa2f9438501ee102aad62a9ff18a5ce7d08774755c0").asBytes();
|
byte[] expectedTxidLE = HashCode.fromString("fea4b0c1abcf8f0f3ddc2fa2f9438501ee102aad62a9ff18a5ce7d08774755c0").asBytes();
|
||||||
@ -161,7 +157,7 @@ public class PirateChainTests extends Common {
|
|||||||
String p2shAddress = "ba6Q5HWrWtmfU2WZqQbrFdRYsafA45cUAt";
|
String p2shAddress = "ba6Q5HWrWtmfU2WZqQbrFdRYsafA45cUAt";
|
||||||
long p2shFee = 10000;
|
long p2shFee = 10000;
|
||||||
final long minimumAmount = 10000 + p2shFee;
|
final long minimumAmount = 10000 + p2shFee;
|
||||||
String txid = PirateChainHTLC.getUnspentFundingTxid(pirateChain.getBlockchainProvider(), p2shAddress, minimumAmount);
|
String txid = PirateChainHTLC.getUnspentFundingTxid(bitcoiny.getBlockchainProvider(), p2shAddress, minimumAmount);
|
||||||
|
|
||||||
// Reverse the byte order of the txid used by block explorers, to get to big-endian form
|
// Reverse the byte order of the txid used by block explorers, to get to big-endian form
|
||||||
byte[] expectedTxidLE = HashCode.fromString("fea4b0c1abcf8f0f3ddc2fa2f9438501ee102aad62a9ff18a5ce7d08774755c0").asBytes();
|
byte[] expectedTxidLE = HashCode.fromString("fea4b0c1abcf8f0f3ddc2fa2f9438501ee102aad62a9ff18a5ce7d08774755c0").asBytes();
|
||||||
@ -174,7 +170,7 @@ public class PirateChainTests extends Common {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetTxidForSpentAddress() throws ForeignBlockchainException {
|
public void testGetTxidForSpentAddress() throws ForeignBlockchainException {
|
||||||
String p2shAddress = "bE49izfVxz8odhu8c2BcUaVFUnt7NLFRgv"; //"t3KtVxeEb8srJofo6atMEpMpEP6TjEi8VqA";
|
String p2shAddress = "bE49izfVxz8odhu8c2BcUaVFUnt7NLFRgv"; //"t3KtVxeEb8srJofo6atMEpMpEP6TjEi8VqA";
|
||||||
String txid = PirateChainHTLC.getFundingTxid(pirateChain.getBlockchainProvider(), p2shAddress);
|
String txid = PirateChainHTLC.getFundingTxid(bitcoiny.getBlockchainProvider(), p2shAddress);
|
||||||
|
|
||||||
// Reverse the byte order of the txid used by block explorers, to get to big-endian form
|
// Reverse the byte order of the txid used by block explorers, to get to big-endian form
|
||||||
byte[] expectedTxidLE = HashCode.fromString("fb386fc8eea0fbf3ea37047726b92c39441652b32d8d62a274331687f7a1eca8").asBytes();
|
byte[] expectedTxidLE = HashCode.fromString("fb386fc8eea0fbf3ea37047726b92c39441652b32d8d62a274331687f7a1eca8").asBytes();
|
||||||
@ -187,7 +183,7 @@ public class PirateChainTests extends Common {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetTransactionsForAddress() throws ForeignBlockchainException {
|
public void testGetTransactionsForAddress() throws ForeignBlockchainException {
|
||||||
String p2shAddress = "bE49izfVxz8odhu8c2BcUaVFUnt7NLFRgv"; //"t3KtVxeEb8srJofo6atMEpMpEP6TjEi8VqA";
|
String p2shAddress = "bE49izfVxz8odhu8c2BcUaVFUnt7NLFRgv"; //"t3KtVxeEb8srJofo6atMEpMpEP6TjEi8VqA";
|
||||||
List<BitcoinyTransaction> transactions = pirateChain.getBlockchainProvider()
|
List<BitcoinyTransaction> transactions = bitcoiny.getBlockchainProvider()
|
||||||
.getAddressBitcoinyTransactions(p2shAddress, false);
|
.getAddressBitcoinyTransactions(p2shAddress, false);
|
||||||
|
|
||||||
assertEquals(2, transactions.size());
|
assertEquals(2, transactions.size());
|
||||||
@ -232,66 +228,17 @@ public class PirateChainTests extends Common {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Doesn't work, to be fixed later")
|
@Ignore(value = "Doesn't work, to be fixed later")
|
||||||
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
public void testFindHtlcSecret() {}
|
||||||
// This actually exists on TEST3 but can take a while to fetch
|
|
||||||
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
|
|
||||||
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
|
||||||
byte[] secret = BitcoinyHTLC.findHtlcSecret(pirateChain, p2shAddress);
|
|
||||||
|
|
||||||
assertNotNull("secret not found", secret);
|
|
||||||
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Needs adapting for Pirate Chain")
|
@Ignore(value = "Needs adapting for Pirate Chain")
|
||||||
public void testBuildSpend() {
|
public void testBuildSpend() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String recipient = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
long amount = 1000L;
|
|
||||||
|
|
||||||
Transaction transaction = pirateChain.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
transaction = pirateChain.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Needs adapting for Pirate Chain")
|
@Ignore(value = "Needs adapting for Pirate Chain")
|
||||||
public void testGetWalletBalance() throws ForeignBlockchainException {
|
public void testGetWalletBalance() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
Long balance = pirateChain.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(balance);
|
|
||||||
|
|
||||||
System.out.println(pirateChain.format(balance));
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
Long repeatBalance = pirateChain.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(repeatBalance);
|
|
||||||
|
|
||||||
System.out.println(pirateChain.format(repeatBalance));
|
|
||||||
|
|
||||||
assertEquals(balance, repeatBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Needs adapting for Pirate Chain")
|
@Ignore(value = "Needs adapting for Pirate Chain")
|
||||||
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
public void testGetUnusedReceiveAddress() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String address = pirateChain.getUnusedReceiveAddress(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(address);
|
|
||||||
|
|
||||||
System.out.println(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,115 +1,47 @@
|
|||||||
package org.qortal.test.crosschain;
|
package org.qortal.test.crosschain;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bitcoinj.core.Transaction;
|
|
||||||
import org.bitcoinj.store.BlockStoreException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.qortal.crosschain.ForeignBlockchainException;
|
import org.qortal.crosschain.Bitcoiny;
|
||||||
import org.qortal.crosschain.Ravencoin;
|
import org.qortal.crosschain.Ravencoin;
|
||||||
import org.qortal.crosschain.BitcoinyHTLC;
|
|
||||||
import org.qortal.repository.DataException;
|
|
||||||
import org.qortal.test.common.Common;
|
|
||||||
|
|
||||||
public class RavencoinTests extends Common {
|
public class RavencoinTests extends BitcoinyTests {
|
||||||
|
|
||||||
private Ravencoin ravencoin;
|
@Override
|
||||||
|
protected String getCoinName() {
|
||||||
@Before
|
return "Ravencoin";
|
||||||
public void beforeTest() throws DataException {
|
|
||||||
Common.useDefaultSettings(); // TestNet3
|
|
||||||
ravencoin = Ravencoin.getInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected String getCoinSymbol() {
|
||||||
|
return "RVN";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Bitcoiny getCoin() {
|
||||||
|
return Ravencoin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetCoinForTesting() {
|
||||||
Ravencoin.resetForTesting();
|
Ravencoin.resetForTesting();
|
||||||
ravencoin = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void testGetMedianBlockTime() throws BlockStoreException, ForeignBlockchainException {
|
protected String getDeterministicKey58() {
|
||||||
long before = System.currentTimeMillis();
|
return "xpub661MyMwAqRbcEt3Ge1wNmkagyb1J7yTQu4Kquvy77Ycg2iPoh7Urg8s9Jdwp7YmrqGkDKJpUVjsZXSSsQgmAVUC17ZVQQeoWMzm7vDTt1y7";
|
||||||
System.out.println(String.format("Ravencoin median blocktime: %d", ravencoin.getMedianBlockTime()));
|
}
|
||||||
long afterFirst = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println(String.format("Ravencoin median blocktime: %d", ravencoin.getMedianBlockTime()));
|
@Override
|
||||||
long afterSecond = System.currentTimeMillis();
|
protected String getRecipient() {
|
||||||
|
return null;
|
||||||
long firstPeriod = afterFirst - before;
|
|
||||||
long secondPeriod = afterSecond - afterFirst;
|
|
||||||
|
|
||||||
System.out.println(String.format("1st call: %d ms, 2nd call: %d ms", firstPeriod, secondPeriod));
|
|
||||||
|
|
||||||
assertTrue("2nd call should be quicker than 1st", secondPeriod < firstPeriod);
|
|
||||||
assertTrue("2nd call should take less than 5 seconds", secondPeriod < 5000L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "Doesn't work, to be fixed later")
|
@Ignore(value = "Doesn't work, to be fixed later")
|
||||||
public void testFindHtlcSecret() throws ForeignBlockchainException {
|
public void testFindHtlcSecret() {}
|
||||||
// This actually exists on TEST3 but can take a while to fetch
|
|
||||||
String p2shAddress = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
|
|
||||||
byte[] expectedSecret = "This string is exactly 32 bytes!".getBytes();
|
|
||||||
byte[] secret = BitcoinyHTLC.findHtlcSecret(ravencoin, p2shAddress);
|
|
||||||
|
|
||||||
assertNotNull("secret not found", secret);
|
|
||||||
assertTrue("secret incorrect", Arrays.equals(expectedSecret, secret));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore(value = "No testnet nodes available, so we can't regularly test buildSpend yet")
|
@Ignore(value = "No testnet nodes available, so we can't regularly test buildSpend yet")
|
||||||
public void testBuildSpend() {
|
public void testBuildSpend() {}
|
||||||
String xprv58 = "tprv8ZgxMBicQKsPdahhFSrCdvC1bsWyzHHZfTneTVqUXN6s1wEtZLwAkZXzFP6TYLg2aQMecZLXLre5bTVGajEB55L1HYJcawpdFG66STVAWPJ";
|
|
||||||
|
|
||||||
String recipient = "2N8WCg52ULCtDSMjkgVTm5mtPdCsUptkHWE";
|
|
||||||
long amount = 1000L;
|
|
||||||
|
|
||||||
Transaction transaction = ravencoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
transaction = ravencoin.buildSpend(xprv58, recipient, amount);
|
|
||||||
assertNotNull("insufficient funds", transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetWalletBalance() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "xpub661MyMwAqRbcEt3Ge1wNmkagyb1J7yTQu4Kquvy77Ycg2iPoh7Urg8s9Jdwp7YmrqGkDKJpUVjsZXSSsQgmAVUC17ZVQQeoWMzm7vDTt1y7";
|
|
||||||
|
|
||||||
Long balance = ravencoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(balance);
|
|
||||||
|
|
||||||
System.out.println(ravencoin.format(balance));
|
|
||||||
|
|
||||||
// Check spent key caching doesn't affect outcome
|
|
||||||
|
|
||||||
Long repeatBalance = ravencoin.getWalletBalance(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(repeatBalance);
|
|
||||||
|
|
||||||
System.out.println(ravencoin.format(repeatBalance));
|
|
||||||
|
|
||||||
assertEquals(balance, repeatBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetUnusedReceiveAddress() throws ForeignBlockchainException {
|
|
||||||
String xprv58 = "xpub661MyMwAqRbcEt3Ge1wNmkagyb1J7yTQu4Kquvy77Ycg2iPoh7Urg8s9Jdwp7YmrqGkDKJpUVjsZXSSsQgmAVUC17ZVQQeoWMzm7vDTt1y7";
|
|
||||||
|
|
||||||
String address = ravencoin.getUnusedReceiveAddress(xprv58);
|
|
||||||
|
|
||||||
assertNotNull(address);
|
|
||||||
|
|
||||||
System.out.println(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user