本文整理汇总了Java中com.google.bitcoin.params.UnitTestParams类的典型用法代码示例。如果您正苦于以下问题:Java UnitTestParams类的具体用法?Java UnitTestParams怎么用?Java UnitTestParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitTestParams类属于com.google.bitcoin.params包,在下文中一共展示了UnitTestParams类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
BriefLogFormatter.initVerbose();
testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams) {
@Override
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
int relativityOffset) throws VerificationException {
super.receiveFromBlock(tx, block, blockType, relativityOffset);
BlockChainTest.this.block[0] = block;
if (tx.isCoinBase()) {
BlockChainTest.this.coinbaseTransaction = tx;
}
}
};
wallet.addKey(new ECKey());
resetBlockStore();
chain = new BlockChain(unitTestParams, wallet, blockStore);
coinbaseTo = wallet.getKeys().get(0).toAddress(unitTestParams);
}
示例2: deserializeFilteredBlock
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Test
// Simple deserialization sanity check
public void deserializeFilteredBlock() throws Exception {
NetworkParameters params = UnitTestParams.get();
// Random real block (000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45)
// With one tx
FilteredBlock block = new FilteredBlock(params, Hex.decode("0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f19630101"));
// Check that the header was properly deserialized
assertTrue(block.getBlockHeader().getHash().equals(new Sha256Hash("000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45")));
// Check that the partial merkle tree is correct
List<Sha256Hash> txesMatched = block.getTransactionHashes();
assertTrue(txesMatched.size() == 1);
assertTrue(txesMatched.contains(new Sha256Hash("63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5")));
}
示例3: testDecode
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Test
// Test that we can decode version messages which miss data which some old nodes may not include
public void testDecode() throws Exception {
NetworkParameters params = UnitTestParams.get();
VersionMessage ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f0004000000"));
assertTrue(!ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 1024);
assertTrue(ver.subVer.equals("/"+CoinDefinition.coinName+"J:0.7-SNAPSHOT/"));
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f00040000"));
assertTrue(ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 1024);
assertTrue(ver.subVer.equals("/"+CoinDefinition.coinName+"J:0.7-SNAPSHOT/"));
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f"));
assertTrue(ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 0);
assertTrue(ver.subVer.equals("/"+CoinDefinition.coinName+"J:0.7-SNAPSHOT/"));
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000"));
assertTrue(ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 0);
assertTrue(ver.subVer.equals(""));
}
示例4: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
BriefLogFormatter.init();
unitTestParams = UnitTestParams.get();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
this.blockStore = blockStore;
wallet = new Wallet(unitTestParams);
key = new ECKey();
address = key.toAddress(unitTestParams);
wallet.addKey(key);
blockChain = new BlockChain(unitTestParams, wallet, blockStore);
startPeerServers();
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER)
channels.startAndWait();
socketAddress = new InetSocketAddress("127.0.0.1", 1111);
}
示例5: testDecode
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Test
// Test that we can decode version messages which miss data which some old nodes may not include
public void testDecode() throws Exception {
NetworkParameters params = UnitTestParams.get();
VersionMessage ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f0004000000"));
assertTrue(!ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 1024);
assertTrue(ver.subVer.equals("/BitCoinJ:0.7-SNAPSHOT/"));
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f00040000"));
assertTrue(ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 1024);
assertTrue(ver.subVer.equals("/BitCoinJ:0.7-SNAPSHOT/"));
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f"));
assertTrue(ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 0);
assertTrue(ver.subVer.equals("/BitCoinJ:0.7-SNAPSHOT/"));
ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000"));
assertTrue(ver.relayTxesBeforeFilter);
assertTrue(ver.bestHeight == 0);
assertTrue(ver.subVer.equals(""));
}
示例6: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
BriefLogFormatter.init();
unitTestParams = UnitTestParams.get();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
this.blockStore = blockStore;
wallet = new Wallet(unitTestParams);
key = new ECKey();
address = key.toAddress(unitTestParams);
wallet.addKey(key);
blockChain = new BlockChain(unitTestParams, wallet, blockStore);
startPeerServers();
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER) {
channels.startAsync();
channels.awaitRunning();
}
socketAddress = new InetSocketAddress("127.0.0.1", 1111);
}
示例7: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
public void setUp(BlockStore blockStore) throws Exception {
BriefLogFormatter.init();
control = createStrictControl();
control.checkOrder(false);
unitTestParams = UnitTestParams.get();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
this.blockStore = blockStore;
wallet = new Wallet(unitTestParams);
key = new ECKey();
address = key.toAddress(unitTestParams);
wallet.addKey(key);
blockChain = new BlockChain(unitTestParams, wallet, blockStore);
socketAddress = new InetSocketAddress("127.0.0.1", 1111);
ctx = createChannelHandlerContext();
channel = createChannel();
pipeline = createPipeline(channel);
}
示例8: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
BriefLogFormatter.init();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams);
wallet.addKey(new ECKey());
wallet.addKey(new ECKey());
blockStore = new MemoryBlockStore(unitTestParams);
chain = new BlockChain(unitTestParams, wallet, blockStore);
coinsTo = wallet.getKeys().get(0).toAddress(unitTestParams);
coinsTo2 = wallet.getKeys().get(1).toAddress(unitTestParams);
someOtherGuy = new ECKey().toAddress(unitTestParams);
}
示例9: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp(new MemoryBlockStore(UnitTestParams.get()));
peerGroup.addWallet(wallet);
// Fix the random permutation that TransactionBroadcast uses to shuffle the peers.
TransactionBroadcast.random = new Random(0);
peerGroup.setMinBroadcastConnections(2);
peerGroup.startAndWait();
}
示例10: roundTripDumpedPrivKey
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Test
public void roundTripDumpedPrivKey() throws Exception {
ECKey key = new ECKey();
assertTrue(key.isCompressed());
NetworkParameters params = UnitTestParams.get();
String base58 = key.getPrivateKeyEncoded(params).toString();
ECKey key2 = new DumpedPrivateKey(params, base58).getKey();
assertTrue(key2.isCompressed());
assertTrue(Arrays.equals(key.getPrivKeyBytes(), key2.getPrivKeyBytes()));
assertTrue(Arrays.equals(key.getPubKey(), key2.getPubKey()));
}
示例11: testUpdateLength
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Test
public void testUpdateLength() {
NetworkParameters params = UnitTestParams.get();
Block block = params.getGenesisBlock().createNextBlockWithCoinbase(new ECKey().getPubKey());
assertEquals(block.bitcoinSerialize().length, block.length);
final int origBlockLen = block.length;
Transaction tx = new Transaction(params);
// this is broken until the transaction has > 1 input + output (which is required anyway...)
//assertTrue(tx.length == tx.bitcoinSerialize().length && tx.length == 8);
byte[] outputScript = new byte[10];
Arrays.fill(outputScript, (byte) ScriptOpCodes.OP_FALSE);
tx.addOutput(new TransactionOutput(params, null, BigInteger.valueOf(1), outputScript));
tx.addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1}))));
int origTxLength = 8 + 2 + 8 + 1 + 10 + 40 + 1 + 1;
assertEquals(tx.bitcoinSerialize().length, tx.length);
assertEquals(origTxLength, tx.length);
block.addTransaction(tx);
assertEquals(block.bitcoinSerialize().length, block.length);
assertEquals(origBlockLen + tx.length, block.length);
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {(byte) ScriptOpCodes.OP_FALSE, (byte) ScriptOpCodes.OP_FALSE});
assertEquals(block.length, origBlockLen + tx.length);
assertEquals(tx.length, origTxLength + 1);
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {});
assertEquals(block.length, block.bitcoinSerialize().length);
assertEquals(block.length, origBlockLen + tx.length);
assertEquals(tx.length, origTxLength - 1);
block.getTransactions().get(1).addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1}))));
assertEquals(block.length, origBlockLen + tx.length);
assertEquals(tx.length, origTxLength + 41); // - 1 + 40 + 1 + 1
}
示例12: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
peerToMessageCount = new HashMap<Peer, AtomicInteger>();
connectedPeers = new LinkedBlockingQueue<Peer>();
disconnectedPeers = new LinkedBlockingQueue<Peer>();
listener = new AbstractPeerEventListener() {
@Override
public void onPeerConnected(Peer peer, int peerCount) {
connectedPeers.add(peer);
}
@Override
public void onPeerDisconnected(Peer peer, int peerCount) {
disconnectedPeers.add(peer);
}
@Override
public Message onPreMessageReceived(Peer peer, Message m) {
AtomicInteger messageCount = peerToMessageCount.get(peer);
if (messageCount == null) {
messageCount = new AtomicInteger(0);
peerToMessageCount.put(peer, messageCount);
}
messageCount.incrementAndGet();
// Just pass the message right through for further processing.
return m;
}
};
super.setUp(new MemoryBlockStore(UnitTestParams.get()));
peerGroup.addWallet(wallet);
}
示例13: setUp
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
BriefLogFormatter.init();
params = new UnitTestParams() {
@Override public int getInterval() {
return 10000;
}
};
}
示例14: basics
import com.google.bitcoin.params.UnitTestParams; //导入依赖的package包/类
@Test
public void basics() throws Exception {
NetworkParameters params = UnitTestParams.get();
File f = File.createTempFile("spvblockstore", null);
f.delete();
f.deleteOnExit();
SPVBlockStore store = new SPVBlockStore(params, f);
Address to = new ECKey().toAddress(params);
// Check the first block in a new store is the genesis block.
StoredBlock genesis = store.getChainHead();
assertEquals(params.getGenesisBlock(), genesis.getHeader());
assertEquals(0, genesis.getHeight());
// Build a new block.
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
store.put(b1);
store.setChainHead(b1);
store.close();
// Check we can get it back out again if we rebuild the store object.
store = new SPVBlockStore(params, f);
StoredBlock b2 = store.get(b1.getHeader().getHash());
assertEquals(b1, b2);
// Check the chain head was stored correctly also.
StoredBlock chainHead = store.getChainHead();
assertEquals(b1, chainHead);
}