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

Function TestBeginBlockValidators

state/execution_test.go:63–125  ·  view source on GitHub ↗

TestBeginBlockValidators ensures we send absent validators list.

(t *testing.T)

Source from the content-addressed store, hash-verified

61
62// TestBeginBlockValidators ensures we send absent validators list.
63func TestBeginBlockValidators(t *testing.T) {
64 app := &testApp{}
65 cc := proxy.NewLocalClientCreator(app)
66 proxyApp := proxy.NewAppConns(cc)
67 err := proxyApp.Start()
68 require.Nil(t, err)
69 defer proxyApp.Stop() //nolint:errcheck // no need to check error again
70
71 state, stateDB, _ := makeState(2, 2)
72 stateStore := sm.NewStore(stateDB, sm.StoreOptions{
73 DiscardABCIResponses: false,
74 })
75
76 prevHash := state.LastBlockID.Hash
77 prevParts := types.PartSetHeader{}
78 prevBlockID := types.BlockID{Hash: prevHash, PartSetHeader: prevParts}
79
80 var (
81 now = tmtime.Now()
82 commitSig0 = types.NewCommitSigForBlock(
83 []byte("Signature1"),
84 state.Validators.Validators[0].Address,
85 now)
86 commitSig1 = types.NewCommitSigForBlock(
87 []byte("Signature2"),
88 state.Validators.Validators[1].Address,
89 now)
90 absentSig = types.NewCommitSigAbsent()
91 )
92
93 testCases := []struct {
94 desc string
95 lastCommitSigs []types.CommitSig
96 expectedAbsentValidators []int
97 }{
98 {"none absent", []types.CommitSig{commitSig0, commitSig1}, []int{}},
99 {"one absent", []types.CommitSig{commitSig0, absentSig}, []int{1}},
100 {"multiple absent", []types.CommitSig{absentSig, absentSig}, []int{0, 1}},
101 }
102
103 for _, tc := range testCases {
104 lastCommit := types.NewCommit(1, 0, prevBlockID, tc.lastCommitSigs)
105
106 // block for height 2
107 block, _ := state.MakeBlock(2, makeTxs(2), lastCommit, nil, state.Validators.GetProposer().Address)
108
109 _, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), stateStore, 1)
110 require.Nil(t, err, tc.desc)
111
112 // -> app receives a list of validators with a bool indicating if they signed
113 ctr := 0
114 for i, v := range app.CommitVotes {
115 if ctr < len(tc.expectedAbsentValidators) &&
116 tc.expectedAbsentValidators[ctr] == i {
117
118 assert.False(t, v.SignedLastBlock)
119 ctr++
120 } else {

Callers

nothing calls this directly

Calls 13

ConsensusMethod · 0.95
NewLocalClientCreatorFunction · 0.92
NewAppConnsFunction · 0.92
NewCommitSigForBlockFunction · 0.92
NewCommitSigAbsentFunction · 0.92
NewCommitFunction · 0.92
TestingLoggerFunction · 0.92
MakeBlockMethod · 0.80
makeStateFunction · 0.70
makeTxsFunction · 0.70
StartMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected