Added a bunch of tests

This commit is contained in:
nkohen 2018-06-07 16:19:43 -05:00
parent 53a617fea6
commit bce491f5ec
3 changed files with 42 additions and 32 deletions

View File

@ -2,13 +2,14 @@ package org.bitcoins.rpc.jsonmodels
import java.net.InetAddress
import org.bitcoins.core.crypto.{ DoubleSha256Digest, ECPublicKey, Sha256Hash160Digest }
import org.bitcoins.core.crypto.{DoubleSha256Digest, ECPublicKey, Sha256Hash160Digest}
import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.core.number.{ Int32, UInt32 }
import org.bitcoins.core.number.{Int32, UInt32}
import org.bitcoins.core.protocol.blockchain.Block
import org.bitcoins.core.protocol.{ Address, BitcoinAddress }
import org.bitcoins.core.protocol.{Address, BitcoinAddress}
import org.bitcoins.core.protocol.script.ScriptPubKey
import org.bitcoins.core.protocol.transaction.{ Transaction, TransactionInput }
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput}
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
sealed abstract class NetworkResult
@ -98,14 +99,12 @@ case class GetMemPoolEntryResult(
modifiedfee: Bitcoins,
time: UInt32,
height: Int,
startingpriority: BigDecimal,
currentpriority: BigDecimal,
descendantcount: Int,
descendantsize: Int,
descendantfees: Int,
descendantfees: Bitcoins, // Should be BitcoinFeeUnit
ancestorcount: Int,
ancestorsize: Int,
ancestorfees: Int,
ancestorfees: Bitcoins, // Should be BitcoinFeeUnit
depends: Option[Vector[DoubleSha256Digest]]) extends NetworkResult
case class GetMemPoolInfoResult(
@ -113,7 +112,7 @@ case class GetMemPoolInfoResult(
bytes: Int,
usage: Int,
maxmempool: Int,
mempoolminfee: Bitcoins,
mempoolminfee: BitcoinFeeUnit,
minrelaytxfee: Bitcoins) extends NetworkResult
case class GetTxOutSetInfoResult(
@ -121,8 +120,9 @@ case class GetTxOutSetInfoResult(
bestblock: DoubleSha256Digest,
transactions: Int,
txouts: Int,
bytes_serialized: Int,
hash_serialized: DoubleSha256Digest,
bogosize: Int,
hash_serialized_2: DoubleSha256Digest,
disk_size: Int,
total_amount: Bitcoins) extends NetworkResult
case class GetBlockResult(
@ -174,7 +174,7 @@ case class RpcTransaction(
locktime: UInt32,
vin: Vector[TransactionInput],
vout: Vector[RpcTransactionOutput],
hex: Option[Block]) extends NetworkResult
hex: Option[Transaction]) extends NetworkResult
case class RpcTransactionOutput(
value: Bitcoins,
@ -184,9 +184,9 @@ case class RpcTransactionOutput(
case class RpcScriptPubKey(
asm: String,
hex: String,
reqSigs: Int,
reqSigs: Option[Int],
scriptType: String,
addresses: Vector[BitcoinAddress]) extends NetworkResult
addresses: Option[Vector[BitcoinAddress]]) extends NetworkResult
case class ListSinceBlockResult(
@ -195,7 +195,7 @@ case class ListSinceBlockResult(
case class Payment(
involvesWatchonly: Option[Boolean],
account: String,
account: Option[String],
address: Option[BitcoinAddress],
category: String,
amount: Bitcoins,
@ -212,11 +212,10 @@ case class Payment(
timereceived: UInt32,
bip125_replaceable: String,
comment: Option[String],
to: Option[String],
lastblock: DoubleSha256Digest) extends NetworkResult
to: Option[String]) extends NetworkResult
case class ListTransactionsResult(
account: String,
account: Option[String],
address: Option[BitcoinAddress],
category: String,
amount: Bitcoins,
@ -332,4 +331,10 @@ case class Bip9Softfork(
startTime: Int,
timeout: BigInt,
since: Int
) extends NetworkResult
) extends NetworkResult
case class EstimateSmartFeeResult(
feerate: Option[BitcoinFeeUnit], // Given in BTC/kB
errors: Option[Vector[String]],
blocks: Int
) extends NetworkResult

View File

@ -6,6 +6,7 @@ import org.bitcoins.core.number.UInt32
import org.bitcoins.core.protocol.{Address, BitcoinAddress, P2PKHAddress, P2SHAddress}
import org.bitcoins.core.protocol.script.ScriptPubKey
import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
sealed abstract class WalletResult
@ -19,9 +20,10 @@ case class GetWalletInfoResult(
keypoololdest: UInt32,
keypoolsize: Int,
keypoolsize_hd_internal: Int,
paytxfee: Bitcoins, // Should be BitcoinFeeUnit
paytxfee: BitcoinFeeUnit,
hdmasterkeyid: Sha256Hash160Digest,
unlocked_until: Option[Int]) extends WalletResult
case class BumpFeeResult(
txid: DoubleSha256Digest,
origfee: Bitcoins,

View File

@ -2,17 +2,18 @@ package org.bitcoins.rpc.serializers
import java.net.InetAddress
import org.bitcoins.core.crypto.{ DoubleSha256Digest, ECPublicKey, Sha256Hash160Digest }
import org.bitcoins.core.crypto.{DoubleSha256Digest, ECPublicKey, Sha256Hash160Digest}
import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.core.number.{ Int32, UInt32 }
import org.bitcoins.core.protocol.{ Address, BitcoinAddress, P2PKHAddress, P2SHAddress }
import org.bitcoins.core.protocol.blockchain.{ Block, BlockHeader, MerkleBlock }
import org.bitcoins.core.number.{Int32, UInt32}
import org.bitcoins.core.protocol.{Address, BitcoinAddress, P2PKHAddress, P2SHAddress}
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock}
import org.bitcoins.core.protocol.script.ScriptPubKey
import org.bitcoins.core.protocol.transaction.{ Transaction, TransactionInput, TransactionOutPoint, TransactionOutput }
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput, TransactionOutPoint, TransactionOutput}
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
import org.bitcoins.rpc.jsonmodels._
import org.bitcoins.rpc.serializers.JsonReaders._
import org.bitcoins.rpc.serializers.JsonWriters._
import play.api.libs.json.{ Json, Reads, Writes, __ }
import play.api.libs.json.{Json, Reads, Writes, __}
import play.api.libs.functional.syntax._
object JsonSerializers {
@ -38,6 +39,7 @@ object JsonSerializers {
implicit val merkleBlockReads: Reads[MerkleBlock] = MerkleBlockReads
implicit val transactionReads: Reads[Transaction] = TransactionReads
implicit val transactionOutPointReads: Reads[TransactionOutPoint] = TransactionOutPointReads
implicit val bitcoinFeeUnitReads: Reads[BitcoinFeeUnit] = BitcoinFeeUnitReads
implicit val bitcoinsWrites: Writes[Bitcoins] = BitcoinsWrites
implicit val bitcoinAddressWrites: Writes[BitcoinAddress] = BitcoinAddressWrites
@ -72,9 +74,9 @@ object JsonSerializers {
implicit val rpcScriptPubKeyReads: Reads[RpcScriptPubKey] = (
(__ \ "asm").read[String] and
(__ \ "hex").read[String] and
(__ \ "reqSigs").read[Int] and
(__ \ "reqSigs").readNullable[Int] and
(__ \ "type").read[String] and
(__ \ "addresses").read[Vector[BitcoinAddress]]
(__ \ "addresses").readNullable[Vector[BitcoinAddress]]
) (RpcScriptPubKey)
implicit val rpcTransactionOutputReads: Reads[RpcTransactionOutput] = Json.reads[RpcTransactionOutput]
implicit val rpcTransactionReads: Reads[RpcTransaction] = Json.reads[RpcTransaction]
@ -82,7 +84,7 @@ object JsonSerializers {
implicit val paymentReads: Reads[Payment] = (
(__ \ "involvesWatchonly").readNullable[Boolean] and
(__ \ "account").read[String] and
(__ \ "account").readNullable[String] and
(__ \ "address").readNullable[BitcoinAddress] and
(__ \ "category").read[String] and
(__ \ "amount").read[Bitcoins] and
@ -99,13 +101,12 @@ object JsonSerializers {
(__ \ "timereceived").read[UInt32] and
(__ \ "bip125-replaceable").read[String] and
(__ \ "comment").readNullable[String] and
(__ \ "to").readNullable[String] and
(__ \ "lastblock").read[DoubleSha256Digest]
(__ \ "to").readNullable[String]
)(Payment)
implicit val listSinceBlockResultReads: Reads[ListSinceBlockResult] = Json.reads[ListSinceBlockResult]
implicit val listTransactionsResultReads: Reads[ListTransactionsResult] = (
(__ \ "account").read[String] and
(__ \ "account").readNullable[String] and
(__ \ "address").readNullable[BitcoinAddress] and
(__ \ "category").read[String] and
(__ \ "amount").read[Bitcoins] and
@ -162,6 +163,8 @@ object JsonSerializers {
implicit val bip9SoftforkReads: Reads[Bip9Softfork] = Json.reads[Bip9Softfork]
implicit val getBlockChainInfoResultReads: Reads[GetBlockChainInfoResult] = Json.reads[GetBlockChainInfoResult]
implicit val estimateSmartFeeResultReads: Reads[EstimateSmartFeeResult] = Json.reads[EstimateSmartFeeResult]
// Mining Models
implicit val miningInfoReads: Reads[GetMiningInfoResult] = Json.reads[GetMiningInfoResult]