github.com/koko1123/flow-go-1@v0.29.6/utils/unittest/execution_state.go (about)

     1  package unittest
     2  
     3  import (
     4  	"encoding/hex"
     5  	"fmt"
     6  
     7  	"github.com/onflow/flow-go/crypto"
     8  	"github.com/onflow/flow-go/crypto/hash"
     9  
    10  	"github.com/onflow/cadence"
    11  
    12  	"github.com/koko1123/flow-go-1/model/flow"
    13  )
    14  
    15  // Used below with random service key
    16  // privateKey := flow.AccountPrivateKey{
    17  //	 PrivateKey: rootKey,
    18  //	 SignAlgo:   crypto.ECDSAP256,
    19  //	 HashAlgo:   hash.SHA2_256,
    20  // }
    21  
    22  const ServiceAccountPrivateKeyHex = "8ae3d0461cfed6d6f49bfc25fa899351c39d1bd21fdba8c87595b6c49bb4cc43"
    23  const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256
    24  const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256
    25  
    26  // Pre-calculated state commitment with root account with the above private key
    27  const GenesisStateCommitmentHex = "48bc690ac7ebf7cdb41df24c6f8ba011b206408623b6d56b3723910664cdb5aa"
    28  
    29  var GenesisStateCommitment flow.StateCommitment
    30  
    31  var GenesisTokenSupply = func() cadence.UFix64 {
    32  	// value, err := cadence.NewUFix64("10000000000.0") // 10 billion
    33  	value, err := cadence.NewUFix64("1000000000.0") // 1 billion
    34  	if err != nil {
    35  		panic(fmt.Errorf("invalid genesis token supply: %w", err))
    36  	}
    37  	return value
    38  }()
    39  
    40  var ServiceAccountPrivateKey flow.AccountPrivateKey
    41  var ServiceAccountPublicKey flow.AccountPublicKey
    42  
    43  func init() {
    44  	var err error
    45  	GenesisStateCommitmentBytes, err := hex.DecodeString(GenesisStateCommitmentHex)
    46  	if err != nil {
    47  		panic("error while hex decoding hardcoded state commitment")
    48  	}
    49  	GenesisStateCommitment, err = flow.ToStateCommitment(GenesisStateCommitmentBytes)
    50  	if err != nil {
    51  		panic("genesis state commitment size is invalid")
    52  	}
    53  
    54  	serviceAccountPrivateKeyBytes, err := hex.DecodeString(ServiceAccountPrivateKeyHex)
    55  	if err != nil {
    56  		panic("error while hex decoding hardcoded root key")
    57  	}
    58  
    59  	ServiceAccountPrivateKey.SignAlgo = ServiceAccountPrivateKeySignAlgo
    60  	ServiceAccountPrivateKey.HashAlgo = ServiceAccountPrivateKeyHashAlgo
    61  	ServiceAccountPrivateKey.PrivateKey, err = crypto.DecodePrivateKey(
    62  		ServiceAccountPrivateKey.SignAlgo, serviceAccountPrivateKeyBytes)
    63  	if err != nil {
    64  		panic("error while decoding hardcoded root key bytes")
    65  	}
    66  
    67  	// Cannot import virtual machine, due to circular dependency. Just use the value of
    68  	// fvm.AccountKeyWeightThreshold here
    69  	ServiceAccountPublicKey = ServiceAccountPrivateKey.PublicKey(1000)
    70  }