mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +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
|
package neotest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/cli/smartcontract"
|
"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
|
contracts[cacheKey] = c
|
||||||
return 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