From b08cfe3f54711b605c939dbc3382225057bcfb9e Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Wed, 18 Apr 2018 14:28:04 +0200 Subject: [PATCH] Remove TestNet2. --- .../org/bitcoinj/core/NetworkParameters.java | 6 -- .../java/org/bitcoinj/params/Networks.java | 2 +- .../org/bitcoinj/params/RegTestParams.java | 25 +++++- .../org/bitcoinj/params/TestNet2Params.java | 73 ------------------ .../org/bitcoinj/params/TestNet3Params.java | 11 ++- .../org/bitcoinj/core/BlockChainTest.java | 28 +++---- .../java/org/bitcoinj/core/BlockTest.java | 62 ++++++--------- .../store/WalletProtobufSerializerTest.java | 5 +- .../org/bitcoinj/core/block_testnet700000.dat | Bin 0 -> 1761 bytes 9 files changed, 74 insertions(+), 138 deletions(-) delete mode 100644 core/src/main/java/org/bitcoinj/params/TestNet2Params.java create mode 100644 core/src/test/resources/org/bitcoinj/core/block_testnet700000.dat diff --git a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java index 22f74aa1..deee6fd2 100644 --- a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java +++ b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java @@ -162,12 +162,6 @@ public abstract class NetworkParameters { return TestNet3Params.get(); } - /** Alias for TestNet2Params.get(), use that instead. */ - @Deprecated - public static NetworkParameters testNet2() { - return TestNet2Params.get(); - } - /** Alias for TestNet3Params.get(), use that instead. */ @Deprecated public static NetworkParameters testNet3() { diff --git a/core/src/main/java/org/bitcoinj/params/Networks.java b/core/src/main/java/org/bitcoinj/params/Networks.java index 6c2dc007..011be87f 100644 --- a/core/src/main/java/org/bitcoinj/params/Networks.java +++ b/core/src/main/java/org/bitcoinj/params/Networks.java @@ -25,7 +25,7 @@ import java.util.Set; /** * Utility class that holds all the registered NetworkParameters types used for address auto discovery. - * By default only MainNetParams and TestNet3Params are used. If you want to use TestNet2, RegTestParams or + * By default only MainNetParams and TestNet3Params are used. If you want to use RegTestParams or * UnitTestParams use the register and unregister the TestNet3Params as they don't have their own address * version/type code. */ diff --git a/core/src/main/java/org/bitcoinj/params/RegTestParams.java b/core/src/main/java/org/bitcoinj/params/RegTestParams.java index 1bf6cbf1..70eb7e9e 100644 --- a/core/src/main/java/org/bitcoinj/params/RegTestParams.java +++ b/core/src/main/java/org/bitcoinj/params/RegTestParams.java @@ -1,5 +1,6 @@ /* * Copyright 2013 Google Inc. + * Copyright 2018 Andreas Schildbach * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +26,31 @@ import static com.google.common.base.Preconditions.checkState; /** * Network parameters for the regression test mode of bitcoind in which all blocks are trivially solvable. */ -public class RegTestParams extends TestNet2Params { +public class RegTestParams extends AbstractBitcoinNetParams { private static final BigInteger MAX_TARGET = new BigInteger("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16); public RegTestParams() { super(); - // Difficulty adjustments are disabled for regtest. - // By setting the block interval for difficulty adjustments to Integer.MAX_VALUE we make sure difficulty never changes. + packetMagic = 0xfabfb5daL; + addressHeader = 111; + p2shHeader = 196; + targetTimespan = TARGET_TIMESPAN; + dumpedPrivateKeyHeader = 239; + segwitAddressHrp = "tb"; + genesisBlock.setTime(1296688602L); + genesisBlock.setDifficultyTarget(0x1d07fff8L); + genesisBlock.setNonce(384568319); + spendableCoinbaseDepth = 100; + String genesisHash = genesisBlock.getHashAsString(); + checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); + dnsSeeds = null; + addrSeeds = null; + bip32HeaderPub = 0x043587CF; + bip32HeaderPriv = 0x04358394; + + // Difficulty adjustments are disabled for regtest. + // By setting the block interval for difficulty adjustments to Integer.MAX_VALUE we make sure difficulty never + // changes. interval = Integer.MAX_VALUE; maxTarget = MAX_TARGET; subsidyDecreaseBlockCount = 150; diff --git a/core/src/main/java/org/bitcoinj/params/TestNet2Params.java b/core/src/main/java/org/bitcoinj/params/TestNet2Params.java deleted file mode 100644 index cf1ee440..00000000 --- a/core/src/main/java/org/bitcoinj/params/TestNet2Params.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.bitcoinj.params; - -import org.bitcoinj.core.Utils; - -import static com.google.common.base.Preconditions.checkState; - -/** - * Parameters for the old version 2 testnet. This is not useful to you - it exists only because some unit tests are - * based on it. - */ -public class TestNet2Params extends AbstractBitcoinNetParams { - public static final int TESTNET_MAJORITY_WINDOW = 100; - public static final int TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED = 75; - public static final int TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE = 51; - - public TestNet2Params() { - super(); - id = ID_TESTNET; - packetMagic = 0xfabfb5daL; - port = 18333; - addressHeader = 111; - p2shHeader = 196; - interval = INTERVAL; - targetTimespan = TARGET_TIMESPAN; - maxTarget = Utils.decodeCompactBits(0x1d0fffffL); - dumpedPrivateKeyHeader = 239; - segwitAddressHrp = "tb"; - genesisBlock.setTime(1296688602L); - genesisBlock.setDifficultyTarget(0x1d07fff8L); - genesisBlock.setNonce(384568319); - spendableCoinbaseDepth = 100; - subsidyDecreaseBlockCount = 210000; - String genesisHash = genesisBlock.getHashAsString(); - checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); - dnsSeeds = null; - addrSeeds = null; - bip32HeaderPub = 0x043587CF; - bip32HeaderPriv = 0x04358394; - - majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; - majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; - majorityWindow = TESTNET_MAJORITY_WINDOW; - } - - private static TestNet2Params instance; - public static synchronized TestNet2Params get() { - if (instance == null) { - instance = new TestNet2Params(); - } - return instance; - } - - @Override - public String getPaymentProtocolId() { - return null; - } -} diff --git a/core/src/main/java/org/bitcoinj/params/TestNet3Params.java b/core/src/main/java/org/bitcoinj/params/TestNet3Params.java index 051f6002..74e5e489 100644 --- a/core/src/main/java/org/bitcoinj/params/TestNet3Params.java +++ b/core/src/main/java/org/bitcoinj/params/TestNet3Params.java @@ -35,10 +35,13 @@ import static com.google.common.base.Preconditions.checkState; * and testing of applications and new Bitcoin versions. */ public class TestNet3Params extends AbstractBitcoinNetParams { + public static final int TESTNET_MAJORITY_WINDOW = 100; + public static final int TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED = 75; + public static final int TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE = 51; + public TestNet3Params() { super(); id = ID_TESTNET; - // Genesis hash is 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943 packetMagic = 0x0b110907; interval = INTERVAL; targetTimespan = TARGET_TIMESPAN; @@ -68,9 +71,9 @@ public class TestNet3Params extends AbstractBitcoinNetParams { bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; - majorityEnforceBlockUpgrade = TestNet2Params.TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; - majorityRejectBlockOutdated = TestNet2Params.TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; - majorityWindow = TestNet2Params.TESTNET_MAJORITY_WINDOW; + majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; + majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; + majorityWindow = TESTNET_MAJORITY_WINDOW; } private static TestNet3Params instance; diff --git a/core/src/test/java/org/bitcoinj/core/BlockChainTest.java b/core/src/test/java/org/bitcoinj/core/BlockChainTest.java index 1abd1e93..9a9bb9ec 100644 --- a/core/src/test/java/org/bitcoinj/core/BlockChainTest.java +++ b/core/src/test/java/org/bitcoinj/core/BlockChainTest.java @@ -18,7 +18,7 @@ package org.bitcoinj.core; import org.bitcoinj.params.MainNetParams; -import org.bitcoinj.params.TestNet2Params; +import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.store.BlockStore; import org.bitcoinj.store.MemoryBlockStore; @@ -59,12 +59,12 @@ public class BlockChainTest { private final StoredBlock[] block = new StoredBlock[1]; private Transaction coinbaseTransaction; - private static class TweakableTestNet2Params extends TestNet2Params { + private static class TweakableTestNet3Params extends TestNet3Params { public void setMaxTarget(BigInteger limit) { maxTarget = limit; } } - private static final TweakableTestNet2Params TESTNET = new TweakableTestNet2Params(); + private static final TweakableTestNet3Params TESTNET = new TweakableTestNet3Params(); private static final NetworkParameters UNITTEST = UnitTestParams.get(); private static final NetworkParameters MAINNET = MainNetParams.get(); @@ -396,22 +396,24 @@ public class BlockChainTest { // Some blocks from the test net. private static Block getBlock2() throws Exception { Block b2 = new Block(TESTNET, Block.BLOCK_VERSION_GENESIS); - b2.setMerkleRoot(Sha256Hash.wrap("addc858a17e21e68350f968ccd384d6439b64aafa6c193c8b9dd66320470838b")); - b2.setNonce(2642058077L); - b2.setTime(1296734343L); - b2.setPrevBlockHash(Sha256Hash.wrap("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604")); - assertEquals("000000037b21cac5d30fc6fda2581cf7b2612908aed2abbcc429c45b0557a15f", b2.getHashAsString()); + b2.setMerkleRoot(Sha256Hash.wrap("20222eb90f5895556926c112bb5aa0df4ab5abc3107e21a6950aec3b2e3541e2")); + b2.setNonce(875942400L); + b2.setTime(1296688946L); + b2.setDifficultyTarget(0x1d00ffff); + b2.setPrevBlockHash(Sha256Hash.wrap("00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206")); + assertEquals("000000006c02c8ea6e4ff69651f7fcde348fb9d557a06e6957b65552002a7820", b2.getHashAsString()); b2.verifyHeader(); return b2; } private static Block getBlock1() throws Exception { Block b1 = new Block(TESTNET, Block.BLOCK_VERSION_GENESIS); - b1.setMerkleRoot(Sha256Hash.wrap("0e8e58ecdacaa7b3c6304a35ae4ffff964816d2b80b62b58558866ce4e648c10")); - b1.setNonce(236038445); - b1.setTime(1296734340); - b1.setPrevBlockHash(Sha256Hash.wrap("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); - assertEquals("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604", b1.getHashAsString()); + b1.setMerkleRoot(Sha256Hash.wrap("f0315ffc38709d70ad5647e22048358dd3745f3ce3874223c80a7c92fab0c8ba")); + b1.setNonce(1924588547); + b1.setTime(1296688928); + b1.setDifficultyTarget(0x1d00ffff); + b1.setPrevBlockHash(Sha256Hash.wrap("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")); + assertEquals("00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206", b1.getHashAsString()); b1.verifyHeader(); return b1; } diff --git a/core/src/test/java/org/bitcoinj/core/BlockTest.java b/core/src/test/java/org/bitcoinj/core/BlockTest.java index ab3a09b0..630ddcf0 100644 --- a/core/src/test/java/org/bitcoinj/core/BlockTest.java +++ b/core/src/test/java/org/bitcoinj/core/BlockTest.java @@ -21,7 +21,6 @@ import com.google.common.io.ByteStreams; import org.bitcoinj.core.AbstractBlockChain.NewBlockType; import org.bitcoinj.params.MainNetParams; -import org.bitcoinj.params.TestNet2Params; import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.script.Script; @@ -32,61 +31,54 @@ import org.bitcoinj.wallet.Wallet.BalanceType; import org.junit.Before; import org.junit.Test; -import java.io.InputStreamReader; import java.math.BigInteger; import java.util.Arrays; import java.util.EnumSet; import java.util.List; -import static org.bitcoinj.core.Utils.HEX; import static org.junit.Assert.*; public class BlockTest { - private static final NetworkParameters TESTNET2 = TestNet2Params.get(); - private static final NetworkParameters TESTNET3 = TestNet3Params.get(); + private static final NetworkParameters TESTNET = TestNet3Params.get(); private static final NetworkParameters UNITTEST = UnitTestParams.get(); private static final NetworkParameters MAINNET = MainNetParams.get(); - public static final byte[] blockBytes; - - static { - // Block 00000000a6e5eb79dcec11897af55e90cd571a4335383a3ccfbc12ec81085935 - // One with lots of transactions in, so a good test of the merkle tree hashing. - blockBytes = HEX.decode("0100000040f11b68435988807d64dff20261f7d9827825fbb37542601fb94d45000000000f28f7c69e2669981f92ff081c129e196200c60f4fad7911d93a682de0b49ea2ecd9d24c1844011d00d361050c01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07041844011d0142ffffffff0100f2052a01000000434104a313febd5f91b6a13bd9c5317030518fee96d1319a0eb10076917294933d09c17dc1588a06953a264738f2acea0c66b99e796caa4f28158e0dd5f6fed69a185bac000000000100000001aa18a952c3f73e5d7440bc570b2aa78f72059887b25b6a1790514b7feedec090000000008b483045022100a970ee6e96fa8bea1cf76d3bda3fb70441a6ec50014d4ea3adcdeae9fbfb5129022025ce9e090366dd6175071a0a5b4a4727571b9bd7bdd5a74d3d3bad7f63eb5dd4014104ac44bdf511477465cb70fef1d06b9241e74d26047ccbdfa641ec9a0115ad35594cbb58a61a6fd56893a405bcffbf6555995ddedc7e6cd4e5ceb83a37e1cf8f98ffffffff02004d92d86a0000001976a914b8083945473bc8289efb681f94de7b07a5b851ad88ac00743ba40b0000001976a914ef01911c9efec6799d1ee5f7c6fb072d9669da8088ac000000000100000001438bd97cb2172e0dd6f341e455e00b7d089747bd4e7f54bd802afe6a6d006c7c000000008a47304402207db94026c96572519101a08e2c864bbe51c987eda6266079a35286df68f123ca02202d7d24c616776a70cce6cb2f97a424e47c30d466e96b750ca03564810249073c014104880286646dab4c894a5ff1bf62bd80047a50b86446b326f2155de94a54d01f9058d4cbc7452563a7c18b2bfb353262fc5adac6307a9446e8c4669daa58e97071ffffffff0200743ba40b0000001976a914fce443c743b456606d1e70ff0d98c4609addc10688ac00ba1dd2050000001976a91411e3e67c08e5d791c97b3d49a8d52025d3f78d3a88ac000000000100000001dc4a6300b6eca8d7ab8e119e9fc4b18890c0e26ec950e681b8d5e46c214aee24010000008b48304502202bcf8632a11192f6b4998343c13589771e6715a080236087dcb1771cbab01809022100edcc38488dd70cd38c058994f143ca5d259071b8fe54c66bf67e55d4468dcacb01410475106e33e14e9cf35bc359dd4120b580ecf5412bb8803f2a927aecd4218d1346e242c7056dca2e4c114fcf2f60799bc5e79107bd1a8b8d5135c92f02bdb59834ffffffff0200f2052a010000001976a9146c9715e09fb00ba84af1ff916ff409b4a5dc9ae288ac00c817a8040000001976a914f7be161206700eb7be1bca5768232c61e4694f4788ac000000000100000001b6cc12ff76247895cb7a604d888012136f06bba64654262044ecb93ff7762c2f000000008b48304502206d795045622c7cdfb4a211c5b41d477920437c21e69214ab4a14f10fe0306b78022100840e55114d6922f3c5e44c7cdcf85dc800d1caef64e7846998423e4ba86714e6014104f88ae9067bc05136cb53a8c18f8549f544ff55ab87ada8f3ba7e2aea773ec73585b61f18ade1c0ddd6c447788578be5fb785c245a64d29b7ff5d28b85cbec58cffffffff0200743ba40b0000001976a914c8081083a8b741da2da260bc0656b88c7bfa6fbf88ac00743ba40b0000001976a914fce443c743b456606d1e70ff0d98c4609addc10688ac0000000001000000019a8d70c7a27560b28dfe778db9ce7f2ff235faf98d5123c07991682be90a4c16000000008b483045022100a118c34f63854ee03d15cca2918d592c295035c42e03be7b0c7e86e66d40ea790220558336d2583a1da00ed5bcad2de5d3b9d485431f702bf2f002267b35ab0b41a0014104f88ae9067bc05136cb53a8c18f8549f544ff55ab87ada8f3ba7e2aea773ec73585b61f18ade1c0ddd6c447788578be5fb785c245a64d29b7ff5d28b85cbec58cffffffff0200743ba40b0000001976a914a440ef00c2e1d39be93607da66568caa26e0501888ac00743ba40b0000001976a914e1d3e65f78f962c4e9dfd04db2119aeefa4e111088ac000000000100000001883acd4bff920f19c4e570e6b3e2d7503d1072d3ca098a124e23534ecdc879d5000000008a473044022040677305de69fd8c18e2c54d5b3c67c5c05735cf6b73d420ccd306762c4bfda2022032cd32ac15ac1820265ffce82654a6008cda22a79fb619ebb65e0af806e14f9b0141044423ef78a2859eb57c4a59dc0878141cf5a4b1fdef71d649d3fb5cf8ea6b1114f4086e5d684a0999d4435db99217a994cc3cf7ad435c8f4e44613d9d160916c4ffffffff0100743ba40b0000001976a914fce443c743b456606d1e70ff0d98c4609addc10688ac000000000100000001ceb27fb142ce3bf9a1f263653dc3971332c71dd10e0e83d647037f608c459f12000000008b4830450220389218287e87d0d7b7113eb20cc1cbf1a00d7acdca32bba7f184cd066db74d6a022100b0998058e5a242699a48f931004cf5550f4e8802b866ce1baf1a0b2616861f27014104255a048d416984101c17514a89289a7d5d3dc8c562850c7a3599f0c7c39bcf9c3a43df75e1e614e51d70c5f85212c99298a21f087be93ecba7ef3900d02c0e8bffffffff0200743ba40b0000001976a914211fd13b614521ed566ddd42738381e42c3c2b2088ac00d956345f0000001976a914d3cc345ba8bdf51d7097955f0f259731f4c34f4388ac000000000100000001703701493f08e82bf6d8cb7c517070eee9f62d14904e14636a7b4af4f34180c7010000008a4730440220061a61eae90ffcf13c10c88a88c085b02954f488823c2f5c81e83a5a833e9f3b02204a61498a9668b2793e77fe3b68585f2daff4dd5daf6097a82615035325ada4730141040db6308d6170333e2c50dee4c9f18f0ab84a7a5c4c88a6836a91f39cb8f4712e08bd72979c542d4b3b60e8dc2021c1b3cc45ffaa83f36a9dec3c4473ea2aa2f3ffffffff0200f2052a010000001976a9143e7e087b9b09149e0266b7a416da2709b4ccf58788ac00d6117e030000001976a914777af71a3b2a48e48f2e467f65028d85c1b5eb5288ac0000000001000000014bdc82abc7db9c06613a712e488685c6feb4522d25017b856222171c17d144e0000000008b4830450221009eb7edcbf8d6be63529264b07bb9f40cf1a0ca779235999e40f5311d70706f1102207f65c5f66982519e6d82e13ca3e61f4f071c73da6c5830b3c4461252012b474e0141045af9665878e6696fd069669951acc54a87c5e3b256a9e20cd8858e0dc5a8c53624e0c979096c00af8a8c60136eef9ffa3d511309417b8315b7f9e3e41e805e8fffffffff0100743ba40b0000001976a914e1d3e65f78f962c4e9dfd04db2119aeefa4e111088ac000000000100000001a854b2b84a76e43de59db647121cdfe481bd8ae9623a345c2188369775b533f7010000008c493046022100c4db6ecf679264c9b525628ec5a983710ff45a1d2d4aa0b54ee218ca9a1ad4df022100dc2e0077cfdd3cbeb28f7463632902ad5306f6d5c77c8149e5b9249bfea8060e014104f9a476b612bb9788c64b9b1e4c9d2deaae1ef0baf6eb593a95d00e2ef8a2beb897ea1fb7c3832e842dd6307fd162816c19c8f458fd8dae331dbc9062fb02e5d8ffffffff0200651b90530000001976a914d5c7c9aec292a807005f013c4d2122f7126e257788ac00743ba40b0000001976a914211fd13b614521ed566ddd42738381e42c3c2b2088ac0000000001000000012908482e9f7d31e9dd392bb6e788a329458a3bc95230b468e4b8c578d27a63b3000000008a4730440220549a7b422fc2020671acabfb937349bd87d985b2e4b9698e4ccacc985f61aee102204dc272322079e9114746db2f8d035d82b64523a69cd7be674173e063090cc8ac014104011a6c220a5549ff112c92c6c38dec93f66ef1f0a21d1409b92f0ccf0fb159aa8173a5b2413a45140fc02b45d63775bae03691d9dc87fd7a10d709a04922900cffffffff0200743ba40b0000001976a914211fd13b614521ed566ddd42738381e42c3c2b2088ac00f1dfeb470000001976a9140adcb4e90cc87f53d7618294222a8a4e193ae9f088ac00000000"); - } + private byte[] block700000Bytes; + private Block block700000; @Before public void setUp() throws Exception { - Context context = new Context(TESTNET2); + new Context(TESTNET); + // One with some of transactions in, so a good test of the merkle tree hashing. + block700000Bytes = ByteStreams.toByteArray(BlockTest.class.getResourceAsStream("block_testnet700000.dat")); + block700000 = TESTNET.getDefaultSerializer().makeBlock(block700000Bytes); + assertEquals("000000000000406178b12a4dea3b27e13b3c4fe4510994fd667d7c1e6a3f4dc1", block700000.getHashAsString()); } @Test public void testWork() throws Exception { - BigInteger work = TESTNET2.getGenesisBlock().getWork(); + BigInteger work = TESTNET.getGenesisBlock().getWork(); + double log2Work = Math.log(work.longValue()) / Math.log(2); // This number is printed by Bitcoin Core at startup as the calculated value of chainWork on testnet: - // - // SetBestChain: new best=00000007199508e34a9f height=0 work=536879104 - assertEquals(BigInteger.valueOf(536879104L), work); + // UpdateTip: new best=000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943 height=0 version=0x00000001 log2_work=32.000022 tx=1 date='2011-02-02 23:16:42' ... + assertEquals(32.000022, log2Work, 0.0000001); } @Test public void testBlockVerification() throws Exception { - Block block = TESTNET2.getDefaultSerializer().makeBlock(blockBytes); - block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); - assertEquals("00000000a6e5eb79dcec11897af55e90cd571a4335383a3ccfbc12ec81085935", block.getHashAsString()); + block700000.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); } @SuppressWarnings("deprecation") @Test public void testDate() throws Exception { - Block block = TESTNET2.getDefaultSerializer().makeBlock(blockBytes); - assertEquals("4 Nov 2010 16:06:04 GMT", block.getTime().toGMTString()); + assertEquals("2016-02-13T22:59:39Z", Utils.dateTimeFormat(block700000.getTime())); } @Test public void testProofOfWork() throws Exception { // This params accepts any difficulty target. - Block block = UNITTEST.getDefaultSerializer().makeBlock(blockBytes); + Block block = UNITTEST.getDefaultSerializer().makeBlock(block700000Bytes); block.setNonce(12346); try { block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); @@ -110,19 +102,17 @@ public class BlockTest { // Should find an acceptable nonce. block.solve(); block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); - assertEquals(block.getNonce(), 2); } @Test public void testBadTransactions() throws Exception { - Block block = TESTNET2.getDefaultSerializer().makeBlock(blockBytes); // Re-arrange so the coinbase transaction is not first. - Transaction tx1 = block.transactions.get(0); - Transaction tx2 = block.transactions.get(1); - block.transactions.set(0, tx2); - block.transactions.set(1, tx1); + Transaction tx1 = block700000.transactions.get(0); + Transaction tx2 = block700000.transactions.get(1); + block700000.transactions.set(0, tx2); + block700000.transactions.set(1, tx1); try { - block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); + block700000.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); fail(); } catch (VerificationException e) { // We should get here. @@ -131,9 +121,8 @@ public class BlockTest { @Test public void testHeaderParse() throws Exception { - Block block = TESTNET2.getDefaultSerializer().makeBlock(blockBytes); - Block header = block.cloneAsHeader(); - Block reparsed = TESTNET2.getDefaultSerializer().makeBlock(header.bitcoinSerialize()); + Block header = block700000.cloneAsHeader(); + Block reparsed = TESTNET.getDefaultSerializer().makeBlock(header.bitcoinSerialize()); assertEquals(reparsed, header); } @@ -143,8 +132,7 @@ public class BlockTest { // proves that transaction serialization works, along with all its subobjects like scripts and in/outpoints. // // NB: This tests the bitcoin serialization protocol. - Block block = TESTNET2.getDefaultSerializer().makeBlock(blockBytes); - assertTrue(Arrays.equals(blockBytes, block.bitcoinSerialize())); + assertTrue(Arrays.equals(block700000Bytes, block700000.bitcoinSerialize())); } @Test @@ -185,7 +173,7 @@ public class BlockTest { // contains a coinbase transaction whose height is two bytes, which is // shorter than we see in most other cases. - Block block = TESTNET3.getDefaultSerializer().makeBlock( + Block block = TESTNET.getDefaultSerializer().makeBlock( ByteStreams.toByteArray(getClass().getResourceAsStream("block_testnet21066.dat"))); // Check block. @@ -197,7 +185,7 @@ public class BlockTest { // fit in two bytes. This test primarily ensures script encoding checks // are applied correctly. - block = TESTNET3.getDefaultSerializer().makeBlock( + block = TESTNET.getDefaultSerializer().makeBlock( ByteStreams.toByteArray(getClass().getResourceAsStream("block_testnet32768.dat"))); // Check block. diff --git a/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java b/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java index deba7215..d25f0745 100644 --- a/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java +++ b/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java @@ -44,6 +44,8 @@ import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.Threading; import org.bitcoinj.wallet.DeterministicKeyChain; import org.bitcoinj.wallet.KeyChain; + +import com.google.common.io.ByteStreams; import com.google.protobuf.ByteString; import org.bitcoinj.wallet.MarriedKeyChain; @@ -212,7 +214,8 @@ public class WalletProtobufSerializerTest { assertTrue(lastSeenBlockHash.isEmpty()); // Create a block. - Block block = UNITTEST.getDefaultSerializer().makeBlock(BlockTest.blockBytes); + Block block = UNITTEST.getDefaultSerializer() + .makeBlock(ByteStreams.toByteArray(BlockTest.class.getResourceAsStream("block_testnet700000.dat"))); Sha256Hash blockHash = block.getHash(); wallet.setLastBlockSeenHash(blockHash); wallet.setLastBlockSeenHeight(1); diff --git a/core/src/test/resources/org/bitcoinj/core/block_testnet700000.dat b/core/src/test/resources/org/bitcoinj/core/block_testnet700000.dat new file mode 100644 index 0000000000000000000000000000000000000000..e1a248d2d9743d21004a5f7355e5cc25ae9f2c1f GIT binary patch literal 1761 zcmZQzU@%y4rl4lcofdC<^Yi9ryRIxd<;Qr+>ZPD-g&hMJJYTlFB&XPg+0#(l-cw-1 z&##?FdpQr>i&Qx2GK8eCG8SW=p+4>Eye`u2w^AckbwN)b)P=`*7Xf|SbxbCox7C|{lJ zKBu5#%`a6okOHuZ*IOftlO?`B=rCk;oDjRkxz?=jV#k`w^N+{$W+=6alwY&rh~1++X8@Mnjm@7Ch)>?U~LitI;uJ~>nwz>Nh zTAg$6Z}oeN|8yS@ad$Gr<1}uU+L%eFi*U>fR96pTVq<;eL>k>+~*zV*AVHX zEm?QMRFmF$WXHG%awcYfV=4Q!cD;JX`$@?wt^JyIW`V*I8cYi`L;dp~+ijeA$JKvv zjP0I{v1fl@ne+Hp`3I{P>lQGiF)5_pk3zBn?g|aY|=pRqn9ppXlrRX&vOSv^QXP zLdTkrbzI&;2}~)j7$ZLAYyyu-Ju0`Ag0q|8+x>!QP5f zH-3J4{qHx|dyn|Lf{uQ7UmtwSGx6T31*^q>z4z_~`tMpjI8F6@4C_K+kIw5zVvg2aE~Cl*5#la*Q@<>y3w@<=Y;e%6eZi+ zZcJZi-gLiLi2484@E2T_Vx3F~H(v^VF|oB!}KVBH^qVvJL7=T-S6pBH@2E2sVWer*2_`@ZSwQtl;Yq%8oS+hT@<|1IL=2@q^@=v)p0o zB>~Niwklag5ObT*c$xD}AIa9tXd#S4M z+`9(4tNk{22C(_6o>|PDc#m}{FaX@lrnz6(@~C2;safyJv)yy6=ayfbClLFoEL`NG zfAE=A0o?k@2ajFL$qEoX>$&lJRBGmly3$*EpTrs#8FHyH&jAI%+=Z^?J1)9$HvYSL zNJTwT^sY_dmZlANzW7I6Jo46Z@p(`}gE*Pvsau=(otl2Wf6Mna@$J9JaP*KclV7lQ zbz6u1p---*ObTMUy9H7|PI8KS;p}`lwpH0i-tItRw}OJn;=3R9K03BiDb837q!Dp8 z+wWziZddDpOa8XET-F;ua45Ut)v*Ry#gZFYjuX4y3%{P|%otf#W6$b3DXe3Sf*&X{ RAhC))-Wh(1!d2jocL3(b_LKks literal 0 HcmV?d00001