@@ -28,6 +28,20 @@ func TestComputeRequestHash_Deterministic(t *testing.T) {
2828 require .Equal (t , sampleComputeRequest ().Hash (), sampleComputeRequest ().Hash ())
2929}
3030
31+ func TestUsesLegacyComputeRequestHash (t * testing.T ) {
32+ for _ , v := range []string {computeRequestLegacyVersion , "0.0.1" , "0.0.5" } {
33+ require .True (t , usesLegacyComputeRequestHash (v ), "version %q should use the legacy hashing scheme" , v )
34+ }
35+
36+ for _ , v := range []string {"0.0.7" , "0.1.0" , "1.2.3" } {
37+ require .False (t , usesLegacyComputeRequestHash (v ), "version %q should use the current hashing scheme" , v )
38+ }
39+
40+ for _ , v := range []string {"" , "not-a-version" , "1.x" } {
41+ require .False (t , usesLegacyComputeRequestHash (v ), "unparseable version %q degrades to the current scheme" , v )
42+ }
43+ }
44+
3145// Every field the source binds must change the hash. (Conformance with
3246// confidential-compute's source Hash is enforced by a test in that repo, which can
3347// import this package; chainlink-common cannot import confidential-compute.)
@@ -61,9 +75,9 @@ func TestComputeRequestHash_IgnoresEncryptedShares(t *testing.T) {
6175 require .Equal (t , sampleComputeRequest ().Hash (), withShares .Hash ())
6276}
6377
64- // Version is hashed only for the legacy version , matching confidential-compute (which is
78+ // Version is hashed for the legacy scheme , matching confidential-compute (which is
6579// migrating Version out of the hash). Non-legacy versions are excluded, so different
66- // non-legacy versions hash identically, while the legacy version is bound.
80+ // non-legacy versions hash identically, while legacy-scheme versions are bound.
6781func TestComputeRequestHash_VersionOnlyHashedForLegacy (t * testing.T ) {
6882 nonLegacyA := sampleComputeRequest ()
6983 nonLegacyA .Version = "0.0.7"
@@ -74,6 +88,12 @@ func TestComputeRequestHash_VersionOnlyHashedForLegacy(t *testing.T) {
7488 legacy := sampleComputeRequest ()
7589 legacy .Version = computeRequestLegacyVersion
7690 require .NotEqual (t , legacy .Hash (), nonLegacyA .Hash (), "legacy Version must be bound into the hash" )
91+
92+ olderLegacyA := sampleComputeRequest ()
93+ olderLegacyA .Version = "0.0.5"
94+ olderLegacyB := sampleComputeRequest ()
95+ olderLegacyB .Version = "0.0.4"
96+ require .NotEqual (t , olderLegacyA .Hash (), olderLegacyB .Hash (), "versions at or below legacy must be bound into the hash" )
7797}
7898
7999// ApplicationRequestID is the post-legacy replacement for binding application-level
@@ -85,6 +105,14 @@ func TestComputeRequestHash_ApplicationRequestIDOnlyHashedForNonLegacy(t *testin
85105 legacyB .ApplicationRequestID = "exec-b"
86106 require .Equal (t , legacyA .Hash (), legacyB .Hash (), "legacy ApplicationRequestID must not affect the hash" )
87107
108+ olderLegacyA := sampleComputeRequest ()
109+ olderLegacyA .Version = "0.0.5"
110+ olderLegacyA .ApplicationRequestID = "exec-a"
111+ olderLegacyB := sampleComputeRequest ()
112+ olderLegacyB .Version = "0.0.5"
113+ olderLegacyB .ApplicationRequestID = "exec-b"
114+ require .Equal (t , olderLegacyA .Hash (), olderLegacyB .Hash (), "legacy-scheme ApplicationRequestID must not affect the hash" )
115+
88116 nonLegacyA := sampleComputeRequest ()
89117 nonLegacyA .Version = "0.0.7"
90118 nonLegacyA .ApplicationRequestID = "exec-a"
0 commit comments