github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/id/filtered_provider_test.go (about)

     1  package id
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/onflow/flow-go/model/flow"
    10  	"github.com/onflow/flow-go/model/flow/filter"
    11  
    12  	"github.com/onflow/flow-go/utils/unittest"
    13  )
    14  
    15  func TestFilteredIdentitiesProvider(t *testing.T) {
    16  	identities := make([]*flow.Identity, 10)
    17  	for i := 0; i < len(identities); i++ {
    18  		identities[i] = unittest.IdentityFixture()
    19  	}
    20  	identifiers := (flow.IdentityList)(identities).NodeIDs()
    21  
    22  	oddIdentifiers := make([]flow.Identifier, 5)
    23  	for j := 0; j < 5; j++ {
    24  		oddIdentifiers[j] = identifiers[2*j+1]
    25  	}
    26  
    27  	oddIdentities := make([]*flow.Identity, 5)
    28  	for j := 0; j < 5; j++ {
    29  		oddIdentities[j] = identities[2*j+1]
    30  	}
    31  
    32  	ip := NewFixedIdentityProvider(identities)
    33  	fp := NewIdentityFilterIdentifierProvider(filter.In(oddIdentities), ip)
    34  
    35  	assert.ElementsMatch(t, fp.Identifiers(),
    36  		(flow.IdentityList)(oddIdentities).NodeIDs())
    37  
    38  	in := 0
    39  	out := 0
    40  	for _, id := range identifiers {
    41  		if contains(fp.Identifiers(), id) {
    42  			in++
    43  		} else {
    44  			out++
    45  		}
    46  	}
    47  	require.Equal(t, 5, in)
    48  	require.Equal(t, 5, out)
    49  
    50  }