|
1 | 1 | package neotest
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "encoding/json" |
4 | 5 | "io"
|
| 6 | + "os" |
5 | 7 | "testing"
|
6 | 8 |
|
7 | 9 | "github.com/nspcc-dev/neo-go/cli/smartcontract"
|
@@ -90,3 +92,37 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s
|
90 | 92 | contracts[cacheKey] = c
|
91 | 93 | return c
|
92 | 94 | }
|
| 95 | + |
| 96 | +// ReadNEF loads a contract from the specified NEF and manifest files. |
| 97 | +func ReadNEF(t testing.TB, sender util.Uint160, nefPath, manifestPath string) *Contract { |
| 98 | + cacheKey := sender.StringLE() + "|" + nefPath + "|" + manifestPath |
| 99 | + if c, ok := contracts[cacheKey]; ok { |
| 100 | + return c |
| 101 | + } |
| 102 | + |
| 103 | + nefBytes, err := os.ReadFile(nefPath) |
| 104 | + require.NoError(t, err) |
| 105 | + |
| 106 | + ne, err := nef.FileFromBytes(nefBytes) |
| 107 | + require.NoError(t, err) |
| 108 | + |
| 109 | + manifestBytes, err := os.ReadFile(manifestPath) |
| 110 | + require.NoError(t, err) |
| 111 | + |
| 112 | + m := new(manifest.Manifest) |
| 113 | + err = json.Unmarshal(manifestBytes, m) |
| 114 | + require.NoError(t, err) |
| 115 | + |
| 116 | + hash := state.CreateContractHash(sender, ne.Checksum, m.Name) |
| 117 | + err = m.IsValid(hash, true) |
| 118 | + require.NoError(t, err) |
| 119 | + |
| 120 | + c := &Contract{ |
| 121 | + Hash: hash, |
| 122 | + NEF: &ne, |
| 123 | + Manifest: m, |
| 124 | + } |
| 125 | + |
| 126 | + contracts[cacheKey] = c |
| 127 | + return c |
| 128 | +} |
0 commit comments