Java Code Examples for org.bitcoinj.testing.FakeTxBuilder#createFakeBlock()

The following examples show how to use org.bitcoinj.testing.FakeTxBuilder#createFakeBlock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VersionTallyTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testInitialize() throws BlockStoreException {
    final BlockStore blockStore = new MemoryBlockStore(UNITTEST);
    final BlockChain chain = new BlockChain(UNITTEST, blockStore);

    // Build a historical chain of version 2 blocks
    long timeSeconds = 1231006505;
    StoredBlock chainHead = null;
    for (int height = 0; height < UNITTEST.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock;
        assertEquals(2, chainHead.getHeader().getVersion());
        timeSeconds += 60;
    }

    VersionTally instance = new VersionTally(UNITTEST);
    instance.initialize(blockStore, chainHead);
    assertEquals(UNITTEST.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue());
}
 
Example 2
Source File: VersionTallyTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testInitialize() throws BlockStoreException {
    final BlockStore blockStore = new MemoryBlockStore(PARAMS);
    final BlockChain chain = new BlockChain(PARAMS, blockStore);

    // Build a historical chain of version 2 blocks
    long timeSeconds = 1231006505;
    StoredBlock chainHead = null;
    for (int height = 0; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock;
        assertEquals(2, chainHead.getHeader().getVersion());
        timeSeconds += 60;
    }

    VersionTally instance = new VersionTally(PARAMS);
    instance.initialize(blockStore, chainHead);
    assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue());
}
 
Example 3
Source File: VersionTallyTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testInitialize() throws BlockStoreException {
    final BlockStore blockStore = new MemoryBlockStore(PARAMS);
    final BlockChain chain = new BlockChain(PARAMS, blockStore);

    // Build a historical chain of version 2 blocks
    long timeSeconds = 1231006505;
    StoredBlock chainHead = null;
    for (int height = 0; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock;
        assertEquals(2, chainHead.getHeader().getVersion());
        timeSeconds += 60;
    }

    VersionTally instance = new VersionTally(PARAMS);
    instance.initialize(blockStore, chainHead);
    assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue());
}
 
Example 4
Source File: BlockChainTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion)
        throws Exception {
    final BlockStore versionBlockStore = new MemoryBlockStore(UNITTEST);
    final BlockChain versionChain = new BlockChain(UNITTEST, versionBlockStore);

    // Build a historical chain of version 3 blocks
    long timeSeconds = 1231006505;
    int height = 0;
    FakeTxBuilder.BlockPair chainHead = null;

    // Put in just enough v2 blocks to be a minority
    for (height = 0; height < (UNITTEST.getMajorityWindow() - UNITTEST.getMajorityRejectBlockOutdated()); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }
    // Fill the rest of the window with v3 blocks
    for (; height < UNITTEST.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }

    chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
    // Trying to add a new v2 block should result in rejection
    thrown.expect(VerificationException.BlockVersionOutOfDate.class);
    try {
        versionChain.add(chainHead.block);
    } catch (final VerificationException ex) {
        throw (Exception) ex.getCause();
    }
}
 
Example 5
Source File: BlockChainTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion)
        throws Exception {
    final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS);
    final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore);

    // Build a historical chain of version 3 blocks
    long timeSeconds = 1231006505;
    int height = 0;
    FakeTxBuilder.BlockPair chainHead = null;

    // Put in just enough v2 blocks to be a minority
    for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }
    // Fill the rest of the window with v3 blocks
    for (; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }

    chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
    // Trying to add a new v2 block should result in rejection
    thrown.expect(VerificationException.BlockVersionOutOfDate.class);
    try {
        versionChain.add(chainHead.block);
    } catch(final VerificationException ex) {
        throw (Exception) ex.getCause();
    }
}
 
Example 6
Source File: BlockChainTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion)
        throws Exception {
    final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS);
    final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore);

    // Build a historical chain of version 3 blocks
    long timeSeconds = 1231006505;
    int height = 0;
    FakeTxBuilder.BlockPair chainHead = null;

    // Put in just enough v2 blocks to be a minority
    for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }
    // Fill the rest of the window with v3 blocks
    for (; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }

    chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
    // Trying to add a new v2 block should result in rejection
    thrown.expect(VerificationException.BlockVersionOutOfDate.class);
    try {
        versionChain.add(chainHead.block);
    } catch(final VerificationException ex) {
        throw (Exception) ex.getCause();
    }
}