/** * Constructs a peer address from the given IP address. Port and version number * are default for Bitcoin mainnet. */ public PeerAddress(InetAddress addr) { this(addr, MainNetParams.get().getPort()); }
/** Alias for MainNetParams.get(), use that instead */ @Deprecated public static NetworkParameters prodNet() { return MainNetParams.get(); }
@Test(expected = BufferUnderflowException.class) public void testSeekPastMagicBytes() { // Fail in another way, there is data in the stream but no magic bytes. byte[] brokenMessage = HEX.decode("000000"); MainNetParams.get().getDefaultSerializer().seekPastMagicBytes(ByteBuffer.wrap(brokenMessage)); }
@Test public void getNetwork() throws Exception { NetworkParameters params = Address.getParametersFromAddress("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"); assertEquals(MainNetParams.get().getId(), params.getId()); params = Address.getParametersFromAddress("n4eA2nbYqErp7H6jebchxAN59DmNpksexv"); assertEquals(TestNet3Params.get().getId(), params.getId()); }
/** Alias for MainNetParams.get(), use that instead */ @Deprecated public static NetworkParameters prodNet() { return MainNetParams.get(); }
/** * Constructs a peer address from the given IP address. Port and version number are default for the given * parameters. */ public PeerAddress(NetworkParameters params, InetAddress addr) { this(params, addr, MainNetParams.get().getPort()); }
/** * @return The Bitcoinj NetworkParameters for the given key */ public NetworkParameters get() { switch (this) { case MAIN_NET: return MainNetParams.get(); default: throw new IllegalStateException("Unknown entry: " + this.name()); } }
@Test public void testPeerAddressRoundtrip() throws Exception { // copied verbatim from https://en.bitcoin.it/wiki/Protocol_specification#Network_address String fromSpec = "010000000000000000000000000000000000ffff0a000001208d"; PeerAddress pa = new PeerAddress(MainNetParams.get(), HEX.decode(fromSpec), 0, 0); String reserialized = Utils.HEX.encode(pa.unsafeBitcoinSerialize()); assertEquals(reserialized,fromSpec ); }
@Test public void getPeer_one() throws Exception{ SeedPeers seedPeers = new SeedPeers(MainNetParams.get()); assertThat(seedPeers.getPeer(), notNullValue()); }
@Test public void testSaveMetadataHdNodes() throws Exception { String metadataB58 = "xprv9twfkEhG8UPRWCrX3HnowyQk7vMCVeGY5ZHWsLANZqxqBaiAHPN3MvuuFedVNBhixki7WBvYW8gcg2mCemfV6XNNpCZ31JusEHUhdmdhsvp"; String sharedMetadataB58 = "xprv9twfkEhLiMZnQ5Gjf8w2f5wn5ASrQ9qMVwLo458shQmfMWhus8oo9aecvsAmSDXfgGbX2xQgeXi9Luj9ao5xGLKGjCj7gKiwvBGnjhdVEji"; mockInterceptor.setResponseString("{\"status\": \"success\"}"); metadataNodeFactory.saveMetadataHdNodes(HDKeyDerivation.createMasterPrivateKey(Hex.decode(masterKeyHex))); Assert.assertTrue(metadataNodeFactory.getMetadataNode().serializePrivB58(MainNetParams.get()).equals(metadataB58)); Assert.assertTrue(metadataNodeFactory.getSharedMetadataNode().serializePrivB58(MainNetParams.get()).equals(sharedMetadataB58)); }
@Test public void testTransactionsRetain() throws Exception { testTransaction(MainNetParams.get(), txMessage, false, true); testTransaction(PARAMS, tx1BytesWithHeader, false, true); testTransaction(PARAMS, tx2BytesWithHeader, false, true); }
@Test public void getPath() throws Exception { HDAccount account = new HDAccount(MainNetParams.get(), key, 0); Assert.assertEquals("M/0H",account.getPath()); } }
@Test public void estimatedBlockTime() throws Exception { NetworkParameters params = MainNetParams.get(); BlockChain prod = new BlockChain(new Context(params), new MemoryBlockStore(params)); Date d = prod.estimateBlockTime(200000); // The actual date of block 200,000 was 2012-09-22 10:47:00 assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d); }
@Test public void getId() throws Exception { HDAccount account = new HDAccount(MainNetParams.get(), xpub, 1); Assert.assertEquals(xpub,account.getXpub()); Assert.assertEquals(1,account.getId()); account = new HDAccount(MainNetParams.get(), xpub); Assert.assertEquals(xpub,account.getXpub()); Assert.assertEquals(0,account.getId()); }
@Test public void bip38testvector_ecMultiply_noCompression_noLotAndSequence_test1() throws Exception { BIP38PrivateKey encryptedKey = BIP38PrivateKey.fromBase58(MainNetParams.get(), "6PfQu77ygVyJLZjfvMLyhLMQbYnu5uguoJJ4kMCLqWwPEdfpwANVS76gTX"); ECKey key = encryptedKey.decrypt("TestingOneTwoThree"); assertEquals("5K4caxezwjGCGfnoPTZ8tMcJBLB7Jvyjv4xxeacadhq8nLisLR2", key.getPrivateKeyEncoded(MAINNET) .toString()); }
@Test public void bip38testvector_compression_noEcMultiply_test2() throws Exception { BIP38PrivateKey encryptedKey = BIP38PrivateKey.fromBase58(MainNetParams.get(), "6PYLtMnXvfG3oJde97zRyLYFZCYizPU5T3LwgdYJz1fRhh16bU7u6PPmY7"); ECKey key = encryptedKey.decrypt("Satoshi"); assertEquals("KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7", key.getPrivateKeyEncoded(MAINNET) .toString()); }
@Test public void bip38testvector_ecMultiply_noCompression_lotAndSequence_test1() throws Exception { BIP38PrivateKey encryptedKey = BIP38PrivateKey.fromBase58(MainNetParams.get(), "6PgNBNNzDkKdhkT6uJntUXwwzQV8Rr2tZcbkDcuC9DZRsS6AtHts4Ypo1j"); ECKey key = encryptedKey.decrypt("MOLON LABE"); assertEquals("5JLdxTtcTHcfYcmJsNVy1v2PMDx432JPoYcBTVVRHpPaxUrdtf8", key.getPrivateKeyEncoded(MAINNET) .toString()); }
@Test public void testToString() throws Exception { ECKey key = ECKey.fromPrivate(BigInteger.TEN).decompress(); // An example private key. NetworkParameters params = MainNetParams.get(); assertEquals("ECKey{pub HEX=04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7, isEncrypted=false, isPubKeyOnly=false}", key.toString()); assertEquals("ECKey{pub HEX=04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7, priv HEX=000000000000000000000000000000000000000000000000000000000000000a, priv WIF=5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreBoNWTw6, isEncrypted=false, isPubKeyOnly=false}", key.toStringWithPrivate(params)); }
@Test public void getChange() throws Exception { HDAccount account = new HDAccount(MainNetParams.get(), key, 0); Assert.assertFalse(account.getChange().isReceive()); Assert.assertEquals("M/0H/1",account.getChange().getPath()); Assert.assertEquals("12boKefnALjsXoQXyHg79aU7qSAFfg5Nze",account.getChange().getAddressAt(0).getAddressString()); }