Skip to content

Commit 79d446d

Browse files
author
Tural Devrishev
committed
compiler: set SourceURL in NEF file
Close #3543. Signed-off-by: Tural Devrishev <[email protected]>
1 parent 82f975e commit 79d446d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

pkg/compiler/codegen.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,11 +2003,11 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
20032003
emit.Opcodes(c.prog.BinWriter, opcode.DUP, opcode.SIZE) // x y cnt x y len(y)
20042004
emit.Opcodes(c.prog.BinWriter, opcode.PUSH3, opcode.PICK) // x y cnt x y len(y) cnt
20052005
after := c.newLabel()
2006-
emit.Jmp(c.prog.BinWriter, opcode.JMPEQL, after) // x y cnt x y
2006+
emit.Jmp(c.prog.BinWriter, opcode.JMPEQL, after) // x y cnt x y
20072007
emit.Opcodes(c.prog.BinWriter, opcode.PUSH2, opcode.PICK, // x y cnt x y cnt
20082008
opcode.PICKITEM, // x y cnt x y[cnt]
20092009
opcode.APPEND, // x=append(x, y[cnt]) y cnt
2010-
opcode.INC) // x y cnt+1
2010+
opcode.INC) // x y cnt+1
20112011
emit.Jmp(c.prog.BinWriter, opcode.JMPL, start)
20122012
c.setLabel(after)
20132013
for range 4 { // leave x on stack
@@ -2508,6 +2508,9 @@ func codeGen(info *buildInfo) (*nef.File, *DebugInfo, error) {
25082508
if c.callTokens != nil {
25092509
f.Tokens = c.callTokens
25102510
}
2511+
if info.options != nil && len(info.options.SourceURL) > 0 {
2512+
f.Source = info.options.SourceURL
2513+
}
25112514
f.Checksum = f.CalculateChecksum()
25122515
return f, di, vm.IsScriptCorrect(buf, methods)
25132516
}

pkg/neotest/compile.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s
6262
// nef.NewFile() cares about version a lot.
6363
config.Version = "neotest"
6464

65-
ne, di, err := compiler.CompileWithOptions(srcPath, nil, nil)
66-
require.NoError(t, err)
67-
6865
conf, err := smartcontract.ParseContractConfig(configPath)
6966
require.NoError(t, err)
7067

7168
o := &compiler.Options{}
69+
o.SourceURL = conf.SourceURL
70+
71+
ne, di, err := compiler.CompileWithOptions(srcPath, nil, o)
72+
require.NoError(t, err)
73+
7274
o.Name = conf.Name
7375
o.ContractEvents = conf.Events
7476
o.DeclaredNamedTypes = conf.NamedTypes
@@ -79,7 +81,6 @@ func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath s
7981
}
8082
o.SafeMethods = conf.SafeMethods
8183
o.Overloads = conf.Overloads
82-
o.SourceURL = conf.SourceURL
8384
m, err := compiler.CreateManifest(di, o)
8485
require.NoError(t, err)
8586

pkg/neotest/compile_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ func TestCompileFileCashedIdentifiers(t *testing.T) {
2626
contract2 := CompileFile(t, sender, srcPath, configPath2)
2727
require.NotEqual(t, contract1, contract2)
2828
}
29+
30+
func TestAddSourceURLToNEFI(t *testing.T) {
31+
srcPath := "../../internal/basicchain/testdata/test_contract.go"
32+
configPath := "../../internal/basicchain/testdata/test_contract.yml"
33+
ctr := CompileFile(t, util.Uint160{}, srcPath, configPath)
34+
require.NotEqual(t, "", ctr.NEF.Source)
35+
}

0 commit comments

Comments
 (0)