neotest: provide both validator and committee

It will become useful for multi-node committee.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgeniy Stratonikov 2021-11-03 15:22:08 +03:00
parent 950adb7b89
commit bef2a6f7ae
2 changed files with 7 additions and 5 deletions

View file

@ -16,7 +16,7 @@ import (
func newNSClient(t *testing.T) *neotest.ContractInvoker { func newNSClient(t *testing.T) *neotest.ContractInvoker {
bc, acc := chain.NewSingle(t) bc, acc := chain.NewSingle(t)
e := neotest.NewExecutor(t, bc, acc) e := neotest.NewExecutor(t, bc, acc, acc)
c := neotest.CompileFile(t, e.CommitteeHash, "..", "../nns.yml") c := neotest.CompileFile(t, e.CommitteeHash, "..", "../nns.yml")
e.DeployContract(t, c, nil) e.DeployContract(t, c, nil)

View file

@ -27,18 +27,20 @@ import (
// Executor is a wrapper over chain state. // Executor is a wrapper over chain state.
type Executor struct { type Executor struct {
Chain blockchainer.Blockchainer Chain blockchainer.Blockchainer
Validator Signer
Committee Signer Committee Signer
CommitteeHash util.Uint160 CommitteeHash util.Uint160
Contracts map[string]*Contract Contracts map[string]*Contract
} }
// NewExecutor creates new executor instance from provided blockchain and committee. // NewExecutor creates new executor instance from provided blockchain and committee.
func NewExecutor(t *testing.T, bc blockchainer.Blockchainer, committee Signer) *Executor { func NewExecutor(t *testing.T, bc blockchainer.Blockchainer, validator, committee Signer) *Executor {
require.Equal(t, 1, len(bc.GetConfig().StandbyCommittee)) require.Equal(t, 1, len(bc.GetConfig().StandbyCommittee))
require.IsType(t, multiSigner{}, committee, "committee must be a multi-signer") require.IsType(t, multiSigner{}, committee, "committee must be a multi-signer")
return &Executor{ return &Executor{
Chain: bc, Chain: bc,
Validator: validator,
Committee: committee, Committee: committee,
CommitteeHash: committee.ScriptHash(), CommitteeHash: committee.ScriptHash(),
Contracts: make(map[string]*Contract), Contracts: make(map[string]*Contract),
@ -191,9 +193,9 @@ func (e *Executor) NewUnsignedBlock(t *testing.T, txs ...*transaction.Transactio
lastBlock := e.TopBlock(t) lastBlock := e.TopBlock(t)
b := &block.Block{ b := &block.Block{
Header: block.Header{ Header: block.Header{
NextConsensus: e.Committee.ScriptHash(), NextConsensus: e.Validator.ScriptHash(),
Script: transaction.Witness{ Script: transaction.Witness{
VerificationScript: e.Committee.Script(), VerificationScript: e.Validator.Script(),
}, },
Timestamp: lastBlock.Timestamp + 1, Timestamp: lastBlock.Timestamp + 1,
}, },
@ -219,7 +221,7 @@ func (e *Executor) AddNewBlock(t *testing.T, txs ...*transaction.Transaction) *b
// SignBlock add validators signature to b. // SignBlock add validators signature to b.
func (e *Executor) SignBlock(b *block.Block) *block.Block { func (e *Executor) SignBlock(b *block.Block) *block.Block {
invoc := e.Committee.SignHashable(uint32(e.Chain.GetConfig().Magic), b) invoc := e.Validator.SignHashable(uint32(e.Chain.GetConfig().Magic), b)
b.Script.InvocationScript = invoc b.Script.InvocationScript = invoc
return b return b
} }