Sort PrivAccounts so Commit signatures are sorted
This commit is contained in:
parent
7bbd21f7ee
commit
28667a9a9f
|
@ -1,7 +1,8 @@
|
||||||
package ibc
|
package ibc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"bytes"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -15,6 +16,8 @@ import (
|
||||||
tm "github.com/tendermint/tendermint/types"
|
tm "github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NOTE: PrivAccounts are sorted by Address,
|
||||||
|
// GenesisDoc, not necessarily.
|
||||||
func genGenesisDoc(chainID string, numVals int) (*tm.GenesisDoc, []types.PrivAccount) {
|
func genGenesisDoc(chainID string, numVals int) (*tm.GenesisDoc, []types.PrivAccount) {
|
||||||
var privAccs []types.PrivAccount
|
var privAccs []types.PrivAccount
|
||||||
genDoc := &tm.GenesisDoc{
|
genDoc := &tm.GenesisDoc{
|
||||||
|
@ -33,9 +36,33 @@ func genGenesisDoc(chainID string, numVals int) (*tm.GenesisDoc, []types.PrivAcc
|
||||||
privAccs = append(privAccs, privAcc)
|
privAccs = append(privAccs, privAcc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort PrivAccounts
|
||||||
|
sort.Sort(PrivAccountsByAddress(privAccs))
|
||||||
|
|
||||||
return genDoc, privAccs
|
return genDoc, privAccs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
// Implements sort for sorting PrivAccount by address.
|
||||||
|
|
||||||
|
type PrivAccountsByAddress []types.PrivAccount
|
||||||
|
|
||||||
|
func (pas PrivAccountsByAddress) Len() int {
|
||||||
|
return len(pas)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pas PrivAccountsByAddress) Less(i, j int) bool {
|
||||||
|
return bytes.Compare(pas[i].Account.PubKey.Address(), pas[j].Account.PubKey.Address()) == -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pas PrivAccountsByAddress) Swap(i, j int) {
|
||||||
|
it := pas[i]
|
||||||
|
pas[i] = pas[j]
|
||||||
|
pas[j] = it
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
func TestIBCPlugin(t *testing.T) {
|
func TestIBCPlugin(t *testing.T) {
|
||||||
|
|
||||||
tree := eyes.NewLocalClient("", 0)
|
tree := eyes.NewLocalClient("", 0)
|
||||||
|
@ -119,9 +146,10 @@ func TestIBCPlugin(t *testing.T) {
|
||||||
resCommit := tree.CommitSync()
|
resCommit := tree.CommitSync()
|
||||||
appHash := resCommit.Data
|
appHash := resCommit.Data
|
||||||
header := tm.Header{
|
header := tm.Header{
|
||||||
ChainID: "test_chain",
|
ChainID: "test_chain",
|
||||||
Height: 999,
|
Height: 999,
|
||||||
AppHash: appHash,
|
AppHash: appHash,
|
||||||
|
ValidatorsHash: []byte("must_exist"), // TODO make optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a Commit that signs above header
|
// Construct a Commit that signs above header
|
||||||
|
@ -138,12 +166,11 @@ func TestIBCPlugin(t *testing.T) {
|
||||||
Height: 999,
|
Height: 999,
|
||||||
Round: 0,
|
Round: 0,
|
||||||
Type: tm.VoteTypePrecommit,
|
Type: tm.VoteTypePrecommit,
|
||||||
BlockID: tm.BlockID{},
|
BlockID: tm.BlockID{Hash: blockHash},
|
||||||
}
|
}
|
||||||
vote.Signature = privAcc.PrivKey.Sign(
|
vote.Signature = privAcc.PrivKey.Sign(
|
||||||
tm.SignBytes("test_chain", vote),
|
tm.SignBytes("test_chain", vote),
|
||||||
)
|
)
|
||||||
fmt.Println(">>", i, privAcc, vote)
|
|
||||||
commit.Precommits[i] = vote
|
commit.Precommits[i] = vote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue