Skip to content

Commit

Permalink
neotest: Add 'LoadContract' method
Browse files Browse the repository at this point in the history
Signed-off-by: Chubru <[email protected]>
  • Loading branch information
Chubru committed Dec 19, 2024
1 parent 6d20772 commit 0362359
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/neotest/compile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package neotest

import (
"encoding/json"
"io"
"os"
"testing"

"github.com/nspcc-dev/neo-go/cli/smartcontract"
Expand Down Expand Up @@ -90,3 +92,30 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s
contracts[cacheKey] = c
return c
}

// LoadContract loads a contract from the specified NEF and manifest files.
func LoadContract(t testing.TB, sender util.Uint160, nefPath, manifestPath string) (*Contract, error) {
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)

err = m.IsValid(util.Uint160{}, true)
require.NoError(t, err)

hash := state.CreateContractHash(sender, ne.Checksum, m.Name)

return &Contract{
Hash: hash,
NEF: &ne,
Manifest: m,
}, nil

Check warning on line 120 in pkg/neotest/compile.go

View check run for this annotation

Codecov / codecov/patch

pkg/neotest/compile.go#L97-L120

Added lines #L97 - L120 were not covered by tests
}

0 comments on commit 0362359

Please sign in to comment.