diff --git a/cli/vm/cli_test.go b/cli/vm/cli_test.go index acb74e77d2..106776bb7c 100644 --- a/cli/vm/cli_test.go +++ b/cli/vm/cli_test.go @@ -1129,7 +1129,7 @@ func TestRunWithHistoricState(t *testing.T) { e.checkNextLine(t, "READY: loaded 36 instructions") e.checkStack(t, []byte{1}) e.checkNextLine(t, "READY: loaded 36 instructions") - e.checkNextLineExact(t, "Error: at instruction 31 (SYSCALL): System.Contract.Call failed: called contract 0f825b050eb8ce9eaa82993e90615025ab798016 not found: key not found\n") + e.checkNextLineExact(t, "Error: at instruction 31 (SYSCALL): System.Contract.Call failed: called contract fc78291ebacd4dc1d4d6a16399ccb1fac8438d93 not found: key not found\n") } func TestEvents(t *testing.T) { diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 3139f6c7d7..bf20185c8c 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -2508,6 +2508,12 @@ func codeGen(info *buildInfo) (*nef.File, *DebugInfo, error) { if c.callTokens != nil { f.Tokens = c.callTokens } + if info.options != nil && info.options.SourceURL != "" { + if len(info.options.SourceURL) > nef.MaxSourceURLLength { + return nil, nil, errors.New("too long source URL") + } + f.Source = info.options.SourceURL + } f.Checksum = f.CalculateChecksum() return f, di, vm.IsScriptCorrect(buf, methods) } diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 6222c67ca9..f04099b983 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -2,7 +2,6 @@ package compiler import ( "encoding/json" - "errors" "fmt" "go/ast" "go/parser" @@ -267,13 +266,6 @@ func CompileAndSave(src string, o *Options) ([]byte, error) { if err != nil { return nil, fmt.Errorf("error while trying to compile smart contract file: %w", err) } - if o.SourceURL != "" { - if len(o.SourceURL) > nef.MaxSourceURLLength { - return nil, errors.New("too long source URL") - } - f.Source = o.SourceURL - f.Checksum = f.CalculateChecksum() - } bytes, err := f.Bytes() if err != nil { return nil, fmt.Errorf("error while serializing .nef file: %w", err) diff --git a/pkg/neotest/compile.go b/pkg/neotest/compile.go index e727f1b5f5..c890ec04a8 100644 --- a/pkg/neotest/compile.go +++ b/pkg/neotest/compile.go @@ -62,9 +62,6 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s // nef.NewFile() cares about version a lot. config.Version = "neotest" - ne, di, err := compiler.CompileWithOptions(srcPath, nil, nil) - require.NoError(t, err) - conf, err := smartcontract.ParseContractConfig(configPath) require.NoError(t, err) @@ -80,6 +77,8 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s o.SafeMethods = conf.SafeMethods o.Overloads = conf.Overloads o.SourceURL = conf.SourceURL + ne, di, err := compiler.CompileWithOptions(srcPath, nil, o) + require.NoError(t, err) m, err := compiler.CreateManifest(di, o) require.NoError(t, err) diff --git a/pkg/neotest/compile_test.go b/pkg/neotest/compile_test.go index c4e05bc940..f24a85bbc7 100644 --- a/pkg/neotest/compile_test.go +++ b/pkg/neotest/compile_test.go @@ -26,3 +26,10 @@ func TestCompileFileCashedIdentifiers(t *testing.T) { contract2 := CompileFile(t, sender, srcPath, configPath2) require.NotEqual(t, contract1, contract2) } + +func TestAddSourceURLToNEF(t *testing.T) { + srcPath := "../../internal/basicchain/testdata/test_contract.go" + configPath := "../../internal/basicchain/testdata/test_contract.yml" + ctr := CompileFile(t, util.Uint160{}, srcPath, configPath) + require.NotEqual(t, "", ctr.NEF.Source) +}