mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +01:00
Fix the time based test cases in BitcoindV17RpcClientTest (#1224)
This commit is contained in:
parent
69783f9ed8
commit
6e5c0e4c8e
3 changed files with 28 additions and 13 deletions
|
@ -16,7 +16,6 @@ import org.bitcoins.rpc.client.v17.BitcoindV17RpcClient
|
|||
import org.bitcoins.rpc.util.AsyncUtil
|
||||
import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil
|
||||
import org.bitcoins.testkit.util.BitcoindRpcTest
|
||||
import java.time.LocalDateTime
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
|
@ -108,13 +107,16 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
|||
} yield assert(signed.complete)
|
||||
}
|
||||
|
||||
private val SpreadInSeconds = 30
|
||||
|
||||
it should "be able to get the address info for a given address" in {
|
||||
for {
|
||||
(client, _) <- clientsF
|
||||
addr <- client.getNewAddress
|
||||
info <- client.getAddressInfo(addr)
|
||||
} yield assert(
|
||||
info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear))
|
||||
info.timestamp.map(_.toEpochSecond).getOrElse(0L) === System
|
||||
.currentTimeMillis() / 1000 +- SpreadInSeconds)
|
||||
}
|
||||
|
||||
it should "be able to get the address info for a given P2SHSegwit address" in {
|
||||
|
@ -123,7 +125,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
|||
addr <- client.getNewAddress(addressType = AddressType.P2SHSegwit)
|
||||
info <- client.getAddressInfo(addr)
|
||||
} yield assert(
|
||||
info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear))
|
||||
info.timestamp.map(_.toEpochSecond).getOrElse(0L) === System
|
||||
.currentTimeMillis() / 1000 +- SpreadInSeconds)
|
||||
}
|
||||
|
||||
it should "be able to get the address info for a given Legacy address" in {
|
||||
|
@ -132,7 +135,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
|||
addr <- client.getNewAddress(addressType = AddressType.Legacy)
|
||||
info <- client.getAddressInfo(addr)
|
||||
} yield assert(
|
||||
info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear))
|
||||
info.timestamp.map(_.toEpochSecond).getOrElse(0L) === System
|
||||
.currentTimeMillis() / 1000 +- SpreadInSeconds)
|
||||
}
|
||||
|
||||
// needs #360 to be merged
|
||||
|
@ -144,7 +148,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
|||
} yield {
|
||||
assert(info.address.networkParameters == RegTest)
|
||||
assert(
|
||||
info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear))
|
||||
info.timestamp.map(_.toEpochSecond).getOrElse(0L) === System
|
||||
.currentTimeMillis() / 1000 +- SpreadInSeconds)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.rpc.jsonmodels
|
||||
|
||||
import java.io.File
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
import org.bitcoins.core.crypto.{
|
||||
DoubleSha256DigestBE,
|
||||
|
@ -221,7 +221,7 @@ case class AddressInfoResult(
|
|||
pubkey: Option[ECPublicKey],
|
||||
embedded: Option[EmbeddedResult],
|
||||
label: String,
|
||||
timestamp: Option[LocalDateTime],
|
||||
timestamp: Option[ZonedDateTime],
|
||||
hdkeypath: Option[BIP32Path],
|
||||
hdseedid: Option[RipeMd160Digest],
|
||||
hdmasterkeyid: Option[RipeMd160Digest],
|
||||
|
|
|
@ -2,12 +2,13 @@ package org.bitcoins.rpc.serializers
|
|||
|
||||
import java.io.File
|
||||
import java.net.{InetAddress, URI}
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset
|
||||
import java.time._
|
||||
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency.{Bitcoins, Satoshis}
|
||||
import org.bitcoins.core.number.{Int32, UInt32, UInt64}
|
||||
import org.bitcoins.core.p2p.ServiceIdentifier
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock}
|
||||
import org.bitcoins.core.protocol.script.{
|
||||
ScriptPubKey,
|
||||
|
@ -31,8 +32,6 @@ import org.bitcoins.rpc.serializers.JsonSerializers._
|
|||
import play.api.libs.json._
|
||||
|
||||
import scala.util.{Failure, Success, Try}
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.p2p.ServiceIdentifier
|
||||
|
||||
object JsonReaders {
|
||||
|
||||
|
@ -67,10 +66,21 @@ object JsonReaders {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
implicit object ZonedDateTimeReads extends Reads[ZonedDateTime] {
|
||||
override def reads(json: JsValue): JsResult[ZonedDateTime] =
|
||||
SerializerUtil.processJsNumberBigInt[ZonedDateTime](
|
||||
bigInt =>
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochSecond(bigInt.toLong),
|
||||
ZoneOffset.UTC))(json)
|
||||
}
|
||||
|
||||
implicit object LocalDateTimeReads extends Reads[LocalDateTime] {
|
||||
override def reads(json: JsValue): JsResult[LocalDateTime] =
|
||||
SerializerUtil.processJsNumberBigInt[LocalDateTime](bigInt =>
|
||||
LocalDateTime.ofEpochSecond(bigInt.toLong, 0, ZoneOffset.UTC))(json)
|
||||
SerializerUtil.processJsNumberBigInt[LocalDateTime](
|
||||
bigInt =>
|
||||
LocalDateTime.ofInstant(Instant.ofEpochSecond(bigInt.toLong),
|
||||
ZoneId.systemDefault()))(json)
|
||||
}
|
||||
|
||||
implicit object BigIntReads extends Reads[BigInt] {
|
||||
|
|
Loading…
Add table
Reference in a new issue