Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov committed Sep 12, 2024
1 parent 0caf588 commit d43c935
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 125 deletions.
9 changes: 8 additions & 1 deletion src/test/scala/units/BlockBriefValidationTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ class BlockBriefValidationTestSuite extends BaseIntegrationTestSuite {
}

"otherwise ignoring" in test { d =>
val ecBlock = d.createEcBlockBuilder("0", minerRewardL2Address = EthAddress.empty, parent = d.ecGenesisBlock).build()
val ecBlock = d
.createEcBlockBuilder(
"0",
minerRewardL2Address = EthAddress.empty,
parent = d.ecGenesisBlock,
epochNumber = d.blockchain.height
)
.build()

step(s"Receive ecBlock ${ecBlock.hash} from a peer")
d.receiveNetworkBlock(ecBlock, miner.account)
Expand Down
18 changes: 6 additions & 12 deletions src/test/scala/units/BlockFullValidationTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite {

"Full validation when the block is available on EL and CL" - {
"doesn't happen for finalized blocks" in withExtensionDomain(defaultSettings.copy(initialMiners = List(reliable))) { d =>
val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs)

step("Start new epoch for ecBlock")
d.advanceNewBlocks(reliable.address)
val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs)
d.advanceConsensusLayerChanged()

step(s"Receive ecBlock ${ecBlock.hash} from a peer")
Expand All @@ -42,7 +41,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite {

d.waitForWorking("Block considered validated and following") { s =>
val vs = s.fullValidationStatus
vs.validated should contain(ecBlock.hash)
vs.lastValidatedBlock.hash shouldBe ecBlock.hash
vs.lastElWithdrawalIndex shouldBe empty

is[FollowingChain](s.chainStatus)
Expand All @@ -51,10 +50,9 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite {

"happens for not finalized blocks" - {
"successful validation updates the chain information" in withExtensionDomain() { d =>
val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs)

step("Start new epoch for ecBlock")
d.advanceNewBlocks(reliable.address)
val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs)
d.advanceConsensusLayerChanged()

step(s"Receive ecBlock ${ecBlock.hash} from a peer")
Expand All @@ -73,7 +71,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite {

d.waitForWorking("Block considered validated") { s =>
val vs = s.fullValidationStatus
vs.validated should contain(ecBlock.hash)
vs.lastValidatedBlock.hash shouldBe ecBlock.hash
vs.lastElWithdrawalIndex.value shouldBe -1L
}
}
Expand Down Expand Up @@ -107,12 +105,8 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite {
d.receiveNetworkBlock(ecBlock2, malfunction.account)
d.triggerScheduledTasks()

d.waitForWorking("Block considered validated and forking") { s =>
val vs = s.fullValidationStatus
vs.validated should contain(ecBlock2.hash)
vs.lastElWithdrawalIndex shouldBe empty

is[WaitForNewChain](s.chainStatus)
d.waitForCS[WaitForNewChain]("Forking") { cs =>
cs.chainSwitchInfo.referenceBlock.hash shouldBe ecBlock1.hash
}
}

Expand Down
56 changes: 28 additions & 28 deletions src/test/scala/units/BlockIssuesForgingTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {

"We're on the main chain and" - {
def test(f: (ExtensionDomain, EcBlock, Int) => Unit): Unit = withExtensionDomain() { d =>
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1 ${ecBlock1.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1")
d.advanceNewBlocks(otherMiner1.address)
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
d.ecClients.addKnown(ecBlock1)
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1))
d.waitForCS[FollowingChain]() { s =>
s.nodeChainInfo.lastBlock.hash shouldBe ecBlock1.hash
}

val ecBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock2 ${ecBlock2.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock2")
d.advanceNewBlocks(otherMiner1.address)
val ecBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
val ecBlock2Epoch = d.blockchain.height
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock2))

Expand Down Expand Up @@ -76,9 +76,9 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {

"We're on the alternative chain and" - {
"EC-block comes within timeout - then we continue forging" in withExtensionDomain() { d =>
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1 ${ecBlock1.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1")
d.advanceNewBlocks(otherMiner1.address)
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
d.ecClients.addKnown(ecBlock1)
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1))

Expand All @@ -87,19 +87,19 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
s.nodeChainInfo.lastBlock.hash shouldBe ecBlock1.hash
}

val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2 ${ecBadBlock2.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2")
d.advanceNewBlocks(otherMiner1.address)
val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBadBlock2))

d.waitForCS[FollowingChain]() { s =>
s.nodeChainInfo.isMain shouldBe true
s.nodeChainInfo.lastBlock.hash shouldBe ecBadBlock2.hash
}

val ecBlock2 = d.createEcBlockBuilder("0-1", otherMiner2, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of otherMiner2 ${otherMiner2.address} with alternative chain ecBlock2 ${ecBlock2.hash}")
step(s"Start a new epoch of otherMiner2 ${otherMiner2.address} with alternative chain ecBlock2")
d.advanceNewBlocks(otherMiner2.address)
val ecBlock2 = d.createEcBlockBuilder("0-1", otherMiner2, ecBlock1).rewardPrevMiner().buildAndSetLogs()

d.waitForCS[WaitForNewChain]() { s =>
s.chainSwitchInfo.referenceBlock.hash shouldBe ecBlock1.hash
Expand All @@ -120,9 +120,9 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
s.nextExpectedBlock shouldBe empty
}

val ecBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, parent = ecBlock2).rewardPrevMiner(1).buildAndSetLogs()
step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBlock3 ${ecBlock3.hash}")
step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBlock3")
d.advanceNewBlocks(otherMiner2.address)
val ecBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, parent = ecBlock2).rewardPrevMiner(1).buildAndSetLogs()
val ecBlock3Epoch = d.blockchain.height
d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, ecBlock3, chainId = 1))

Expand Down Expand Up @@ -153,9 +153,9 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
}

"We mined before the alternative chain before and EC-block doesn't come - then we still wait for it" in withExtensionDomain() { d =>
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1 ${ecBlock1.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1")
d.advanceNewBlocks(otherMiner1.address)
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
d.ecClients.addKnown(ecBlock1)
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1))

Expand All @@ -164,19 +164,19 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
s.nodeChainInfo.lastBlock.hash shouldBe ecBlock1.hash
}

val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2 ${ecBadBlock2.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2")
d.advanceNewBlocks(otherMiner1.address)
val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBadBlock2))

d.waitForCS[FollowingChain]() { s =>
s.nodeChainInfo.isMain shouldBe true
s.nodeChainInfo.lastBlock.hash shouldBe ecBadBlock2.hash
}

val ecBlock2 = d.createEcBlockBuilder("0-1", thisMiner, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of thisMiner ${thisMiner.address} with alternative chain ecBlock2 ${ecBlock2.hash}")
step(s"Start a new epoch of thisMiner ${thisMiner.address} with alternative chain ecBlock2")
d.advanceNewBlocks(thisMiner.address)
val ecBlock2 = d.createEcBlockBuilder("0-1", thisMiner, ecBlock1).rewardPrevMiner().buildAndSetLogs()
d.ecClients.willForge(ecBlock2)
d.ecClients.willForge(d.createEcBlockBuilder("0-1-i", thisMiner, ecBlock2).buildAndSetLogs())

Expand All @@ -193,9 +193,9 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
ci.lastBlock.hash shouldBe ecBlock2.hash
}

val ecBadBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, ecBlock2).rewardMiner(otherMiner2.elRewardAddress, 1).buildAndSetLogs()
step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBadBlock3 ${ecBadBlock3.hash}")
step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBadBlock3")
d.advanceNewBlocks(otherMiner2.address)
val ecBadBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, ecBlock2).rewardMiner(otherMiner2.elRewardAddress, 1).buildAndSetLogs()
d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, ecBadBlock3, chainId = 1))

d.waitForCS[FollowingChain]() { s =>
Expand All @@ -219,9 +219,9 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {

"We haven't mined the alternative chain before and EC-block doesn't come - then we wait for a new alternative chain" in
withExtensionDomain() { d =>
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1 ${ecBlock1.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBlock1")
d.advanceNewBlocks(otherMiner1.address)
val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs()
d.ecClients.addKnown(ecBlock1)
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1))

Expand All @@ -230,19 +230,19 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
s.nodeChainInfo.lastBlock.hash shouldBe ecBlock1.hash
}

val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2 ${ecBadBlock2.hash}")
step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2")
d.advanceNewBlocks(otherMiner1.address)
val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs()
d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBadBlock2))

d.waitForCS[FollowingChain]() { s =>
s.nodeChainInfo.isMain shouldBe true
s.nodeChainInfo.lastBlock.hash shouldBe ecBadBlock2.hash
}

val ecBlock2 = d.createEcBlockBuilder("0-1", otherMiner2, ecBlock1).rewardPrevMiner().buildAndSetLogs()
step(s"Start a new epoch of otherMiner2 ${otherMiner2.address} with alternative chain ecBlock2 ${ecBlock2.hash}")
step(s"Start a new epoch of otherMiner2 ${otherMiner2.address} with alternative chain ecBlock2")
d.advanceNewBlocks(otherMiner2.address)
val ecBlock2 = d.createEcBlockBuilder("0-1", otherMiner2, ecBlock1).rewardPrevMiner().buildAndSetLogs()

d.waitForCS[WaitForNewChain]() { s =>
s.chainSwitchInfo.referenceBlock.hash shouldBe ecBlock1.hash
Expand All @@ -263,9 +263,9 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite {
s.nextExpectedBlock shouldBe empty
}

val ecBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, ecBlock2).rewardPrevMiner(1).buildAndSetLogs()
step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBlock3 ${ecBlock3.hash}")
step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBlock3")
d.advanceNewBlocks(otherMiner2.address)
val ecBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, ecBlock2).rewardPrevMiner(1).buildAndSetLogs()
d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, ecBlock3, chainId = 1))

d.waitForCS[FollowingChain]() { s =>
Expand Down
Loading

0 comments on commit d43c935

Please sign in to comment.