Skip to content

Commit

Permalink
[FAB-2096] Remove xxxCryptHelper to mocks
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2096

The orderer temporarily used a fake crypto helper, but when the real one
was added, the fake one stayed in the non-test code although it was only
used in tests.  This CR remedies that.

Change-Id: Icc51400c49bee0e21a838925828621d075ee6987
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 7, 2017
1 parent 5ed12d2 commit 514db40
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
8 changes: 4 additions & 4 deletions orderer/multichain/chainsupport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (mc *mockCommitter) Commit() {
func TestCommitConfig(t *testing.T) {
ml := &mockLedgerReadWriter{}
cm := &mockconfigtx.Manager{}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &xxxCryptoHelper{}}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &mockCryptoHelper{}}
txs := []*cb.Envelope{makeNormalTx("foo", 0), makeNormalTx("bar", 1)}
committers := []filter.Committer{&mockCommitter{}, &mockCommitter{}}
block := cs.CreateNextBlock(txs)
Expand All @@ -90,7 +90,7 @@ func TestCommitConfig(t *testing.T) {
func TestWriteBlockSignatures(t *testing.T) {
ml := &mockLedgerReadWriter{}
cm := &mockconfigtx.Manager{}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &xxxCryptoHelper{}}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &mockCryptoHelper{}}

if utils.GetMetadataFromBlockOrPanic(cs.WriteBlock(cb.NewBlock(0, nil), nil, nil), cb.BlockMetadataIndex_SIGNATURES) == nil {
t.Fatalf("Block should have block signature")
Expand All @@ -100,7 +100,7 @@ func TestWriteBlockSignatures(t *testing.T) {
func TestWriteBlockOrdererMetadata(t *testing.T) {
ml := &mockLedgerReadWriter{}
cm := &mockconfigtx.Manager{}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &xxxCryptoHelper{}}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &mockCryptoHelper{}}

value := []byte("foo")
expected := &cb.Metadata{Value: value}
Expand All @@ -118,7 +118,7 @@ func TestWriteBlockOrdererMetadata(t *testing.T) {
func TestWriteLastConfig(t *testing.T) {
ml := &mockLedgerReadWriter{}
cm := &mockconfigtx.Manager{}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &xxxCryptoHelper{}}
cs := &chainSupport{ledgerResources: &ledgerResources{configResources: &configResources{Manager: cm}, ledger: ml}, signer: &mockCryptoHelper{}}

expected := uint64(0)

Expand Down
16 changes: 0 additions & 16 deletions orderer/multichain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ import (

var logger = logging.MustGetLogger("orderer/multichain")

// XXX This crypto helper is a stand in until we have a real crypto handler
// it considers all signatures to be valid
type xxxCryptoHelper struct{}

func (xxx xxxCryptoHelper) VerifySignature(sd *cb.SignedData) error {
return nil
}

func (xxx xxxCryptoHelper) NewSignatureHeader() (*cb.SignatureHeader, error) {
return &cb.SignatureHeader{}, nil
}

func (xxx xxxCryptoHelper) Sign(message []byte) ([]byte, error) {
return message, nil
}

// Manager coordinates the creation and access of chains
type Manager interface {
// GetChain retrieves the chain support for a chain (and whether it exists)
Expand Down
22 changes: 18 additions & 4 deletions orderer/multichain/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ func init() {
genesisBlock = provisional.New(conf).GenesisBlock()
}

type mockCryptoHelper struct{}

func (xxx mockCryptoHelper) VerifySignature(sd *cb.SignedData) error {
return nil
}

func (xxx mockCryptoHelper) NewSignatureHeader() (*cb.SignatureHeader, error) {
return &cb.SignatureHeader{}, nil
}

func (xxx mockCryptoHelper) Sign(message []byte) ([]byte, error) {
return message, nil
}

func NewRAMLedgerAndFactory(maxSize int) (ordererledger.Factory, ordererledger.ReadWriter) {
rlf := ramledger.New(10)
rl, err := rlf.GetOrCreate(provisional.TestChainID)
Expand Down Expand Up @@ -115,7 +129,7 @@ func TestNoSystemChain(t *testing.T) {
consenters := make(map[string]Consenter)
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

NewManagerImpl(lf, consenters, &xxxCryptoHelper{})
NewManagerImpl(lf, consenters, &mockCryptoHelper{})
}

// This test essentially brings the entire system up and is ultimately what main.go will replicate
Expand All @@ -125,7 +139,7 @@ func TestManagerImpl(t *testing.T) {
consenters := make(map[string]Consenter)
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

manager := NewManagerImpl(lf, consenters, &xxxCryptoHelper{})
manager := NewManagerImpl(lf, consenters, &mockCryptoHelper{})

_, ok := manager.GetChain("Fake")
if ok {
Expand Down Expand Up @@ -171,7 +185,7 @@ func TestSignatureFilter(t *testing.T) {
consenters := make(map[string]Consenter)
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

manager := NewManagerImpl(lf, consenters, &xxxCryptoHelper{})
manager := NewManagerImpl(lf, consenters, &mockCryptoHelper{})

cs, ok := manager.GetChain(provisional.TestChainID)

Expand Down Expand Up @@ -209,7 +223,7 @@ func TestNewChain(t *testing.T) {
consenters := make(map[string]Consenter)
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

manager := NewManagerImpl(lf, consenters, &xxxCryptoHelper{})
manager := NewManagerImpl(lf, consenters, &mockCryptoHelper{})

generator := provisional.New(conf)
items := generator.TemplateItems()
Expand Down

0 comments on commit 514db40

Please sign in to comment.