Refactoring codebase from using BitcoinSLogger as a mixin trait -- refactoring BitcoinSLogger as abstract class

This commit is contained in:
Chris Stewart 2017-08-22 21:09:08 -05:00
parent 60be687211
commit 090d848ebc
51 changed files with 104 additions and 82 deletions

View file

@ -19,7 +19,9 @@ import org.bitcoins.core.util.{BitcoinSLogger, BitcoinSUtil, BitcoinScriptUtil,
* bitcoinj version of this
* [[https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/core/Transaction.java#L924-L1008]]
*/
trait TransactionSignatureSerializer extends RawBitcoinSerializerHelper with BitcoinSLogger {
trait TransactionSignatureSerializer extends RawBitcoinSerializerHelper {
private def logger = BitcoinSLogger.logger
/**
* Bitcoin Core's bug is that SignatureHash was supposed to return a hash and on this codepath it

View file

@ -7,7 +7,7 @@ import org.bitcoins.core.serializers.{RawBitcoinSerializerHelper, RawSatoshisSer
import org.bitcoins.core.util.{BitcoinSLogger, Factory}
sealed trait CurrencyUnit extends NetworkElement with BitcoinSLogger {
sealed trait CurrencyUnit extends NetworkElement {
type A
def underlying : A

View file

@ -12,7 +12,7 @@ import scala.util.{Failure, Success, Try}
/**
* A number can either be a signed or an unsigned number
*/
sealed trait Number extends NetworkElement with BitcoinSLogger {
sealed trait Number extends NetworkElement {
type A
def underlying : A
def toInt : Int
@ -319,7 +319,7 @@ trait BaseNumbers[T] {
def max : T
}
object UInt32 extends Factory[UInt32] with BitcoinSLogger with BaseNumbers[UInt32] {
object UInt32 extends Factory[UInt32] with BaseNumbers[UInt32] {
private case class UInt32Impl(underlying : Long) extends UInt32 {
require(underlying >= 0, "We cannot have a negative number in an unsigned number, got: " + underlying)
require(underlying <= 4294967295L, "We cannot have a number larger than 2^32 -1 in UInt32, got: " + underlying)
@ -345,7 +345,7 @@ object UInt32 extends Factory[UInt32] with BitcoinSLogger with BaseNumbers[UInt3
object UInt64 extends Factory[UInt64] with BitcoinSLogger with BaseNumbers[UInt64] {
object UInt64 extends Factory[UInt64] with BaseNumbers[UInt64] {
private case class UInt64Impl(underlying : BigInt) extends UInt64 {
require(underlying >= 0, "We cannot have a negative number in an unsigned number: " + underlying)
require(underlying <= BigInt("18446744073709551615"), "We cannot have a number larger than 2^64 -1 in UInt64, got: " + underlying)

View file

@ -8,7 +8,7 @@ import org.bitcoins.core.util.{BitcoinSLogger, BitcoinSUtil}
* This represents a element that can be serialized to
* be sent over the network
*/
trait NetworkElement extends BitcoinSLogger {
trait NetworkElement {
/** The size of the NetworkElement in bytes. */
def size : Int = bytes.size
@ -18,4 +18,6 @@ trait NetworkElement extends BitcoinSLogger {
/** The byte representation of the NetworkElement */
def bytes : Seq[Byte] = BitcoinSUtil.decodeHex(hex)
def logger: BitcoinSLogger = BitcoinSLogger
}

View file

@ -20,7 +20,7 @@ import org.bitcoins.core.util.{BitcoinSUtil, CryptoUtil, BitcoinSLogger, Factory
* Bitcoin Core implementation:
* https://github.com/bitcoin/bitcoin/blob/master/src/primitives/block.h#L20
*/
sealed trait BlockHeader extends NetworkElement with BitcoinSLogger {
sealed trait BlockHeader extends NetworkElement {
/**
* The block version number indicates which set of block validation rules to follow.

View file

@ -20,7 +20,7 @@ import scala.util.{Failure, Success, Try}
/**
* Created by chris on 12/26/15.
*/
sealed trait ScriptPubKey extends NetworkElement with BitcoinSLogger {
sealed trait ScriptPubKey extends NetworkElement {
/** The size of the script, this is used for network serialization */
def compactSizeUInt : CompactSizeUInt = CompactSizeUInt.parseCompactSizeUInt(bytes)
@ -134,7 +134,7 @@ sealed trait MultiSignatureScriptPubKey extends ScriptPubKey {
}
}
object MultiSignatureScriptPubKey extends ScriptFactory[MultiSignatureScriptPubKey] with BitcoinSLogger {
object MultiSignatureScriptPubKey extends ScriptFactory[MultiSignatureScriptPubKey] {
private case class MultiSignatureScriptPubKeyImpl(hex : String) extends MultiSignatureScriptPubKey
@ -234,7 +234,7 @@ sealed trait P2SHScriptPubKey extends ScriptPubKey {
def scriptHash : Sha256Hash160Digest = Sha256Hash160Digest(asm(asm.length - 2).bytes)
}
object P2SHScriptPubKey extends ScriptFactory[P2SHScriptPubKey] with BitcoinSLogger {
object P2SHScriptPubKey extends ScriptFactory[P2SHScriptPubKey] {
private case class P2SHScriptPubKeyImpl(hex : String) extends P2SHScriptPubKey
@ -499,7 +499,7 @@ case object EmptyScriptPubKey extends ScriptPubKey {
}
/** Factory companion object used to create ScriptPubKey objects */
object ScriptPubKey extends Factory[ScriptPubKey] with BitcoinSLogger {
object ScriptPubKey extends Factory[ScriptPubKey] {
def empty : ScriptPubKey = fromAsm(Nil)
/** Creates a scriptPubKey from its asm representation */

View file

@ -394,7 +394,7 @@ case object EmptyScriptSignature extends ScriptSignature {
def hex = "00"
}
object ScriptSignature extends Factory[ScriptSignature] with BitcoinSLogger {
object ScriptSignature extends Factory[ScriptSignature] {
/** Returns an empty script signature */

View file

@ -1,11 +1,11 @@
package org.bitcoins.core.script.arithmetic
import org.bitcoins.core.script.control.{ControlOperationsInterpreter, OP_VERIFY}
import org.bitcoins.core.script.result._
import org.bitcoins.core.script.flag.ScriptFlagUtil
import org.bitcoins.core.script.{ExecutedScriptProgram, PreExecutionScriptProgram, ExecutionInProgressScriptProgram, ScriptProgram}
import org.bitcoins.core.script.constant._
import org.bitcoins.core.util.{BitcoinScriptUtil, BitcoinSUtil}
import org.bitcoins.core.script.control.{ControlOperationsInterpreter, OP_VERIFY}
import org.bitcoins.core.script.flag.ScriptFlagUtil
import org.bitcoins.core.script.result._
import org.bitcoins.core.script.{ExecutedScriptProgram, ExecutionInProgressScriptProgram, PreExecutionScriptProgram, ScriptProgram}
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil}
import scala.annotation.tailrec
@ -13,7 +13,7 @@ import scala.annotation.tailrec
* Created by chris on 1/25/16.
*/
trait ArithmeticInterpreter extends ControlOperationsInterpreter {
private def logger = BitcoinSLogger.logger
/** a is added to b. */
def opAdd(program : ScriptProgram) : ScriptProgram = {
require(program.script.headOption.contains(OP_ADD), "Script top must be OP_ADD")

View file

@ -5,12 +5,13 @@ import org.bitcoins.core.script.constant._
import org.bitcoins.core.script.control.{ControlOperationsInterpreter, OP_VERIFY}
import org.bitcoins.core.script.result._
import org.bitcoins.core.script.{ExecutedScriptProgram, ExecutionInProgressScriptProgram, PreExecutionScriptProgram, ScriptProgram}
import org.bitcoins.core.util.BitcoinSLogger
/**
* Created by chris on 1/6/16.
*/
trait BitwiseInterpreter extends ControlOperationsInterpreter {
private def logger = BitcoinSLogger.logger
/** Returns 1 if the inputs are exactly equal, 0 otherwise. */
def opEqual(program : ScriptProgram) : ScriptProgram = {
require(program.script.headOption.contains(OP_EQUAL), "Script operation must be OP_EQUAL")

View file

@ -10,7 +10,8 @@ import scala.annotation.tailrec
/**
* Created by chris on 1/24/16.
*/
trait ConstantInterpreter extends BitcoinSLogger {
trait ConstantInterpreter {
private def logger = BitcoinSLogger.logger
/** The next byte contains the number of bytes to be pushed onto the stack. */
def opPushData1(program : ScriptProgram) : ScriptProgram = {

View file

@ -12,8 +12,8 @@ import scala.annotation.tailrec
/**
* Created by chris on 1/6/16.
*/
trait ControlOperationsInterpreter extends BitcoinSLogger {
trait ControlOperationsInterpreter {
private def logger = BitcoinSLogger.logger
/** If the top stack value is not 0, the statements are executed. The top stack value is removed. */
def opIf(program : ScriptProgram) : ScriptProgram = {
require(program.script.headOption.contains(OP_IF), "Script top was not OP_IF")

View file

@ -1,11 +1,11 @@
package org.bitcoins.core.script.crypto
import org.bitcoins.core.crypto._
import org.bitcoins.core.script.{ScriptProgram, _}
import org.bitcoins.core.script.constant._
import org.bitcoins.core.script.control.{ControlOperationsInterpreter, OP_VERIFY}
import org.bitcoins.core.script.flag.ScriptFlagUtil
import org.bitcoins.core.script.result._
import org.bitcoins.core.script.{ScriptProgram, _}
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil, CryptoUtil}
import scala.annotation.tailrec
@ -14,7 +14,9 @@ import scala.annotation.tailrec
/**
* Created by chris on 1/6/16.
*/
trait CryptoInterpreter extends ControlOperationsInterpreter with BitcoinSLogger {
trait CryptoInterpreter extends ControlOperationsInterpreter {
private def logger = BitcoinSLogger.logger
/** The input is hashed twice: first with SHA-256 and then with RIPEMD-160. */
def opHash160(program : ScriptProgram) : ScriptProgram = {

View file

@ -28,8 +28,9 @@ import scala.util.{Failure, Success, Try}
*/
trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with ControlOperationsInterpreter
with BitwiseInterpreter with ConstantInterpreter with ArithmeticInterpreter with SpliceInterpreter
with LockTimeInterpreter with BitcoinSLogger {
with LockTimeInterpreter {
private def logger = BitcoinSLogger.logger
/**
* Currently bitcoin core limits the maximum number of non-push operations per script
* to 201

View file

@ -13,9 +13,9 @@ import scala.annotation.tailrec
/**
* Created by chris on 2/8/16.
*/
trait LockTimeInterpreter extends BitcoinSLogger {
trait LockTimeInterpreter {
private def logger = BitcoinSLogger.logger
/**
* Marks transaction as invalid if the top stack item is greater than the transaction's nLockTime field,
* otherwise script evaluation continues as though an OP_NOP was executed. Transaction is also invalid if

View file

@ -1,17 +1,16 @@
package org.bitcoins.core.script.splice
import org.bitcoins.core.script.{ScriptOperationFactory, ScriptProgram}
import org.bitcoins.core.script.ScriptProgram
import org.bitcoins.core.script.constant._
import Math._
import org.bitcoins.core.script.result.ScriptErrorInvalidStackOperation
import org.bitcoins.core.util.BitcoinSLogger
/**
* Created by chris on 2/4/16.
*/
trait SpliceInterpreter extends BitcoinSLogger {
trait SpliceInterpreter {
private def logger = BitcoinSLogger.logger
/** Pushes the string length of the top element of the stack (without popping it). */
def opSize(program: ScriptProgram): ScriptProgram = {
require(program.script.headOption.contains(OP_SIZE), "Script top must be OP_SIZE")

View file

@ -14,7 +14,8 @@ import scala.util.{Failure, Success, Try}
* Stack operations implemented in the script programming language
* https://en.bitcoin.it/wiki/Script#Stack
*/
trait StackInterpreter extends BitcoinSLogger {
trait StackInterpreter {
private def logger = BitcoinSLogger.logger
/** Duplicates the element on top of the stack
* expects the first element in script to be the OP_DUP operation. */

View file

@ -1,12 +1,13 @@
package org.bitcoins.core.serializers
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinSUtil}
import org.slf4j.Logger
/**
* Created by chris on 1/11/16.
* A common trait for reading/writing bitcoin objects to/from bytes/hex
*/
trait RawBitcoinSerializer[T] extends RawBitcoinSerializerHelper with BitcoinSLogger {
abstract class RawBitcoinSerializer[T] extends RawBitcoinSerializerHelper {
/** Reads a hexadecimal value and transforms it into the native scala type T. */
def read(hex : String) : T = read(BitcoinSUtil.decodeHex(hex))
@ -20,4 +21,6 @@ trait RawBitcoinSerializer[T] extends RawBitcoinSerializerHelper with BitcoinSLo
/** Takes a type T and writes it into the appropriate hexadecimal serialization for type T. */
def write(t : T) : String
def logger: Logger = BitcoinSLogger.logger
}

View file

@ -11,7 +11,7 @@ import scala.util.Try
/**
* Created by chris on 1/12/16.
*/
trait RawScriptSignatureParser extends RawBitcoinSerializer[ScriptSignature] with BitcoinSLogger {
trait RawScriptSignatureParser extends RawBitcoinSerializer[ScriptSignature] {
def read(bytes : List[Byte]) : ScriptSignature = {
if (bytes.isEmpty) EmptyScriptSignature

View file

@ -14,7 +14,7 @@ import scala.annotation.tailrec
* Created by chris on 1/13/16.
* https://bitcoin.org/en/developer-reference#txin
*/
trait RawTransactionInputParser extends RawBitcoinSerializer[Seq[TransactionInput]] with BitcoinSLogger {
trait RawTransactionInputParser extends RawBitcoinSerializer[Seq[TransactionInput]] {
override def read(bytes : List[Byte]) : Seq[TransactionInput] = {

View file

@ -12,7 +12,7 @@ import org.bitcoins.core.util.{BitcoinSLogger, BitcoinSUtil, NumberUtil}
* https://bitcoin.org/en/developer-reference#outpoint
*
*/
trait RawTransactionOutPointParser extends RawBitcoinSerializer[TransactionOutPoint] with BitcoinSLogger {
trait RawTransactionOutPointParser extends RawBitcoinSerializer[TransactionOutPoint] {
override def read(bytes : List[Byte]) : TransactionOutPoint = {

View file

@ -14,7 +14,7 @@ import scala.annotation.tailrec
* Created by chris on 1/11/16.
* https://bitcoin.org/en/developer-reference#txout
*/
trait RawTransactionOutputParser extends RawBitcoinSerializer[Seq[TransactionOutput]] with ScriptParser {
trait RawTransactionOutputParser extends RawBitcoinSerializer[Seq[TransactionOutput]] {
/** Reads a sequence of outputs, expects first element in the byte array to be a [[org.bitcoins.core.protocol.CompactSizeUInt]]
* indicating how many outputs we need to read

View file

@ -1,10 +1,12 @@
package org.bitcoins.core.util
import org.slf4j.Logger
/**
* Created by chris on 2/26/16.
* Trait to implement ubiquitous factory functions across our codebase
*/
trait Factory[T] extends BitcoinSLogger {
trait Factory[T] {
/** Creates a T out of a hex string. */
def fromHex(hex : String) : T = fromBytes(BitcoinSUtil.decodeHex(hex))
@ -17,4 +19,6 @@ trait Factory[T] extends BitcoinSLogger {
/** Creates a T from a hex string. */
def apply(hex : String) : T = fromHex(hex)
def logger: Logger = BitcoinSLogger.logger
}

View file

@ -7,7 +7,8 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 3/7/16.
*/
class ECPrivateKeyTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class ECPrivateKeyTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
"ECPrivateKey" must "have the same byte representation as a bitcoinj private key" in {
val bitcoinjPrivateKey = CryptoTestUtil.bitcoinjPrivateKey.getPrivateKeyAsHex

View file

@ -10,7 +10,8 @@ import org.scalacheck.{Prop, Properties}
/**
* Created by chris on 7/25/16.
*/
class TransactionSignatureCreatorSpec extends Properties("TransactionSignatureCreatorSpec") with BitcoinSLogger {
class TransactionSignatureCreatorSpec extends Properties("TransactionSignatureCreatorSpec") {
private def logger = BitcoinSLogger.logger
property("Must generate a valid signature for a p2pk transaction") =
Prop.forAll(TransactionGenerators.signedP2PKTransaction) {

View file

@ -14,7 +14,8 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 7/21/16.
*/
class TransactionSignatureCreatorTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class TransactionSignatureCreatorTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
"TransactionSignatureCreator" must "create a signature for a scriptSignature in a transaction" in {
//this is a signed tx, but since TransactionSignatureSerializer removes scriptSigs, it will work for testing this

View file

@ -27,7 +27,8 @@ import scala.collection.JavaConversions._
/**
* Created by chris on 2/19/16.
*/
class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
val scriptPubKey = BitcoinjConversions.toScriptPubKey(BitcoinJTestUtil.multiSigScript)
"TransactionSignatureSerializer" must "serialize a transaction for SIGHASH_ALL correctly" in {

View file

@ -9,7 +9,7 @@ import scala.util.Try
/**
* Created by chris on 6/21/16.
*/
class Int32Spec extends Properties("Int32Spec") with BitcoinSLogger {
class Int32Spec extends Properties("Int32Spec") {
property("Serialization symmetry") =
Prop.forAll(NumberGenerator.int32s) { int32: Int32 =>

View file

@ -9,7 +9,7 @@ import scala.util.Try
/**
* Created by chris on 6/16/16.
*/
class UInt32Spec extends Properties("UInt32") with BitcoinSLogger {
class UInt32Spec extends Properties("UInt32") {
property("serialization symmetry") = {

View file

@ -9,7 +9,7 @@ import scala.util.Try
/**
* Created by chris on 6/20/16.
*/
class UInt64Spec extends Properties("UInt64Spec") with BitcoinSLogger {
class UInt64Spec extends Properties("UInt64Spec") {
property("Serialization symmetry") =

View file

@ -6,6 +6,6 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 3/23/15.
*/
class AddressTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class AddressTest extends FlatSpec with MustMatchers {
}

View file

@ -8,7 +8,7 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 7/15/16.
*/
class BlockTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class BlockTest extends FlatSpec with MustMatchers {
"Block" must "deserialize and serialize a block with two txs" in {

View file

@ -10,7 +10,8 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 5/24/16.
*/
class ChainParamsTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class ChainParamsTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
val genesisBlock = MainNetChainParams.genesisBlock
val genesisTransaction = genesisBlock.transactions.head

View file

@ -10,7 +10,7 @@ import org.scalacheck.{Properties, Prop}
/**
* Created by tom on 8/23/16.
*/
class CLTVScriptPubKeySpec extends Properties("CLTVScriptPubKeySpec") with BitcoinSLogger {
class CLTVScriptPubKeySpec extends Properties("CLTVScriptPubKeySpec") {
property("Serialization symmetry") =
Prop.forAll(ScriptGenerators.cltvScriptPubKey) { case (cltvScriptPubKey, _) =>
CLTVScriptPubKey(cltvScriptPubKey.hex) == cltvScriptPubKey

View file

@ -7,7 +7,7 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 3/8/16.
*/
class MultiSignatureScriptSignatureTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class MultiSignatureScriptSignatureTest extends FlatSpec with MustMatchers {
"MultiSignatureScriptSignature" must "find all of the digital signatures for a multisignature scriptSig" in {
val (spendingTx,inputIndex,_,_) = TransactionTestUtil.signedMultiSignatureTransaction

View file

@ -7,7 +7,9 @@ import org.scalacheck.{Prop, Properties}
/**
* Created by chris on 6/22/16.
*/
class P2PKScriptSignatureSpec extends Properties("P2PKSpec") with BitcoinSLogger {
class P2PKScriptSignatureSpec extends Properties("P2PKSpec") {
private def logger = BitcoinSLogger.logger
property("Serialization symmetry") =
Prop.forAll(ScriptGenerators.p2pkScriptSignature) { p2pkScriptSig =>
logger.info("P2PKScriptSig: " + p2pkScriptSig)

View file

@ -7,7 +7,7 @@ import org.scalacheck.{Prop, Properties}
/**
* Created by chris on 6/24/16.
*/
class P2SHScriptSignatureSpec extends Properties("P2SHScriptSignatureSpec") with BitcoinSLogger {
class P2SHScriptSignatureSpec extends Properties("P2SHScriptSignatureSpec") {
property("Symmetrical serialization") =

View file

@ -9,7 +9,8 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 3/8/16.
*/
class P2SHScriptSignatureTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class P2SHScriptSignatureTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
"P2SHScriptSignature" must "find the public keys embedded inside of the redeemScript" in {
val rawP2SHScriptSig = TestUtil.rawP2shInputScript2Of2

View file

@ -16,7 +16,8 @@ import scala.io.Source
/**
* Created by chris on 2/17/16.
*/
class ScriptSignatureTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class ScriptSignatureTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
"ScriptSignature" must "find the digital signature for the transaction inside of a p2pkh script signature" in {
val scriptSig = ScriptSignature(TestUtil.rawScriptSig)

View file

@ -1,13 +1,12 @@
package org.bitcoins.core.protocol.transaction
import org.bitcoins.core.gen.TransactionGenerators
import org.bitcoins.core.util.BitcoinSLogger
import org.scalacheck.{Prop, Properties}
/**
* Created by chris on 6/24/16.
*/
class TransactionInputSpec extends Properties("TranactionInputSpec") with BitcoinSLogger {
class TransactionInputSpec extends Properties("TranactionInputSpec") {
property("Serialization symmetry") =
Prop.forAllNoShrink(TransactionGenerators.inputs) { input =>

View file

@ -1,13 +1,12 @@
package org.bitcoins.core.protocol.transaction
import org.bitcoins.core.gen.TransactionGenerators
import org.bitcoins.core.util.BitcoinSLogger
import org.scalacheck.{Prop, Properties}
/**
* Created by chris on 6/21/16.
*/
class TransactionOutPointSpec extends Properties("TransactionOutPointSpec") with BitcoinSLogger {
class TransactionOutPointSpec extends Properties("TransactionOutPointSpec") {
property("Serialization symmetry") =
Prop.forAll(TransactionGenerators.outPoints) { outPoint =>

View file

@ -18,8 +18,8 @@ import scala.io.Source
/**
* Created by chris on 7/14/15.
*/
class TransactionTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class TransactionTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
"Transaction" must "derive the correct txid from the transaction contents" in {

View file

@ -7,7 +7,7 @@ import org.scalacheck.{Prop, Properties}
/**
* Created by tom on 7/5/16.
*/
class ScriptNumberSpec extends Properties("ScriptNumberSpec") with BitcoinSLogger {
class ScriptNumberSpec extends Properties("ScriptNumberSpec") {
property("Additive identity") =
Prop.forAll(NumberGenerator.scriptNumbers) { num : ScriptNumber =>
num + ScriptNumber.zero == num

View file

@ -14,7 +14,8 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 1/6/16.
*/
class CryptoInterpreterTest extends FlatSpec with MustMatchers with CryptoInterpreter with BitcoinSLogger {
class CryptoInterpreterTest extends FlatSpec with MustMatchers with CryptoInterpreter {
private def logger = BitcoinSLogger.logger
val stack = List(ScriptConstant("02218AD6CDC632E7AE7D04472374311CEBBBBF0AB540D2D08C3400BB844C654231".toLowerCase))
"CryptoInterpreter" must "evaluate OP_HASH160 correctly when it is on top of the script stack" in {

View file

@ -21,8 +21,8 @@ import scala.io.Source
/**
* Created by chris on 1/6/16.
*/
class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterpreter with BitcoinSLogger {
class ScriptInterpreterTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
"ScriptInterpreter" must "evaluate all the scripts from the bitcoin core script_tests.json" in {
val source = Source.fromURL(getClass.getResource("/script_tests.json"))

View file

@ -4,13 +4,12 @@ import org.bitcoins.core.crypto.DoubleSha256Digest
import org.bitcoins.core.number.{UInt32, UInt64}
import org.bitcoins.core.protocol.CompactSizeUInt
import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinSUtil}
import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by tom on 6/3/16.
*/
class RawBlockSerializerTest extends FlatSpec with MustMatchers with BitcoinSLogger {
class RawBlockSerializerTest extends FlatSpec with MustMatchers {
//genesis block
//https://en.bitcoin.it/wiki/Genesis_block
//https://webbtc.com/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

View file

@ -9,15 +9,15 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 1/12/16.
*/
class RawScriptSignatureParserTest extends FlatSpec with MustMatchers with RawScriptSignatureParser with BitcoinSLogger {
class RawScriptSignatureParserTest extends FlatSpec with MustMatchers {
//from bitcoin developer examples
//https://bitcoin.org/en/developer-reference#raw-transaction-format
val rawScriptSig = "4a494830450221008949f0cb400094ad2b5eb399d59d01c14d73d8fe6e96df1a7150deb388ab8935022079656090d7f6bac4c9a94e0aad311a4268e082a725f8aeae0573fb12ff866a5f01"
"RawScriptSignatureParser" must "write a raw script sig" in {
val scriptSig = read(rawScriptSig)
write(scriptSig) must be (rawScriptSig)
val scriptSig = RawScriptSignatureParser.read(rawScriptSig)
RawScriptSignatureParser.write(scriptSig) must be (rawScriptSig)
}
it must "read then write a raw script sig" in {
@ -81,7 +81,7 @@ class RawScriptSignatureParserTest extends FlatSpec with MustMatchers with RawSc
scriptSig.asm(3).hex must be (expectedAsm(3).hex)
scriptSig.hex must be (rawScriptSig)
write(scriptSig) must be (rawScriptSig)
RawScriptSignatureParser.write(scriptSig) must be (rawScriptSig)
}

View file

@ -11,7 +11,7 @@ import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 1/13/16.
*/
class RawTransactionInputParserTest extends FlatSpec with MustMatchers with RawTransactionInputParser with BitcoinSLogger {
class RawTransactionInputParserTest extends FlatSpec with MustMatchers {
//txid cad1082e674a7bd3bc9ab1bc7804ba8a57523607c876b8eb2cbe645f2b1803d6
val rawTxInput = "01" + "85d6b0da2edf96b282030d3f4f79d14cc8c882cfef1b3064170c850660317de100000000" + "6f0047304402207df6dd8dad22d49c3c83d8031733c32a53719278eb7985d3b35b375d776f84f102207054f9209a1e87d55feafc90aa04c33008e5bae9191da22aeaa16efde96f41f00125512102b022902a0fdd71e831c37e4136c2754a59887be0618fb75336d7ab67e2982ff551ae" + "ffffffff"
@ -20,7 +20,7 @@ class RawTransactionInputParserTest extends FlatSpec with MustMatchers with RawT
"df80e3e6eba7dcd4650281d3c13f140dafbb823a7227a78eb6ee9f6cedd04001340000006b483045022100cf317c320d078c5b884c44e7488825dab5bcdf3f88c66314ac925770cd8773a7022033fde60d33cc2842ea73fce5d9cf4f8da6fadf414a75b7085efdcd300407f438012102605c23537b27b80157c770cd23e066cd11db3800d3066a38b9b592fc08ae9c70ffffffff"
"RawTransactionInputParser" must "parse a raw serialized transaction input" in {
val txInputs : Seq[TransactionInput] = read(rawTxInput)
val txInputs : Seq[TransactionInput] = RawTransactionInputParser.read(rawTxInput)
txInputs.head.previousOutput.vout must be (UInt32.zero)
txInputs.head.previousOutput.txId.hex must be (BitcoinSUtil.flipEndianness("e17d316006850c1764301befcf82c8c84cd1794f3f0d0382b296df2edab0d685"))
txInputs.head.scriptSignature.hex must be (TestUtil.rawP2shInputScript)

View file

@ -14,14 +14,14 @@ import org.scalatest.{FlatSpec, MustMatchers}
* Created by chris on 1/11/16.
* https://bitcoin.org/en/developer-reference#txout
*/
class RawTransactionOutputParserTest extends FlatSpec with MustMatchers with RawTransactionOutputParser {
class RawTransactionOutputParserTest extends FlatSpec with MustMatchers {
//txid cad1082e674a7bd3bc9ab1bc7804ba8a57523607c876b8eb2cbe645f2b1803d6
val rawTxOutput = "02204e00000000000017a914eda8ae08b5c9f973f49543e90a7c292367b3337c87" +
"197d2d000000000017a914be2319b9060429692ebeffaa3be38497dc5380c887"
"RawTransactionOutputTest" must "read a serialized tx output" in {
val txOutput : Seq[TransactionOutput] = read(rawTxOutput)
val txOutput : Seq[TransactionOutput] = RawTransactionOutputParser.read(rawTxOutput)
val firstOutput = txOutput.head
val secondOutput = txOutput(1)
firstOutput.value must be (Satoshis(Int64(20000)))
@ -31,13 +31,13 @@ class RawTransactionOutputParserTest extends FlatSpec with MustMatchers with Raw
}
it must "seralialize a transaction output" in {
val txOutput = read(rawTxOutput)
write(txOutput) must be (rawTxOutput)
val txOutput = RawTransactionOutputParser.read(rawTxOutput)
RawTransactionOutputParser.write(txOutput) must be (rawTxOutput)
}
it must "serialize a single transaction output not in a sequence" in {
val txOutputs = read(rawTxOutput)
write(txOutputs.head) must be ("204e00000000000017a914eda8ae08b5c9f973f49543e90a7c292367b3337c87")
val txOutputs = RawTransactionOutputParser.read(rawTxOutput)
RawTransactionOutputParser.write(txOutputs.head) must be ("204e00000000000017a914eda8ae08b5c9f973f49543e90a7c292367b3337c87")
}

View file

@ -12,7 +12,7 @@ import scala.io.Source
/**
* Created by tom on 5/17/16.
*/
class Base58Test extends FlatSpec with MustMatchers with BitcoinSLogger {
class Base58Test extends FlatSpec with MustMatchers {
"Base58" must "encode byte value of 0 to character of 1" in {
Base58.encode(0.toByte) must be ("1")
}
@ -96,7 +96,6 @@ class Base58Test extends FlatSpec with MustMatchers with BitcoinSLogger {
Base58.isValid(testCase.addressOrWIFPrivKey.left.get.value) must be (true)
}
else {
logger.info(testCase.addressOrWIFPrivKey.right.get + " should be true, but showed as " + Base58.isValid(testCase.addressOrWIFPrivKey.right.get))
Base58.isValid(testCase.addressOrWIFPrivKey.right.get) must be (true)
}
}

View file

@ -5,7 +5,7 @@ import org.scalacheck.{Gen, Prop, Properties}
/**
* Created by chris on 6/20/16.
*/
class BitcoinSUtilSpec extends Properties("BitcoinSUtilSpec") with BitcoinSLogger {
class BitcoinSUtilSpec extends Properties("BitcoinSUtilSpec") {
property("Serialization symmetry for encodeHex & decodeHex") =
Prop.forAll(StringGenerators.hexString) { hex : String =>

View file

@ -15,7 +15,7 @@ trait ConfigParams {
case class ConfigParamsImpl(addrTypeOrIsCompressed : Either[String, Boolean], isPrivKey : Boolean,
isTestNet : Boolean) extends ConfigParams
object ConfigParamsProtocol extends DefaultJsonProtocol with BitcoinSLogger {
object ConfigParamsProtocol extends DefaultJsonProtocol {
val addrTypeKey = "addrType"
val isCompressedKey = "isCompressed"
val isPrivKeyKey = "isPrivkey"