Skip to content

Commit

Permalink
Use bitcoin 0.18.1 in the test (#1148)
Browse files Browse the repository at this point in the history
* Use bitcoin 0.18.1 during test
  • Loading branch information
araspitzu authored Oct 3, 2019
1 parent 320af43 commit 37cc526
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 96 deletions.
18 changes: 9 additions & 9 deletions eclair-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<bitcoind.url>https://bitcoin.org/bin/bitcoin-core-0.17.1/bitcoin-0.17.1-x86_64-linux-gnu.tar.gz
<bitcoind.url>https://bitcoin.org/bin/bitcoin-core-0.18.1/bitcoin-0.18.1-x86_64-linux-gnu.tar.gz
</bitcoind.url>
<bitcoind.md5>724043999e2b5ed0c088e8db34f15d43</bitcoind.md5>
<bitcoind.sha1>546ee35d4089c7ccc040a01cdff3362599b8bc53</bitcoind.sha1>
<bitcoind.md5>d3159a28702ca0cba2e0459e83219dfb</bitcoind.md5>
<bitcoind.sha1>969020835c1f0c759032def0d7b99669db06d8f7</bitcoind.sha1>
</properties>
</profile>
<profile>
Expand All @@ -93,10 +93,10 @@
</os>
</activation>
<properties>
<bitcoind.url>https://bitcoin.org/bin/bitcoin-core-0.17.1/bitcoin-0.17.1-osx64.tar.gz
<bitcoind.url>https://bitcoin.org/bin/bitcoin-core-0.18.1/bitcoin-0.18.1-osx64.tar.gz
</bitcoind.url>
<bitcoind.md5>b5a792c6142995faa42b768273a493bd</bitcoind.md5>
<bitcoind.sha1>8bd51c7024d71de07df381055993e9f472013db8</bitcoind.sha1>
<bitcoind.md5>0334b1024f28e83341c89df14e622bb6</bitcoind.md5>
<bitcoind.sha1>80354b40b409f342f5d35acd6b2c0e71f689285b</bitcoind.sha1>
</properties>
</profile>
<profile>
Expand All @@ -107,9 +107,9 @@
</os>
</activation>
<properties>
<bitcoind.url>https://bitcoin.org/bin/bitcoin-core-0.17.1/bitcoin-0.17.1-win64.zip</bitcoind.url>
<bitcoind.md5>b0e824e9dd02580b5b01f073f3c89858</bitcoind.md5>
<bitcoind.sha1>4e17bad7d08c465b444143a93cd6eb1c95076e3f</bitcoind.sha1>
<bitcoind.url>https://bitcoin.org/bin/bitcoin-core-0.18.1/bitcoin-0.18.1-win64.zip</bitcoind.url>
<bitcoind.md5>637776ca50b4354ca2f523bdee576bdb</bitcoind.md5>
<bitcoind.sha1>44771cc2161853b5230a7a159278dc8f27e7d4c2</bitcoind.sha1>
</properties>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import fr.acinq.eclair.blockchain._
import fr.acinq.eclair.blockchain.bitcoind.BitcoinCoreWallet.FundTransactionResponse
import fr.acinq.eclair.blockchain.bitcoind.rpc.{BasicBitcoinJsonRPCClient, JsonRPCError}
import fr.acinq.eclair.transactions.Scripts
import fr.acinq.eclair.{LongToBtcAmount, addressToPublicKeyScript, randomKey}
import fr.acinq.eclair.{LongToBtcAmount, TestConstants, addressToPublicKeyScript, randomKey}
import grizzled.slf4j.Logging
import org.json4s.JsonAST._
import org.json4s.{DefaultFormats, JString}
import org.json4s.JsonAST.{JString, _}
import org.json4s.DefaultFormats
import org.scalatest.{BeforeAndAfterAll, FunSuiteLike}

import scala.collection.JavaConversions._
Expand Down Expand Up @@ -275,8 +275,7 @@ class BitcoinCoreWalletSpec extends TestKit(ActorSystem("test")) with BitcoindSe
wallet.doubleSpent(tx1).pipeTo(sender.ref)
sender.expectMsg(false)
// let's confirm tx2
sender.send(bitcoincli, BitcoinReq("generate", 1))
sender.expectMsgType[JValue](10 seconds)
generateBlocks(bitcoincli, 1)
// this time tx1 has been double spent
wallet.doubleSpent(tx1).pipeTo(sender.ref)
sender.expectMsg(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait BitcoindService extends Logging {
val INTEGRATION_TMP_DIR = new File(TestUtils.BUILD_DIRECTORY, s"integration-${UUID.randomUUID()}")
logger.info(s"using tmp dir: $INTEGRATION_TMP_DIR")

val PATH_BITCOIND = new File(TestUtils.BUILD_DIRECTORY, "bitcoin-0.17.1/bin/bitcoind")
val PATH_BITCOIND = new File(TestUtils.BUILD_DIRECTORY, "bitcoin-0.18.1/bin/bitcoind")
val PATH_BITCOIND_DATADIR = new File(INTEGRATION_TMP_DIR, "datadir-bitcoin")

var bitcoind: Process = null
Expand Down Expand Up @@ -107,14 +107,26 @@ trait BitcoindService extends Logging {
}
}, max = 3 minutes, interval = 2 seconds)
logger.info(s"generating initial blocks...")
sender.send(bitcoincli, BitcoinReq("generate", 150))
val JArray(res) = sender.expectMsgType[JValue](3 minutes)
assert(res.size == 150)
generateBlocks(bitcoincli, 150)
awaitCond({
sender.send(bitcoincli, BitcoinReq("getbalance"))
val JDecimal(balance) = sender.expectMsgType[JDecimal](30 seconds)
balance > 100
}, max = 3 minutes, interval = 2 second)
}

def generateBlocks(bitcoinCli: ActorRef, blockCount: Int, address: Option[String] = None, timeout: FiniteDuration = 10 seconds)(implicit system: ActorSystem): Unit = {
val sender = TestProbe()
val addressToUse = address match {
case Some(addr) => addr
case None =>
sender.send(bitcoinCli, BitcoinReq("getnewaddress"))
val JString(address) = sender.expectMsgType[JValue](timeout)
address
}
sender.send(bitcoinCli, BitcoinReq("generatetoaddress", blockCount, addressToUse))
val JArray(blocks) = sender.expectMsgType[JValue](timeout)
assert(blocks.size == blockCount)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import com.typesafe.config.ConfigFactory
import fr.acinq.bitcoin.Transaction
import fr.acinq.eclair.blockchain.bitcoind.rpc.{BasicBitcoinJsonRPCClient, ExtendedBitcoinClient}
import grizzled.slf4j.Logging
import org.json4s.JsonAST._
import org.json4s.{DefaultFormats, JString}
import org.json4s.JsonAST.{JString, _}
import org.json4s.{DefaultFormats}
import org.scalatest.{BeforeAndAfterAll, FunSuiteLike}

import scala.collection.JavaConversions._
Expand Down Expand Up @@ -88,7 +88,9 @@ class ExtendedBitcoinClientSpec extends TestKit(ActorSystem("test")) with Bitcoi
client.publishTransaction(tx).pipeTo(sender.ref)
sender.expectMsg(txid)
// let's confirm the tx
bitcoinClient.invoke("generate", 1).pipeTo(sender.ref)
sender.send(bitcoincli, BitcoinReq("getnewaddress"))
val JString(generatingAddress) = sender.expectMsgType[JValue]
bitcoinClient.invoke("generatetoaddress", 1, generatingAddress).pipeTo(sender.ref)
sender.expectMsgType[JValue]
// and publish the tx a third time to test idempotence
client.publishTransaction(tx).pipeTo(sender.ref)
Expand All @@ -110,7 +112,7 @@ class ExtendedBitcoinClientSpec extends TestKit(ActorSystem("test")) with Bitcoi
client.publishTransaction(tx).pipeTo(sender.ref)
sender.expectMsg(txid)
// let's confirm the tx
bitcoinClient.invoke("generate", 1).pipeTo(sender.ref)
bitcoinClient.invoke("generatetoaddress", 1, generatingAddress).pipeTo(sender.ref)
sender.expectMsgType[JValue]
// and publish the tx a fifth time to test idempotence
client.publishTransaction(tx).pipeTo(sender.ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
sender.receiveOne(5 second).isInstanceOf[JValue]
}, max = 30 seconds, interval = 500 millis)
logger.info(s"generating initial blocks...")
sender.send(bitcoincli, BitcoinReq("generate", 150))
sender.expectMsgType[JValue](30 seconds)
generateBlocks(bitcoincli, 150, timeout = 30 seconds)
DockerReadyChecker.LogLineContains("INFO:BlockProcessor:height: 151").looped(attempts = 15, delay = 1 second)
}

Expand Down Expand Up @@ -119,9 +118,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
}, max = 30 seconds, interval = 1 second)

// confirm our tx
probe.send(bitcoincli, BitcoinReq("generate", 1))
probe.expectMsgType[JValue]

generateBlocks(bitcoincli, 1)
awaitCond({
val GetBalanceResponse(confirmed1, unconfirmed1) = getBalance(probe)
confirmed1 == confirmed + 100000000.sat
Expand All @@ -135,9 +132,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
logger.info(s"sending 0.5 btc to $address1")
probe.send(bitcoincli, BitcoinReq("sendtoaddress", address1, 0.5))
probe.expectMsgType[JValue]

probe.send(bitcoincli, BitcoinReq("generate", 1))
probe.expectMsgType[JValue]
generateBlocks(bitcoincli, 1)

awaitCond({
val GetBalanceResponse(confirmed1, _) = getBalance(probe)
Expand Down Expand Up @@ -172,9 +167,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
unconfirmed1 == unconfirmed + amount + amount
}, max = 30 seconds, interval = 1 second)

probe.send(bitcoincli, BitcoinReq("generate", 1))
probe.expectMsgType[JValue]

generateBlocks(bitcoincli, 1)
awaitCond({
val GetBalanceResponse(confirmed1, _) = getBalance(probe)
confirmed1 == confirmed + amount + amount
Expand Down Expand Up @@ -204,9 +197,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
assert(received === 100000000.sat)

logger.info("generating a new block")
probe.send(bitcoincli, BitcoinReq("generate", 1))
probe.expectMsgType[JValue]

generateBlocks(bitcoincli, 1)
awaitCond({
val GetBalanceResponse(confirmed1, _) = getBalance(probe)
confirmed1 - confirmed === 100000000.sat
Expand Down Expand Up @@ -237,8 +228,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
probe.send(wallet, BroadcastTransaction(tx1))
val BroadcastTransactionResponse(_, None) = probe.expectMsgType[BroadcastTransactionResponse]

probe.send(bitcoincli, BitcoinReq("generate", 1))
probe.expectMsgType[JValue]
generateBlocks(bitcoincli, 1)

awaitCond({
probe.send(bitcoincli, BitcoinReq("getreceivedbyaddress", address))
Expand Down Expand Up @@ -270,8 +260,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
probe.send(wallet, BroadcastTransaction(tx1))
val BroadcastTransactionResponse(_, None) = probe.expectMsgType[BroadcastTransactionResponse]

probe.send(bitcoincli, BitcoinReq("generate", 1))
probe.expectMsgType[JValue]
generateBlocks(bitcoincli, 1)

awaitCond({
val GetBalanceResponse(confirmed1, _) = getBalance(probe)
Expand Down Expand Up @@ -328,8 +317,7 @@ class ElectrumWalletSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
probe.send(wallet, IsDoubleSpent(tx2))
probe.expectMsg(IsDoubleSpentResponse(tx2, false))

probe.send(bitcoincli, BitcoinReq("generate", 2))
probe.expectMsgType[JValue]
generateBlocks(bitcoincli, 2)

awaitCond({
probe.send(wallet, GetData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import fr.acinq.eclair.blockchain.electrum.ElectrumClientPool.ElectrumServerAddr
import fr.acinq.eclair.blockchain._
import fr.acinq.eclair.channel.{BITCOIN_FUNDING_DEPTHOK, BITCOIN_FUNDING_SPENT}
import grizzled.slf4j.Logging
import org.json4s
import org.json4s.JsonAST.{JArray, JString, JValue}
import org.scalatest.{BeforeAndAfterAll, FunSuiteLike}
import scodec.bits._
Expand Down Expand Up @@ -72,9 +73,7 @@ class ElectrumWatcherSpec extends TestKit(ActorSystem("test")) with FunSuiteLike

val listener = TestProbe()
probe.send(watcher, WatchConfirmed(listener.ref, tx.txid, tx.txOut(0).publicKeyScript, 4, BITCOIN_FUNDING_DEPTHOK))
probe.send(bitcoincli, BitcoinReq("generate", 3))
listener.expectNoMsg(1 second)
probe.send(bitcoincli, BitcoinReq("generate", 2))
generateBlocks(bitcoincli, 5)
val confirmed = listener.expectMsgType[WatchEventConfirmed](20 seconds)
assert(confirmed.tx.txid.toHex === txid)
system.stop(watcher)
Expand Down Expand Up @@ -119,10 +118,8 @@ class ElectrumWatcherSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
listener.expectNoMsg(1 second)
probe.send(bitcoincli, BitcoinReq("sendrawtransaction", spendingTx.toString))
probe.expectMsgType[JValue]
probe.send(bitcoincli, BitcoinReq("generate", 2))
val blocks = probe.expectMsgType[JValue]
val JArray(List(JString(block1), JString(block2))) = blocks
val spent = listener.expectMsgType[WatchEventSpent](20 seconds)
generateBlocks(bitcoincli, 2)
listener.expectMsgType[WatchEventSpent](20 seconds)
system.stop(watcher)
}

Expand Down
Loading

0 comments on commit 37cc526

Please sign in to comment.