forked from TrueCloudLab/neoneo-go
Merge pull request #2272 from nspcc-dev/fix-sender-custom-scopes
Fix custom sender scopes in CreateTxFromScript
This commit is contained in:
commit
a6e5c18359
4 changed files with 52 additions and 10 deletions
|
@ -466,9 +466,17 @@ func TestComlileAndInvokeFunction(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("with cosigner", func(t *testing.T) {
|
||||
t.Run("cosigner is sender", func(t *testing.T) {
|
||||
t.Run("cosigner is sender (none)", func(t *testing.T) {
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, append(cmd, hVerify.StringLE(), "verify", "--", validatorAddr+":Global")...)
|
||||
e.RunWithError(t, append(cmd, h.StringLE(), "checkSenderWitness", "--", validatorAddr+":None")...)
|
||||
})
|
||||
t.Run("cosigner is sender (customcontract)", func(t *testing.T) {
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, append(cmd, h.StringLE(), "checkSenderWitness", "--", validatorAddr+":CustomContracts:"+h.StringLE())...)
|
||||
})
|
||||
t.Run("cosigner is sender (global)", func(t *testing.T) {
|
||||
e.In.WriteString("one\r")
|
||||
e.Run(t, append(cmd, h.StringLE(), "checkSenderWitness", "--", validatorAddr+":Global")...)
|
||||
})
|
||||
|
||||
acc, err := wallet.NewAccount()
|
||||
|
|
8
cli/testdata/deploy/main.go
vendored
8
cli/testdata/deploy/main.go
vendored
|
@ -40,6 +40,14 @@ func Fail() {
|
|||
panic("as expected")
|
||||
}
|
||||
|
||||
// CheckSenderWitness checks sender's witness.
|
||||
func CheckSenderWitness() {
|
||||
tx := runtime.GetScriptContainer()
|
||||
if !runtime.CheckWitness(tx.Sender) {
|
||||
panic("not witnessed")
|
||||
}
|
||||
}
|
||||
|
||||
// Update updates contract with the new one.
|
||||
func Update(script, manifest []byte) {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
|
|
|
@ -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,6 +710,7 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
|||
gasContractHash, err := c.GetNativeContractHash(nativenames.Gas)
|
||||
require.NoError(t, err)
|
||||
|
||||
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))
|
||||
|
@ -717,6 +718,31 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
|||
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