<commit_before>package org.mastercoin

import com.msgilligan.bitcoin.rpc.RPCURL
import org.mastercoin.rpc.MastercoinCLIClient
import org.mastercoin.rpc.MastercoinClient
import groovy.json.JsonSlurper
import org.mastercoin.rpc.MastercoinClientDelegate
import spock.lang.Shared
import spock.lang.Specification

/**
 * User: sean
 * Date: 7/20/14
 * Time: 12:53 AM
 */
abstract class BaseMainNetSpec extends Specification implements MastercoinClientDelegate {
    {
        client = new MastercoinCLIClient(RPCURL.defaultMainNetURL, BaseMainNetSpec.rpcuser, BaseMainNetSpec.rpcpassword)
    }
//abstract class BaseMainNetSpec extends Specification  {
    static final String rpcuser = "bitcoinrpc"
    static final String rpcpassword = "<PASSWORD>"

//    @Shared
//    MastercoinClient client;

    void setupSpec() {
//        client = new MastercoinClient(RPCURL.defaultMainNetURL, rpcuser, rpcpassword)
        System.err.println("Waiting for server...")
        Boolean available = client.waitForServer(3*60*60)   // Wait up to 3 hours
        if (!available) {
            System.err.println("Timeout error.")
        }

        //
        // Get in sync with Blockchain.info
        //
        def curHeight = 0
        def newHeight = new JsonSlurper().parse(new URL("http://blockchain.info/latestblock")).height
        println "Blockchain.info current height: ${newHeight}"
        while ( newHeight > curHeight ) {
            curHeight = newHeight
            Boolean upToDate = client.waitForSync(curHeight, 60*60)
            newHeight = new JsonSlurper().parse(new URL("http://blockchain.info/latestblock")).height
            println "Blockchain.info current height: ${newHeight}"
        }
    }

//    def methodMissing(String name, args) {
//        client."$name"(*args)
//    }
//
//    def propertyMissing(String name) {
//        client."$name"
//    }
//
//    def propertyMissing(String name, value) {
//        client."$name" = value
//    }

}<commit_msg>Create getReferenceBlockHeight() method, cleanup, document.<commit_after>package org.mastercoin

import com.msgilligan.bitcoin.rpc.RPCURL
import org.mastercoin.rpc.MastercoinCLIClient
import groovy.json.JsonSlurper
import org.mastercoin.rpc.MastercoinClientDelegate
import spock.lang.Specification

/**
 * Base specification for tests on Main net
 *
 * Creates an RPC client (currently <code>MastercoinCLIClient</code>), waits for
 * RPC server to be responding (typical integration/functional requests require starting
 * an RPC server which can take minutes or even hours) and to be in sync with the main
 * Bitcoin Blockchain.
 *
 */
abstract class BaseMainNetSpec extends Specification implements MastercoinClientDelegate {
    {
        client = new MastercoinCLIClient(RPCURL.defaultMainNetURL, BaseMainNetSpec.rpcuser, BaseMainNetSpec.rpcpassword)
    }
    static final String rpcuser = "bitcoinrpc"
    static final String rpcpassword = "<PASSWORD>"
    static final Integer rpcWaitTimeoutSeconds = 3*60*60  // Wait up to 3 hours for RPC response

    /**
     * Wait for RPC server to be responding and to be in sync with the Bitcoin Blockchain
     */
    void setupSpec() {
        println "Waiting for server..."
        Boolean available = client.waitForServer(rpcWaitTimeoutSeconds)
        if (!available) {
            println "Timeout error."
        }

        //
        // Get in sync with the Blockchain
        //
        def curHeight = 0
        def newHeight = getReferenceBlockHeight()
        println "Blockchain.info current height: ${newHeight}"
        while ( newHeight > curHeight ) {
            curHeight = newHeight
            Boolean upToDate = client.waitForSync(curHeight, 60*60)
            newHeight = getReferenceBlockHeight()
            println "Current reference block height: ${newHeight}"
        }
    }

    /**
     * Use an external service to get the current block height
     * Currently uses blockchain.info
     */
    def getReferenceBlockHeight() {
        // Use Blockchain.info to get the current block height
        def height = new JsonSlurper().parse(new URL("http://blockchain.info/latestblock")).height
        return height
    }
}
{'fraction_non_alphanumeric': 0.09408666507062485, 'fraction_numerical': 0.007421594445774479, 'mean_word_length': 2.8400735294117645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7387654', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1129, 'n_words': 316}