@@ -9,6 +9,10 @@ import org.scalatest.wordspec.AnyWordSpec
99import org .scalatest .matchers .should ._
1010import org .bouncycastle .util .encoders .Hex
1111
12+ import io .iohk .ethereum .rlp ._
13+ import io .iohk .ethereum .rlp .RLPImplicits ._
14+
15+
1216class ForkIdSpec extends AnyWordSpec with Matchers {
1317
1418 val config = blockchains
@@ -79,22 +83,22 @@ class ForkIdSpec extends AnyWordSpec with Matchers {
7983 create(11700000 ) shouldBe ForkId (0xB20AFE12L, None )
8084 }
8185
82-
8386 // Here’s a couple of tests to verify the proper RLP encoding (since FORK_HASH is a 4 byte binary but FORK_NEXT is an 8 byte quantity):
8487 " be correctly encoded via rlp" in {
85- import ForkId ._
86- import io .iohk .ethereum .rlp ._
87- import io .iohk .ethereum .rlp .RLPImplicits ._
88-
89- encode(ForkId (0 , None ).toRLPEncodable) shouldBe Hex .decode(" c6840000000080" )
90- encode(ForkId (0xdeadbeefL, Some (0xBADDCAFEL)).toRLPEncodable) shouldBe Hex .decode(" ca84deadbeef84baddcafe" )
88+ roundTrip(ForkId (0 , None ), " c6840000000080" )
89+ roundTrip(ForkId (0xdeadbeefL, Some (0xBADDCAFEL)), " ca84deadbeef84baddcafe" )
9190
9291 val maxUInt64 = (BigInt (0x7FFFFFFFFFFFFFFFL) << 1 ) + 1
9392 maxUInt64.toByteArray shouldBe Array (0 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 )
9493 val maxUInt32 = BigInt (0xFFFFFFFFL)
9594 maxUInt32.toByteArray shouldBe Array (0 , - 1 , - 1 , - 1 , - 1 )
9695
97- encode (ForkId (maxUInt32, Some (maxUInt64)).toRLPEncodable) shouldBe Hex .decode( " ce84ffffffff88ffffffffffffffff" )
96+ roundTrip (ForkId (maxUInt32, Some (maxUInt64)), " ce84ffffffff88ffffffffffffffff" )
9897 }
9998 }
99+
100+ private def roundTrip (forkId : ForkId , hex : String ) = {
101+ encode(forkId.toRLPEncodable) shouldBe Hex .decode(hex)
102+ decode[ForkId ](Hex .decode(hex)) shouldBe forkId
103+ }
100104}
0 commit comments