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