github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/basic_chain_test.go (about) 1 package core_test 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 "time" 8 9 "github.com/nspcc-dev/neo-go/internal/basicchain" 10 "github.com/nspcc-dev/neo-go/pkg/config" 11 "github.com/nspcc-dev/neo-go/pkg/core/chaindump" 12 "github.com/nspcc-dev/neo-go/pkg/io" 13 "github.com/nspcc-dev/neo-go/pkg/neotest" 14 "github.com/nspcc-dev/neo-go/pkg/neotest/chain" 15 "github.com/stretchr/testify/require" 16 ) 17 18 const ( 19 // basicChainPrefix is a prefix used to store Basic chain .acc file for tests. 20 // It is also used to retrieve smart contracts that should be deployed to 21 // Basic chain. 22 basicChainPrefix = "../services/rpcsrv/testdata/" 23 // bcPersistInterval is the time period Blockchain persists changes to the 24 // underlying storage. 25 bcPersistInterval = time.Second 26 ) 27 28 var ( 29 pathToInternalContracts = filepath.Join("..", "..", "internal", "contracts") 30 ) 31 32 // TestCreateBasicChain generates "../rpc/testdata/testblocks.acc" file which 33 // contains data for RPC unit tests. It also is a nice integration test. 34 // To generate new "../rpc/testdata/testblocks.acc", follow the steps: 35 // 1. Set saveChain down below to true 36 // 2. Run tests with `$ make test` 37 func TestCreateBasicChain(t *testing.T) { 38 const saveChain = false 39 40 bc, validators, committee := chain.NewMultiWithCustomConfig(t, func(cfg *config.Blockchain) { 41 cfg.P2PSigExtensions = true 42 }) 43 e := neotest.NewExecutor(t, bc, validators, committee) 44 45 basicchain.Init(t, "../../", e) 46 47 if saveChain { 48 outStream, err := os.Create(basicChainPrefix + "testblocks.acc") 49 require.NoError(t, err) 50 t.Cleanup(func() { 51 outStream.Close() 52 }) 53 54 writer := io.NewBinWriterFromIO(outStream) 55 writer.WriteU32LE(bc.BlockHeight()) 56 err = chaindump.Dump(bc, writer, 1, bc.BlockHeight()) 57 require.NoError(t, err) 58 } 59 60 require.False(t, saveChain) 61 }