Skip to content

Commit f696dc9

Browse files
committed
chore: fix unit tests
1 parent a1cacf3 commit f696dc9

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

pkg/rpc/core/blocks_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
cmtlog "github.com/cometbft/cometbft/libs/log"
1010
"github.com/cometbft/cometbft/libs/math"
1111
"github.com/cometbft/cometbft/light"
12+
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
1213
ctypes "github.com/cometbft/cometbft/rpc/core/types"
1314
rpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
1415
cmttypes "github.com/cometbft/cometbft/types"
@@ -239,8 +240,8 @@ func TestCommit_VerifyCometBFTLightClientCompatibility_MultipleBlocks(t *testing
239240
err = env.Adapter.Store.SaveBlockID(context.Background(), blockHeight, blockID)
240241
require.NoError(err, "Failed to save BlockID for height %d", blockHeight)
241242

242-
// create the signature for the rollkit block
243-
realSignature := signBlock(t, env.Adapter, rollkitHeader, aggregatorPrivKey)
243+
// Create signature over the actual blockID for light client compatibility
244+
realSignature := signBlockWithBlockID(t, rollkitHeader, aggregatorPrivKey, blockID)
244245

245246
// mock the store to return our signed block
246247
mockBlock(blockHeight, rollkitHeader, blockData, realSignature, aggregatorPubKey, validatorAddress)
@@ -297,6 +298,27 @@ func signBlock(t *testing.T, executor *adapter.Adapter, header types.Header, pri
297298
return signature
298299
}
299300

301+
func signBlockWithBlockID(t *testing.T, header types.Header, privKey crypto.PrivKey, blockID *cmttypes.BlockID) []byte {
302+
// create vote bytes using the createVote helper from adapter
303+
vote := cmtproto.Vote{
304+
Type: cmtproto.PrecommitType,
305+
Height: int64(header.Height()),
306+
BlockID: blockID.ToProto(),
307+
Round: 0,
308+
Timestamp: header.Time(),
309+
ValidatorAddress: header.ProposerAddress,
310+
ValidatorIndex: 0,
311+
}
312+
313+
chainID := header.ChainID()
314+
signBytes := cmttypes.VoteSignBytes(chainID, &vote)
315+
316+
signature, err := privKey.Sign(signBytes)
317+
require.NoError(t, err)
318+
319+
return signature
320+
}
321+
300322
func mockBlock(height uint64, header types.Header, data *types.Data, signature []byte, pubKey crypto.PubKey, address []byte) {
301323
signedHeader := &types.SignedHeader{
302324
Header: header,

0 commit comments

Comments
 (0)