interop/runtime: allow calling script hash to pass CheckWitness
See neo-project/neo#1924 and neo-project/neo#1925.
This commit is contained in:
parent
bf3ed10951
commit
53c9690bdc
4 changed files with 12 additions and 1 deletions
|
@ -431,6 +431,8 @@ func TestVerifyTx(t *testing.T) {
|
||||||
VerificationScript: testchain.CommitteeVerificationScript(),
|
VerificationScript: testchain.CommitteeVerificationScript(),
|
||||||
}}
|
}}
|
||||||
ic := bc.newInteropContext(trigger.All, bc.dao, nil, txSetOracle)
|
ic := bc.newInteropContext(trigger.All, bc.dao, nil, txSetOracle)
|
||||||
|
ic.SpawnVM()
|
||||||
|
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
||||||
require.NoError(t, bc.contracts.Oracle.SetOracleNodes(ic, oraclePubs))
|
require.NoError(t, bc.contracts.Oracle.SetOracleNodes(ic, oraclePubs))
|
||||||
bc.contracts.Oracle.OnPersistEnd(ic.DAO)
|
bc.contracts.Oracle.OnPersistEnd(ic.DAO)
|
||||||
_, err = ic.DAO.Persist()
|
_, err = ic.DAO.Persist()
|
||||||
|
|
|
@ -17,6 +17,10 @@ import (
|
||||||
// CheckHashedWitness checks given hash against current list of script hashes
|
// CheckHashedWitness checks given hash against current list of script hashes
|
||||||
// for verifying in the interop context.
|
// for verifying in the interop context.
|
||||||
func CheckHashedWitness(ic *interop.Context, hash util.Uint160) (bool, error) {
|
func CheckHashedWitness(ic *interop.Context, hash util.Uint160) (bool, error) {
|
||||||
|
callingSH := ic.VM.GetCallingScriptHash()
|
||||||
|
if !callingSH.Equals(util.Uint160{}) && hash.Equals(callingSH) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
if tx, ok := ic.Container.(*transaction.Transaction); ok {
|
if tx, ok := ic.Container.(*transaction.Transaction); ok {
|
||||||
return checkScope(ic.DAO, tx, ic.VM, hash)
|
return checkScope(ic.DAO, tx, ic.VM, hash)
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ func TestNEO_SetGasPerBlock(t *testing.T) {
|
||||||
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
||||||
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
|
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
|
||||||
ic.VM = vm.New()
|
ic.VM = vm.New()
|
||||||
|
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
||||||
|
|
||||||
h := neo.GetCommitteeAddress()
|
h := neo.GetCommitteeAddress()
|
||||||
t.Run("Default", func(t *testing.T) {
|
t.Run("Default", func(t *testing.T) {
|
||||||
|
@ -177,6 +178,8 @@ func TestNEO_CalculateBonus(t *testing.T) {
|
||||||
neo := bc.contracts.NEO
|
neo := bc.contracts.NEO
|
||||||
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
||||||
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
|
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
|
||||||
|
ic.SpawnVM()
|
||||||
|
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
||||||
t.Run("Invalid", func(t *testing.T) {
|
t.Run("Invalid", func(t *testing.T) {
|
||||||
_, err := neo.CalculateBonus(ic, new(big.Int).SetInt64(-1), 0, 1)
|
_, err := neo.CalculateBonus(ic, new(big.Int).SetInt64(-1), 0, 1)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
|
@ -139,6 +139,8 @@ func TestOracle_Request(t *testing.T) {
|
||||||
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
||||||
setSigner(tx, testchain.CommitteeScriptHash())
|
setSigner(tx, testchain.CommitteeScriptHash())
|
||||||
ic := bc.newInteropContext(trigger.Application, bc.dao, nil, tx)
|
ic := bc.newInteropContext(trigger.Application, bc.dao, nil, tx)
|
||||||
|
ic.SpawnVM()
|
||||||
|
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
||||||
err = orc.SetOracleNodes(ic, keys.PublicKeys{pub})
|
err = orc.SetOracleNodes(ic, keys.PublicKeys{pub})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
orc.OnPersistEnd(ic.DAO)
|
orc.OnPersistEnd(ic.DAO)
|
||||||
|
@ -164,7 +166,6 @@ func TestOracle_Request(t *testing.T) {
|
||||||
|
|
||||||
// We need to ensure that callback is called thus, executing full script is necessary.
|
// We need to ensure that callback is called thus, executing full script is necessary.
|
||||||
resp.ID = 1
|
resp.ID = 1
|
||||||
ic.VM = ic.SpawnVM()
|
|
||||||
ic.VM.LoadScriptWithFlags(tx.Script, smartcontract.All)
|
ic.VM.LoadScriptWithFlags(tx.Script, smartcontract.All)
|
||||||
require.NoError(t, ic.VM.Run())
|
require.NoError(t, ic.VM.Run())
|
||||||
|
|
||||||
|
@ -223,6 +224,7 @@ func TestOracle_SetOracleNodes(t *testing.T) {
|
||||||
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
tx := transaction.New(netmode.UnitTestNet, []byte{}, 0)
|
||||||
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
|
ic := bc.newInteropContext(trigger.System, bc.dao, nil, tx)
|
||||||
ic.VM = vm.New()
|
ic.VM = vm.New()
|
||||||
|
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
||||||
|
|
||||||
pubs := orc.GetOracleNodes()
|
pubs := orc.GetOracleNodes()
|
||||||
require.Equal(t, 0, len(pubs))
|
require.Equal(t, 0, len(pubs))
|
||||||
|
|
Loading…
Reference in a new issue