Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epoch setup random source update #5088

Merged
merged 18 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
serviceEvents, err := systemcontracts.ServiceEventsForChain(execCtx.Chain.ChainID())
require.NoError(t, err)

payload, err := ccf.Decode(nil, unittest.EpochSetupFixtureCCF)
randomSource := unittest.EpochSetupRandomSourceFixture()
payload, err := ccf.Decode(nil, unittest.EpochSetupFixtureCCF(randomSource))
require.NoError(t, err)

serviceEventA, ok := payload.(cadence.Event)
Expand Down Expand Up @@ -1256,7 +1257,7 @@ func Test_ExecutingSystemCollection(t *testing.T) {
noopCollector := metrics.NewNoopCollector()

expectedNumberOfEvents := 3
expectedEventSize := 1434
expectedEventSize := 1493
// bootstrapping does not cache programs
expectedCachedPrograms := 0

Expand Down
2 changes: 1 addition & 1 deletion engine/execution/state/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) {
}

func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
expectedStateCommitmentBytes, _ := hex.DecodeString("33ff069b59f8eab1e58a15875bf859ebfc2068432c5cd7680ca084dbfc6c60ed")
expectedStateCommitmentBytes, _ := hex.DecodeString("7dc2d3ec95c5f7376512f558e4349b60d535b4f48371f9846dcf7076dd589889")
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ require (
github.com/onflow/atree v0.6.0
github.com/onflow/cadence v0.42.5
github.com/onflow/flow v0.3.4
github.com/onflow/flow-core-contracts/lib/go/contracts v0.14.0
github.com/onflow/flow-core-contracts/lib/go/templates v0.14.0
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231130031602-3a326a55abcf
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231130031602-3a326a55abcf
github.com/onflow/flow-go-sdk v0.41.16
github.com/onflow/flow-go/crypto v0.24.9
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231121210617-52ee94b830c2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1329,10 +1329,10 @@ github.com/onflow/cadence v0.42.5 h1:QCilotmJzfRToLd+02o3N62JIioSr8FfN7cujmR/IXQ
github.com/onflow/cadence v0.42.5/go.mod h1:raU8va8QRyTa/eUbhej4mbyW2ETePfSaywoo36MddgE=
github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE=
github.com/onflow/flow v0.3.4/go.mod h1:lzyAYmbu1HfkZ9cfnL5/sjrrsnJiUU8fRL26CqLP7+c=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.14.0 h1:DpkgyNAP3SAe7dMQX/Tb7BWFstodqtREo4hxWFHwdS0=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.14.0/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI=
github.com/onflow/flow-core-contracts/lib/go/templates v0.14.0 h1:qZoMYSe7LaO2s6DWyB781FDntyded/gX5Guihldiv54=
github.com/onflow/flow-core-contracts/lib/go/templates v0.14.0/go.mod h1:ZeLxwaBkzuSInESGjL8/IPZWezF+YOYsYbMrZlhN+q4=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231130031602-3a326a55abcf h1:pTtEnxbfsnPwYsPpAgwZdg5QlvynkfMdFEFpdaafz1I=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231130031602-3a326a55abcf/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI=
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231130031602-3a326a55abcf h1:9N4rwnWbJ392bcqa4MmQszsvLpl+gFrOoDfPdkZB5EA=
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231130031602-3a326a55abcf/go.mod h1:ZeLxwaBkzuSInESGjL8/IPZWezF+YOYsYbMrZlhN+q4=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 h1:B4ll7e3j+MqTJv2122Enq3RtDNzmIGRu9xjV7fo7un0=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13/go.mod h1:kTMFIySzEJJeupk+7EmXs0EJ6CBWY/MV9fv9iYQk+RU=
github.com/onflow/flow-go-sdk v0.24.0/go.mod h1:IoptMLPyFXWvyd9yYA6/4EmSeeozl6nJoIv4FaEMg74=
Expand Down
4 changes: 2 additions & 2 deletions insecure/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onflow/atree v0.6.0 // indirect
github.com/onflow/cadence v0.42.5 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231130031602-3a326a55abcf // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231130031602-3a326a55abcf // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 // indirect
github.com/onflow/flow-go-sdk v0.41.16 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.1.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions insecure/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1303,10 +1303,10 @@ github.com/onflow/atree v0.6.0/go.mod h1:gBHU0M05qCbv9NN0kijLWMgC47gHVNBIp4KmsVF
github.com/onflow/cadence v0.20.1/go.mod h1:7mzUvPZUIJztIbr9eTvs+fQjWWHTF8veC+yk4ihcNIA=
github.com/onflow/cadence v0.42.5 h1:QCilotmJzfRToLd+02o3N62JIioSr8FfN7cujmR/IXQ=
github.com/onflow/cadence v0.42.5/go.mod h1:raU8va8QRyTa/eUbhej4mbyW2ETePfSaywoo36MddgE=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f h1:S8yIZw9LFXfYD1V5H9BiixihHw3GrXVPrmfplSzYaww=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI=
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f h1:Ep+Mpo2miWMe4pjPGIaEvEzshRep30dvNgxqk+//FrQ=
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:ZeLxwaBkzuSInESGjL8/IPZWezF+YOYsYbMrZlhN+q4=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231130031602-3a326a55abcf h1:pTtEnxbfsnPwYsPpAgwZdg5QlvynkfMdFEFpdaafz1I=
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20231130031602-3a326a55abcf/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI=
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231130031602-3a326a55abcf h1:9N4rwnWbJ392bcqa4MmQszsvLpl+gFrOoDfPdkZB5EA=
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20231130031602-3a326a55abcf/go.mod h1:ZeLxwaBkzuSInESGjL8/IPZWezF+YOYsYbMrZlhN+q4=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 h1:B4ll7e3j+MqTJv2122Enq3RtDNzmIGRu9xjV7fo7un0=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13/go.mod h1:kTMFIySzEJJeupk+7EmXs0EJ6CBWY/MV9fv9iYQk+RU=
github.com/onflow/flow-go-sdk v0.24.0/go.mod h1:IoptMLPyFXWvyd9yYA6/4EmSeeozl6nJoIv4FaEMg74=
Expand Down
8 changes: 4 additions & 4 deletions integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ require (
github.com/onflow/cadence v0.42.5
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f
github.com/onflow/flow-emulator v0.54.1-0.20231110220143-28061d9b37e7
github.com/onflow/flow-emulator v0.58.0
github.com/onflow/flow-go v0.32.7
github.com/onflow/flow-go-sdk v0.41.16
github.com/onflow/flow-go/crypto v0.24.9
github.com/onflow/flow-go/crypto v0.24.10
github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231121210617-52ee94b830c2
github.com/plus3it/gorecurcopy v0.0.1
Expand Down Expand Up @@ -149,7 +149,7 @@ require (
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/zerolog/v2 v2.0.0-rc.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
Expand Down Expand Up @@ -290,7 +290,7 @@ require (
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
Expand Down
16 changes: 9 additions & 7 deletions integration/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
Expand Down Expand Up @@ -644,8 +645,9 @@ github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRid
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand Down Expand Up @@ -1398,16 +1400,16 @@ github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI=
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f h1:Ep+Mpo2miWMe4pjPGIaEvEzshRep30dvNgxqk+//FrQ=
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:ZeLxwaBkzuSInESGjL8/IPZWezF+YOYsYbMrZlhN+q4=
github.com/onflow/flow-emulator v0.54.1-0.20231110220143-28061d9b37e7 h1:rMqbd3ZYtemFCdP/QvLbHloQn4+ZOakQrPMZdojvKpE=
github.com/onflow/flow-emulator v0.54.1-0.20231110220143-28061d9b37e7/go.mod h1:AaHzJfv3jIanaty6RnSf0oEmvokSErtUsW8xotR2z2I=
github.com/onflow/flow-emulator v0.58.0 h1:/Zo+qznjqN2jJNOGQu1mFK2lZT3L6c8V18AmAzXLKZ8=
github.com/onflow/flow-emulator v0.58.0/go.mod h1:pi23Sx7kuj65dJRT7OIlio53XRAhLTUUhf3zV9TN3PA=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 h1:B4ll7e3j+MqTJv2122Enq3RtDNzmIGRu9xjV7fo7un0=
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13/go.mod h1:kTMFIySzEJJeupk+7EmXs0EJ6CBWY/MV9fv9iYQk+RU=
github.com/onflow/flow-go-sdk v0.24.0/go.mod h1:IoptMLPyFXWvyd9yYA6/4EmSeeozl6nJoIv4FaEMg74=
github.com/onflow/flow-go-sdk v0.41.16 h1:HsmHwEVmj+iK+GszHbFseHh7Ii5W3PWOIRNAH/En08Q=
github.com/onflow/flow-go-sdk v0.41.16/go.mod h1:bVrVNoJKiwB6vW5Qbm5tFAfJBQ5we4uSQWnn9gNAFhQ=
github.com/onflow/flow-go/crypto v0.21.3/go.mod h1:vI6V4CY3R6c4JKBxdcRiR/AnjBfL8OSD97bJc60cLuQ=
github.com/onflow/flow-go/crypto v0.24.9 h1:0EQp+kSZYJepMIiSypfJVe7tzsPcb6UXOdOtsTCDhBs=
github.com/onflow/flow-go/crypto v0.24.9/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7Q6u+bCI78lfNX0=
github.com/onflow/flow-go/crypto v0.24.10 h1:nH97tnnC0RaFXO5GuJic5lt/5IEiOuuWa3gaJI2Le3w=
github.com/onflow/flow-go/crypto v0.24.10/go.mod h1:O7jjGhgJEp94t9qXfBWdwW5BArm5L5gYa6XoBJiTdHc=
github.com/onflow/flow-nft/lib/go/contracts v1.1.0 h1:rhUDeD27jhLwOqQKI/23008CYfnqXErrJvc4EFRP2a0=
github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9jxdwoTuuhjK8WYWXTyLkIigZY=
github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8=
Expand Down Expand Up @@ -1662,8 +1664,8 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
Expand Down
21 changes: 12 additions & 9 deletions model/convert/service_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,25 @@ func convertServiceEventEpochSetup(event flow.Event) (*flow.ServiceEvent, error)
DKGPhase3FinalView: uint64(dkgPhase3FinalView),
}

// Cadence's unsafeRandom().toString() produces a string of variable length.
// Here we pad it with enough 0s to meet the required length.
paddedRandomSrcHex := fmt.Sprintf(
"%0*s",
2*flow.EpochSetupRandomSourceLength,
string(randomSrcHex),
)
setup.RandomSource, err = hex.DecodeString(paddedRandomSrcHex)
// random source from the event must be a hex string
// containing exactly 128 bits (equivalent to 16 bytes or 32 hex characters)
setup.RandomSource, err = hex.DecodeString(string(randomSrcHex))
if err != nil {
return nil, fmt.Errorf(
"could not decode random source hex (%v): %w",
paddedRandomSrcHex,
randomSrcHex,
err,
)
}

if len(setup.RandomSource) != flow.EpochSetupRandomSourceLength {
return nil, fmt.Errorf(
"random source in epoch setup event must be of (%d) bytes, got (%d)",
flow.EpochSetupRandomSourceLength,
len(setup.RandomSource),
)
}

// parse cluster assignments
setup.Assignments, err = convertClusterAssignments(cdcClusters.Values)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions model/convert/service_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ func TestEventConversion(t *testing.T) {
},
)

t.Run(
tarakby marked this conversation as resolved.
Show resolved Hide resolved
"epoch setup invalid random source", func(t *testing.T) {

fixture, _ := unittest.EpochSetupFixtureByChainID(chainID)
// update the random source in event fixture
randomSource := unittest.EpochSetupRandomSourceFixture()
fixture.Payload = unittest.EpochSetupFixtureCCF(randomSource[:flow.EpochSetupRandomSourceLength-1])

// convert Cadence types to Go types
event, err := convert.ServiceEvent(chainID, fixture)
require.Error(t, err)
require.Nil(t, event)
},
)

t.Run(
"epoch commit", func(t *testing.T) {

Expand Down
2 changes: 1 addition & 1 deletion utils/unittest/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256
const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256

// Pre-calculated state commitment with root account with the above private key
const GenesisStateCommitmentHex = "8476e9a47da2f993fd0d04efc10238113f217b0c037ccf903613088d51027d6a"
const GenesisStateCommitmentHex = "436f6ac1de4738ed17405527dee7e639bc89600f329f6453d320311d84750211"

var GenesisStateCommitment flow.StateCommitment

Expand Down
32 changes: 20 additions & 12 deletions utils/unittest/service_events_fixtures.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package unittest

import (
"crypto/rand"
"encoding/hex"

"github.com/onflow/cadence"
"github.com/onflow/cadence/encoding/ccf"
"github.com/onflow/cadence/runtime/common"
Expand All @@ -12,6 +15,15 @@ import (

// This file contains service event fixtures for testing purposes.

func EpochSetupRandomSourceFixture() []byte {
source := make([]byte, flow.EpochSetupRandomSourceLength)
_, err := rand.Read(source)
if err != nil {
panic(err)
}
return source
}

// EpochSetupFixtureByChainID returns an EpochSetup service event as a Cadence event
// representation and as a protocol model representation.
func EpochSetupFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochSetup) {
Expand All @@ -21,13 +33,8 @@ func EpochSetupFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochSetu
}

event := EventFixture(events.EpochSetup.EventType(), 1, 1, IdentifierFixture(), 0)
event.Payload = EpochSetupFixtureCCF

// randomSource is [0,0,...,1,2,3,4]
randomSource := make([]uint8, flow.EpochSetupRandomSourceLength)
for i := 0; i < 4; i++ {
randomSource[flow.EpochSetupRandomSourceLength-1-i] = uint8(4 - i)
}
randomSource := EpochSetupRandomSourceFixture()
event.Payload = EpochSetupFixtureCCF(randomSource)

expected := &flow.EpochSetup{
Counter: 1,
Expand Down Expand Up @@ -174,7 +181,8 @@ func VersionBeaconFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.Versio
return event, expected
}

func createEpochSetupEvent() cadence.Event {
func createEpochSetupEvent(randomSource []byte) cadence.Event {
randomSourceHex := hex.EncodeToString(randomSource)

return cadence.NewEvent([]cadence.Value{
// counter
Expand All @@ -193,7 +201,7 @@ func createEpochSetupEvent() cadence.Event {
createEpochCollectors(),

// randomSource
cadence.String("01020304"),
cadence.String(randomSourceHex),

// DKGPhase1FinalView
cadence.UInt64(150),
Expand Down Expand Up @@ -1028,8 +1036,8 @@ func ufix64FromString(s string) cadence.UFix64 {
return f
}

var EpochSetupFixtureCCF = func() []byte {
b, err := ccf.Encode(createEpochSetupEvent())
func EpochSetupFixtureCCF(randomSource []byte) []byte {
b, err := ccf.Encode(createEpochSetupEvent(randomSource))
if err != nil {
panic(err)
}
Expand All @@ -1038,7 +1046,7 @@ var EpochSetupFixtureCCF = func() []byte {
panic(err)
}
return b
}()
}

var EpochCommitFixtureCCF = func() []byte {
b, err := ccf.Encode(createEpochCommittedEvent())
Expand Down