github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/signature/randombeacon_reconstructor_test.go (about)

     1  package signature
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	mockhotstuff "github.com/koko1123/flow-go-1/consensus/hotstuff/mocks"
    10  	"github.com/koko1123/flow-go-1/utils/unittest"
    11  )
    12  
    13  // TestRandomBeaconReconstructor_InvalidSignerID tests that RandomBeaconReconstructor doesn't forward calls to
    14  // RandomBeaconInspector if it fails to map signerID to signerIndex
    15  func TestRandomBeaconReconstructor_InvalidSignerID(t *testing.T) {
    16  	dkg := &mockhotstuff.DKG{}
    17  	inspector := &mockhotstuff.RandomBeaconInspector{}
    18  	reconstructor := NewRandomBeaconReconstructor(dkg, inspector)
    19  	exception := errors.New("invalid-signer-id")
    20  	t.Run("trustedAdd", func(t *testing.T) {
    21  		signerID := unittest.IdentifierFixture()
    22  		dkg.On("Index", signerID).Return(uint(0), exception).Once()
    23  		_, err := reconstructor.TrustedAdd(signerID, unittest.SignatureFixture())
    24  		require.ErrorAs(t, err, &exception)
    25  		inspector.AssertNotCalled(t, "TrustedAdd")
    26  	})
    27  	t.Run("verify", func(t *testing.T) {
    28  		signerID := unittest.IdentifierFixture()
    29  		dkg.On("Index", signerID).Return(uint(0), exception).Once()
    30  		err := reconstructor.Verify(signerID, unittest.SignatureFixture())
    31  		require.ErrorAs(t, err, &exception)
    32  		inspector.AssertNotCalled(t, "Verify")
    33  	})
    34  
    35  	dkg.AssertExpectations(t)
    36  	inspector.AssertExpectations(t)
    37  }