Implemented CryptoPrices (Coinbase API), replacing the Bitcoin module.
This commit is contained in:
parent
1f965a1833
commit
f580f0f7f2
7 changed files with 145 additions and 168 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* BitcoinTest.kt
|
||||
* CryptoPricesTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2021, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -31,25 +31,43 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
|
||||
import net.thauvin.erik.crypto.CryptoException
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.Bitcoin.Companion.marketPrice
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The `BitcoinTest` class.
|
||||
* The `CryptoPricesTest` class.
|
||||
*/
|
||||
class BitcoinTest : LocalProperties() {
|
||||
class CryptoPricesTest {
|
||||
@Test
|
||||
@Throws(ModuleException::class)
|
||||
fun testMarketPrice() {
|
||||
var messages = marketPrice("USD")
|
||||
assertThat(messages).`as`("not empty").isNotEmpty
|
||||
assertThat(messages[0].msg).`as`("bitcoin, BTC, $").startsWith("Bitcoin").contains("BTC").contains("$")
|
||||
//assertThat(messages[1].msg).`as`("15m").contains("15m")
|
||||
var price = marketPrice("BTC", "USD")
|
||||
assertThat(price.base).`as`("is BTC").isEqualTo("BTC")
|
||||
assertThat(price.currency).`as`("is USD").isEqualTo("USD")
|
||||
assertThat(price.amount).`as`("BTC > 0").isGreaterThan(0.00)
|
||||
|
||||
messages = marketPrice("GBP")
|
||||
assertThat(messages[0].msg).`as`("£").contains("£").contains("GBP")
|
||||
//assertThat(messages[1].msg).`as`("GBP 15m").contains("15m")
|
||||
price = marketPrice("ETH", "EUR")
|
||||
assertThat(price.base).`as`("is ETH").isEqualTo("ETH")
|
||||
assertThat(price.currency).`as`("is EUR").isEqualTo("EUR")
|
||||
assertThat(price.amount).`as`("ETH > 0").isGreaterThan(0.00)
|
||||
|
||||
price = marketPrice("ETH2", "GBP")
|
||||
assertThat(price.base).`as`("is ETH2").isEqualTo("ETH2")
|
||||
assertThat(price.currency).`as`("is GBP").isEqualTo("GBP")
|
||||
assertThat(price.amount).`as`("ETH2 > 0").isGreaterThan(0.00)
|
||||
|
||||
assertThatThrownBy { marketPrice("FOO", "USD") }
|
||||
.`as`("FOO")
|
||||
.isInstanceOf(CryptoException::class.java)
|
||||
.hasMessageContaining("Invalid base currency")
|
||||
|
||||
assertThatThrownBy { marketPrice("FOO", "BAR") }
|
||||
.`as`("FOO-BAR")
|
||||
.isInstanceOf(CryptoException::class.java)
|
||||
.hasMessageContaining("Invalid currency (BAR)")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue