@@ -111,46 +111,7 @@ func TestAssertValidForNextState(t *testing.T) {
111111 data : & Data {},
112112 expectedError : "dataHash from the header does not match with hash" ,
113113 },
114- "last header hash mismatch (first time)" : {
115- state : State {
116- ChainID : "test-chain" ,
117- LastHeaderHash : []byte ("hash" ),
118- LastBlockHeight : 1 ,
119- LastBlockTime : now ,
120- },
121- header : & SignedHeader {
122- Header : Header {
123- BaseHeader : BaseHeader {
124- ChainID : "test-chain" , Height : 2 ,
125- Time : nowUnixNano ,
126- },
127- DataHash : dataHashForEmptyTxs ,
128- LastHeaderHash : []byte ("other-hash" ),
129- },
130- },
131- data : & Data {},
132- expectedError : "" ,
133- },
134- "last header hash mismatch (second time)" : {
135- state : State {
136- ChainID : "test-chain" ,
137- LastHeaderHash : []byte ("hash" ),
138- LastBlockHeight : 1 ,
139- LastBlockTime : now ,
140- },
141- header : & SignedHeader {
142- Header : Header {
143- BaseHeader : BaseHeader {
144- ChainID : "test-chain" , Height : 2 ,
145- Time : nowUnixNano ,
146- },
147- DataHash : dataHashForEmptyTxs ,
148- LastHeaderHash : []byte ("other-hash" ),
149- },
150- },
151- data : & Data {},
152- expectedError : "invalid last header hash" ,
153- },
114+
154115 "app hash mismatch" : {
155116 state : State {
156117 ChainID : "test-chain" ,
@@ -184,4 +145,37 @@ func TestAssertValidForNextState(t *testing.T) {
184145 assert .ErrorContains (t , err , tc .expectedError )
185146 })
186147 }
148+
149+ // The last-header-hash grace period is stateful: the first mismatch is
150+ // tolerated (based-sequencer transition), the second is an error.
151+ // These two calls must run in order on the same global state, so they
152+ // cannot be independent map entries.
153+ t .Run ("last header hash mismatch grace period" , func (t * testing.T ) {
154+ state := State {
155+ ChainID : "test-chain" ,
156+ LastHeaderHash : []byte ("hash" ),
157+ LastBlockHeight : 1 ,
158+ LastBlockTime : now ,
159+ }
160+ header := & SignedHeader {
161+ Header : Header {
162+ BaseHeader : BaseHeader {
163+ ChainID : "test-chain" , Height : 2 ,
164+ Time : nowUnixNano ,
165+ },
166+ DataHash : dataHashForEmptyTxs ,
167+ LastHeaderHash : []byte ("other-hash" ),
168+ },
169+ }
170+ data := & Data {}
171+
172+ // First mismatch: tolerated (based-sequencer grace period).
173+ err := state .AssertValidForNextState (header , data )
174+ assert .NoError (t , err , "first last-header-hash mismatch should be tolerated" )
175+
176+ // Second mismatch on the same state: must be an error.
177+ err = state .AssertValidForNextState (header , data )
178+ assert .ErrorContains (t , err , "invalid last header hash" ,
179+ "second last-header-hash mismatch should be rejected" )
180+ })
187181}
0 commit comments