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 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.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.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.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 sealed abstract class NetworkResult
@ -98,14 +99,12 @@ case class GetMemPoolEntryResult(
modifiedfee: Bitcoins, modifiedfee: Bitcoins,
time: UInt32, time: UInt32,
height: Int, height: Int,
startingpriority: BigDecimal,
currentpriority: BigDecimal,
descendantcount: Int, descendantcount: Int,
descendantsize: Int, descendantsize: Int,
descendantfees: Int, descendantfees: Bitcoins, // Should be BitcoinFeeUnit
ancestorcount: Int, ancestorcount: Int,
ancestorsize: Int, ancestorsize: Int,
ancestorfees: Int, ancestorfees: Bitcoins, // Should be BitcoinFeeUnit
depends: Option[Vector[DoubleSha256Digest]]) extends NetworkResult depends: Option[Vector[DoubleSha256Digest]]) extends NetworkResult
case class GetMemPoolInfoResult( case class GetMemPoolInfoResult(
@ -113,7 +112,7 @@ case class GetMemPoolInfoResult(
bytes: Int, bytes: Int,
usage: Int, usage: Int,
maxmempool: Int, maxmempool: Int,
mempoolminfee: Bitcoins, mempoolminfee: BitcoinFeeUnit,
minrelaytxfee: Bitcoins) extends NetworkResult minrelaytxfee: Bitcoins) extends NetworkResult
case class GetTxOutSetInfoResult( case class GetTxOutSetInfoResult(
@ -121,8 +120,9 @@ case class GetTxOutSetInfoResult(
bestblock: DoubleSha256Digest, bestblock: DoubleSha256Digest,
transactions: Int, transactions: Int,
txouts: Int, txouts: Int,
bytes_serialized: Int, bogosize: Int,
hash_serialized: DoubleSha256Digest, hash_serialized_2: DoubleSha256Digest,
disk_size: Int,
total_amount: Bitcoins) extends NetworkResult total_amount: Bitcoins) extends NetworkResult
case class GetBlockResult( case class GetBlockResult(
@ -174,7 +174,7 @@ case class RpcTransaction(
locktime: UInt32, locktime: UInt32,
vin: Vector[TransactionInput], vin: Vector[TransactionInput],
vout: Vector[RpcTransactionOutput], vout: Vector[RpcTransactionOutput],
hex: Option[Block]) extends NetworkResult hex: Option[Transaction]) extends NetworkResult
case class RpcTransactionOutput( case class RpcTransactionOutput(
value: Bitcoins, value: Bitcoins,
@ -184,9 +184,9 @@ case class RpcTransactionOutput(
case class RpcScriptPubKey( case class RpcScriptPubKey(
asm: String, asm: String,
hex: String, hex: String,
reqSigs: Int, reqSigs: Option[Int],
scriptType: String, scriptType: String,
addresses: Vector[BitcoinAddress]) extends NetworkResult addresses: Option[Vector[BitcoinAddress]]) extends NetworkResult
case class ListSinceBlockResult( case class ListSinceBlockResult(
@ -195,7 +195,7 @@ case class ListSinceBlockResult(
case class Payment( case class Payment(
involvesWatchonly: Option[Boolean], involvesWatchonly: Option[Boolean],
account: String, account: Option[String],
address: Option[BitcoinAddress], address: Option[BitcoinAddress],
category: String, category: String,
amount: Bitcoins, amount: Bitcoins,
@ -212,11 +212,10 @@ case class Payment(
timereceived: UInt32, timereceived: UInt32,
bip125_replaceable: String, bip125_replaceable: String,
comment: Option[String], comment: Option[String],
to: Option[String], to: Option[String]) extends NetworkResult
lastblock: DoubleSha256Digest) extends NetworkResult
case class ListTransactionsResult( case class ListTransactionsResult(
account: String, account: Option[String],
address: Option[BitcoinAddress], address: Option[BitcoinAddress],
category: String, category: String,
amount: Bitcoins, amount: Bitcoins,
@ -332,4 +331,10 @@ case class Bip9Softfork(
startTime: Int, startTime: Int,
timeout: BigInt, timeout: BigInt,
since: Int 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.{Address, BitcoinAddress, P2PKHAddress, P2SHAddress}
import org.bitcoins.core.protocol.script.ScriptPubKey import org.bitcoins.core.protocol.script.ScriptPubKey
import org.bitcoins.core.protocol.transaction.Transaction import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
sealed abstract class WalletResult sealed abstract class WalletResult
@ -19,9 +20,10 @@ case class GetWalletInfoResult(
keypoololdest: UInt32, keypoololdest: UInt32,
keypoolsize: Int, keypoolsize: Int,
keypoolsize_hd_internal: Int, keypoolsize_hd_internal: Int,
paytxfee: Bitcoins, // Should be BitcoinFeeUnit paytxfee: BitcoinFeeUnit,
hdmasterkeyid: Sha256Hash160Digest, hdmasterkeyid: Sha256Hash160Digest,
unlocked_until: Option[Int]) extends WalletResult unlocked_until: Option[Int]) extends WalletResult
case class BumpFeeResult( case class BumpFeeResult(
txid: DoubleSha256Digest, txid: DoubleSha256Digest,
origfee: Bitcoins, origfee: Bitcoins,

View File

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