github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/root_qc_test.go (about)

     1  package operation
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/dgraph-io/badger/v3"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/koko1123/flow-go-1/model/flow"
    11  	"github.com/koko1123/flow-go-1/utils/unittest"
    12  )
    13  
    14  func TestInsertRetrieveRootQC(t *testing.T) {
    15  	qc := unittest.QuorumCertificateFixture()
    16  
    17  	unittest.RunWithBadgerDB(t, func(db *badger.DB) {
    18  		err := db.Update(InsertRootQuorumCertificate(qc))
    19  		require.NoError(t, err)
    20  
    21  		// should be able to retrieve
    22  		var retrieved flow.QuorumCertificate
    23  		err = db.View(RetrieveRootQuorumCertificate(&retrieved))
    24  		require.NoError(t, err)
    25  		assert.Equal(t, qc, &retrieved)
    26  
    27  		// should not be able to overwrite
    28  		qc2 := unittest.QuorumCertificateFixture()
    29  		err = db.Update(InsertRootQuorumCertificate(qc2))
    30  		require.Error(t, err)
    31  	})
    32  }