solution: revise for the latest etherjar

This commit is contained in:
Igor Artamonov
2019-10-26 23:33:12 -04:00
parent bc6fd4d1db
commit 90648ecd8c
4 changed files with 14 additions and 11 deletions

View File

@@ -52,7 +52,7 @@ class StreamHead(
return BlockchainOuterClass.ChainHead.newBuilder() return BlockchainOuterClass.ChainHead.newBuilder()
.setChainValue(chain.id) .setChainValue(chain.id)
.setHeight(block.number) .setHeight(block.number)
.setTimestamp(block.timestamp.time) .setTimestamp(block.timestamp.toEpochMilli())
.setWeight(ByteString.copyFrom(block.totalDifficulty.toByteArray())) .setWeight(ByteString.copyFrom(block.totalDifficulty.toByteArray()))
.setBlockId(block.hash.toHex().substring(2)) .setBlockId(block.hash.toHex().substring(2))
.build() .build()

View File

@@ -197,7 +197,7 @@ class TrackTx(
return if (block.number != null && block.totalDifficulty != null) { return if (block.number != null && block.totalDifficulty != null) {
tx.withStatus( tx.withStatus(
blockTotalDifficulty = block.totalDifficulty, blockTotalDifficulty = block.totalDifficulty,
blockTime = block.timestamp.toInstant() blockTime = block.timestamp
) )
} else { } else {
tx.withStatus( tx.withStatus(

View File

@@ -26,11 +26,13 @@ import io.emeraldpay.grpc.Chain
import io.infinitape.etherjar.domain.BlockHash import io.infinitape.etherjar.domain.BlockHash
import io.infinitape.etherjar.domain.TransactionId import io.infinitape.etherjar.domain.TransactionId
import io.infinitape.etherjar.rpc.json.BlockJson import io.infinitape.etherjar.rpc.json.BlockJson
import io.infinitape.etherjar.rpc.json.TransactionRefJson
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
import reactor.test.StepVerifier import reactor.test.StepVerifier
import spock.lang.Specification import spock.lang.Specification
import java.time.Duration import java.time.Duration
import java.time.Instant
class StreamHeadSpec extends Specification { class StreamHeadSpec extends Specification {
@@ -52,11 +54,11 @@ class StreamHeadSpec extends Specification {
setup: setup:
def blocks = (100..105).collect { i -> def blocks = (100..105).collect { i ->
return new BlockJson<TransactionId>().with { return new BlockJson<TransactionRefJson>().with {
it.number = i it.number = i
it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a27${i}") it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a27${i}")
it.totalDifficulty = i * 1000 it.totalDifficulty = i * 1000
it.timestamp = new Date(1566000000000 + i * 10000) it.timestamp = Instant.ofEpochMilli(1566000000000 + i * 10000)
return it return it
} }
} }
@@ -64,7 +66,7 @@ class StreamHeadSpec extends Specification {
def heads = blocks.collect { def heads = blocks.collect {
return BlockchainOuterClass.ChainHead.newBuilder() return BlockchainOuterClass.ChainHead.newBuilder()
.setChain(Common.ChainRef.CHAIN_ETHEREUM) .setChain(Common.ChainRef.CHAIN_ETHEREUM)
.setTimestamp(it.timestamp.time) .setTimestamp(it.timestamp.toEpochMilli())
.setBlockId(it.hash.toHex().substring(2)) .setBlockId(it.hash.toHex().substring(2))
.setWeight(ByteString.copyFrom(it.totalDifficulty.toByteArray())) .setWeight(ByteString.copyFrom(it.totalDifficulty.toByteArray()))
.setHeight(it.number) .setHeight(it.number)

View File

@@ -27,6 +27,7 @@ import io.infinitape.etherjar.domain.TransactionId
import io.infinitape.etherjar.rpc.ReactorRpcClient import io.infinitape.etherjar.rpc.ReactorRpcClient
import io.infinitape.etherjar.rpc.json.BlockJson import io.infinitape.etherjar.rpc.json.BlockJson
import io.infinitape.etherjar.rpc.json.TransactionJson import io.infinitape.etherjar.rpc.json.TransactionJson
import io.infinitape.etherjar.rpc.json.TransactionRefJson
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
import reactor.core.scheduler.Schedulers import reactor.core.scheduler.Schedulers
import reactor.test.StepVerifier import reactor.test.StepVerifier
@@ -51,7 +52,7 @@ class TrackTxSpec extends Specification {
def blockJson = new BlockJson().with { def blockJson = new BlockJson().with {
it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a27c22") it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a27c22")
it.timestamp = new Date(156400000000) it.timestamp = Instant.ofEpochMilli(156400000000)
it.number = 100 it.number = 100
it.totalDifficulty = BigInteger.valueOf(500) it.totalDifficulty = BigInteger.valueOf(500)
it it
@@ -59,7 +60,7 @@ class TrackTxSpec extends Specification {
def blockHeadJson = new BlockJson().with { def blockHeadJson = new BlockJson().with {
it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a27c22") it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a27c22")
it.timestamp = new Date(156400200000) it.timestamp = Instant.ofEpochMilli(156400200000)
it.number = 108 it.number = 108
it.totalDifficulty = BigInteger.valueOf(800) it.totalDifficulty = BigInteger.valueOf(800)
it it
@@ -84,7 +85,7 @@ class TrackTxSpec extends Specification {
.setHeight(blockJson.number) .setHeight(blockJson.number)
.setWeight(ByteString.copyFrom(blockJson.totalDifficulty.toByteArray())) .setWeight(ByteString.copyFrom(blockJson.totalDifficulty.toByteArray()))
.setBlockId(blockJson.hash.toHex().substring(2)) .setBlockId(blockJson.hash.toHex().substring(2))
.setTimestamp(blockJson.timestamp.getTime()) .setTimestamp(blockJson.timestamp.toEpochMilli())
).build() ).build()
def apiMock = TestingCommons.api(Stub(ReactorRpcClient)) def apiMock = TestingCommons.api(Stub(ReactorRpcClient))
@@ -230,10 +231,10 @@ class TrackTxSpec extends Specification {
.setTxId(txId) .setTxId(txId)
.build() .build()
List<BlockJson<TransactionId>> blocks = (0..9).collect { i -> List<BlockJson<TransactionRefJson>> blocks = (0..9).collect { i ->
return new BlockJson().with { return new BlockJson().with {
it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a2000${i}") it.hash = BlockHash.from("0xa0e65cbc1b52a8ca60562112c6060552d882f16f34a9dba2ccdc05c0a6a2000${i}")
it.timestamp = new Date(156400000000 + i * 10000) it.timestamp = Instant.ofEpochMilli(156400000000 + i * 10000)
it.setNumber(100L + i.longValue()) it.setNumber(100L + i.longValue())
it.totalDifficulty = BigInteger.valueOf(500 + i) it.totalDifficulty = BigInteger.valueOf(500 + i)
it it
@@ -271,7 +272,7 @@ class TrackTxSpec extends Specification {
.setHeight(blocks[2].number) .setHeight(blocks[2].number)
.setWeight(ByteString.copyFrom(blocks[2].totalDifficulty.toByteArray())) .setWeight(ByteString.copyFrom(blocks[2].totalDifficulty.toByteArray()))
.setBlockId(blocks[2].hash.toHex().substring(2)) .setBlockId(blocks[2].hash.toHex().substring(2))
.setTimestamp(blocks[2].timestamp.getTime()) .setTimestamp(blocks[2].timestamp.toEpochMilli())
) )