Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/vm/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/compiler/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package compiler

import (
"encoding/json"
"errors"
"fmt"
"go/ast"
"go/parser"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions pkg/neotest/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ 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)

o := &compiler.Options{}
o.SourceURL = conf.SourceURL
o.Name = conf.Name
o.ContractEvents = conf.Events
o.DeclaredNamedTypes = conf.NamedTypes
Expand All @@ -79,7 +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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless change.

ne, di, err := compiler.CompileWithOptions(srcPath, nil, o)
require.NoError(t, err)
m, err := compiler.CreateManifest(di, o)
require.NoError(t, err)

Expand Down
7 changes: 7 additions & 0 deletions pkg/neotest/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading