Skip to content

Commit ae277cd

Browse files
committed
[FAB-3091] TX ID missing from TX in genesis block
This changeset: 1. Modifies the `Factory`'s `Block` method so that a TX ID is set. 2. Adds a test for the issue in question. The test fails w/o this changeset, and passes otherwise. It also: 1. Add comments to the exported identifiers of the genesis package. 2. Renames all instances of `chainID` to `channelID` (we have to start this transition eventually). 3. Modifies the tests so that they use the `assert` package. Change-Id: I13db93326cbf43544812c1de4a515940163760e8 Signed-off-by: Kostas Christidis <[email protected]>
1 parent 441b308 commit ae277cd

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

common/configtx/tool/provisional/provisional.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const (
5959

6060
// TestChainID is the default value of ChainID. It is used by all testing
6161
// networks. It it necessary to set and export this variable so that test
62-
// clients can connect without being rejected for targetting a chain which
62+
// clients can connect without being rejected for targeting a chain which
6363
// does not exist.
6464
TestChainID = "testchainid"
6565

common/genesis/genesis.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,24 @@ const (
3131
epoch = 0
3232
)
3333

34+
// Factory facilitates the creation of genesis blocks.
3435
type Factory interface {
35-
Block(chainID string) (*cb.Block, error)
36+
// Block returns a genesis block for a given channel ID.
37+
Block(channelID string) (*cb.Block, error)
3638
}
3739

3840
type factory struct {
3941
template configtx.Template
4042
}
4143

44+
// NewFactoryImpl creates a new Factory.
4245
func NewFactoryImpl(template configtx.Template) Factory {
4346
return &factory{template: template}
4447
}
4548

46-
func (f *factory) Block(chainID string) (*cb.Block, error) {
47-
configEnv, err := f.template.Envelope(chainID)
49+
// Block constructs and returns a genesis block for a given channel ID.
50+
func (f *factory) Block(channelID string) (*cb.Block, error) {
51+
configEnv, err := f.template.Envelope(channelID)
4852
if err != nil {
4953
return nil, err
5054
}
@@ -55,8 +59,9 @@ func (f *factory) Block(chainID string) (*cb.Block, error) {
5559
return nil, err
5660
}
5761

58-
payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG, msgVersion, chainID, epoch)
62+
payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG, msgVersion, channelID, epoch)
5963
payloadSignatureHeader := utils.MakeSignatureHeader(nil, utils.CreateNonceOrPanic())
64+
utils.SetTxID(payloadChannelHeader, payloadSignatureHeader)
6065
payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader)
6166
payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(&cb.ConfigEnvelope{Config: &cb.Config{ChannelGroup: configUpdate.WriteSet}})}
6267
envelope := &cb.Envelope{Payload: utils.MarshalOrPanic(payload), Signature: nil}

common/genesis/genesis_test.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@ import (
2020
"testing"
2121

2222
"github.com/hyperledger/fabric/common/configtx"
23+
"github.com/hyperledger/fabric/protos/utils"
24+
"github.com/stretchr/testify/assert"
2325
)
2426

25-
func TestSanity(t *testing.T) {
27+
func TestBasicSanity(t *testing.T) {
2628
impl := NewFactoryImpl(configtx.NewSimpleTemplate())
27-
_, err := impl.Block("TestChainID")
28-
if err != nil {
29-
t.Fatalf("Basic sanity fails")
30-
}
29+
_, err := impl.Block("testchainid")
30+
assert.NoError(t, err, "Basic sanity fails")
31+
}
32+
33+
func TestForTransactionID(t *testing.T) {
34+
impl := NewFactoryImpl(configtx.NewSimpleTemplate())
35+
block, _ := impl.Block("testchainid")
36+
configEnv, _ := utils.ExtractEnvelope(block, 0)
37+
configEnvPayload, _ := utils.ExtractPayload(configEnv)
38+
configEnvPayloadChannelHeader, _ := utils.UnmarshalChannelHeader(configEnvPayload.GetHeader().ChannelHeader)
39+
assert.NotEmpty(t, configEnvPayloadChannelHeader.TxId, "tx_id of configuration transaction should not be empty")
3140
}

0 commit comments

Comments
 (0)