internal: extend committee for unit tests
Committee should differ from the set of validators, to catch possible bugs during testing.
This commit is contained in:
parent
3468f97836
commit
b0c051b817
2 changed files with 57 additions and 3 deletions
|
@ -7,6 +7,8 @@ ProtocolConfiguration:
|
||||||
- 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e
|
- 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e
|
||||||
- 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699
|
- 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699
|
||||||
- 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62
|
- 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62
|
||||||
|
- 02c429b3ea1aa486cb2edfd6e99d8055c1f81f1a9206664e2c40a586d187257557
|
||||||
|
- 02c4de32252c50fa171dbe25379e4e2d55cdc12f69e382c39f59a44573ecff2f9d
|
||||||
ValidatorsCount: 4
|
ValidatorsCount: 4
|
||||||
SeedList:
|
SeedList:
|
||||||
- 127.0.0.1:20334
|
- 127.0.0.1:20334
|
||||||
|
|
|
@ -23,18 +23,31 @@ var privNetKeys = []string{
|
||||||
"KzgWE3u3EDp13XPXXuTKZxeJ3Gi8Bsm8f9ijY3ZsCKKRvZUo1Cdn",
|
"KzgWE3u3EDp13XPXXuTKZxeJ3Gi8Bsm8f9ijY3ZsCKKRvZUo1Cdn",
|
||||||
"KxyjQ8eUa4FHt3Gvioyt1Wz29cTUrE4eTqX3yFSk1YFCsPL8uNsY",
|
"KxyjQ8eUa4FHt3Gvioyt1Wz29cTUrE4eTqX3yFSk1YFCsPL8uNsY",
|
||||||
"L2oEXKRAAMiPEZukwR5ho2S6SMeQLhcK9mF71ZnF7GvT8dU4Kkgz",
|
"L2oEXKRAAMiPEZukwR5ho2S6SMeQLhcK9mF71ZnF7GvT8dU4Kkgz",
|
||||||
|
|
||||||
|
// Provide 2 committee extra members so that committee address differs from
|
||||||
|
// the validators one.
|
||||||
|
"L1Tr1iq5oz1jaFaMXP21sHDkJYDDkuLtpvQ4wRf1cjKvJYvnvpAb",
|
||||||
|
"Kz6XTUrExy78q8f4MjDHnwz8fYYyUE8iPXwPRAkHa3qN2JcHYm7e",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidatorsCount returns number of validators in the testchain.
|
||||||
|
const ValidatorsCount = 4
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ids maps validators order by public key sorting to validators ID.
|
// ids maps validators order by public key sorting to validators ID.
|
||||||
// which is an order of the validator in the StandByValidators list.
|
// which is an order of the validator in the StandByValidators list.
|
||||||
ids = []int{1, 3, 0, 2}
|
ids = []int{1, 3, 0, 2, 4, 5}
|
||||||
// orders maps to validators id to it's order by public key sorting.
|
// orders maps to validators id to it's order by public key sorting.
|
||||||
orders = []int{2, 0, 3, 1}
|
orders = []int{2, 0, 3, 1, 4, 5}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Size returns testchain initial validators amount.
|
// Size returns testchain initial validators amount.
|
||||||
func Size() int {
|
func Size() int {
|
||||||
|
return ValidatorsCount
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommitteeSize returns testchain committee size.
|
||||||
|
func CommitteeSize() int {
|
||||||
return len(privNetKeys)
|
return len(privNetKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +79,7 @@ func PrivateKeyByID(id int) *keys.PrivateKey {
|
||||||
// MultisigVerificationScript returns script hash of the consensus multisig address.
|
// MultisigVerificationScript returns script hash of the consensus multisig address.
|
||||||
func MultisigVerificationScript() []byte {
|
func MultisigVerificationScript() []byte {
|
||||||
var pubs keys.PublicKeys
|
var pubs keys.PublicKeys
|
||||||
for i := range privNetKeys {
|
for i := range privNetKeys[:ValidatorsCount] {
|
||||||
priv := PrivateKey(ids[i])
|
priv := PrivateKey(ids[i])
|
||||||
pubs = append(pubs, priv.PublicKey())
|
pubs = append(pubs, priv.PublicKey())
|
||||||
}
|
}
|
||||||
|
@ -88,6 +101,31 @@ func MultisigAddress() string {
|
||||||
return address.Uint160ToString(MultisigScriptHash())
|
return address.Uint160ToString(MultisigScriptHash())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommitteeVerificationScript returns script hash of the committee multisig address.
|
||||||
|
func CommitteeVerificationScript() []byte {
|
||||||
|
var pubs keys.PublicKeys
|
||||||
|
for i := range privNetKeys {
|
||||||
|
priv := PrivateKey(ids[i])
|
||||||
|
pubs = append(pubs, priv.PublicKey())
|
||||||
|
}
|
||||||
|
|
||||||
|
script, err := smartcontract.CreateMajorityMultiSigRedeemScript(pubs)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return script
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommitteeScriptHash returns committee address as Uint160.
|
||||||
|
func CommitteeScriptHash() util.Uint160 {
|
||||||
|
return hash.Hash160(CommitteeVerificationScript())
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommitteeAddress return committee address as string.
|
||||||
|
func CommitteeAddress() string {
|
||||||
|
return address.Uint160ToString(CommitteeScriptHash())
|
||||||
|
}
|
||||||
|
|
||||||
// Sign signs data by all consensus nodes and returns invocation script.
|
// Sign signs data by all consensus nodes and returns invocation script.
|
||||||
func Sign(data []byte) []byte {
|
func Sign(data []byte) []byte {
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
|
@ -102,6 +140,20 @@ func Sign(data []byte) []byte {
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignCommittee signs data by a majority of committee members.
|
||||||
|
func SignCommittee(data []byte) []byte {
|
||||||
|
buf := io.NewBufBinWriter()
|
||||||
|
for i := 0; i < CommitteeSize()/2+1; i++ {
|
||||||
|
pKey := PrivateKey(i)
|
||||||
|
sig := pKey.Sign(data)
|
||||||
|
if len(sig) != 64 {
|
||||||
|
panic("wrong signature length")
|
||||||
|
}
|
||||||
|
emit.Bytes(buf.BinWriter, sig)
|
||||||
|
}
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
// NewBlock creates new block for the given blockchain with the given offset
|
// NewBlock creates new block for the given blockchain with the given offset
|
||||||
// (usually, 1), primary node index and transactions.
|
// (usually, 1), primary node index and transactions.
|
||||||
func NewBlock(t *testing.T, bc blockchainer.Blockchainer, offset uint32, primary uint32, txs ...*transaction.Transaction) *block.Block {
|
func NewBlock(t *testing.T, bc blockchainer.Blockchainer, offset uint32, primary uint32, txs ...*transaction.Transaction) *block.Block {
|
||||||
|
|
Loading…
Reference in a new issue