Skip to content

Commit

Permalink
core: fix TestRestoreAfterDeploy
Browse files Browse the repository at this point in the history
A bit longer script easily solves the size problem.
  • Loading branch information
roman-khimov committed Dec 8, 2021
1 parent 06fc450 commit f87c595
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/core/native_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/stateroot"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm"
"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/stackitem"
"github.com/stretchr/testify/require"
)

// This is in a separate test because test test for long manifest
// prevents chain from being dumped. In any real scenario
// restrictions on tx script length will be applied before
// restrictions on manifest size. In this test providing manifest of max size
// leads to tx deserialization failure.
func TestRestoreAfterDeploy(t *testing.T) {
func TestDeployManifestOverflow(t *testing.T) {
bc := newTestChain(t)

// nef.NewFile() cares about version a lot.
Expand All @@ -45,9 +43,26 @@ func TestRestoreAfterDeploy(t *testing.T) {
nef1b, err := nef1.Bytes()
require.NoError(t, err)

res, err := invokeContractMethod(bc, 100_00000000, mgmtHash, "deploy", nef1b, append(manif1, make([]byte, manifest.MaxManifestSize)...))
w := io.NewBufBinWriter()
emit.Bytes(w.BinWriter, manif1)
emit.Int(w.BinWriter, manifest.MaxManifestSize)
emit.Opcodes(w.BinWriter, opcode.NEWBUFFER, opcode.CAT)
emit.Bytes(w.BinWriter, nef1b)
emit.Int(w.BinWriter, 2)
emit.Opcodes(w.BinWriter, opcode.PACK)
emit.AppCallNoArgs(w.BinWriter, mgmtHash, "deploy", callflag.All)
require.NoError(t, w.Err)
script := w.Bytes()

tx := transaction.New(script, 0)
tx.ValidUntilBlock = bc.blockHeight + 1
addSigners(neoOwner, tx)
setTxSystemFee(bc, 100_00000000, tx)
require.NoError(t, testchain.SignTx(bc, tx))

aers, err := persistBlock(bc, tx)
require.NoError(t, err)
checkFAULTState(t, res)
checkFAULTState(t, aers[0])
}

type memoryStore struct {
Expand Down

0 comments on commit f87c595

Please sign in to comment.