mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-30 03:21:23 +00:00
Move some classes into new packages.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.bouncycastle.util.encoders.Hex;
|
||||
import com.google.bitcoin.store.MemoryBlockStore;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright 2011 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 com.google.bitcoin.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.io.File;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BoundedOverheadBlockStoreTest {
|
||||
@Test
|
||||
public void testStorage() throws Exception {
|
||||
File temp = File.createTempFile("bitcoinj-test", null, null);
|
||||
System.out.println(temp.getAbsolutePath());
|
||||
temp.deleteOnExit();
|
||||
|
||||
NetworkParameters params = NetworkParameters.unitTests();
|
||||
Address to = new ECKey().toAddress(params);
|
||||
BoundedOverheadBlockStore store = new BoundedOverheadBlockStore(params, temp);
|
||||
// Check the first block in a new store is the genesis block.
|
||||
StoredBlock genesis = store.getChainHead();
|
||||
assertEquals(params.genesisBlock, genesis.getHeader());
|
||||
|
||||
// Build a new block.
|
||||
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
|
||||
store.put(b1);
|
||||
store.setChainHead(b1);
|
||||
// Check we can get it back out again if we rebuild the store object.
|
||||
store = new BoundedOverheadBlockStore(params, temp);
|
||||
StoredBlock b2 = store.get(b1.getHeader().getHash());
|
||||
assertEquals(b1, b2);
|
||||
// Check the chain head was stored correctly also.
|
||||
assertEquals(b1, store.getChainHead());
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.store.MemoryBlockStore;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright 2011 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 com.google.bitcoin.core;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.io.File;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class DiskBlockStoreTest {
|
||||
@Test
|
||||
public void testStorage() throws Exception {
|
||||
File temp = File.createTempFile("bitcoinj-test", null, null);
|
||||
System.out.println(temp.getAbsolutePath());
|
||||
//temp.deleteOnExit();
|
||||
|
||||
NetworkParameters params = NetworkParameters.unitTests();
|
||||
Address to = new ECKey().toAddress(params);
|
||||
DiskBlockStore store = new DiskBlockStore(params, temp);
|
||||
// Check the first block in a new store is the genesis block.
|
||||
StoredBlock genesis = store.getChainHead();
|
||||
assertEquals(params.genesisBlock, genesis.getHeader());
|
||||
|
||||
// Build a new block.
|
||||
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
|
||||
store.put(b1);
|
||||
store.setChainHead(b1);
|
||||
// Check we can get it back out again if we rebuild the store object.
|
||||
store = new DiskBlockStore(params, temp);
|
||||
StoredBlock b2 = store.get(b1.getHeader().getHash());
|
||||
assertEquals(b1, b2);
|
||||
// Check the chain head was stored correctly also.
|
||||
assertEquals(b1, store.getChainHead());
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
/**
|
||||
* Copyright John Sample
|
||||
*
|
||||
* 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 com.google.bitcoin.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IrcDiscoveryTest {
|
||||
// TODO: Inject a mock IRC server and more thoroughly exercise this class.
|
||||
|
||||
@Test
|
||||
public void testParseUserList() throws UnknownHostException {
|
||||
// Test some random addresses grabbed from the channel.
|
||||
String[] userList = new String[]{ "x201500200","u4stwEBjT6FYyVV", "u5BKEqDApa8SbA7"};
|
||||
|
||||
ArrayList<InetSocketAddress> addresses = IrcDiscovery.parseUserList(userList);
|
||||
|
||||
// Make sure the "x" address is excluded.
|
||||
assertEquals("Too many addresses.", 2, addresses.size());
|
||||
|
||||
String[] ips = new String[]{"69.4.98.82:8333","74.92.222.129:8333"};
|
||||
InetSocketAddress[] decoded = addresses.toArray(new InetSocketAddress[]{});
|
||||
|
||||
for (int i = 0; i < decoded.length; i++) {
|
||||
String formattedIP = decoded[0].getAddress().getHostAddress() + ":" + ((Integer)decoded[i].getPort()).toString();
|
||||
assertEquals("IPs decoded improperly", ips[0], formattedIP);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright 2011 Micheal Swiggs
|
||||
*
|
||||
* 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 com.google.bitcoin.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class SeedPeersTest {
|
||||
@Test
|
||||
public void getPeer_one() throws Exception{
|
||||
SeedPeers seedPeers = new SeedPeers(NetworkParameters.prodNet());
|
||||
assertThat(seedPeers.getPeer(), notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPeer_all() throws Exception{
|
||||
SeedPeers seedPeers = new SeedPeers(NetworkParameters.prodNet());
|
||||
for(int i = 0; i < SeedPeers.seedAddrs.length; ++i){
|
||||
assertThat("Failed on index: "+i, seedPeers.getPeer(), notNullValue());
|
||||
}
|
||||
assertThat(seedPeers.getPeer(), equalTo(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPeers_length() throws Exception{
|
||||
SeedPeers seedPeers = new SeedPeers(NetworkParameters.prodNet());
|
||||
InetSocketAddress[] addresses = seedPeers.getPeers();
|
||||
assertThat(addresses.length, equalTo(SeedPeers.seedAddrs.length));
|
||||
}
|
||||
}
|
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.store.BlockStore;
|
||||
import com.google.bitcoin.store.BlockStoreException;
|
||||
import com.google.bitcoin.store.MemoryBlockStore;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
Reference in New Issue
Block a user