@@ -3,7 +3,6 @@ package io.iohk.ethereum.consensus.blocks
33import akka .util .ByteString
44import io .iohk .ethereum .blockchain .data .GenesisDataLoader
55import io .iohk .ethereum .blockchain .sync .EphemBlockchainTestSetup
6- import io .iohk .ethereum .consensus .blocks .BlockTimestampProvider
76import io .iohk .ethereum .consensus .pow .validators .ValidatorsExecutor
87import io .iohk .ethereum .consensus .validators ._
98import io .iohk .ethereum .crypto
@@ -12,6 +11,7 @@ import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields
1211import io .iohk .ethereum .domain .BlockHeader .HeaderExtraFields .{HefEmpty , HefPostEcip1097 }
1312import io .iohk .ethereum .domain .SignedTransaction .FirstByteOfAddress
1413import io .iohk .ethereum .domain ._
14+ import io .iohk .ethereum .ledger .BlockExecutionError .ValidationAfterExecError
1515import io .iohk .ethereum .ledger .{BlockExecution , BlockQueue , BlockValidation }
1616import io .iohk .ethereum .mpt .MerklePatriciaTrie .MPTException
1717import io .iohk .ethereum .utils ._
@@ -496,25 +496,25 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
496496 }
497497
498498 it should " generate blocks with the correct extra fields" in {
499- val table = Table [Boolean , Boolean , Boolean , HeaderExtraFields ](
500- (" ecip1098Activated" , " ecip1097Activated" , " selectedOptOut " , " expectedExtraFields" ),
499+ val table = Table [Boolean , Boolean , HeaderExtraFields ](
500+ (" ecip1098Activated" , " ecip1097Activated" , " expectedExtraFields" ),
501501 // No ecip activated
502- (false , false , true , HefEmpty ),
503- (false , false , false , HefEmpty ),
502+ (false , false , HefEmpty ),
503+ (false , false , HefEmpty ),
504504 // ECIP 1098 activated
505- (true , false , true , HefEmpty ),
506- (true , false , false , HefEmpty ),
505+ (true , false , HefEmpty ),
506+ (true , false , HefEmpty ),
507507 // ECIP 1097 and 1098 activated
508- (true , true , true , HefPostEcip1097 (None )),
509- (true , true , false , HefPostEcip1097 (None ))
508+ (true , true , HefPostEcip1097 (None )),
509+ (true , true , HefPostEcip1097 (None ))
510510 )
511511
512- forAll(table) { case (ecip1098Activated, ecip1097Activated, selectedOptOut, headerExtraFields) =>
512+ forAll(table) { case (ecip1098Activated, ecip1097Activated, headerExtraFields) =>
513513 val testSetup = new TestSetup {
514514 override lazy val blockchainConfig =
515515 baseBlockchainConfig.copy(ecip1098BlockNumber = 1000 , ecip1097BlockNumber = 2000 )
516516
517- override lazy val consensusConfig = buildConsensusConfig().copy(treasuryOptOut = selectedOptOut)
517+ override lazy val consensusConfig = buildConsensusConfig()
518518 }
519519 import testSetup ._
520520
@@ -531,7 +531,51 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
531531
532532 generatedBlock.block.header.extraFields shouldBe headerExtraFields
533533 }
534+ }
534535
536+ it should " generate a failure if treasury transfer was not made" in {
537+ val setup1 = new TestSetup {
538+ override lazy val blockchainConfig = baseBlockchainConfig.copy(ecip1098BlockNumber = 20000000 , treasuryAddress = treasuryAccount, customGenesisFileOpt = Some (" test-genesis-treasury.json" ))
539+ override lazy val consensusConfig = buildConsensusConfig()
540+ }
541+ val block = {
542+ import setup1 ._
543+ blockGenerator.generateBlock(bestBlock.get, Seq .empty, Address (testAddress), blockGenerator.emptyX, None ).pendingBlock
544+ }
545+
546+ val setup2 = new TestSetup {
547+ override lazy val blockchainConfig = baseBlockchainConfig.copy(ecip1098BlockNumber = 1 , treasuryAddress = treasuryAccount, customGenesisFileOpt = Some (" test-genesis-treasury.json" ))
548+ override lazy val consensusConfig = buildConsensusConfig()
549+ }
550+
551+ {
552+ import setup2 ._
553+
554+ blockExecution.executeAndValidateBlock(block.block, alreadyValidated = true ) shouldBe
555+ Left (ValidationAfterExecError (" Block has invalid state root hash, expected 47344722e6c52a85685f9c1bb1e0fe66cfaf6be00c1a752f43cc835fb7415e81 but got 41b63e59d34b5b35a040d496582fc587887af79f762210f6cf55c24d2c307d61" ))
556+ }
557+ }
558+
559+ it should " generate a failure if treasury transfer was made to a different treasury account" in {
560+ val setup1 = new TestSetup {
561+ override lazy val blockchainConfig = baseBlockchainConfig.copy(ecip1098BlockNumber = 1 , treasuryAddress = maliciousAccount, customGenesisFileOpt = Some (" test-genesis-treasury.json" ))
562+ override lazy val consensusConfig = buildConsensusConfig()
563+ }
564+ val block = {
565+ import setup1 ._
566+ blockGenerator.generateBlock(bestBlock.get, Seq .empty, Address (testAddress), blockGenerator.emptyX, None ).pendingBlock
567+ }
568+
569+ val setup2 = new TestSetup {
570+ override lazy val blockchainConfig = baseBlockchainConfig.copy(ecip1098BlockNumber = 1 , treasuryAddress = treasuryAccount, customGenesisFileOpt = Some (" test-genesis-treasury.json" ))
571+ override lazy val consensusConfig = buildConsensusConfig()
572+ }
573+
574+ {
575+ import setup2 ._
576+ blockExecution.executeAndValidateBlock(block.block, alreadyValidated = true ) shouldBe
577+ Left (ValidationAfterExecError (" Block has invalid state root hash, expected 5bfc811dfee1fecaefbaef2dba502082a8cc72e52260368d83ed6e4ebcecae75 but got 41b63e59d34b5b35a040d496582fc587887af79f762210f6cf55c24d2c307d61" ))
578+ }
535579 }
536580
537581 trait TestSetup extends EphemBlockchainTestSetup {
@@ -553,6 +597,10 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
553597 payload = ByteString .empty
554598 )
555599
600+ // defined in test-genesis-treasury.json
601+ val treasuryAccount = Address (0xeeeeee )
602+ val maliciousAccount = Address (0x123 )
603+
556604 lazy val signedTransaction = SignedTransaction .sign(transaction, keyPair, Some (0x3d .toByte))
557605 lazy val duplicatedSignedTransaction =
558606 SignedTransaction .sign(transaction.copy(gasLimit = 2 ), keyPair, Some (0x3d .toByte))
0 commit comments