github.com/onflow/flow-go@v0.33.17/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/onflow/flow-go/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 = "e4674bba14f59af783bbf70b2a43c1696a7d9888eeaca86cf74b033580fe1c23" 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 } 71 72 // this is done by printing the state commitment in TestBootstrapLedger test with different chain ID 73 func GenesisStateCommitmentByChainID(chainID flow.ChainID) flow.StateCommitment { 74 commitString := genesisCommitHexByChainID(chainID) 75 bytes, err := hex.DecodeString(commitString) 76 if err != nil { 77 panic("error while hex decoding hardcoded state commitment") 78 } 79 commit, err := flow.ToStateCommitment(bytes) 80 if err != nil { 81 panic("genesis state commitment size is invalid") 82 } 83 return commit 84 } 85 86 func genesisCommitHexByChainID(chainID flow.ChainID) string { 87 if chainID == flow.Mainnet { 88 return GenesisStateCommitmentHex 89 } 90 if chainID == flow.Testnet { 91 return "bfe964655cf13711b93dbaf156aaebbc24a607beed69dd36d71b593832b5129c" 92 } 93 if chainID == flow.Sandboxnet { 94 return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1" 95 } 96 return "a56a2750708bc981eb949a3b02a41061dc6b7e6bfa9f31a19a48f560f616bed3" 97 }