@@ -34,6 +34,7 @@ import (
3434 "github.com/multiversx/mx-chain-go/testscommon"
3535 consensusMocks "github.com/multiversx/mx-chain-go/testscommon/consensus"
3636 "github.com/multiversx/mx-chain-go/testscommon/consensus/initializers"
37+ "github.com/multiversx/mx-chain-go/testscommon/cryptoMocks"
3738 "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
3839 "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
3940 "github.com/multiversx/mx-chain-go/testscommon/p2pmocks"
@@ -1898,6 +1899,43 @@ func TestVerifyInvalidSigners(t *testing.T) {
18981899 require .Equal (t , expectedErr , err )
18991900 })
19001901
1902+ t .Run ("peer signature binding fails should error" , func (t * testing.T ) {
1903+ t .Parallel ()
1904+
1905+ container := consensusMocks .InitConsensusCore ()
1906+
1907+ consensusMsg := & consensus.Message {
1908+ BlockHeaderHash : headerHash ,
1909+ PubKey : pubKey ,
1910+ MsgType : int64 (bls .MtSignature ),
1911+ }
1912+ consensusMsgBytes , _ := container .Marshalizer ().Marshal (consensusMsg )
1913+
1914+ invalidSigners := []p2p.MessageP2P {& factory.Message {
1915+ FromField : []byte ("attackerPid" ),
1916+ DataField : consensusMsgBytes ,
1917+ }}
1918+ invalidSignersBytes , _ := container .Marshalizer ().Marshal (invalidSigners )
1919+
1920+ messageSigningHandler := & mock.MessageSigningHandlerStub {
1921+ DeserializeCalled : func (messagesBytes []byte ) ([]p2p.MessageP2P , error ) {
1922+ return invalidSigners , nil
1923+ },
1924+ }
1925+ container .SetMessageSigningHandler (messageSigningHandler )
1926+
1927+ container .SetPeerSignatureHandler (& cryptoMocks.PeerSignatureHandlerStub {
1928+ VerifyPeerSignatureCalled : func (pk []byte , pid core.PeerID , signature []byte ) error {
1929+ return expectedErr
1930+ },
1931+ })
1932+
1933+ sr := initSubroundEndRoundWithContainer (container , & statusHandler.AppStatusHandlerStub {})
1934+
1935+ _ , err := sr .VerifyInvalidSigners (headerHash , invalidSignersBytes )
1936+ require .Equal (t , v2 .ErrPublicKeyMismatch , err )
1937+ })
1938+
19011939 t .Run ("invalid message type should err" , func (t * testing.T ) {
19021940 t .Parallel ()
19031941
@@ -1940,6 +1978,37 @@ func TestVerifyInvalidSigners(t *testing.T) {
19401978 require .False (t , wasCalled )
19411979 })
19421980
1981+ t .Run ("signer not in consensus group should err" , func (t * testing.T ) {
1982+ t .Parallel ()
1983+
1984+ container := consensusMocks .InitConsensusCore ()
1985+
1986+ unknownPubKey := []byte ("unknownKey" )
1987+ consensusMsg := & consensus.Message {
1988+ PubKey : unknownPubKey ,
1989+ MsgType : int64 (bls .MtSignature ),
1990+ }
1991+ consensusMsgBytes , _ := container .Marshalizer ().Marshal (consensusMsg )
1992+
1993+ invalidSigners := []p2p.MessageP2P {& factory.Message {
1994+ FromField : []byte ("from" ),
1995+ DataField : consensusMsgBytes ,
1996+ }}
1997+ invalidSignersBytes , _ := container .Marshalizer ().Marshal (invalidSigners )
1998+
1999+ messageSigningHandler := & mock.MessageSigningHandlerStub {
2000+ DeserializeCalled : func (messagesBytes []byte ) ([]p2p.MessageP2P , error ) {
2001+ return invalidSigners , nil
2002+ },
2003+ }
2004+ container .SetMessageSigningHandler (messageSigningHandler )
2005+
2006+ sr := initSubroundEndRoundWithContainer (container , & statusHandler.AppStatusHandlerStub {})
2007+
2008+ _ , err := sr .VerifyInvalidSigners (headerHash , invalidSignersBytes )
2009+ require .Equal (t , v2 .ErrSignerNotInConsensusGroup , err )
2010+ })
2011+
19432012 t .Run ("failed to verify signature share" , func (t * testing.T ) {
19442013 t .Parallel ()
19452014
0 commit comments