github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/blueprints/system_test.go (about) 1 package blueprints_test 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/fvm/blueprints" 10 "github.com/onflow/flow-go/model/flow" 11 ) 12 13 // TestSystemChunkTransactionHash tests the hash of the system chunk transaction hash does not change. 14 // We currently give no guarantees about the system transaction hash not changing block-to-block, but the community 15 // currently depends on the hash not changing. If the hash changes, the community should be notified in the release notes. 16 func TestSystemChunkTransactionHash(t *testing.T) { 17 t.Parallel() 18 19 // this is formatted in a way that the resulting error message is easy to copy-paste into the test. 20 expectedHashes := []chainHash{ 21 {chainId: "flow-mainnet", expectedHash: "0a7ea89ad32d79a30b91b4c1202230a1e29310e1b92e01c76d036d2e3839159b"}, 22 {chainId: "flow-testnet", expectedHash: "368434cb7c792c3c35647f30aa90aae5798a45efcf2ff6abb7123b70c1e7850c"}, 23 {chainId: "flow-previewnet", expectedHash: "e90268cb6e8385d9eb50f2956f47c1c5f77a7b3111de2f66756b2a48855e05ce"}, 24 {chainId: "flow-emulator", expectedHash: "c6ccd6b805adcfaa6f9719f1dc71c831c40712977f12d82332ba23e2cb499475"}, 25 } 26 27 var actualHashes []chainHash 28 29 for _, expected := range expectedHashes { 30 chain := flow.ChainID(expected.chainId) 31 32 txBody, err := blueprints.SystemChunkTransaction(chain.Chain()) 33 require.NoError(t, err) 34 35 actualID := txBody.ID().String() 36 actualHashes = append(actualHashes, chainHash{chainId: expected.chainId, expectedHash: actualID}) 37 } 38 39 require.Equal(t, expectedHashes, actualHashes, 40 "Hashes of the system transactions have changed.\n"+ 41 "The community should be notified!\n\n"+ 42 "Update the expected hashes with the following values:\n%s", formatHashes(actualHashes)) 43 44 } 45 46 type chainHash struct { 47 chainId string 48 expectedHash string 49 } 50 51 func formatHashes(hashes []chainHash) string { 52 b := strings.Builder{} 53 for _, h := range hashes { 54 b.WriteString("{chainId: \"") 55 b.WriteString(h.chainId) 56 b.WriteString("\", expectedHash: \"") 57 b.WriteString(h.expectedHash) 58 b.WriteString("\"},\n") 59 } 60 return b.String() 61 }