forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BFT chain unit tests: successful tx propagation
Signed-off-by: May Rosenbaum <[email protected]> Signed-off-by: Emil Elizarov <[email protected]>
- Loading branch information
1 parent
7424152
commit f1f0ef7
Showing
15 changed files
with
2,511 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright IBM Corp. All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package smartbft_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"testing" | ||
|
||
cb "github.com/hyperledger/fabric-protos-go/common" | ||
"github.com/hyperledger/fabric-protos-go/msp" | ||
"github.com/hyperledger/fabric/protoutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
nonce uint64 = 0 | ||
) | ||
|
||
// Scenario: | ||
// 1. Start a network of 4 nodes | ||
// 2. Submit a TX | ||
// 3. Wait for the TX to be received by all nodes | ||
func TestSuccessfulTxPropagation(t *testing.T) { | ||
dir := t.TempDir() | ||
channelId := "testchannel" | ||
|
||
networkSetupInfo := NewNetworkSetupInfo(t, channelId, dir) | ||
nodeMap := networkSetupInfo.CreateNodes(4) | ||
networkSetupInfo.StartAllNodes() | ||
|
||
for _, node := range nodeMap { | ||
node.State.WaitLedgerHeightToBe(1) | ||
} | ||
|
||
env := createEndorserTxEnvelope("TEST_MESSAGE #1", channelId) | ||
err := networkSetupInfo.SendTxToAllAvailableNodes(env) | ||
require.NoError(t, err) | ||
for _, node := range nodeMap { | ||
node.State.WaitLedgerHeightToBe(2) | ||
} | ||
} | ||
|
||
func createEndorserTxEnvelope(message string, channelId string) *cb.Envelope { | ||
return &cb.Envelope{ | ||
Payload: protoutil.MarshalOrPanic(&cb.Payload{ | ||
Header: &cb.Header{ | ||
ChannelHeader: protoutil.MarshalOrPanic(&cb.ChannelHeader{ | ||
Type: int32(cb.HeaderType_ENDORSER_TRANSACTION), | ||
ChannelId: channelId, | ||
}), | ||
SignatureHeader: protoutil.MarshalOrPanic(&cb.SignatureHeader{ | ||
Creator: protoutil.MarshalOrPanic(&msp.SerializedIdentity{ | ||
Mspid: "mockMSP", | ||
IdBytes: []byte("mockClient"), | ||
}), | ||
Nonce: generateNonce(), | ||
}), | ||
}, | ||
Data: []byte(message), | ||
}), | ||
Signature: []byte{1, 2, 3}, | ||
} | ||
} | ||
|
||
func generateNonce() []byte { | ||
nonceBuf := new(bytes.Buffer) | ||
err := binary.Write(nonceBuf, binary.LittleEndian, nonce) | ||
if err != nil { | ||
panic("Cannot generate nonce") | ||
} | ||
nonce++ | ||
return nonceBuf.Bytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package smartbft | ||
|
||
import ( | ||
"sync/atomic" | ||
|
||
protos "github.com/SmartBFT-Go/consensus/smartbftprotos" | ||
"github.com/hyperledger/fabric/common/policies" | ||
"github.com/hyperledger/fabric/orderer/common/cluster" | ||
"github.com/hyperledger/fabric/orderer/consensus" | ||
) | ||
|
||
//go:generate mockery --dir . --name ConsenterSupport --case underscore --with-expecter=true --output mocks | ||
|
||
// ConsenterSupport provides the resources available to a Consenter implementation. | ||
type ConsenterSupport interface { | ||
consensus.ConsenterSupport | ||
} | ||
|
||
//go:generate mockery --dir . --name Communicator --case underscore --with-expecter=true --output mocks | ||
|
||
// Communicator defines communication for a consenter | ||
type Communicator interface { | ||
cluster.Communicator | ||
} | ||
|
||
//go:generate mockery --dir . --name PolicyManager --case underscore --with-expecter=true --output mocks | ||
|
||
// PolicyManager is a read only subset of the policy ManagerImpl | ||
type PolicyManager interface { | ||
policies.Manager | ||
} | ||
|
||
//go:generate mockery --dir . --name Policy --case underscore --with-expecter=true --output mocks | ||
|
||
// Policy is used to determine if a signature is valid | ||
type Policy interface { | ||
policies.Policy | ||
} | ||
|
||
//go:generate mockery --dir . --name EgressComm --case underscore --with-expecter=true --output mocks | ||
|
||
type EgressCommFactory func(runtimeConfig *atomic.Value, channelId string, comm Communicator) EgressComm | ||
|
||
// Comm enables the communications between the nodes. | ||
type EgressComm interface { | ||
// SendConsensus sends the consensus protocol related message m to the node with id targetID. | ||
SendConsensus(targetID uint64, m *protos.Message) | ||
// SendTransaction sends the given client's request to the node with id targetID. | ||
SendTransaction(targetID uint64, request []byte) | ||
// Nodes returns a set of ids of participating nodes. | ||
// In case you need to change or keep this slice, create a copy. | ||
Nodes() []uint64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.