mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 09:19:08 +00:00
Merge pull request #3771 from Chubru/feat/add_LoadContract
Add 'neotest.ReadNEF' method
This commit is contained in:
commit
992890721a
1 changed files with 36 additions and 0 deletions
|
@ -1,7 +1,9 @@
|
|||
package neotest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/cli/smartcontract"
|
||||
|
@ -90,3 +92,37 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s
|
|||
contracts[cacheKey] = c
|
||||
return c
|
||||
}
|
||||
|
||||
// ReadNEF loads a contract from the specified NEF and manifest files.
|
||||
func ReadNEF(t testing.TB, sender util.Uint160, nefPath, manifestPath string) *Contract {
|
||||
cacheKey := sender.StringLE() + "|" + nefPath + "|" + manifestPath
|
||||
if c, ok := contracts[cacheKey]; ok {
|
||||
return c
|
||||
}
|
||||
|
||||
nefBytes, err := os.ReadFile(nefPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
ne, err := nef.FileFromBytes(nefBytes)
|
||||
require.NoError(t, err)
|
||||
|
||||
manifestBytes, err := os.ReadFile(manifestPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
m := new(manifest.Manifest)
|
||||
err = json.Unmarshal(manifestBytes, m)
|
||||
require.NoError(t, err)
|
||||
|
||||
hash := state.CreateContractHash(sender, ne.Checksum, m.Name)
|
||||
err = m.IsValid(hash, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := &Contract{
|
||||
Hash: hash,
|
||||
NEF: &ne,
|
||||
Manifest: m,
|
||||
}
|
||||
|
||||
contracts[cacheKey] = c
|
||||
return c
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue