@@ -9,6 +9,10 @@ import org.scalatest.wordspec.AnyWordSpec
9
9
import org .scalatest .matchers .should ._
10
10
import org .bouncycastle .util .encoders .Hex
11
11
12
+ import io .iohk .ethereum .rlp ._
13
+ import io .iohk .ethereum .rlp .RLPImplicits ._
14
+
15
+
12
16
class ForkIdSpec extends AnyWordSpec with Matchers {
13
17
14
18
val config = blockchains
@@ -79,22 +83,22 @@ class ForkIdSpec extends AnyWordSpec with Matchers {
79
83
create(11700000 ) shouldBe ForkId (0xB20AFE12L, None )
80
84
}
81
85
82
-
83
86
// 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):
84
87
" 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" )
91
90
92
91
val maxUInt64 = (BigInt (0x7FFFFFFFFFFFFFFFL) << 1 ) + 1
93
92
maxUInt64.toByteArray shouldBe Array (0 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 )
94
93
val maxUInt32 = BigInt (0xFFFFFFFFL)
95
94
maxUInt32.toByteArray shouldBe Array (0 , - 1 , - 1 , - 1 , - 1 )
96
95
97
- encode (ForkId (maxUInt32, Some (maxUInt64)).toRLPEncodable) shouldBe Hex .decode( " ce84ffffffff88ffffffffffffffff" )
96
+ roundTrip (ForkId (maxUInt32, Some (maxUInt64)), " ce84ffffffff88ffffffffffffffff" )
98
97
}
99
98
}
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
+ }
100
104
}
0 commit comments