mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
native: add Oracle.finish reentrancy test
This commit is contained in:
parent
da2db74bc9
commit
8d170a1eb8
5 changed files with 31 additions and 2 deletions
|
@ -1,8 +1,11 @@
|
|||
package oraclecontract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/oracle"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||
)
|
||||
|
@ -22,3 +25,18 @@ func Handle(url string, data interface{}, code int, res []byte) {
|
|||
params := []interface{}{url, data, code, res}
|
||||
storage.Put(storage.GetContext(), "lastOracleResponse", std.Serialize(params))
|
||||
}
|
||||
|
||||
// HandleRecursive invokes oracle.finish again to test Oracle reentrance.
|
||||
func HandleRecursive(url string, data interface{}, code int, res []byte) {
|
||||
// Regular safety check.
|
||||
callingHash := runtime.GetCallingScriptHash()
|
||||
if !callingHash.Equals(oracle.Hash) {
|
||||
panic("not called from oracle contract")
|
||||
}
|
||||
|
||||
runtime.Notify("Invocation")
|
||||
if runtime.GetInvocationCounter() == 1 {
|
||||
// We provide no wrapper for finish in interops, it's not usually needed.
|
||||
contract.Call(interop.Hash160(oracle.Hash), "finish", contract.All)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue