rpc/client: fix custom* scope processing in CreateTxFromScript
Copying just the scope doesn't work for CustomContracts, CustomGroups and Rules because they all contain additional metadata. Thanks @mialbu for reporting this.
This commit is contained in:
parent
aa06770b3d
commit
f58d424c6d
2 changed files with 34 additions and 8 deletions
|
@ -714,7 +714,7 @@ func getSigners(sender *wallet.Account, cosigners []SignerAccount) ([]transactio
|
|||
}
|
||||
for _, c := range cosigners {
|
||||
if c.Signer.Account == from {
|
||||
s.Scopes = c.Signer.Scopes
|
||||
s = c.Signer
|
||||
continue
|
||||
}
|
||||
signers = append(signers, c.Signer)
|
||||
|
|
|
@ -710,13 +710,39 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
|||
gasContractHash, err := c.GetNativeContractHash(nativenames.Gas)
|
||||
require.NoError(t, err)
|
||||
|
||||
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, acc.SignTx(testchain.Network(), tx))
|
||||
require.NoError(t, chain.VerifyTx(tx))
|
||||
v, _ := chain.GetTestVM(trigger.Application, tx, nil)
|
||||
v.LoadScriptWithFlags(tx.Script, callflag.All)
|
||||
require.NoError(t, v.Run())
|
||||
t.Run("default scope", func(t *testing.T) {
|
||||
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, acc.SignTx(testchain.Network(), tx))
|
||||
require.NoError(t, chain.VerifyTx(tx))
|
||||
v, _ := chain.GetTestVM(trigger.Application, tx, nil)
|
||||
v.LoadScriptWithFlags(tx.Script, callflag.All)
|
||||
require.NoError(t, v.Run())
|
||||
})
|
||||
t.Run("none scope", func(t *testing.T) {
|
||||
_, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []client.SignerAccount{{
|
||||
Signer: transaction.Signer{
|
||||
Account: priv.PublicKey().GetScriptHash(),
|
||||
Scopes: transaction.None,
|
||||
},
|
||||
}})
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("customcontracts scope", func(t *testing.T) {
|
||||
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []client.SignerAccount{{
|
||||
Signer: transaction.Signer{
|
||||
Account: priv.PublicKey().GetScriptHash(),
|
||||
Scopes: transaction.CustomContracts,
|
||||
AllowedContracts: []util.Uint160{gasContractHash},
|
||||
},
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, acc.SignTx(testchain.Network(), tx))
|
||||
require.NoError(t, chain.VerifyTx(tx))
|
||||
v, _ := chain.GetTestVM(trigger.Application, tx, nil)
|
||||
v.LoadScriptWithFlags(tx.Script, callflag.All)
|
||||
require.NoError(t, v.Run())
|
||||
})
|
||||
}
|
||||
|
||||
func TestInvokeVerify(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue