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("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.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()
|
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")
|
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.
|
// Update updates contract with the new one.
|
||||||
func Update(script, manifest []byte) {
|
func Update(script, manifest []byte) {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
|
|
@ -714,7 +714,7 @@ func getSigners(sender *wallet.Account, cosigners []SignerAccount) ([]transactio
|
||||||
}
|
}
|
||||||
for _, c := range cosigners {
|
for _, c := range cosigners {
|
||||||
if c.Signer.Account == from {
|
if c.Signer.Account == from {
|
||||||
s.Scopes = c.Signer.Scopes
|
s = c.Signer
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
signers = append(signers, c.Signer)
|
signers = append(signers, c.Signer)
|
||||||
|
|
|
@ -710,13 +710,39 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
||||||
gasContractHash, err := c.GetNativeContractHash(nativenames.Gas)
|
gasContractHash, err := c.GetNativeContractHash(nativenames.Gas)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, nil)
|
t.Run("default scope", func(t *testing.T) {
|
||||||
require.NoError(t, err)
|
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, nil)
|
||||||
require.NoError(t, acc.SignTx(testchain.Network(), tx))
|
require.NoError(t, err)
|
||||||
require.NoError(t, chain.VerifyTx(tx))
|
require.NoError(t, acc.SignTx(testchain.Network(), tx))
|
||||||
v, _ := chain.GetTestVM(trigger.Application, tx, nil)
|
require.NoError(t, chain.VerifyTx(tx))
|
||||||
v.LoadScriptWithFlags(tx.Script, callflag.All)
|
v, _ := chain.GetTestVM(trigger.Application, tx, nil)
|
||||||
require.NoError(t, v.Run())
|
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) {
|
func TestInvokeVerify(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue