2022-03-10 14:12:04 +00:00
|
|
|
package core_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2022-03-11 14:47:59 +00:00
|
|
|
"time"
|
2022-03-10 14:12:04 +00:00
|
|
|
|
2022-06-08 12:17:40 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/basicchain"
|
2022-03-10 14:12:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/chaindump"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// basicChainPrefix is a prefix used to store Basic chain .acc file for tests.
|
|
|
|
// It is also used to retrieve smart contracts that should be deployed to
|
|
|
|
// Basic chain.
|
2022-07-21 13:21:44 +00:00
|
|
|
basicChainPrefix = "../services/rpcsrv/testdata/"
|
2022-03-11 14:47:59 +00:00
|
|
|
// bcPersistInterval is the time period Blockchain persists changes to the
|
|
|
|
// underlying storage.
|
|
|
|
bcPersistInterval = time.Second
|
2022-03-10 14:12:04 +00:00
|
|
|
)
|
|
|
|
|
2022-03-11 14:47:59 +00:00
|
|
|
var (
|
|
|
|
pathToInternalContracts = filepath.Join("..", "..", "internal", "contracts")
|
|
|
|
)
|
2022-03-10 14:12:04 +00:00
|
|
|
|
|
|
|
// TestCreateBasicChain generates "../rpc/testdata/testblocks.acc" file which
|
|
|
|
// contains data for RPC unit tests. It also is a nice integration test.
|
|
|
|
// To generate new "../rpc/testdata/testblocks.acc", follow the steps:
|
2022-08-08 10:23:21 +00:00
|
|
|
// 1. Set saveChain down below to true
|
|
|
|
// 2. Run tests with `$ make test`
|
2022-03-10 14:12:04 +00:00
|
|
|
func TestCreateBasicChain(t *testing.T) {
|
|
|
|
const saveChain = false
|
|
|
|
|
2022-12-06 13:34:38 +00:00
|
|
|
bc, validators, committee := chain.NewMultiWithCustomConfig(t, func(cfg *config.Blockchain) {
|
2022-03-10 14:12:04 +00:00
|
|
|
cfg.P2PSigExtensions = true
|
|
|
|
})
|
|
|
|
e := neotest.NewExecutor(t, bc, validators, committee)
|
|
|
|
|
2022-06-08 12:17:40 +00:00
|
|
|
basicchain.Init(t, "../../", e)
|
2022-03-10 14:12:04 +00:00
|
|
|
|
|
|
|
if saveChain {
|
|
|
|
outStream, err := os.Create(basicChainPrefix + "testblocks.acc")
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Cleanup(func() {
|
|
|
|
outStream.Close()
|
|
|
|
})
|
|
|
|
|
|
|
|
writer := io.NewBinWriterFromIO(outStream)
|
|
|
|
writer.WriteU32LE(bc.BlockHeight())
|
|
|
|
err = chaindump.Dump(bc, writer, 1, bc.BlockHeight())
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.False(t, saveChain)
|
|
|
|
}
|