core: compiler contract on-the-fly in helper test

Generate proper manifest file too.
This commit is contained in:
Evgenii Stratonikov 2020-07-23 17:00:06 +03:00
parent 04bf357fa5
commit 54d7882acf
2 changed files with 7 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package core package core
import ( import (
"bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -10,6 +11,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native"
@ -20,7 +22,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/opcode"
@ -223,13 +224,15 @@ func TestCreateBasicChain(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Push some contract into the chain. // Push some contract into the chain.
avm, err := ioutil.ReadFile(prefix + "test_contract.avm") c, err := ioutil.ReadFile(prefix + "test_contract.go")
require.NoError(t, err)
avm, di, err := compiler.CompileWithDebugInfo(bytes.NewReader(c))
require.NoError(t, err) require.NoError(t, err)
t.Logf("contractHash: %s", hash.Hash160(avm).StringLE()) t.Logf("contractHash: %s", hash.Hash160(avm).StringLE())
script := io.NewBufBinWriter() script := io.NewBufBinWriter()
m := manifest.NewManifest(hash.Hash160(avm)) m, err := di.ConvertToManifest(smartcontract.HasStorage)
m.Features = smartcontract.HasStorage require.NoError(t, err)
bs, err := m.MarshalJSON() bs, err := m.MarshalJSON()
require.NoError(t, err) require.NoError(t, err)
emit.Bytes(script.BinWriter, bs) emit.Bytes(script.BinWriter, bs)

Binary file not shown.