@@ -32,8 +32,6 @@ import (
32
32
"github.com/stretchr/testify/assert"
33
33
)
34
34
35
- var newChannelID = "newChannel"
36
-
37
35
type mockSupport struct {
38
36
msc * mockconfig.Orderer
39
37
}
@@ -73,94 +71,96 @@ func (mcc *mockChainCreator) NewChannelConfig(envConfigUpdate *cb.Envelope) (con
73
71
if mcc .NewChannelConfigErr != nil {
74
72
return nil , mcc .NewChannelConfigErr
75
73
}
76
-
77
- pldConfigUpdate := utils .UnmarshalPayloadOrPanic (envConfigUpdate .Payload )
78
- configUpdateEnv := configtx .UnmarshalConfigUpdateEnvelopeOrPanic (pldConfigUpdate .Data )
79
- configUpdate := configtx .UnmarshalConfigUpdateOrPanic (configUpdateEnv .ConfigUpdate )
80
-
81
- configEnvelopeVal := & cb.ConfigEnvelope {
82
- Config : & cb.Config {ChannelGroup : configUpdate .WriteSet },
83
- }
84
-
85
- proposeConfigUpdateVal := configEnvelopeVal
86
- proposeConfigUpdateVal .Config .Sequence = 1
87
- proposeConfigUpdateVal .LastUpdate = envConfigUpdate
88
-
89
- ctxm := & mockconfigtx.Manager {
90
- ConfigEnvelopeVal : configEnvelopeVal ,
91
- ProposeConfigUpdateVal : proposeConfigUpdateVal ,
92
- }
93
-
94
- return ctxm , nil
74
+ confUpdate := configtx .UnmarshalConfigUpdateOrPanic (configtx .UnmarshalConfigUpdateEnvelopeOrPanic (utils .UnmarshalPayloadOrPanic (envConfigUpdate .Payload ).Data ).ConfigUpdate )
75
+ return & mockconfigtx.Manager {
76
+ ConfigEnvelopeVal : & cb.ConfigEnvelope {
77
+ Config : & cb.Config {Sequence : 1 , ChannelGroup : confUpdate .WriteSet },
78
+ LastUpdate : envConfigUpdate ,
79
+ },
80
+ }, nil
95
81
}
96
82
97
83
func TestGoodProposal (t * testing.T ) {
84
+ newChainID := "NewChainID"
85
+
98
86
mcc := newMockChainCreator ()
99
87
100
- configUpdateEnv , _ := configtx .NewCompositeTemplate (
88
+ configEnv , err := configtx .NewCompositeTemplate (
101
89
configtx .NewSimpleTemplate (
102
90
config .DefaultHashingAlgorithm (),
103
91
config .DefaultBlockDataHashingStructure (),
104
92
config .TemplateOrdererAddresses ([]string {"foo" }),
105
93
),
106
94
configtx .NewChainCreationTemplate ("SampleConsortium" , []string {}),
107
- ).Envelope (newChannelID )
108
-
109
- ingressTx := makeConfigTxFromConfigUpdateEnvelope (newChannelID , configUpdateEnv , true )
110
- ordererTx := wrapConfigTx (ingressTx )
95
+ ).Envelope (newChainID )
96
+ if err != nil {
97
+ t .Fatalf ("Error constructing configtx" )
98
+ }
99
+ ingressTx := makeConfigTxFromConfigUpdateEnvelope (newChainID , configEnv )
100
+ wrapped := wrapConfigTx (ingressTx )
111
101
112
102
sysFilter := newSystemChainFilter (mcc .ms , mcc )
113
- action , committer := sysFilter .Apply (ordererTx )
103
+ action , committer := sysFilter .Apply (wrapped )
104
+
114
105
assert .EqualValues (t , action , filter .Accept , "Did not accept valid transaction" )
115
106
assert .True (t , committer .Isolated (), "Channel creation belong in its own block" )
116
107
117
108
committer .Commit ()
118
109
assert .Len (t , mcc .newChains , 1 , "Proposal should only have created 1 new chain" )
110
+
119
111
assert .Equal (t , ingressTx , mcc .newChains [0 ], "New chain should have been created with ingressTx" )
120
112
}
121
113
122
114
func TestProposalRejectedByConfig (t * testing.T ) {
115
+ newChainID := "NewChainID"
116
+
123
117
mcc := newMockChainCreator ()
124
118
mcc .NewChannelConfigErr = fmt .Errorf ("Error creating channel" )
125
119
126
- configUpdateEnv , _ := configtx .NewCompositeTemplate (
120
+ configEnv , err := configtx .NewCompositeTemplate (
127
121
configtx .NewSimpleTemplate (
128
122
config .DefaultHashingAlgorithm (),
129
123
config .DefaultBlockDataHashingStructure (),
130
124
config .TemplateOrdererAddresses ([]string {"foo" }),
131
125
),
132
126
configtx .NewChainCreationTemplate ("SampleConsortium" , []string {}),
133
- ).Envelope (newChannelID )
134
-
135
- ingressTx := makeConfigTxFromConfigUpdateEnvelope (newChannelID , configUpdateEnv , true )
136
- ordererTx := wrapConfigTx (ingressTx )
127
+ ).Envelope (newChainID )
128
+ if err != nil {
129
+ t .Fatalf ("Error constructing configtx" )
130
+ }
131
+ ingressTx := makeConfigTxFromConfigUpdateEnvelope (newChainID , configEnv )
132
+ wrapped := wrapConfigTx (ingressTx )
137
133
138
134
sysFilter := newSystemChainFilter (mcc .ms , mcc )
139
- action , _ := sysFilter .Apply (ordererTx )
135
+ action , _ := sysFilter .Apply (wrapped )
140
136
141
- assert .EqualValues (t , action , filter .Reject , "Did not reject invalid transaction" )
137
+ assert .EqualValues (t , action , filter .Reject , "Did not accept valid transaction" )
142
138
assert .Len (t , mcc .newChains , 0 , "Proposal should not have created a new chain" )
143
139
}
144
140
145
141
func TestNumChainsExceeded (t * testing.T ) {
142
+ newChainID := "NewChainID"
143
+
146
144
mcc := newMockChainCreator ()
147
145
mcc .ms .msc .MaxChannelsCountVal = 1
148
146
mcc .newChains = make ([]* cb.Envelope , 2 )
149
147
150
- configUpdateEnv , _ := configtx .NewCompositeTemplate (
148
+ configEnv , err := configtx .NewCompositeTemplate (
151
149
configtx .NewSimpleTemplate (
152
150
config .DefaultHashingAlgorithm (),
153
151
config .DefaultBlockDataHashingStructure (),
154
152
config .TemplateOrdererAddresses ([]string {"foo" }),
155
153
),
156
154
configtx .NewChainCreationTemplate ("SampleConsortium" , []string {}),
157
- ).Envelope (newChannelID )
158
-
159
- ingressTx := makeConfigTxFromConfigUpdateEnvelope (newChannelID , configUpdateEnv , true )
160
- ordererTx := wrapConfigTx (ingressTx )
155
+ ).Envelope (newChainID )
156
+ if err != nil {
157
+ t .Fatalf ("Error constructing configtx" )
158
+ }
159
+ ingressTx := makeConfigTxFromConfigUpdateEnvelope (newChainID , configEnv )
160
+ wrapped := wrapConfigTx (ingressTx )
161
161
162
162
sysFilter := newSystemChainFilter (mcc .ms , mcc )
163
- action , _ := sysFilter .Apply (ordererTx )
163
+ action , _ := sysFilter .Apply (wrapped )
164
164
165
165
assert .EqualValues (t , filter .Reject , action , "Transaction had created too many channels" )
166
166
}
0 commit comments