@@ -12,6 +12,7 @@ import (
1212
1313 abci "github.com/tendermint/tendermint/abci/types"
1414 cfg "github.com/tendermint/tendermint/config"
15+ "github.com/tendermint/tendermint/crypto/ed25519"
1516 "github.com/tendermint/tendermint/libs/log"
1617 "github.com/tendermint/tendermint/libs/pubsub/query"
1718 "github.com/tendermint/tendermint/proxy"
@@ -44,7 +45,16 @@ func doTestCreateBlock(t *testing.T, fraudProofsEnabled bool) {
4445 state := types.State {}
4546 state .ConsensusParams .Block .MaxBytes = 100
4647 state .ConsensusParams .Block .MaxGas = 100000
47- state .Validators = tmtypes .NewValidatorSet (nil )
48+ vKey := ed25519 .GenPrivKey ()
49+ validators := []* tmtypes.Validator {
50+ {
51+ Address : vKey .PubKey ().Address (),
52+ PubKey : vKey .PubKey (),
53+ VotingPower : int64 (100 ),
54+ ProposerPriority : int64 (1 ),
55+ },
56+ }
57+ state .Validators = tmtypes .NewValidatorSet (validators )
4858
4959 // empty block
5060 block := executor .CreateBlock (1 , & types.Commit {}, []byte {}, state )
@@ -124,10 +134,19 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
124134 require .NoError (err )
125135 require .NotNil (headerSub )
126136
137+ vKey := ed25519 .GenPrivKey ()
138+ validators := []* tmtypes.Validator {
139+ {
140+ Address : vKey .PubKey ().Address (),
141+ PubKey : vKey .PubKey (),
142+ VotingPower : int64 (100 ),
143+ ProposerPriority : int64 (1 ),
144+ },
145+ }
127146 state := types.State {
128- NextValidators : tmtypes .NewValidatorSet (nil ),
129- Validators : tmtypes .NewValidatorSet (nil ),
130- LastValidators : tmtypes .NewValidatorSet (nil ),
147+ NextValidators : tmtypes .NewValidatorSet (validators ),
148+ Validators : tmtypes .NewValidatorSet (validators ),
149+ LastValidators : tmtypes .NewValidatorSet (validators ),
131150 }
132151 state .InitialHeight = 1
133152 state .LastBlockHeight = 0
@@ -136,11 +155,23 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
136155
137156 _ = mpool .CheckTx ([]byte {1 , 2 , 3 , 4 }, func (r * abci.Response ) {}, mempool.TxInfo {})
138157 require .NoError (err )
139- block := executor .CreateBlock (1 , & types.Commit {}, []byte {}, state )
158+ block := executor .CreateBlock (1 , & types.Commit {Signatures : []types. Signature { types . Signature ([] byte { 1 , 1 , 1 })} }, []byte {}, state )
140159 require .NotNil (block )
141160 assert .Equal (int64 (1 ), block .SignedHeader .Header .Height ())
142161 assert .Len (block .Data .Txs , 1 )
143162
163+ // Update the signature on the block to current from last
164+ headerBytes , _ := block .SignedHeader .Header .MarshalBinary ()
165+ sig , _ := vKey .Sign (headerBytes )
166+ block .SignedHeader .Commit = types.Commit {
167+ Signatures : []types.Signature {sig },
168+ }
169+ block .SignedHeader .Validators = types.ValidatorSet {
170+ Validators : []types.Validator {{
171+ PublicKey : vKey .PubKey ().Bytes (),
172+ }},
173+ }
174+
144175 newState , resp , err := executor .ApplyBlock (context .Background (), state , block )
145176 require .NoError (err )
146177 require .NotNil (newState )
@@ -154,11 +185,22 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
154185 require .NoError (mpool .CheckTx ([]byte {5 , 6 , 7 , 8 , 9 }, func (r * abci.Response ) {}, mempool.TxInfo {}))
155186 require .NoError (mpool .CheckTx ([]byte {1 , 2 , 3 , 4 , 5 }, func (r * abci.Response ) {}, mempool.TxInfo {}))
156187 require .NoError (mpool .CheckTx (make ([]byte , 90 ), func (r * abci.Response ) {}, mempool.TxInfo {}))
157- block = executor .CreateBlock (2 , & types.Commit {}, []byte {}, newState )
188+ block = executor .CreateBlock (2 , & types.Commit {Signatures : []types. Signature { types . Signature ([] byte { 1 , 1 , 1 })} }, []byte {}, newState )
158189 require .NotNil (block )
159190 assert .Equal (int64 (2 ), block .SignedHeader .Header .Height ())
160191 assert .Len (block .Data .Txs , 3 )
161192
193+ headerBytes , _ = block .SignedHeader .Header .MarshalBinary ()
194+ sig , _ = vKey .Sign (headerBytes )
195+ block .SignedHeader .Commit = types.Commit {
196+ Signatures : []types.Signature {sig },
197+ }
198+ block .SignedHeader .Validators = types.ValidatorSet {
199+ Validators : []types.Validator {{
200+ PublicKey : vKey .PubKey ().Bytes (),
201+ }},
202+ }
203+
162204 newState , resp , err = executor .ApplyBlock (context .Background (), newState , block )
163205 require .NoError (err )
164206 require .NotNil (newState )
0 commit comments