MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestEvidencePoolUpdate

Function TestEvidencePoolUpdate

evidence/pool_test.go:182–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestEvidencePoolUpdate(t *testing.T) {
183 height := int64(21)
184 pool, val := defaultTestPool(height)
185 state := pool.State()
186
187 // create new block (no need to save it to blockStore)
188 prunedEv := types.NewMockDuplicateVoteEvidenceWithValidator(1, defaultEvidenceTime.Add(1*time.Minute),
189 val, evidenceChainID)
190 err := pool.AddEvidence(prunedEv)
191 require.NoError(t, err)
192 ev := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultEvidenceTime.Add(21*time.Minute),
193 val, evidenceChainID)
194 lastCommit := makeCommit(height, val.PrivKey.PubKey().Address())
195 block := types.MakeBlock(height+1, []types.Tx{}, lastCommit, []types.Evidence{ev})
196 // update state (partially)
197 state.LastBlockHeight = height + 1
198 state.LastBlockTime = defaultEvidenceTime.Add(22 * time.Minute)
199 err = pool.CheckEvidence(types.EvidenceList{ev})
200 require.NoError(t, err)
201
202 pool.Update(state, block.Evidence.Evidence)
203 // a) Update marks evidence as committed so pending evidence should be empty
204 evList, evSize := pool.PendingEvidence(defaultEvidenceMaxBytes)
205 assert.Empty(t, evList)
206 assert.Zero(t, evSize)
207
208 // b) If we try to check this evidence again it should fail because it has already been committed
209 err = pool.CheckEvidence(types.EvidenceList{ev})
210 if assert.Error(t, err) {
211 assert.Equal(t, "evidence was already committed", err.(*types.ErrInvalidEvidence).Reason.Error())
212 }
213}
214
215func TestVerifyPendingEvidencePasses(t *testing.T) {
216 var height int64 = 1

Callers

nothing calls this directly

Calls 15

MakeBlockFunction · 0.92
defaultTestPoolFunction · 0.85
makeCommitFunction · 0.85
StateMethod · 0.65
AddEvidenceMethod · 0.65
AddressMethod · 0.65
PubKeyMethod · 0.65
CheckEvidenceMethod · 0.65
UpdateMethod · 0.65
PendingEvidenceMethod · 0.65
EmptyMethod · 0.65

Tested by

no test coverage detected