diff --git a/.travis.yml b/.travis.yml index 5dae951cc..51c999050 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ # configuration for https://travis-ci.org/dogecoin/libdohj sudo: false +dist: bionic language: java -jdk: oraclejdk8 -install: -# before_install: - - sudo apt-get -qq update - - sudo apt-get install -y protobuf-compiler +matrix: + include: + - jdk: openjdk8 + env: GRADLE_VERSION=6.7.1 + - jdk: openjdk11 + env: GRADLE_VERSION=6.7.1 +install: true +before_script: + - gradle wrapper --gradle-version=$GRADLE_VERSION script: - - gradle -q clean install - - jdk_switcher use openjdk7 - - cd core - - gradle -q clean build + - ./gradlew clean build diff --git a/build.gradle b/build.gradle index 2043f8c88..74a59e7b0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { jcenter() + mavenCentral() } dependencies { diff --git a/core/build.gradle b/core/build.gradle index 45b2e4c19..f9de088d0 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,40 +1,42 @@ -apply plugin: 'java' +apply plugin: 'java-library' apply plugin: 'maven' version = '0.15-SNAPSHOT' archivesBaseName = 'libdohj-core' dependencies { - compile 'org.bitcoinj:bitcoinj-core:0.15.9' - compile 'com.madgag.spongycastle:core:1.58.0.0' + api 'org.bitcoinj:bitcoinj-core:0.15.10' + implementation 'com.madgag.spongycastle:core:1.58.0.0' + implementation 'com.google.guava:guava:30.0-android' implementation 'com.lambdaworks:scrypt:1.4.0' - implementation 'com.google.guava:guava:24.0-android' - compile 'com.google.protobuf:protobuf-java:3.5.1' - implementation 'com.squareup.okhttp3:okhttp:3.9.1' - implementation 'org.slf4j:slf4j-api:1.7.25' + implementation 'com.google.protobuf:protobuf-java:3.13.0' + implementation 'com.squareup.okhttp3:okhttp:3.12.12' + implementation 'org.slf4j:slf4j-api:1.7.30' implementation 'net.jcip:jcip-annotations:1.0' compileOnly 'org.fusesource.leveldbjni:leveldbjni-all:1.8' - testImplementation 'junit:junit:4.12' - testImplementation 'org.easymock:easymock:3.2' + testImplementation 'junit:junit:4.13.1' testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.5.2' - testImplementation 'org.slf4j:slf4j-jdk14:1.7.25' - testImplementation 'com.h2database:h2:1.3.167' + testImplementation 'org.slf4j:slf4j-jdk14:1.7.30' testImplementation 'org.fusesource.leveldbjni:leveldbjni-all:1.8' } -sourceCompatibility = 1.7 +sourceCompatibility = 1.8 test { exclude 'org/libdohj/net/NetworkAbstractionTests*' + testLogging { + events "failed" + exceptionFormat "full" + } } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc.destinationDir } task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allSource } diff --git a/core/src/main/java/org/libdohj/params/LitecoinTestNet3Params.java b/core/src/main/java/org/libdohj/params/LitecoinTestNet3Params.java index e80c18dac..7d5d1081c 100644 --- a/core/src/main/java/org/libdohj/params/LitecoinTestNet3Params.java +++ b/core/src/main/java/org/libdohj/params/LitecoinTestNet3Params.java @@ -18,7 +18,7 @@ package org.libdohj.params; import org.bitcoinj.core.Utils; -import org.spongycastle.util.encoders.Hex; +import org.bouncycastle.util.encoders.Hex; import static com.google.common.base.Preconditions.checkState; import java.io.ByteArrayOutputStream; diff --git a/core/src/test/java/org/bitcoinj/core/AltcoinBlockTest.java b/core/src/test/java/org/bitcoinj/core/AltcoinBlockTest.java index 4aa525805..802238689 100644 --- a/core/src/test/java/org/bitcoinj/core/AltcoinBlockTest.java +++ b/core/src/test/java/org/bitcoinj/core/AltcoinBlockTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 jrn. + * Copyright 2015, 2021 Ross Nicoll. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +15,16 @@ */ package org.bitcoinj.core; -import java.util.BitSet; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; - import org.libdohj.params.DogecoinMainNetParams; -/** - * - * @author jrn - */ +import java.util.BitSet; + +import static org.junit.Assert.assertEquals; + public class AltcoinBlockTest { - private final NetworkParameters params = DogecoinMainNetParams.get(); + private static final NetworkParameters params = DogecoinMainNetParams.get(); @Before public void setUp() throws Exception { diff --git a/core/src/test/java/org/bitcoinj/core/AuxPoWTest.java b/core/src/test/java/org/bitcoinj/core/AuxPoWTest.java index 424055c7c..bdf49f977 100644 --- a/core/src/test/java/org/bitcoinj/core/AuxPoWTest.java +++ b/core/src/test/java/org/bitcoinj/core/AuxPoWTest.java @@ -1,20 +1,22 @@ package org.bitcoinj.core; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collections; - +import org.junit.Before; +import org.junit.Test; import org.libdohj.core.AltcoinSerializer; import org.libdohj.params.DogecoinMainNetParams; import org.libdohj.params.DogecoinTestNet3Params; -import static org.bitcoinj.core.Util.getBytes; -import static org.junit.Assert.*; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import static org.bitcoinj.core.Util.getBytes; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; /** * AuxPoW header parsing/serialization and validation @@ -34,7 +36,7 @@ public void setUp() throws Exception { @Test public void parseAuxPoWHeader() throws Exception { byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); MerkleBranch branch = auxpow.getCoinbaseBranch(); Sha256Hash expected = Sha256Hash.wrap("089b911f5e471c0e1800f3384281ebec5b372fbb6f358790a92747ade271ccdf"); @@ -54,11 +56,10 @@ public void parseAuxPoWHeader() throws Exception { @Test public void serializeAuxPoWHeader() throws Exception { byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); - byte[] expected = auxpowAsBytes; + AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); byte[] actual = auxpow.bitcoinSerialize(); - assertArrayEquals(expected, actual); + assertArrayEquals(auxpowAsBytes, actual); } /** @@ -67,9 +68,9 @@ public void serializeAuxPoWHeader() throws Exception { @Test public void checkAuxPoWHeader() throws Exception { byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + Utils.decodeCompactBits(0x1b06f8f0), true); } /** @@ -87,13 +88,10 @@ public BigInteger getBlockDifficulty(Block block) { } }; byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header_no_tx_header.bin")); - AuxPoW auxpow = new AuxPoW(namecoinLikeParams, auxpowAsBytes, (ChildMessage) null, namecoinLikeParams.getDefaultSerializer()); + AuxPoW auxpow = new AuxPoW(namecoinLikeParams, auxpowAsBytes, null, namecoinLikeParams.getDefaultSerializer()); auxpow.checkProofOfWork(Sha256Hash.wrap("5fb89c3b18c27bc38d351d516177cbd3504c95ca0494cbbbbd52f2fb5f2ff1ec"), - Utils.decodeCompactBits(0x1b00b269), true); + Utils.decodeCompactBits(0x1b00b269), true); } - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); /** * Check that a non-generate AuxPoW transaction is rejected. @@ -101,12 +99,12 @@ public BigInteger getBlockDifficulty(Block block) { @Test public void shouldRejectNonGenerateAuxPoW() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); auxpow.getCoinbaseBranch().setIndex(0x01); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("AuxPow is not a generate"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("AuxPow is not a generate", org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -116,16 +114,17 @@ public void shouldRejectNonGenerateAuxPoW() throws Exception { @Test public void shouldRejectOwnChainID() throws Exception { byte[] payload = Util.getBytes(getClass().getResourceAsStream("dogecoin_block371337.bin")); - AltcoinSerializer serializer = (AltcoinSerializer)params.getDefaultSerializer(); - final AltcoinBlock block = (AltcoinBlock)serializer.makeBlock(payload); + AltcoinSerializer serializer = (AltcoinSerializer) params.getDefaultSerializer(); + final AltcoinBlock block = (AltcoinBlock) serializer.makeBlock(payload); assertEquals(98, block.getChainID()); final AuxPoW auxpow = block.getAuxPoW(); assertNotNull(auxpow); - auxpow.setParentBlockHeader((AltcoinBlock)block.cloneAsHeader()); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW parent has our chain ID"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + auxpow.setParentBlockHeader((AltcoinBlock) block.cloneAsHeader()); + assertThrows("Aux POW parent has our chain ID", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -134,12 +133,12 @@ public void shouldRejectOwnChainID() throws Exception { @Test public void shouldRejectVeryLongMerkleBranch() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); auxpow.getChainMerkleBranch().setHashes(Arrays.asList(new Sha256Hash[32])); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW chain merkle branch too long"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW chain merkle branch too long", org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -152,12 +151,12 @@ public void shouldRejectVeryLongMerkleBranch() throws Exception { @Test public void shouldRejectIfCoinbaseTransactionNotInMerkleBranch() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); auxpow.getCoinbase().clearOutputs(); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW merkle root incorrect"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW merkle root incorrect", org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -167,17 +166,18 @@ public void shouldRejectIfCoinbaseTransactionNotInMerkleBranch() throws Exceptio @Test public void shouldRejectIfCoinbaseTransactionHasNoInputs() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. auxpow.getCoinbase().clearInputs(); updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Coinbase transaction has no inputs"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Coinbase transaction has no inputs", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -188,7 +188,7 @@ public void shouldRejectIfCoinbaseTransactionHasNoInputs() throws Exception { @Test public void shouldRejectIfMergedMineHeaderMissing() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -199,20 +199,21 @@ public void shouldRejectIfMergedMineHeaderMissing() throws Exception { in.setScriptBytes(paddedScriptBytes); updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW chain merkle root must start in the first 20 bytes of the parent coinbase"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW chain merkle root must start in the first 20 bytes of the parent coinbase", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** - * Catch the case that more than one merged mine header is present in the + * Catch the case that more than one merged mine header is present in the * coinbase transaction (this is considered an attempt to confuse the parser). */ @Test public void shouldRejectIfMergedMineHeaderDuplicated() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -224,12 +225,14 @@ public void shouldRejectIfMergedMineHeaderDuplicated() throws Exception { in.setScriptBytes(newBytes); updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Multiple merged mining headers in coinbase"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Multiple merged mining headers in coinbase", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } + /** * Catch the case that the chain merkle branch is missing from the coinbase * transaction. The chain merkle branch is used to prove that the block was @@ -239,7 +242,7 @@ public void shouldRejectIfMergedMineHeaderDuplicated() throws Exception { @Test public void shouldRejectIfCoinbaseMissingChainMerkleRoot() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -247,10 +250,11 @@ public void shouldRejectIfCoinbaseMissingChainMerkleRoot() throws Exception { in.getScriptBytes()[8] = 0; // Break the first byte of the chain merkle root updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW missing chain merkle root in parent coinbase"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW missing chain merkle root in parent coinbase", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -261,7 +265,7 @@ public void shouldRejectIfCoinbaseMissingChainMerkleRoot() throws Exception { @Test public void shouldRejectIfChainMerkleRootNotAfterHeader() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -277,10 +281,11 @@ public void shouldRejectIfChainMerkleRootNotAfterHeader() throws Exception { in.setScriptBytes(newBytes); updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Merged mining header is not just before chain merkle root"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Merged mining header is not just before chain merkle root", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -291,7 +296,7 @@ public void shouldRejectIfChainMerkleRootNotAfterHeader() throws Exception { @Test public void shouldRejectIfScriptBytesTooShort() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -300,10 +305,11 @@ public void shouldRejectIfScriptBytesTooShort() throws Exception { in.setScriptBytes(newBytes); updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW missing chain merkle tree size and nonce in parent coinbase"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW missing chain merkle tree size and nonce in parent coinbase", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -313,7 +319,7 @@ public void shouldRejectIfScriptBytesTooShort() throws Exception { @Test public void shouldRejectIfCoinbaseMerkleBranchSizeMismatch() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -321,10 +327,11 @@ public void shouldRejectIfCoinbaseMerkleBranchSizeMismatch() throws Exception { in.getScriptBytes()[40] = 3; // Break the merkle branch length updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW merkle branch size does not match parent coinbase"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW merkle branch size does not match parent coinbase", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -334,7 +341,7 @@ public void shouldRejectIfCoinbaseMerkleBranchSizeMismatch() throws Exception { @Test public void shouldRejectIfNonceIncorrect() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); // This will also break the difficulty check, but as that doesn't occur // until the end, we can get away with it. @@ -342,10 +349,11 @@ public void shouldRejectIfNonceIncorrect() throws Exception { in.getScriptBytes()[44] = (byte) 0xff; // Break the nonce value updateMerkleRootToMatchCoinbase(auxpow); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Aux POW wrong index"); - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x1b06f8f0), true); + assertThrows("Aux POW wrong index", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x1b06f8f0), true); + }); } /** @@ -355,13 +363,13 @@ public void shouldRejectIfNonceIncorrect() throws Exception { @Test public void shouldRejectHashAboveTarget() throws Exception { final byte[] auxpowAsBytes = getBytes(getClass().getResourceAsStream("auxpow_header.bin")); - final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, (ChildMessage) null, params.getDefaultSerializer()); + final AuxPoW auxpow = new AuxPoW(params, auxpowAsBytes, null, params.getDefaultSerializer()); - expectedEx.expect(org.bitcoinj.core.VerificationException.class); - expectedEx.expectMessage("Hash is higher than target: 000000000003178bb23160cdbc81af53f47cae9f479acf1e69849da42fd5bfca vs 0"); - - auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), - Utils.decodeCompactBits(0x00), true); + assertThrows("Hash is higher than target: 000000000003178bb23160cdbc81af53f47cae9f479acf1e69849da42fd5bfca vs 0", + org.bitcoinj.core.VerificationException.class, () -> { + auxpow.checkProofOfWork(Sha256Hash.wrap("0c836b86991631d34a8a68054e2f62db919b39d1ee43c27ab3344d6aa82fa609"), + Utils.decodeCompactBits(0x00), true); + }); } /** @@ -371,12 +379,12 @@ public void shouldRejectHashAboveTarget() throws Exception { private void updateMerkleRootToMatchCoinbase(final AuxPoW auxpow) { final Transaction coinbase = auxpow.getCoinbase(); - final Sha256Hash revisedCoinbaseHash = coinbase.getHash(); + final Sha256Hash revisedCoinbaseHash = coinbase.getTxId(); // The coinbase hash is the single leaf node in the merkle tree, // so to get the root we need to hash it with itself. // Note that bytes are reversed for hashing final Sha256Hash revisedMerkleRoot = Sha256Hash.wrapReversed( - Sha256Hash.hashTwice(revisedCoinbaseHash.getReversedBytes(), 0, 32, revisedCoinbaseHash.getReversedBytes(), 0, 32) + Sha256Hash.hashTwice(revisedCoinbaseHash.getReversedBytes(), 0, 32, revisedCoinbaseHash.getReversedBytes(), 0, 32) ); auxpow.getParentBlockHeader().setMerkleRoot(revisedMerkleRoot); auxpow.setCoinbaseBranch(new MerkleBranch(params, auxpow, diff --git a/core/src/test/java/org/bitcoinj/core/DogecoinBlockTest.java b/core/src/test/java/org/bitcoinj/core/DogecoinBlockTest.java index 156476861..d967c3fd7 100644 --- a/core/src/test/java/org/bitcoinj/core/DogecoinBlockTest.java +++ b/core/src/test/java/org/bitcoinj/core/DogecoinBlockTest.java @@ -1,28 +1,20 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.bitcoinj.core; +import org.junit.Before; +import org.junit.Test; import org.libdohj.core.AltcoinSerializer; -import java.io.IOException; -import java.math.BigInteger; import org.libdohj.params.DogecoinMainNetParams; + +import java.io.IOException; + import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -/** - * - * @author jrn - */ public class DogecoinBlockTest { - private final NetworkParameters params = DogecoinMainNetParams.get(); + private static final NetworkParameters params = DogecoinMainNetParams.get(); @Before public void setUp() throws Exception { @@ -59,7 +51,6 @@ public void shouldParseBlock1() throws IOException { /** * Test the first hardfork block. - * @throws IOException */ @Test public void shouldParseBlock250000() throws IOException { @@ -76,8 +67,6 @@ public void shouldParseBlock250000() throws IOException { /** * Confirm parsing of the first merged-mine block. - * - * @throws IOException */ @Test public void shouldParseBlock371337() throws IOException { @@ -125,8 +114,6 @@ public void shouldParseBlock371337() throws IOException { /** * Confirm parsing of block with a nonce value above Integer.MAX_VALUE. * See https://github.com/rnicoll/libdohj/pull/7 - * - * @throws IOException */ @Test public void shouldParseBlock748634() throws IOException { @@ -150,8 +137,6 @@ public void shouldParseBlock748634() throws IOException { /** * Confirm parsing of block with a nonce value above Integer.MAX_VALUE. * See https://github.com/rnicoll/libdohj/issues/5 - * - * @throws IOException */ @Test public void shouldParseBlock894863() throws IOException { diff --git a/core/src/test/java/org/bitcoinj/core/LitecoinBlockTest.java b/core/src/test/java/org/bitcoinj/core/LitecoinBlockTest.java index 0459c425f..145ff8820 100644 --- a/core/src/test/java/org/bitcoinj/core/LitecoinBlockTest.java +++ b/core/src/test/java/org/bitcoinj/core/LitecoinBlockTest.java @@ -1,26 +1,17 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.bitcoinj.core; -import java.io.IOException; - +import org.junit.Before; +import org.junit.Test; import org.libdohj.core.AltcoinSerializer; import org.libdohj.params.LitecoinMainNetParams; +import java.io.IOException; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -/** - * - * @author jrn - */ public class LitecoinBlockTest { - private NetworkParameters params = LitecoinMainNetParams.get(); + private static final NetworkParameters params = LitecoinMainNetParams.get(); @Before public void setUp() throws Exception { diff --git a/core/src/test/java/org/bitcoinj/core/MerkleBranchTest.java b/core/src/test/java/org/bitcoinj/core/MerkleBranchTest.java index 49b16d75e..206198a59 100644 --- a/core/src/test/java/org/bitcoinj/core/MerkleBranchTest.java +++ b/core/src/test/java/org/bitcoinj/core/MerkleBranchTest.java @@ -1,12 +1,10 @@ package org.bitcoinj.core; -import static org.bitcoinj.core.AuxPoWTest.params; import org.bitcoinj.params.TestNet3Params; import org.junit.Test; import static org.bitcoinj.core.Util.getBytes; - import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; diff --git a/core/src/test/java/org/bitcoinj/core/Util.java b/core/src/test/java/org/bitcoinj/core/Util.java index 62907d52c..1003ddefd 100644 --- a/core/src/test/java/org/bitcoinj/core/Util.java +++ b/core/src/test/java/org/bitcoinj/core/Util.java @@ -1,18 +1,9 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.bitcoinj.core; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -/** - * - * @author jrn - */ public class Util { public static byte[] getBytes(InputStream inputStream) throws IOException { diff --git a/core/src/test/java/org/libdohj/names/NameTransactionUtilsTest.java b/core/src/test/java/org/libdohj/names/NameTransactionUtilsTest.java index f9d22d2ac..064862908 100644 --- a/core/src/test/java/org/libdohj/names/NameTransactionUtilsTest.java +++ b/core/src/test/java/org/libdohj/names/NameTransactionUtilsTest.java @@ -15,6 +15,8 @@ */ package org.libdohj.names; +import org.junit.Before; +import org.junit.Test; import org.libdohj.params.AbstractNamecoinParams; import org.libdohj.params.NamecoinMainNetParams; @@ -24,8 +26,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import org.junit.Before; -import org.junit.Test; import java.io.IOException; diff --git a/core/src/test/java/org/libdohj/params/AbstractDogecoinParamsTest.java b/core/src/test/java/org/libdohj/params/AbstractDogecoinParamsTest.java index 444e259c8..9b570eaee 100644 --- a/core/src/test/java/org/libdohj/params/AbstractDogecoinParamsTest.java +++ b/core/src/test/java/org/libdohj/params/AbstractDogecoinParamsTest.java @@ -15,17 +15,16 @@ */ package org.libdohj.params; -import java.io.IOException; -import org.bitcoinj.core.AltcoinBlock; -import org.bitcoinj.core.Coin; -import org.bitcoinj.core.Context; -import org.bitcoinj.core.Sha256Hash; -import org.bitcoinj.core.Util; -import static org.junit.Assert.assertEquals; +import org.bitcoinj.core.*; import org.junit.Before; import org.junit.Test; import org.libdohj.core.AltcoinSerializer; +import java.io.IOException; + + +import static org.junit.Assert.assertEquals; + /** * * @author Ross Nicoll diff --git a/core/src/test/java/org/libdohj/params/AbstractLitecoinParamsTest.java b/core/src/test/java/org/libdohj/params/AbstractLitecoinParamsTest.java index 3f71928b0..e34b1cee4 100644 --- a/core/src/test/java/org/libdohj/params/AbstractLitecoinParamsTest.java +++ b/core/src/test/java/org/libdohj/params/AbstractLitecoinParamsTest.java @@ -17,10 +17,11 @@ import org.bitcoinj.core.Coin; import org.bitcoinj.core.Context; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; + /** * * @author Ross Nicoll diff --git a/core/src/test/java/org/libdohj/params/LitecoinTestNet3ParamsTest.java b/core/src/test/java/org/libdohj/params/LitecoinTestNet3ParamsTest.java index fefc877f1..d2c023f54 100644 --- a/core/src/test/java/org/libdohj/params/LitecoinTestNet3ParamsTest.java +++ b/core/src/test/java/org/libdohj/params/LitecoinTestNet3ParamsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 J. Ross Nicoll + * Copyright 2015, 2021 J. Ross Nicoll * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,11 @@ package org.libdohj.params; import org.bitcoinj.core.Context; -import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; + /** * * @author Ross Nicoll diff --git a/core/src/test/java/org/libdohj/script/NameScriptTest.java b/core/src/test/java/org/libdohj/script/NameScriptTest.java index f936bbb72..c14bf1583 100644 --- a/core/src/test/java/org/libdohj/script/NameScriptTest.java +++ b/core/src/test/java/org/libdohj/script/NameScriptTest.java @@ -25,17 +25,16 @@ import org.bitcoinj.script.Script; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; + +import java.io.IOException; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import org.junit.rules.ExpectedException; - -import java.io.IOException; /** - * * @author Jeremy Rand */ public class NameScriptTest { @@ -46,310 +45,302 @@ public void setUp() throws Exception { Context context = new Context(params); } - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test public void nameNewIsNameOp() throws IOException { final NameScript ns = getNameNewNameScript(); - + assertTrue(ns.isNameOp()); } - + @Test public void nameNewGetAddress() throws IOException { final NameScript ns = getNameNewNameScript(); - + assertEquals("MyVbKbD4MYNUMEpdNAm3Jd3nbr5t8djALC", ns.getAddress().getToAddress(params).toString()); } - + // TODO: getNameOp when it's implemented - + @Test public void nameNewIsAnyUpdate() throws IOException { final NameScript ns = getNameNewNameScript(); - + assertFalse(ns.isAnyUpdate()); } - + @Test public void nameNewGetOpName() throws IOException { final NameScript ns = getNameNewNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not an AnyUpdate op"); - ns.getOpName(); + + assertThrows("Not an AnyUpdate op", + org.bitcoinj.script.ScriptException.class, () -> ns.getOpName()); } - + @Test public void nameNewGetOpValue() throws IOException { final NameScript ns = getNameNewNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not an AnyUpdate op"); - ns.getOpValue(); - + + assertThrows("Not an AnyUpdate op", + org.bitcoinj.script.ScriptException.class, () -> ns.getOpValue()); + } - + // TODO: getOpRand, getOpHash, isNameScript when they're implemented - + @Test public void nameFirstUpdateIsNameOp() throws IOException { final NameScript ns = getNameFirstUpdateNameScript(); - + assertTrue(ns.isNameOp()); } - + @Test public void nameFirstUpdateGetAddress() throws IOException { final NameScript ns = getNameFirstUpdateNameScript(); - + assertEquals("NGcTVLgw6cgdavaE7C9QvWaY7gKiWbLrjP", ns.getAddress().getToAddress(params).toString()); } - + // TODO: getNameOp when it's implemented - + @Test public void nameFirstUpdateIsAnyUpdate() throws IOException { final NameScript ns = getNameFirstUpdateNameScript(); - + assertTrue(ns.isAnyUpdate()); } - + @Test public void nameFirstUpdateGetOpName() throws IOException { final NameScript ns = getNameFirstUpdateNameScript(); - + assertEquals("d/bitcoin", new String(ns.getOpName().data, "ISO-8859-1")); } - + @Test public void nameFirstUpdateGetOpValue() throws IOException { final NameScript ns = getNameFirstUpdateNameScript(); - + assertEquals("webpagedeveloper.me/namecoin", new String(ns.getOpValue().data, "ISO-8859-1")); } - + // TODO: getOpRand, getOpHash, isNameScript when they're implemented - + @Test public void nameUpdateIsNameOp() throws IOException { final NameScript ns = getNameUpdateNameScript(); - + assertTrue(ns.isNameOp()); } - + @Test public void nameUpdateGetAddress() throws IOException { final NameScript ns = getNameUpdateNameScript(); - + assertEquals("N9dLs1zHRfZr5cJNjSrvhWrrUcmNSthdmz", ns.getAddress().getToAddress(params).toString()); } - + // TODO: getNameOp when it's implemented - + @Test public void nameUpdateIsAnyUpdate() throws IOException { final NameScript ns = getNameUpdateNameScript(); - + assertTrue(ns.isAnyUpdate()); } - + @Test public void nameUpdateGetOpName() throws IOException { final NameScript ns = getNameUpdateNameScript(); - + assertEquals("d/bitcoin", new String(ns.getOpName().data, "ISO-8859-1")); } - + @Test public void nameUpdateGetOpValue() throws IOException { final NameScript ns = getNameUpdateNameScript(); - + assertEquals("{\"info\":{\"registrar\":\"http://register.dot-bit.org\"},\"email\": \"register@dot-bit.org\",\"ns\":[\"ns0.web-sweet-web.net\",\"ns1.web-sweet-web.net\"],\"map\":{\"\":{\"ns\":[\"ns0.web-sweet-web.net\",\"ns1.web-sweet-web.net\"]}}}", new String(ns.getOpValue().data, "ISO-8859-1")); } - + // TODO: getOpRand, getOpHash, isNameScript when they're implemented - + @Test public void currencyIsNameOp() throws IOException { final NameScript ns = getCurrencyNameScript(); - + assertFalse(ns.isNameOp()); } - + @Test public void currencyGetAddress() throws IOException { final NameScript ns = getCurrencyNameScript(); - + assertEquals("NCMmrGC7uaJ3uv8feLgBTtwGLQSWfmxMCk", ns.getAddress().getToAddress(params).toString()); } - + // TODO: getNameOp when it's implemented - + @Test public void currencyIsAnyUpdate() throws IOException { final NameScript ns = getCurrencyNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not a name op"); - ns.isAnyUpdate(); + + assertThrows("Not a name op", + org.bitcoinj.script.ScriptException.class, () -> ns.isAnyUpdate()); } - + @Test public void currencyGetOpName() throws IOException { final NameScript ns = getCurrencyNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not an AnyUpdate op"); - ns.getOpName(); + + assertThrows("Not an AnyUpdate op", + org.bitcoinj.script.ScriptException.class, () -> ns.getOpName()); } - + @Test public void currencyGetOpValue() throws IOException { final NameScript ns = getCurrencyNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not an AnyUpdate op"); - ns.getOpValue(); + + assertThrows("Not an AnyUpdate op", + org.bitcoinj.script.ScriptException.class, () -> ns.getOpValue()); } - + // TODO: getOpRand, getOpHash, isNameScript when they're implemented - + @Test public void returnIsNameOp() throws IOException { final NameScript ns = getReturnNameScript(); - + assertFalse(ns.isNameOp()); } - + @Test public void returnGetAddress() throws IOException { final NameScript ns = getReturnNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Cannot cast this script to an address"); - ns.getAddress().getToAddress(params).toString(); + + assertThrows("Cannot cast this script to an address", + org.bitcoinj.script.ScriptException.class, + () -> ns.getAddress().getToAddress(params).toString()); } - + // TODO: getNameOp when it's implemented - + @Test public void returnIsAnyUpdate() throws IOException { final NameScript ns = getReturnNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not a name op"); - ns.isAnyUpdate(); + + assertThrows("Not a name op", + org.bitcoinj.script.ScriptException.class, + () -> ns.isAnyUpdate()); } - + @Test public void returnGetOpName() throws IOException { final NameScript ns = getReturnNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not an AnyUpdate op"); - ns.getOpName(); + + assertThrows("Not an AnyUpdate op", + org.bitcoinj.script.ScriptException.class, + () -> ns.getOpName()); } - + @Test public void returnGetOpValue() throws IOException { final NameScript ns = getReturnNameScript(); - - expectedEx.expect(org.bitcoinj.script.ScriptException.class); - expectedEx.expectMessage("Not an AnyUpdate op"); - ns.getOpValue(); + + assertThrows("Not an AnyUpdate op", + org.bitcoinj.script.ScriptException.class, + () -> ns.getOpValue()); } - + // TODO: getOpRand, getOpHash, isNameScript when they're implemented - + NameScript getNameNewNameScript() throws IOException { byte[] payload; final Transaction tx; final TransactionOutput out; final Script outScript; final NameScript ns; - + // https://namecoin.webbtc.com/tx/6047ce28a076118403aa960909c9c4d0056f97ee0da4d37d109515f8367e2ccb - + payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_new_d_bitcoin.bin")); tx = new Transaction(params, payload); out = tx.getOutputs().get(1); outScript = out.getScriptPubKey(); ns = new NameScript(outScript); - + return ns; } - + NameScript getNameFirstUpdateNameScript() throws IOException { byte[] payload; final Transaction tx; final TransactionOutput out; final Script outScript; final NameScript ns; - + // https://namecoin.webbtc.com/tx/ab1207bd605af57ed0b5325ac94d19578cff3bce668ebe8dda2f42a00b001f5d - + payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_firstupdate_d_bitcoin.bin")); tx = new Transaction(params, payload); out = tx.getOutputs().get(1); outScript = out.getScriptPubKey(); ns = new NameScript(outScript); - + return ns; } - + NameScript getNameUpdateNameScript() throws IOException { byte[] payload; final Transaction tx; final TransactionOutput out; final Script outScript; final NameScript ns; - + // https://namecoin.webbtc.com/tx/3376c5e0e5b69d0a104863de8432d7c13f891065e7628a72487b770c6418d397 - + payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_update_d_bitcoin.bin")); tx = new Transaction(params, payload); out = tx.getOutputs().get(1); outScript = out.getScriptPubKey(); ns = new NameScript(outScript); - + return ns; } - + NameScript getCurrencyNameScript() throws IOException { byte[] payload; final Transaction tx; final TransactionOutput out; final Script outScript; final NameScript ns; - + // https://namecoin.webbtc.com/tx/4ea5d679d63ef46449a44ca056584a986412676641bdaf13d44a7c7c2e32cca1 - + payload = Util.getBytes(getClass().getResourceAsStream("namecoin_p2pkh.bin")); tx = new Transaction(params, payload); out = tx.getOutputs().get(0); outScript = out.getScriptPubKey(); ns = new NameScript(outScript); - + return ns; } - + NameScript getReturnNameScript() throws IOException { byte[] payload; final Transaction tx; final TransactionOutput out; final Script outScript; final NameScript ns; - + // https://namecoin.webbtc.com/tx/ab1207bd605af57ed0b5325ac94d19578cff3bce668ebe8dda2f42a00b001f5d - + payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_firstupdate_d_bitcoin.bin")); tx = new Transaction(params, payload); out = tx.getOutputs().get(2); outScript = out.getScriptPubKey(); ns = new NameScript(outScript); - + return ns; } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d9ca1649..442d9132e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/namecoin/build.gradle b/namecoin/build.gradle index 9cfa1d431..f1057562c 100644 --- a/namecoin/build.gradle +++ b/namecoin/build.gradle @@ -1,12 +1,16 @@ -apply plugin: 'java' +apply plugin: 'java-library' dependencies { implementation project(':core') - implementation 'com.google.guava:guava:24.0-android' + implementation 'org.bitcoinj:bitcoinj-core:0.15.10' + implementation 'com.google.guava:guava:30.0-android' implementation 'net.sf.jopt-simple:jopt-simple:4.3' - implementation 'org.slf4j:slf4j-jdk14:1.7.25' + implementation 'org.slf4j:slf4j-api:1.7.30' implementation 'org.fusesource.leveldbjni:leveldbjni-all:1.8' implementation 'com.fasterxml.jackson.core:jackson-databind:2.5.2' } sourceCompatibility = 1.8 + +test { +} \ No newline at end of file