github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/utils/unittest/execution_state.go (about) 1 package unittest 2 3 import ( 4 "encoding/hex" 5 "fmt" 6 7 "github.com/onflow/cadence" 8 "github.com/onflow/crypto" 9 "github.com/onflow/crypto/hash" 10 11 "github.com/onflow/flow-go/model/flow" 12 ) 13 14 // Used below with random service key 15 // privateKey := flow.AccountPrivateKey{ 16 // PrivateKey: rootKey, 17 // SignAlgo: crypto.ECDSAP256, 18 // HashAlgo: hash.SHA2_256, 19 // } 20 21 const ServiceAccountPrivateKeyHex = "8ae3d0461cfed6d6f49bfc25fa899351c39d1bd21fdba8c87595b6c49bb4cc43" 22 const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256 23 const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256 24 25 // Pre-calculated state commitment with root account with the above private key 26 const GenesisStateCommitmentHex = "62a413fddb95adec3f57550816004322d70147fdc492a0d1a6b40d87202cf1e9" 27 28 var GenesisStateCommitment flow.StateCommitment 29 30 var GenesisTokenSupply = func() cadence.UFix64 { 31 // value, err := cadence.NewUFix64("10000000000.0") // 10 billion 32 value, err := cadence.NewUFix64("1000000000.0") // 1 billion 33 if err != nil { 34 panic(fmt.Errorf("invalid genesis token supply: %w", err)) 35 } 36 return value 37 }() 38 39 var ServiceAccountPrivateKey flow.AccountPrivateKey 40 var ServiceAccountPublicKey flow.AccountPublicKey 41 42 func init() { 43 var err error 44 GenesisStateCommitmentBytes, err := hex.DecodeString(GenesisStateCommitmentHex) 45 if err != nil { 46 panic("error while hex decoding hardcoded state commitment") 47 } 48 GenesisStateCommitment, err = flow.ToStateCommitment(GenesisStateCommitmentBytes) 49 if err != nil { 50 panic("genesis state commitment size is invalid") 51 } 52 53 serviceAccountPrivateKeyBytes, err := hex.DecodeString(ServiceAccountPrivateKeyHex) 54 if err != nil { 55 panic("error while hex decoding hardcoded root key") 56 } 57 58 ServiceAccountPrivateKey.SignAlgo = ServiceAccountPrivateKeySignAlgo 59 ServiceAccountPrivateKey.HashAlgo = ServiceAccountPrivateKeyHashAlgo 60 ServiceAccountPrivateKey.PrivateKey, err = crypto.DecodePrivateKey( 61 ServiceAccountPrivateKey.SignAlgo, serviceAccountPrivateKeyBytes) 62 if err != nil { 63 panic("error while decoding hardcoded root key bytes") 64 } 65 66 // Cannot import virtual machine, due to circular dependency. Just use the value of 67 // fvm.AccountKeyWeightThreshold here 68 ServiceAccountPublicKey = ServiceAccountPrivateKey.PublicKey(1000) 69 } 70 71 // this is done by printing the state commitment in TestBootstrapLedger test with different chain ID 72 func GenesisStateCommitmentByChainID(chainID flow.ChainID) flow.StateCommitment { 73 commitString := genesisCommitHexByChainID(chainID) 74 bytes, err := hex.DecodeString(commitString) 75 if err != nil { 76 panic("error while hex decoding hardcoded state commitment") 77 } 78 commit, err := flow.ToStateCommitment(bytes) 79 if err != nil { 80 panic("genesis state commitment size is invalid") 81 } 82 return commit 83 } 84 85 func genesisCommitHexByChainID(chainID flow.ChainID) string { 86 if chainID == flow.Mainnet { 87 return GenesisStateCommitmentHex 88 } 89 if chainID == flow.Testnet { 90 return "dbe45308cd8230d5fecc4c92f986d77938fcf5eb9d9454b2b96e02355ec8e2dc" 91 } 92 if chainID == flow.Sandboxnet { 93 return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1" 94 } 95 return "ce1e4238dea47fc393b41e05fa0798de8b20fd64816f89f1d233cdecec7c467b" 96 }