github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/cmd/bootstrap/run/execution_state_test.go (about)

     1  package run
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/onflow/crypto"
     9  	"github.com/onflow/crypto/hash"
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/onflow/flow-go/fvm"
    13  	"github.com/onflow/flow-go/model/bootstrap"
    14  	"github.com/onflow/flow-go/model/flow"
    15  	"github.com/onflow/flow-go/utils/unittest"
    16  )
    17  
    18  // This tests generates a checkpoint file to be used by the execution node when booting.
    19  func TestGenerateExecutionState(t *testing.T) {
    20  	seed := make([]byte, 48)
    21  	seed[0] = 1
    22  	sk, err := generateServiceAccountPrivateKey(seed)
    23  	require.NoError(t, err)
    24  
    25  	pk := sk.PublicKey(42)
    26  	bootstrapDir := t.TempDir()
    27  	trieDir := filepath.Join(bootstrapDir, bootstrap.DirnameExecutionState)
    28  	commit, err := GenerateExecutionState(
    29  		trieDir,
    30  		pk,
    31  		flow.Testnet.Chain(),
    32  		fvm.WithInitialTokenSupply(unittest.GenesisTokenSupply))
    33  	require.NoError(t, err)
    34  	fmt.Printf("sk: %v\n", sk)
    35  	fmt.Printf("pk: %v\n", pk)
    36  	fmt.Printf("commit: %x\n", commit)
    37  	fmt.Printf("a checkpoint file is generated at: %v\n", trieDir)
    38  }
    39  
    40  func generateServiceAccountPrivateKey(seed []byte) (flow.AccountPrivateKey, error) {
    41  	priv, err := crypto.GeneratePrivateKey(crypto.ECDSASecp256k1, seed)
    42  	if err != nil {
    43  		return flow.AccountPrivateKey{}, err
    44  	}
    45  
    46  	return flow.AccountPrivateKey{
    47  		PrivateKey: priv,
    48  		SignAlgo:   crypto.ECDSASecp256k1,
    49  		HashAlgo:   hash.SHA2_256,
    50  	}, nil
    51  }