Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics tests fixed #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ import doobie.ConnectionIO
import doobie.implicits._
import fi.spectrum.api.db.repositories.History
import fi.spectrum.api.db.{Api, PGContainer}
import fi.spectrum.api.mocks.{InsertLmCompound, InsertLmDeposit, InsertLmRedeem, MetricsMock, NetworkMock}
import fi.spectrum.api.mocks.{InsertLmDeposit, InsertLmRedeem, MetricsMock, NetworkMock}
import fi.spectrum.api.models.MempoolData
import fi.spectrum.api.v1.endpoints.models.{Paging, TimeWindow}
import fi.spectrum.api.v1.models.AssetAmountApi
import fi.spectrum.api.v1.models.history.ApiOrder.{LmDepositApi, LmRedeemApi}
import fi.spectrum.api.v1.models.history.{HistoryApiQuery, OrderStatus, TxData}
import fi.spectrum.core.domain._
import fi.spectrum.core.domain.analytics.OrderEvaluation.{LmDepositCompoundEvaluation, LmRedeemEvaluation}
import fi.spectrum.core.domain.analytics.Processed
import fi.spectrum.core.domain.order.Order.Compound.CompoundV1
import fi.spectrum.core.domain.order.Order.Deposit.LmDeposit.LmDepositV1
import fi.spectrum.core.domain.order.Order.Redeem.LmRedeem.LmRedeemV1
import fi.spectrum.core.domain.order.{OrderState, Redeemer}
import fi.spectrum.core.domain.order.OrderStatus.Registered
import fi.spectrum.core.domain.{Address, PubKey, TokenId, TxId}
import fi.spectrum.core.domain.order.{OrderState, Redeemer}
import fi.spectrum.graphite.Metrics
import fi.spectrum.parser.evaluation.ProcessedOrderParser
import fi.spectrum.parser.lm.compound.v1.Compound
import fi.spectrum.parser.lm.compound.v1.Compound.compoundBatchTx
import fi.spectrum.parser.lm.order.v1.LM
import fi.spectrum.parser.lm.pool.v1.SelfHosted
import org.scalatest.flatspec.AnyFlatSpec
Expand All @@ -38,7 +37,7 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi

"Mempool api" should "process lm register deposit correct" in {
val registerOrder = Processed(
LM.deposit,
LM.altDeposit,
OrderState(TxId("b5038999043e6ecd617a0a292976fe339d0e4d9ec85296f13610be0c7b16752e"), 0, Registered),
None,
None,
Expand Down Expand Up @@ -74,14 +73,18 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi

"Mempool api" should "process lm eval (both orders are in mempool) deposit correct" in {
val registerOrder = Processed(
LM.deposit,
LM.altDeposit,
OrderState(TxId("b5038999043e6ecd617a0a292976fe339d0e4d9ec85296f13610be0c7b16752e"), 0, Registered),
None,
None,
None
).asInstanceOf[Processed.Any]
val evalOrder =
ProcessedOrderParser.make[IO].evaluated(LM.tx, 0, registerOrder, SelfHosted.pool, 0, List.empty).unsafeRunSync().get
ProcessedOrderParser
.make[IO]
.evaluated(LM.tx, 0, registerOrder, SelfHosted.pool, 0, List.empty)
.unsafeRunSync()
.get

val data = MempoolData(
Address.fromStringUnsafe("9i245HdmSYwYsVR2qudtULu3BRBenPagNbT6uLi2Np9QZzdQWGH"),
Expand All @@ -99,7 +102,10 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi
SelfHosted.pool.poolId,
LM.deposit.params.expectedNumEpochs,
AssetAmountApi.fromAssetAmount(LM.deposit.params.tokens),
evalOrder.evaluation.flatMap(_.widen[LmDepositCompoundEvaluation]).map(_.tokens).map(AssetAmountApi.fromAssetAmount),
evalOrder.evaluation
.flatMap(_.widen[LmDepositCompoundEvaluation])
.map(_.tokens)
.map(AssetAmountApi.fromAssetAmount),
evalOrder.evaluation
.flatMap(_.widen[LmDepositCompoundEvaluation])
.map(_.bundle.id)
Expand All @@ -114,14 +120,18 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi

"Mempool api" should "process lm eval (only eval order is in mempool) deposit correct" in {
val registerOrder = Processed(
LM.deposit,
LM.altDeposit,
OrderState(TxId("b5038999043e6ecd617a0a292976fe339d0e4d9ec85296f13610be0c7b16752e"), 0, Registered),
None,
None,
None
).asInstanceOf[Processed.Any]
val evalOrder =
ProcessedOrderParser.make[IO].evaluated(LM.tx, 0, registerOrder, SelfHosted.pool, 0, List.empty).unsafeRunSync().get
ProcessedOrderParser
.make[IO]
.evaluated(compoundBatchTx, 0, registerOrder, SelfHosted.pool, 0, List.empty)
.unsafeRunSync()
.get

val data = MempoolData(
Address.fromStringUnsafe("9i245HdmSYwYsVR2qudtULu3BRBenPagNbT6uLi2Np9QZzdQWGH"),
Expand All @@ -147,7 +157,10 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi
SelfHosted.pool.poolId,
LM.deposit.params.expectedNumEpochs,
AssetAmountApi.fromAssetAmount(LM.deposit.params.tokens),
evalOrder.evaluation.flatMap(_.widen[LmDepositCompoundEvaluation]).map(_.tokens).map(AssetAmountApi.fromAssetAmount),
evalOrder.evaluation
.flatMap(_.widen[LmDepositCompoundEvaluation])
.map(_.tokens)
.map(AssetAmountApi.fromAssetAmount),
evalOrder.evaluation
.flatMap(_.widen[LmDepositCompoundEvaluation])
.map(_.bundle.id)
Expand Down Expand Up @@ -223,7 +236,7 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi
val expected = LmRedeemApi(
registerOrder.order.id,
OrderStatus.Pending,
SelfHosted.pool.poolId.some,
none,
LM.redeem.bundleKeyId,
AssetAmountApi.fromAssetAmount(LM.redeem.expectedLq),
evalOrder.evaluation.flatMap(_.widen[LmRedeemEvaluation]).map(_.out).map(AssetAmountApi.fromAssetAmount),
Expand All @@ -241,7 +254,7 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi

"Mempool api" should "process lm eval (only eval order is in mempool) redeem correct" in {
val registerOrder = Processed(
LM.redeem,
LM.altRedeem,
OrderState(TxId("b5038999043e6ecd617a0a292976fe339d0e4d9ec85296f13610be0c7b16752e"), 0, Registered),
None,
None,
Expand All @@ -250,7 +263,7 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi
val evalOrder =
ProcessedOrderParser
.make[IO]
.evaluated(LM.redeemEvaluate, 0, registerOrder, SelfHosted.pool, 0, List.empty)
.evaluated(LM.redeemEval, 0, registerOrder, SelfHosted.pool, 0, List.empty)
.unsafeRunSync()
.get

Expand Down Expand Up @@ -314,4 +327,4 @@ final class MempoolApiSpec extends AnyFlatSpec with Matchers with PGContainer wi

println(result)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fi.spectrum.core.domain.order.{OrderId, OrderState, OrderStatus}
import fi.spectrum.core.protocol.ErgoTreeSerializer
import fi.spectrum.indexer.db.Indexer
import fi.spectrum.parser.evaluation.ProcessedOrderParser
import fi.spectrum.parser.lm.compound.v1.Compound.compoundBatchTx
import fi.spectrum.parser.lm.compound.v1.{Compound, CompoundParserV1}
import fi.spectrum.parser.lm.order.v1.LM
import fi.spectrum.parser.lm.pool.v1.SelfHosted
Expand Down Expand Up @@ -57,13 +58,13 @@ class OrderProcessorSpec extends AnyFlatSpec with Matchers with Indexer {
}

// batch
// .map(_.order)
// .sortBy(_.id.value) shouldEqual (Compound.expectedBatchCompoundsEval ::: Compound.expectedBatchCompoundsRegister)
// .map(_.order)
// .sortBy(_.id.value)
// .map(_.order)
// .sortBy(_.id.value) shouldEqual (Compound.expectedBatchCompoundsEval ::: Compound.expectedBatchCompoundsRegister)
// .map(_.order)
// .sortBy(_.id.value)

val one = processOrder[IO](
Compound.compoundTxOneOrder,
compoundBatchTx,
1,
1,
_ => IO.pure(Compound.expectedBatchCompoundsEval.take(1)),
Expand All @@ -74,7 +75,7 @@ class OrderProcessorSpec extends AnyFlatSpec with Matchers with Indexer {

println(one)

one.length shouldEqual 3
one.length shouldEqual 11
}

"Order processor" should "find LM deposit" in {
Expand All @@ -89,27 +90,26 @@ class OrderProcessorSpec extends AnyFlatSpec with Matchers with Indexer {
) shouldEqual register.head

val eval =
processOrder[IO](LM.tx, 1, 1, _ => IO.pure(List(register.head)), _ => IO.pure(SelfHosted.pool.some), IO.unit)
processOrder[IO](compoundBatchTx, 1, 1, _ => IO.pure(List(register.head)), _ => IO.pure(SelfHosted.pool.some), IO.unit)
.unsafeRunSync()

eval.length shouldEqual 2
eval.length shouldEqual 11

ProcessedOrderParser
.make[IO]
.evaluated(LM.tx, 1, register.head, SelfHosted.pool, 1, List.empty)
.evaluated(compoundBatchTx, 1, register.head, SelfHosted.pool, 1, List.empty)
.unsafeRunSync()
.get shouldEqual eval.head

Processed.make(
OrderState(LM.tx.id, 1, OrderStatus.Registered),
OrderState(compoundBatchTx.id, 1, OrderStatus.Registered),
CompoundParserV1.v1Compound
.compound(
LM.compoundCreateForDeposit,
ErgoTreeSerializer.default.deserialize(LM.compoundCreateForDeposit.ergoTree)
)
.get
) shouldEqual eval.last

}

"Order processor" should "find LM redeem" in {
Expand Down Expand Up @@ -141,8 +141,8 @@ class OrderProcessorSpec extends AnyFlatSpec with Matchers with Indexer {
.unsafeRunSync()

eval.length shouldEqual 2
eval.head.order.id shouldEqual OrderId("6293e74ef80b60076ceba4372c9f68c8bcd610eb9ddd6b565e4adf624f4a9d7a")
eval.last.order.id shouldEqual OrderId("353fb1e32f52c4353daf8c66c8426b36f2d1989a88efd64bd38ac3173dc3c4ca")
eval.head.order.id shouldEqual OrderId("00165c410829ff0cc2d176acb1fe8e37d7b65d597faf11f5ce210ef8457cd780")
eval.last.order.id shouldEqual OrderId("c622e40595f7edfdb26ae3709fbcbc8584f26ef258461e247d2516015ae42a43")
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import fi.spectrum.parser.evaluation.ProcessedOrderParser
import fi.spectrum.parser.evaluation.Transactions._
import fi.spectrum.parser.lm.order.v1.{LM, LmOrderParserV1}
import fi.spectrum.parser.lm.compound.v1.Compound
import fi.spectrum.parser.lm.compound.v1.Compound.compoundBatchTx
import fi.spectrum.parser.lm.pool.v1.SelfHosted
import glass.classic.Optional
import org.scalatest.flatspec.AnyFlatSpec
Expand Down Expand Up @@ -342,7 +343,7 @@ class PersistSpec extends AnyFlatSpec with Matchers with PGContainer with Indexe
None
).asInstanceOf[Processed.Any]
val eval =
ProcessedOrderParser.make[IO].evaluated(Compound.compoundTx, 0, register, SelfHosted.pool, 0, List.empty).unsafeRunSync().get
ProcessedOrderParser.make[IO].evaluated(compoundBatchTx, 0, register, SelfHosted.pool, 0, List.empty).unsafeRunSync().get

def run = for {
insertResult <- repo.insertAnyOrder.traverse(_(register)).trans
Expand All @@ -357,8 +358,8 @@ class PersistSpec extends AnyFlatSpec with Matchers with PGContainer with Indexe
} yield {
insertResult.sum shouldEqual 1
resolveResult.sum shouldEqual 1
insertResult2.sum shouldEqual 2
resolveResul2.sum shouldEqual 2
insertResult2.sum shouldEqual 1
resolveResul2.sum shouldEqual 1

expected1.get shouldEqual implicitly[ToDB[Processed[Compound], LmCompoundDB]]
.toDB(register.asInstanceOf[Processed[Compound]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import org.scalatest.propspec.AnyPropSpec
class OrderParserSpec extends AnyPropSpec with Matchers with CatsPlatform {

implicit val e: ErgoAddressEncoder = new ErgoAddressEncoder(ErgoAddressEncoder.MainnetNetworkPrefix)
implicit val spf: TokenId = TokenId.unsafeFromString("")
val parser: OrderParser = OrderParser.make
implicit val spf: TokenId =
TokenId.unsafeFromString("9a06d9e545a41fd51eeffc5e20d818073bf820c635e2a9d922269913e0de369d")
val parser: OrderParser = OrderParser.make

val out =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.scalatest.propspec.AnyPropSpec

class AmmOrderParserSpec extends AnyPropSpec with Matchers with CatsPlatform {

implicit val spf: TokenId = TokenId.unsafeFromString("")
implicit val spf: TokenId = TokenId.unsafeFromString("9a06d9e545a41fd51eeffc5e20d818073bf820c635e2a9d922269913e0de369d")
implicit val e: ErgoAddressEncoder = new ErgoAddressEncoder(ErgoAddressEncoder.MainnetNetworkPrefix)

val parser: AmmOrderParser[Version, AmmType] = AmmOrderParser.make
Expand Down
Loading