neotest: use validators account instead of committee to pay the bills

GAS and NEO tokens are sent to validators account (not the committee's
one). For single-node chain they are the same, but for four-nodes chain
they are different. Thus, use validators multisig address to create new
accounts and to deploy contracts.

Also, allow to provide desired account balance while creating new
account.
This commit is contained in:
Anna Shaleva 2021-12-09 17:58:20 +03:00
parent dcb06163da
commit 6b105e6d10
2 changed files with 22 additions and 9 deletions

View file

@ -109,15 +109,19 @@ func (e *Executor) SignTx(t *testing.T, tx *transaction.Transaction, sysFee int6
return tx
}
// NewAccount returns new signer holding 100.0 GAS. This method advances the chain
// by one block with a transfer transaction.
func (e *Executor) NewAccount(t *testing.T) Signer {
// NewAccount returns new signer holding 100.0 GAS (or given amount is specified).
// This method advances the chain by one block with a transfer transaction.
func (e *Executor) NewAccount(t *testing.T, expectedGASBalance ...int64) Signer {
acc, err := wallet.NewAccount()
require.NoError(t, err)
tx := e.NewTx(t, []Signer{e.Committee},
amount := int64(100_0000_0000)
if len(expectedGASBalance) != 0 {
amount = expectedGASBalance[0]
}
tx := e.NewTx(t, []Signer{e.Validator},
e.NativeHash(t, nativenames.Gas), "transfer",
e.Committee.ScriptHash(), acc.Contract.ScriptHash(), int64(100_0000_0000), nil)
e.Validator.ScriptHash(), acc.Contract.ScriptHash(), amount, nil)
e.AddNewBlock(t, tx)
e.CheckHalt(t, tx.Hash())
return NewSingleSigner(acc)
@ -233,11 +237,11 @@ func (e *Executor) NewDeployTx(t *testing.T, bc blockchainer.Blockchainer, c *Co
tx.Nonce = Nonce()
tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.Signers = []transaction.Signer{{
Account: e.Committee.ScriptHash(),
Account: e.Validator.ScriptHash(),
Scopes: transaction.Global,
}}
addNetworkFee(bc, tx, e.Committee)
require.NoError(t, e.Committee.SignTx(netmode.UnitTestNet, tx))
addNetworkFee(bc, tx, e.Validator)
require.NoError(t, e.Validator.SignTx(netmode.UnitTestNet, tx))
return tx
}

View file

@ -19,7 +19,7 @@ type ContractInvoker struct {
Signers []Signer
}
// CommitteeInvoker creates new ContractInvoker for contract with hash h.
// CommitteeInvoker creates new ContractInvoker for contract with hash h and committee multisignature signer.
func (e *Executor) CommitteeInvoker(h util.Uint160) *ContractInvoker {
return &ContractInvoker{
Executor: e,
@ -28,6 +28,15 @@ func (e *Executor) CommitteeInvoker(h util.Uint160) *ContractInvoker {
}
}
// ValidatorInvoker creates new ContractInvoker for contract with hash h and validators multisignature signer.
func (e *Executor) ValidatorInvoker(h util.Uint160) *ContractInvoker {
return &ContractInvoker{
Executor: e,
Hash: h,
Signers: []Signer{e.Validator},
}
}
// TestInvoke creates test VM and invokes method with args.
func (c *ContractInvoker) TestInvoke(t *testing.T, method string, args ...interface{}) (*vm.Stack, error) {
tx := c.PrepareInvokeNoSign(t, method, args...)