From 6b105e6d1049d6288a39e2b3d725a45d832d2ea6 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 9 Dec 2021 17:58:20 +0300 Subject: [PATCH] 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. --- pkg/neotest/basic.go | 20 ++++++++++++-------- pkg/neotest/client.go | 11 ++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index 501254ae9..dc217f01e 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -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 } diff --git a/pkg/neotest/client.go b/pkg/neotest/client.go index 89ac48cf7..330cf8a3e 100644 --- a/pkg/neotest/client.go +++ b/pkg/neotest/client.go @@ -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...)