github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/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/onflow/flow-go/consensus/hotstuff/mocks"
    10  	"github.com/onflow/flow-go/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  }