Skip to content

Commit

Permalink
Insert events and contract as main_chain = false
Browse files Browse the repository at this point in the history
The same way we do for other entities, the `main_chain = true`
is updated later.
  • Loading branch information
tdroxler committed Jul 4, 2024
1 parent ca8c6ff commit e3f239d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object EventEntity {
eventIndex,
fields,
order,
mainChain = true
mainChain = false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ object CustomGetResult {
destructionTimestamp = result.<<?,
destructionEventOrder = result.<<?,
category = result.<<?,
interfaceId = result.<<?
interfaceId = result.<<?,
mainChain = result.<<
)

implicit val migrationVersionGetResult: GetResult[AppState.MigrationVersion] =
Expand Down
26 changes: 15 additions & 11 deletions app/src/test/scala/org/alephium/explorer/GenDBModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ object GenDBModel {
token = token
)

def eventEntityGen()(implicit groupSetting: GroupSetting): Gen[EventEntity] =
def eventEntityGen(
mainChain: Boolean = false
)(implicit groupSetting: GroupSetting): Gen[EventEntity] =
for {
blockHash <- blockHashGen
hash <- transactionHashGen
Expand All @@ -249,16 +251,18 @@ object GenDBModel {
eventIndex <- Gen.posNum[Int]
fields <- Gen.listOf(valGen())

} yield EventEntity.from(
blockHash,
hash,
contractAddress,
inputAddress,
timestamp,
eventIndex,
fields,
0
)
} yield EventEntity
.from(
blockHash,
hash,
contractAddress,
inputAddress,
timestamp,
eventIndex,
fields,
0
)
.copy(mainChain = mainChain)

def tokenOutputEntityGen(
addressGen: Gen[Address] = addressGen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EventQueriesSpec

"Event Queries" should {
"get event by tx hash" in {
forAll(Gen.nonEmptyListOf(eventEntityGen())) { events =>
forAll(Gen.nonEmptyListOf(eventEntityGen(true))) { events =>
insert(events)

events.map { event =>
Expand All @@ -55,7 +55,7 @@ class EventQueriesSpec
}

"get all events with same tx hash" in {
forAll(Gen.nonEmptyListOf(eventEntityGen())) { events =>
forAll(Gen.nonEmptyListOf(eventEntityGen(true))) { events =>
val txHash = transactionHashGen.sample.get
val uniqueTxHashEvents = events.zipWithIndex.map { case (event, order) =>
event.copy(txHash = txHash, eventOrder = order)
Expand All @@ -73,7 +73,7 @@ class EventQueriesSpec
}

"get event by contract address" in {
forAll(Gen.nonEmptyListOf(eventEntityGen())) { events =>
forAll(Gen.nonEmptyListOf(eventEntityGen(true))) { events =>
insert(events)

events.map { event =>
Expand All @@ -88,7 +88,7 @@ class EventQueriesSpec
}

"get all events with same contractAddress" in {
forAll(Gen.nonEmptyListOf(eventEntityGen())) { events =>
forAll(Gen.nonEmptyListOf(eventEntityGen(true))) { events =>
val contractAddress = addressGen.sample.get
val uniqueContractAddressEvents = events.map { event =>
event.copy(contractAddress = contractAddress)
Expand Down Expand Up @@ -121,7 +121,7 @@ class EventQueriesSpec
}

"get event by contract address and input address" in {
forAll(Gen.nonEmptyListOf(eventEntityGen())) { events =>
forAll(Gen.nonEmptyListOf(eventEntityGen(true))) { events =>
insert(events)

events.map { event =>
Expand Down Expand Up @@ -153,7 +153,7 @@ class EventQueriesSpec
}

"get all events with same contractAddress and input address" in {
forAll(Gen.nonEmptyListOf(eventEntityGen())) { events =>
forAll(Gen.nonEmptyListOf(eventEntityGen(true))) { events =>
val contractAddress = addressGen.sample.get
val inputAddress = addressGen.sample.get
val uniqueContractAddressEvents = events.map { event =>
Expand Down

0 comments on commit e3f239d

Please sign in to comment.