github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/utils/unittest/service_events_fixtures.go (about)

     1  package unittest
     2  
     3  import (
     4  	"crypto/rand"
     5  	"encoding/hex"
     6  	"encoding/json"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/onflow/cadence"
    13  	"github.com/onflow/cadence/encoding/ccf"
    14  	jsoncdc "github.com/onflow/cadence/encoding/json"
    15  	"github.com/onflow/cadence/runtime/common"
    16  	"github.com/onflow/crypto"
    17  
    18  	"github.com/onflow/flow-go/fvm/systemcontracts"
    19  	"github.com/onflow/flow-go/model/flow"
    20  )
    21  
    22  // This file contains service event fixtures for testing purposes.
    23  
    24  func EpochSetupRandomSourceFixture() []byte {
    25  	source := make([]byte, flow.EpochSetupRandomSourceLength)
    26  	_, err := rand.Read(source)
    27  	if err != nil {
    28  		panic(err)
    29  	}
    30  	return source
    31  }
    32  
    33  // EpochSetupFixtureByChainID returns an EpochSetup service event as a Cadence event
    34  // representation and as a protocol model representation.
    35  func EpochSetupFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochSetup) {
    36  	events := systemcontracts.ServiceEventsForChain(chain)
    37  
    38  	event := EventFixture(events.EpochSetup.EventType(), 1, 1, IdentifierFixture(), 0)
    39  	randomSource := EpochSetupRandomSourceFixture()
    40  	event.Payload = EpochSetupFixtureCCF(randomSource)
    41  
    42  	expected := &flow.EpochSetup{
    43  		Counter:            1,
    44  		FirstView:          100,
    45  		FinalView:          200,
    46  		DKGPhase1FinalView: 150,
    47  		DKGPhase2FinalView: 160,
    48  		DKGPhase3FinalView: 170,
    49  		RandomSource:       randomSource,
    50  		TargetDuration:     200,
    51  		TargetEndTime:      2000000000,
    52  		Assignments: flow.AssignmentList{
    53  			{
    54  				flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000001"),
    55  				flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000002"),
    56  			},
    57  			{
    58  				flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000003"),
    59  				flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000004"),
    60  			},
    61  		},
    62  		Participants: flow.IdentitySkeletonList{
    63  			{
    64  				Role:          flow.RoleCollection,
    65  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000001"),
    66  				Address:       "1.flow.com",
    67  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
    68  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
    69  				InitialWeight: 100,
    70  			},
    71  			{
    72  				Role:          flow.RoleCollection,
    73  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000002"),
    74  				Address:       "2.flow.com",
    75  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
    76  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
    77  				InitialWeight: 100,
    78  			},
    79  			{
    80  				Role:          flow.RoleCollection,
    81  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000003"),
    82  				Address:       "3.flow.com",
    83  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
    84  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
    85  				InitialWeight: 100,
    86  			},
    87  			{
    88  				Role:          flow.RoleCollection,
    89  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000004"),
    90  				Address:       "4.flow.com",
    91  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
    92  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
    93  				InitialWeight: 100,
    94  			},
    95  			{
    96  				Role:          flow.RoleConsensus,
    97  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000011"),
    98  				Address:       "11.flow.com",
    99  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "cfdfe8e4362c8f79d11772cb7277ab16e5033a63e8dd5d34caf1b041b77e5b2d63c2072260949ccf8907486e4cfc733c8c42ca0e4e208f30470b0d950856cd47"),
   100  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "8207559cd7136af378bba53a8f0196dee3849a3ab02897c1995c3e3f6ca0c4a776c3ae869d1ddbb473090054be2400ad06d7910aa2c5d1780220fdf3765a3c1764bce10c6fe66a5a2be51a422e878518bd750424bb56b8a0ecf0f8ad2057e83f"),
   101  				InitialWeight: 100,
   102  			},
   103  			{
   104  				Role:          flow.RoleExecution,
   105  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000021"),
   106  				Address:       "21.flow.com",
   107  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "d64318ba0dbf68f3788fc81c41d507c5822bf53154530673127c66f50fe4469ccf1a054a868a9f88506a8999f2386d86fcd2b901779718cba4fb53c2da258f9e"),
   108  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "880b162b7ec138b36af401d07868cb08d25746d905395edbb4625bdf105d4bb2b2f4b0f4ae273a296a6efefa7ce9ccb914e39947ce0e83745125cab05d62516076ff0173ed472d3791ccef937597c9ea12381d76f547a092a4981d77ff3fba83"),
   109  				InitialWeight: 100,
   110  			},
   111  			{
   112  				Role:          flow.RoleVerification,
   113  				NodeID:        flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000031"),
   114  				Address:       "31.flow.com",
   115  				NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "697241208dcc9142b6f53064adc8ff1c95760c68beb2ba083c1d005d40181fd7a1b113274e0163c053a3addd47cd528ec6a1f190cf465aac87c415feaae011ae"),
   116  				StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "b1f97d0a06020eca97352e1adde72270ee713c7daf58da7e74bf72235321048b4841bdfc28227964bf18e371e266e32107d238358848bcc5d0977a0db4bda0b4c33d3874ff991e595e0f537c7b87b4ddce92038ebc7b295c9ea20a1492302aa7"),
   117  				InitialWeight: 100,
   118  			},
   119  		},
   120  	}
   121  
   122  	return event, expected
   123  }
   124  
   125  // EpochCommitFixtureByChainID returns an EpochCommit service event as a Cadence event
   126  // representation and as a protocol model representation.
   127  func EpochCommitFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochCommit) {
   128  
   129  	events := systemcontracts.ServiceEventsForChain(chain)
   130  
   131  	event := EventFixture(events.EpochCommit.EventType(), 1, 1, IdentifierFixture(), 0)
   132  	event.Payload = EpochCommitFixtureCCF
   133  
   134  	expected := &flow.EpochCommit{
   135  		Counter: 1,
   136  		ClusterQCs: []flow.ClusterQCVoteData{
   137  			{
   138  				VoterIDs: []flow.Identifier{
   139  					flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000001"),
   140  					flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000002"),
   141  				},
   142  				SigData: MustDecodeSignatureHex("b072ed22ed305acd44818a6c836e09b4e844eebde6a4fdbf5cec983e2872b86c8b0f6c34c0777bf52e385ab7c45dc55d"),
   143  			},
   144  			{
   145  				VoterIDs: []flow.Identifier{
   146  					flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000003"),
   147  					flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000004"),
   148  				},
   149  				SigData: MustDecodeSignatureHex("899e266a543e1b3a564f68b22f7be571f2e944ec30fadc4b39e2d5f526ba044c0f3cb2648f8334fc216fa3360a0418b2"),
   150  			},
   151  		},
   152  		DKGGroupKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "8c588266db5f5cda629e83f8aa04ae9413593fac19e4865d06d291c9d14fbdd9bdb86a7a12f9ef8590c79cb635e3163315d193087e9336092987150d0cd2b14ac6365f7dc93eec573752108b8c12368abb65f0652d9f644e5aed611c37926950"),
   153  		DKGParticipantKeys: []crypto.PublicKey{
   154  			MustDecodePublicKeyHex(crypto.BLSBLS12381, "87a339e4e5c74f089da20a33f515d8c8f4464ab53ede5a74aa2432cd1ae66d522da0c122249ee176cd747ddc83ca81090498389384201614caf51eac392c1c0a916dfdcfbbdf7363f9552b6468434add3d3f6dc91a92bbe3ee368b59b7828488"),
   155  		},
   156  	}
   157  
   158  	return event, expected
   159  }
   160  
   161  // VersionBeaconFixtureByChainID returns a VersionTable service event as a Cadence event
   162  // representation and as a protocol model representation.
   163  func VersionBeaconFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.VersionBeacon) {
   164  
   165  	events := systemcontracts.ServiceEventsForChain(chain)
   166  
   167  	event := EventFixture(events.VersionBeacon.EventType(), 1, 1, IdentifierFixture(), 0)
   168  	event.Payload = VersionBeaconFixtureCCF
   169  
   170  	expected := &flow.VersionBeacon{
   171  		VersionBoundaries: []flow.VersionBoundary{
   172  			{
   173  				BlockHeight: 44,
   174  				Version:     "2.13.7-test",
   175  			},
   176  		},
   177  		Sequence: 5,
   178  	}
   179  
   180  	return event, expected
   181  }
   182  
   183  func ProtocolStateVersionUpgradeFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.ProtocolStateVersionUpgrade) {
   184  	events := systemcontracts.ServiceEventsForChain(chain)
   185  
   186  	event := EventFixture(events.ProtocolStateVersionUpgrade.EventType(), 1, 1, IdentifierFixture(), 0)
   187  	event.Payload = ProtocolStateVersionUpgradeFixtureCCF
   188  
   189  	expected := &flow.ProtocolStateVersionUpgrade{
   190  		NewProtocolStateVersion: 1,
   191  		ActiveView:              1000,
   192  	}
   193  
   194  	return event, expected
   195  }
   196  
   197  func createEpochSetupEvent(randomSourceHex string) cadence.Event {
   198  
   199  	return cadence.NewEvent([]cadence.Value{
   200  		// counter
   201  		cadence.NewUInt64(1),
   202  
   203  		// nodeInfo
   204  		createEpochNodes(),
   205  
   206  		// firstView
   207  		cadence.NewUInt64(100),
   208  
   209  		// finalView
   210  		cadence.NewUInt64(200),
   211  
   212  		// collectorClusters
   213  		createEpochCollectors(),
   214  
   215  		// randomSource
   216  		cadence.String(randomSourceHex),
   217  
   218  		// DKGPhase1FinalView
   219  		cadence.UInt64(150),
   220  
   221  		// DKGPhase2FinalView
   222  		cadence.UInt64(160),
   223  
   224  		// DKGPhase3FinalView
   225  		cadence.UInt64(170),
   226  
   227  		// targetDuration
   228  		cadence.UInt64(200),
   229  
   230  		// targetEndTime
   231  		cadence.UInt64(2000000000),
   232  	}).WithType(newFlowEpochEpochSetupEventType())
   233  }
   234  
   235  func createEpochNodes() cadence.Array {
   236  
   237  	nodeInfoType := newFlowIDTableStakingNodeInfoStructType()
   238  
   239  	nodeInfo1 := cadence.NewStruct([]cadence.Value{
   240  		// id
   241  		cadence.String("0000000000000000000000000000000000000000000000000000000000000001"),
   242  
   243  		// role
   244  		cadence.UInt8(1),
   245  
   246  		// networkingAddress
   247  		cadence.String("1.flow.com"),
   248  
   249  		// networkingKey
   250  		cadence.String("378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
   251  
   252  		// stakingKey
   253  		cadence.String("af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
   254  
   255  		// tokensStaked
   256  		ufix64FromString("0.00000000"),
   257  
   258  		// tokensCommitted
   259  		ufix64FromString("1350000.00000000"),
   260  
   261  		// tokensUnstaking
   262  		ufix64FromString("0.00000000"),
   263  
   264  		// tokensUnstaked
   265  		ufix64FromString("0.00000000"),
   266  
   267  		// tokensRewarded
   268  		ufix64FromString("0.00000000"),
   269  
   270  		// delegators
   271  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   272  
   273  		// delegatorIDCounter
   274  		cadence.UInt32(0),
   275  
   276  		// tokensRequestedToUnstake
   277  		ufix64FromString("0.00000000"),
   278  
   279  		// initialWeight
   280  		cadence.UInt64(100),
   281  	}).WithType(nodeInfoType)
   282  
   283  	nodeInfo2 := cadence.NewStruct([]cadence.Value{
   284  		// id
   285  		cadence.String("0000000000000000000000000000000000000000000000000000000000000002"),
   286  
   287  		// role
   288  		cadence.UInt8(1),
   289  
   290  		// networkingAddress
   291  		cadence.String("2.flow.com"),
   292  
   293  		// networkingKey
   294  		cadence.String("378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
   295  
   296  		// stakingKey
   297  		cadence.String("af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
   298  
   299  		// tokensStaked
   300  		ufix64FromString("0.00000000"),
   301  
   302  		// tokensCommitted
   303  		ufix64FromString("1350000.00000000"),
   304  
   305  		// tokensUnstaking
   306  		ufix64FromString("0.00000000"),
   307  
   308  		// tokensUnstaked
   309  		ufix64FromString("0.00000000"),
   310  
   311  		// tokensRewarded
   312  		ufix64FromString("0.00000000"),
   313  
   314  		// delegators
   315  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   316  
   317  		// delegatorIDCounter
   318  		cadence.UInt32(0),
   319  
   320  		// tokensRequestedToUnstake
   321  		ufix64FromString("0.00000000"),
   322  
   323  		// initialWeight
   324  		cadence.UInt64(100),
   325  	}).WithType(nodeInfoType)
   326  
   327  	nodeInfo3 := cadence.NewStruct([]cadence.Value{
   328  		// id
   329  		cadence.String("0000000000000000000000000000000000000000000000000000000000000003"),
   330  
   331  		// role
   332  		cadence.UInt8(1),
   333  
   334  		// networkingAddress
   335  		cadence.String("3.flow.com"),
   336  
   337  		// networkingKey
   338  		cadence.String("378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
   339  
   340  		// stakingKey
   341  		cadence.String("af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
   342  
   343  		// tokensStaked
   344  		ufix64FromString("0.00000000"),
   345  
   346  		// tokensCommitted
   347  		ufix64FromString("1350000.00000000"),
   348  
   349  		// tokensUnstaking
   350  		ufix64FromString("0.00000000"),
   351  
   352  		// tokensUnstaked
   353  		ufix64FromString("0.00000000"),
   354  
   355  		// tokensRewarded
   356  		ufix64FromString("0.00000000"),
   357  
   358  		// delegators
   359  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   360  
   361  		// delegatorIDCounter
   362  		cadence.UInt32(0),
   363  
   364  		// tokensRequestedToUnstake
   365  		ufix64FromString("0.00000000"),
   366  
   367  		// initialWeight
   368  		cadence.UInt64(100),
   369  	}).WithType(nodeInfoType)
   370  
   371  	nodeInfo4 := cadence.NewStruct([]cadence.Value{
   372  		// id
   373  		cadence.String("0000000000000000000000000000000000000000000000000000000000000004"),
   374  
   375  		// role
   376  		cadence.UInt8(1),
   377  
   378  		// networkingAddress
   379  		cadence.String("4.flow.com"),
   380  
   381  		// networkingKey
   382  		cadence.String("378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
   383  
   384  		// stakingKey
   385  		cadence.String("af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
   386  
   387  		// tokensStaked
   388  		ufix64FromString("0.00000000"),
   389  
   390  		// tokensCommitted
   391  		ufix64FromString("1350000.00000000"),
   392  
   393  		// tokensUnstaking
   394  		ufix64FromString("0.00000000"),
   395  
   396  		// tokensUnstaked
   397  		ufix64FromString("0.00000000"),
   398  
   399  		// tokensRewarded
   400  		ufix64FromString("0.00000000"),
   401  
   402  		// delegators
   403  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   404  
   405  		// delegatorIDCounter
   406  		cadence.UInt32(0),
   407  
   408  		// tokensRequestedToUnstake
   409  		ufix64FromString("0.00000000"),
   410  
   411  		// initialWeight
   412  		cadence.UInt64(100),
   413  	}).WithType(nodeInfoType)
   414  
   415  	nodeInfo5 := cadence.NewStruct([]cadence.Value{
   416  		// id
   417  		cadence.String("0000000000000000000000000000000000000000000000000000000000000011"),
   418  
   419  		// role
   420  		cadence.UInt8(2),
   421  
   422  		// networkingAddress
   423  		cadence.String("11.flow.com"),
   424  
   425  		// networkingKey
   426  		cadence.String("cfdfe8e4362c8f79d11772cb7277ab16e5033a63e8dd5d34caf1b041b77e5b2d63c2072260949ccf8907486e4cfc733c8c42ca0e4e208f30470b0d950856cd47"),
   427  
   428  		// stakingKey
   429  		cadence.String("8207559cd7136af378bba53a8f0196dee3849a3ab02897c1995c3e3f6ca0c4a776c3ae869d1ddbb473090054be2400ad06d7910aa2c5d1780220fdf3765a3c1764bce10c6fe66a5a2be51a422e878518bd750424bb56b8a0ecf0f8ad2057e83f"),
   430  
   431  		// tokensStaked
   432  		ufix64FromString("0.00000000"),
   433  
   434  		// tokensCommitted
   435  		ufix64FromString("1350000.00000000"),
   436  
   437  		// tokensUnstaking
   438  		ufix64FromString("0.00000000"),
   439  
   440  		// tokensUnstaked
   441  		ufix64FromString("0.00000000"),
   442  
   443  		// tokensRewarded
   444  		ufix64FromString("0.00000000"),
   445  
   446  		// delegators
   447  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   448  
   449  		// delegatorIDCounter
   450  		cadence.UInt32(0),
   451  
   452  		// tokensRequestedToUnstake
   453  		ufix64FromString("0.00000000"),
   454  
   455  		// initialWeight
   456  		cadence.UInt64(100),
   457  	}).WithType(nodeInfoType)
   458  
   459  	nodeInfo6 := cadence.NewStruct([]cadence.Value{
   460  		// id
   461  		cadence.String("0000000000000000000000000000000000000000000000000000000000000021"),
   462  
   463  		// role
   464  		cadence.UInt8(3),
   465  
   466  		// networkingAddress
   467  		cadence.String("21.flow.com"),
   468  
   469  		// networkingKey
   470  		cadence.String("d64318ba0dbf68f3788fc81c41d507c5822bf53154530673127c66f50fe4469ccf1a054a868a9f88506a8999f2386d86fcd2b901779718cba4fb53c2da258f9e"),
   471  
   472  		// stakingKey
   473  		cadence.String("880b162b7ec138b36af401d07868cb08d25746d905395edbb4625bdf105d4bb2b2f4b0f4ae273a296a6efefa7ce9ccb914e39947ce0e83745125cab05d62516076ff0173ed472d3791ccef937597c9ea12381d76f547a092a4981d77ff3fba83"),
   474  
   475  		// tokensStaked
   476  		ufix64FromString("0.00000000"),
   477  
   478  		// tokensCommitted
   479  		ufix64FromString("1350000.00000000"),
   480  
   481  		// tokensUnstaking
   482  		ufix64FromString("0.00000000"),
   483  
   484  		// tokensUnstaked
   485  		ufix64FromString("0.00000000"),
   486  
   487  		// tokensRewarded
   488  		ufix64FromString("0.00000000"),
   489  
   490  		// delegators
   491  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   492  
   493  		// delegatorIDCounter
   494  		cadence.UInt32(0),
   495  
   496  		// tokensRequestedToUnstake
   497  		ufix64FromString("0.00000000"),
   498  
   499  		// initialWeight
   500  		cadence.UInt64(100),
   501  	}).WithType(nodeInfoType)
   502  
   503  	nodeInfo7 := cadence.NewStruct([]cadence.Value{
   504  		// id
   505  		cadence.String("0000000000000000000000000000000000000000000000000000000000000031"),
   506  
   507  		// role
   508  		cadence.UInt8(4),
   509  
   510  		// networkingAddress
   511  		cadence.String("31.flow.com"),
   512  
   513  		// networkingKey
   514  		cadence.String("697241208dcc9142b6f53064adc8ff1c95760c68beb2ba083c1d005d40181fd7a1b113274e0163c053a3addd47cd528ec6a1f190cf465aac87c415feaae011ae"),
   515  
   516  		// stakingKey
   517  		cadence.String("b1f97d0a06020eca97352e1adde72270ee713c7daf58da7e74bf72235321048b4841bdfc28227964bf18e371e266e32107d238358848bcc5d0977a0db4bda0b4c33d3874ff991e595e0f537c7b87b4ddce92038ebc7b295c9ea20a1492302aa7"),
   518  
   519  		// tokensStaked
   520  		ufix64FromString("0.00000000"),
   521  
   522  		// tokensCommitted
   523  		ufix64FromString("1350000.00000000"),
   524  
   525  		// tokensUnstaking
   526  		ufix64FromString("0.00000000"),
   527  
   528  		// tokensUnstaked
   529  		ufix64FromString("0.00000000"),
   530  
   531  		// tokensRewarded
   532  		ufix64FromString("0.00000000"),
   533  
   534  		// delegators
   535  		cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.UInt32Type)),
   536  
   537  		// delegatorIDCounter
   538  		cadence.UInt32(0),
   539  
   540  		// tokensRequestedToUnstake
   541  		ufix64FromString("0.00000000"),
   542  
   543  		// initialWeight
   544  		cadence.UInt64(100),
   545  	}).WithType(nodeInfoType)
   546  
   547  	return cadence.NewArray([]cadence.Value{
   548  		nodeInfo1,
   549  		nodeInfo2,
   550  		nodeInfo3,
   551  		nodeInfo4,
   552  		nodeInfo5,
   553  		nodeInfo6,
   554  		nodeInfo7,
   555  	}).WithType(cadence.NewVariableSizedArrayType(nodeInfoType))
   556  }
   557  
   558  func createEpochCollectors() cadence.Array {
   559  
   560  	clusterType := NewFlowClusterQCClusterStructType()
   561  
   562  	voteType := newFlowClusterQCVoteStructType()
   563  
   564  	cluster1 := cadence.NewStruct([]cadence.Value{
   565  		// index
   566  		cadence.NewUInt16(0),
   567  
   568  		// nodeWeights
   569  		cadence.NewDictionary([]cadence.KeyValuePair{
   570  			{
   571  				Key:   cadence.String("0000000000000000000000000000000000000000000000000000000000000001"),
   572  				Value: cadence.UInt64(100),
   573  			},
   574  			{
   575  				Key:   cadence.String("0000000000000000000000000000000000000000000000000000000000000002"),
   576  				Value: cadence.UInt64(100),
   577  			},
   578  		}).WithType(cadence.NewMeteredDictionaryType(nil, cadence.StringType, cadence.UInt64Type)),
   579  
   580  		// totalWeight
   581  		cadence.NewUInt64(100),
   582  
   583  		// generatedVotes
   584  		cadence.NewDictionary(nil).WithType(cadence.NewDictionaryType(cadence.StringType, voteType)),
   585  
   586  		// uniqueVoteMessageTotalWeights
   587  		cadence.NewDictionary(nil).WithType(cadence.NewDictionaryType(cadence.StringType, cadence.UInt64Type)),
   588  	}).WithType(clusterType)
   589  
   590  	cluster2 := cadence.NewStruct([]cadence.Value{
   591  		// index
   592  		cadence.NewUInt16(1),
   593  
   594  		// nodeWeights
   595  		cadence.NewDictionary([]cadence.KeyValuePair{
   596  			{
   597  				Key:   cadence.String("0000000000000000000000000000000000000000000000000000000000000003"),
   598  				Value: cadence.UInt64(100),
   599  			},
   600  			{
   601  				Key:   cadence.String("0000000000000000000000000000000000000000000000000000000000000004"),
   602  				Value: cadence.UInt64(100),
   603  			},
   604  		}).WithType(cadence.NewMeteredDictionaryType(nil, cadence.StringType, cadence.UInt64Type)),
   605  
   606  		// totalWeight
   607  		cadence.NewUInt64(0),
   608  
   609  		// generatedVotes
   610  		cadence.NewDictionary(nil).WithType(cadence.NewDictionaryType(cadence.StringType, voteType)),
   611  
   612  		// uniqueVoteMessageTotalWeights
   613  		cadence.NewDictionary(nil).WithType(cadence.NewDictionaryType(cadence.StringType, cadence.UInt64Type)),
   614  	}).WithType(clusterType)
   615  
   616  	return cadence.NewArray([]cadence.Value{
   617  		cluster1,
   618  		cluster2,
   619  	}).WithType(cadence.NewVariableSizedArrayType(clusterType))
   620  }
   621  
   622  func createEpochCommitEvent() cadence.Event {
   623  
   624  	clusterQCType := newFlowClusterQCClusterQCStructType()
   625  
   626  	cluster1 := cadence.NewStruct([]cadence.Value{
   627  		// index
   628  		cadence.UInt16(0),
   629  
   630  		// voteSignatures
   631  		cadence.NewArray([]cadence.Value{
   632  			cadence.String("a39cd1e1bf7e2fb0609b7388ce5215a6a4c01eef2aee86e1a007faa28a6b2a3dc876e11bb97cdb26c3846231d2d01e4d"),
   633  			cadence.String("91673ad9c717d396c9a0953617733c128049ac1a639653d4002ab245b121df1939430e313bcbfd06948f6a281f6bf853"),
   634  		}).WithType(cadence.NewVariableSizedArrayType(cadence.StringType)),
   635  
   636  		// voteMessage
   637  		cadence.String("irrelevant_for_these_purposes"),
   638  
   639  		// voterIDs
   640  		cadence.NewArray([]cadence.Value{
   641  			cadence.String("0000000000000000000000000000000000000000000000000000000000000001"),
   642  			cadence.String("0000000000000000000000000000000000000000000000000000000000000002"),
   643  		}).WithType(cadence.NewVariableSizedArrayType(cadence.StringType)),
   644  	}).WithType(clusterQCType)
   645  
   646  	cluster2 := cadence.NewStruct([]cadence.Value{
   647  		// index
   648  		cadence.UInt16(1),
   649  
   650  		// voteSignatures
   651  		cadence.NewArray([]cadence.Value{
   652  			cadence.String("b2bff159971852ed63e72c37991e62c94822e52d4fdcd7bf29aaf9fb178b1c5b4ce20dd9594e029f3574cb29533b857a"),
   653  			cadence.String("9931562f0248c9195758da3de4fb92f24fa734cbc20c0cb80280163560e0e0348f843ac89ecbd3732e335940c1e8dccb"),
   654  		}).WithType(cadence.NewVariableSizedArrayType(cadence.StringType)),
   655  
   656  		// voteMessage
   657  		cadence.String("irrelevant_for_these_purposes"),
   658  
   659  		// voterIDs
   660  		cadence.NewArray([]cadence.Value{
   661  			cadence.String("0000000000000000000000000000000000000000000000000000000000000003"),
   662  			cadence.String("0000000000000000000000000000000000000000000000000000000000000004"),
   663  		}).WithType(cadence.NewVariableSizedArrayType(cadence.StringType)),
   664  	}).WithType(clusterQCType)
   665  
   666  	return cadence.NewEvent([]cadence.Value{
   667  		// counter
   668  		cadence.NewUInt64(1),
   669  
   670  		// clusterQCs
   671  		cadence.NewArray([]cadence.Value{
   672  			cluster1,
   673  			cluster2,
   674  		}).WithType(cadence.NewVariableSizedArrayType(clusterQCType)),
   675  
   676  		// dkgPubKeys
   677  		cadence.NewArray([]cadence.Value{
   678  			cadence.String("8c588266db5f5cda629e83f8aa04ae9413593fac19e4865d06d291c9d14fbdd9bdb86a7a12f9ef8590c79cb635e3163315d193087e9336092987150d0cd2b14ac6365f7dc93eec573752108b8c12368abb65f0652d9f644e5aed611c37926950"),
   679  			cadence.String("87a339e4e5c74f089da20a33f515d8c8f4464ab53ede5a74aa2432cd1ae66d522da0c122249ee176cd747ddc83ca81090498389384201614caf51eac392c1c0a916dfdcfbbdf7363f9552b6468434add3d3f6dc91a92bbe3ee368b59b7828488"),
   680  		}).WithType(cadence.NewVariableSizedArrayType(cadence.StringType)),
   681  	}).WithType(newFlowEpochEpochCommitEventType())
   682  }
   683  
   684  func createVersionBeaconEvent() cadence.Event {
   685  	versionBoundaryType := NewNodeVersionBeaconVersionBoundaryStructType()
   686  
   687  	semverType := NewNodeVersionBeaconSemverStructType()
   688  
   689  	semver := cadence.NewStruct([]cadence.Value{
   690  		// major
   691  		cadence.UInt8(2),
   692  
   693  		// minor
   694  		cadence.UInt8(13),
   695  
   696  		// patch
   697  		cadence.UInt8(7),
   698  
   699  		// preRelease
   700  		cadence.NewOptional(cadence.String("test")),
   701  	}).WithType(semverType)
   702  
   703  	versionBoundary := cadence.NewStruct([]cadence.Value{
   704  		// blockHeight
   705  		cadence.UInt64(44),
   706  
   707  		// version
   708  		semver,
   709  	}).WithType(versionBoundaryType)
   710  
   711  	return cadence.NewEvent([]cadence.Value{
   712  		// versionBoundaries
   713  		cadence.NewArray([]cadence.Value{
   714  			versionBoundary,
   715  		}).WithType(cadence.NewVariableSizedArrayType(versionBoundaryType)),
   716  
   717  		// sequence
   718  		cadence.UInt64(5),
   719  	}).WithType(NewNodeVersionBeaconVersionBeaconEventType())
   720  }
   721  
   722  func createProtocolStateVersionUpgradeEvent() cadence.Event {
   723  	newVersion := cadence.NewUInt64(1)
   724  	activeView := cadence.NewUInt64(1000)
   725  
   726  	return cadence.NewEvent([]cadence.Value{
   727  		newVersion,
   728  		activeView,
   729  	}).WithType(NewProtocolStateVersionUpgradeEventType())
   730  }
   731  
   732  func newFlowClusterQCVoteStructType() cadence.Type {
   733  
   734  	// A.01cf0e2f2f715450.FlowClusterQC.Vote
   735  
   736  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   737  	location := common.NewAddressLocation(nil, address, "FlowClusterQC")
   738  
   739  	return &cadence.StructType{
   740  		Location:            location,
   741  		QualifiedIdentifier: "FlowClusterQC.Vote",
   742  		Fields: []cadence.Field{
   743  			{
   744  				Identifier: "nodeID",
   745  				Type:       cadence.StringType,
   746  			},
   747  			{
   748  				Identifier: "signature",
   749  				Type:       cadence.NewOptionalType(cadence.StringType),
   750  			},
   751  			{
   752  				Identifier: "message",
   753  				Type:       cadence.NewOptionalType(cadence.StringType),
   754  			},
   755  			{
   756  				Identifier: "clusterIndex",
   757  				Type:       cadence.UInt16Type,
   758  			},
   759  			{
   760  				Identifier: "weight",
   761  				Type:       cadence.UInt64Type,
   762  			},
   763  		},
   764  	}
   765  }
   766  
   767  func newFlowIDTableStakingNodeInfoStructType() *cadence.StructType {
   768  
   769  	// A.01cf0e2f2f715450.FlowIDTableStaking.NodeInfo
   770  
   771  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   772  	location := common.NewAddressLocation(nil, address, "FlowIDTableStaking")
   773  
   774  	return &cadence.StructType{
   775  		Location:            location,
   776  		QualifiedIdentifier: "FlowIDTableStaking.NodeInfo",
   777  		Fields: []cadence.Field{
   778  			{
   779  				Identifier: "id",
   780  				Type:       cadence.StringType,
   781  			},
   782  			{
   783  				Identifier: "role",
   784  				Type:       cadence.UInt8Type,
   785  			},
   786  			{
   787  				Identifier: "networkingAddress",
   788  				Type:       cadence.StringType,
   789  			},
   790  			{
   791  				Identifier: "networkingKey",
   792  				Type:       cadence.StringType,
   793  			},
   794  			{
   795  				Identifier: "stakingKey",
   796  				Type:       cadence.StringType,
   797  			},
   798  			{
   799  				Identifier: "tokensStaked",
   800  				Type:       cadence.UFix64Type,
   801  			},
   802  			{
   803  				Identifier: "tokensCommitted",
   804  				Type:       cadence.UFix64Type,
   805  			},
   806  			{
   807  				Identifier: "tokensUnstaking",
   808  				Type:       cadence.UFix64Type,
   809  			},
   810  			{
   811  				Identifier: "tokensUnstaked",
   812  				Type:       cadence.UFix64Type,
   813  			},
   814  			{
   815  				Identifier: "tokensRewarded",
   816  				Type:       cadence.UFix64Type,
   817  			},
   818  			{
   819  				Identifier: "delegators",
   820  				Type:       cadence.NewVariableSizedArrayType(cadence.UInt32Type),
   821  			},
   822  			{
   823  				Identifier: "delegatorIDCounter",
   824  				Type:       cadence.UInt32Type,
   825  			},
   826  			{
   827  				Identifier: "tokensRequestedToUnstake",
   828  				Type:       cadence.UFix64Type,
   829  			},
   830  			{
   831  				Identifier: "initialWeight",
   832  				Type:       cadence.UInt64Type,
   833  			},
   834  		},
   835  	}
   836  }
   837  
   838  func newFlowEpochEpochSetupEventType() *cadence.EventType {
   839  
   840  	// A.01cf0e2f2f715450.FlowEpoch.EpochSetup
   841  
   842  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   843  	location := common.NewAddressLocation(nil, address, "FlowEpoch")
   844  
   845  	return &cadence.EventType{
   846  		Location:            location,
   847  		QualifiedIdentifier: "FlowEpoch.EpochSetup",
   848  		Fields: []cadence.Field{
   849  			{
   850  				Identifier: "counter",
   851  				Type:       cadence.UInt64Type,
   852  			},
   853  			{
   854  				Identifier: "nodeInfo",
   855  				Type:       cadence.NewVariableSizedArrayType(newFlowIDTableStakingNodeInfoStructType()),
   856  			},
   857  			{
   858  				Identifier: "firstView",
   859  				Type:       cadence.UInt64Type,
   860  			},
   861  			{
   862  				Identifier: "finalView",
   863  				Type:       cadence.UInt64Type,
   864  			},
   865  			{
   866  				Identifier: "collectorClusters",
   867  				Type:       cadence.NewVariableSizedArrayType(NewFlowClusterQCClusterStructType()),
   868  			},
   869  			{
   870  				Identifier: "randomSource",
   871  				Type:       cadence.StringType,
   872  			},
   873  			{
   874  				Identifier: "DKGPhase1FinalView",
   875  				Type:       cadence.UInt64Type,
   876  			},
   877  			{
   878  				Identifier: "DKGPhase2FinalView",
   879  				Type:       cadence.UInt64Type,
   880  			},
   881  			{
   882  				Identifier: "DKGPhase3FinalView",
   883  				Type:       cadence.UInt64Type,
   884  			},
   885  			{
   886  				Identifier: "targetDuration",
   887  				Type:       cadence.UInt64Type,
   888  			},
   889  			{
   890  				Identifier: "targetEndTime",
   891  				Type:       cadence.UInt64Type,
   892  			},
   893  		},
   894  	}
   895  }
   896  
   897  func newFlowEpochEpochCommitEventType() *cadence.EventType {
   898  
   899  	// A.01cf0e2f2f715450.FlowEpoch.EpochCommitted
   900  
   901  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   902  	location := common.NewAddressLocation(nil, address, "FlowEpoch")
   903  
   904  	return &cadence.EventType{
   905  		Location:            location,
   906  		QualifiedIdentifier: "FlowEpoch.EpochCommitted",
   907  		Fields: []cadence.Field{
   908  			{
   909  				Identifier: "counter",
   910  				Type:       cadence.UInt64Type,
   911  			},
   912  			{
   913  				Identifier: "clusterQCs",
   914  				Type:       cadence.NewVariableSizedArrayType(newFlowClusterQCClusterQCStructType()),
   915  			},
   916  			{
   917  				Identifier: "dkgPubKeys",
   918  				Type:       cadence.NewVariableSizedArrayType(cadence.StringType),
   919  			},
   920  		},
   921  	}
   922  }
   923  
   924  func newFlowClusterQCClusterQCStructType() *cadence.StructType {
   925  
   926  	// A.01cf0e2f2f715450.FlowClusterQC.ClusterQC"
   927  
   928  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   929  	location := common.NewAddressLocation(nil, address, "FlowClusterQC")
   930  
   931  	return &cadence.StructType{
   932  		Location:            location,
   933  		QualifiedIdentifier: "FlowClusterQC.ClusterQC",
   934  		Fields: []cadence.Field{
   935  			{
   936  				Identifier: "index",
   937  				Type:       cadence.UInt16Type,
   938  			},
   939  			{
   940  				Identifier: "voteSignatures",
   941  				Type:       cadence.NewVariableSizedArrayType(cadence.StringType),
   942  			},
   943  			{
   944  				Identifier: "voteMessage",
   945  				Type:       cadence.StringType,
   946  			},
   947  			{
   948  				Identifier: "voterIDs",
   949  				Type:       cadence.NewVariableSizedArrayType(cadence.StringType),
   950  			},
   951  		},
   952  	}
   953  }
   954  
   955  func NewNodeVersionBeaconVersionBeaconEventType() *cadence.EventType {
   956  
   957  	// A.01cf0e2f2f715450.NodeVersionBeacon.VersionBeacon
   958  
   959  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   960  	location := common.NewAddressLocation(nil, address, "NodeVersionBeacon")
   961  
   962  	return &cadence.EventType{
   963  		Location:            location,
   964  		QualifiedIdentifier: "NodeVersionBeacon.VersionBeacon",
   965  		Fields: []cadence.Field{
   966  			{
   967  				Identifier: "versionBoundaries",
   968  				Type:       cadence.NewVariableSizedArrayType(NewNodeVersionBeaconVersionBoundaryStructType()),
   969  			},
   970  			{
   971  				Identifier: "sequence",
   972  				Type:       cadence.UInt64Type,
   973  			},
   974  		},
   975  	}
   976  }
   977  
   978  func NewNodeVersionBeaconVersionBoundaryStructType() *cadence.StructType {
   979  
   980  	// A.01cf0e2f2f715450.NodeVersionBeacon.VersionBoundary
   981  
   982  	address, _ := common.HexToAddress("01cf0e2f2f715450")
   983  	location := common.NewAddressLocation(nil, address, "NodeVersionBeacon")
   984  
   985  	return &cadence.StructType{
   986  		Location:            location,
   987  		QualifiedIdentifier: "NodeVersionBeacon.VersionBoundary",
   988  		Fields: []cadence.Field{
   989  			{
   990  				Identifier: "blockHeight",
   991  				Type:       cadence.UInt64Type,
   992  			},
   993  			{
   994  				Identifier: "version",
   995  				Type:       NewNodeVersionBeaconSemverStructType(),
   996  			},
   997  		},
   998  	}
   999  }
  1000  
  1001  func NewNodeVersionBeaconSemverStructType() *cadence.StructType {
  1002  
  1003  	// A.01cf0e2f2f715450.NodeVersionBeacon.Semver
  1004  
  1005  	address, _ := common.HexToAddress("01cf0e2f2f715450")
  1006  	location := common.NewAddressLocation(nil, address, "NodeVersionBeacon")
  1007  
  1008  	return &cadence.StructType{
  1009  		Location:            location,
  1010  		QualifiedIdentifier: "NodeVersionBeacon.Semver",
  1011  		Fields: []cadence.Field{
  1012  			{
  1013  				Identifier: "major",
  1014  				Type:       cadence.UInt8Type,
  1015  			},
  1016  			{
  1017  				Identifier: "minor",
  1018  				Type:       cadence.UInt8Type,
  1019  			},
  1020  			{
  1021  				Identifier: "patch",
  1022  				Type:       cadence.UInt8Type,
  1023  			},
  1024  			{
  1025  				Identifier: "preRelease",
  1026  				Type:       cadence.NewOptionalType(cadence.StringType),
  1027  			},
  1028  		},
  1029  	}
  1030  }
  1031  
  1032  func NewProtocolStateVersionUpgradeEventType() *cadence.EventType {
  1033  
  1034  	// A.01cf0e2f2f715450.NodeVersionBeacon.ProtocolStateVersionUpgrade
  1035  
  1036  	address, _ := common.HexToAddress("01cf0e2f2f715450")
  1037  	location := common.NewAddressLocation(nil, address, "ProtocolStateVersionUpgrade")
  1038  
  1039  	return &cadence.EventType{
  1040  		Location:            location,
  1041  		QualifiedIdentifier: "NodeVersionBeacon.ProtocolStateVersionUpgrade",
  1042  		Fields: []cadence.Field{
  1043  			{
  1044  				Identifier: "newProtocolVersion",
  1045  				Type:       cadence.UInt64Type,
  1046  			},
  1047  			{
  1048  				Identifier: "activeView",
  1049  				Type:       cadence.UInt64Type,
  1050  			},
  1051  		},
  1052  	}
  1053  }
  1054  
  1055  func ufix64FromString(s string) cadence.UFix64 {
  1056  	f, err := cadence.NewUFix64(s)
  1057  	if err != nil {
  1058  		panic(err)
  1059  	}
  1060  	return f
  1061  }
  1062  
  1063  func EpochSetupFixtureCCF(randomSource []byte) []byte {
  1064  	randomSourceHex := hex.EncodeToString(randomSource)
  1065  	b, err := ccf.Encode(createEpochSetupEvent(randomSourceHex))
  1066  	if err != nil {
  1067  		panic(err)
  1068  	}
  1069  	_, err = ccf.Decode(nil, b)
  1070  	if err != nil {
  1071  		panic(err)
  1072  	}
  1073  	return b
  1074  }
  1075  
  1076  func EpochSetupCCFWithNonHexRandomSource() []byte {
  1077  	// randomSource of correct length but made of non hex characters
  1078  	randomSource := "ZZ"
  1079  	for len(randomSource) != 2*flow.EpochSetupRandomSourceLength {
  1080  		randomSource = randomSource + "aa"
  1081  	}
  1082  
  1083  	event := createEpochSetupEvent(randomSource)
  1084  
  1085  	b, err := ccf.Encode(event)
  1086  	if err != nil {
  1087  		panic(err)
  1088  	}
  1089  	_, err = ccf.Decode(nil, b)
  1090  	if err != nil {
  1091  		panic(err)
  1092  	}
  1093  	return b
  1094  }
  1095  
  1096  var EpochCommitFixtureCCF = func() []byte {
  1097  	b, err := ccf.Encode(createEpochCommitEvent())
  1098  	if err != nil {
  1099  		panic(err)
  1100  	}
  1101  	_, err = ccf.Decode(nil, b)
  1102  	if err != nil {
  1103  		panic(err)
  1104  	}
  1105  	return b
  1106  }()
  1107  
  1108  var VersionBeaconFixtureCCF = func() []byte {
  1109  	b, err := ccf.Encode(createVersionBeaconEvent())
  1110  	if err != nil {
  1111  		panic(err)
  1112  	}
  1113  	_, err = ccf.Decode(nil, b)
  1114  	if err != nil {
  1115  		panic(err)
  1116  	}
  1117  	return b
  1118  }()
  1119  
  1120  var ProtocolStateVersionUpgradeFixtureCCF = func() []byte {
  1121  	b, err := ccf.Encode(createProtocolStateVersionUpgradeEvent())
  1122  	if err != nil {
  1123  		panic(err)
  1124  	}
  1125  	_, err = ccf.Decode(nil, b)
  1126  	if err != nil {
  1127  		panic(err)
  1128  	}
  1129  	return b
  1130  }()
  1131  
  1132  func VerifyCdcArguments(t *testing.T, expected []cadence.Value, actual []interface{}) {
  1133  
  1134  	for index, arg := range actual {
  1135  
  1136  		// marshal to bytes
  1137  		bz, err := json.Marshal(arg)
  1138  		require.NoError(t, err)
  1139  
  1140  		// parse cadence value
  1141  		decoded, err := jsoncdc.Decode(nil, bz)
  1142  		require.NoError(t, err)
  1143  
  1144  		assert.Equal(t, expected[index], decoded)
  1145  	}
  1146  }
  1147  
  1148  func NewFlowClusterQCClusterStructType() *cadence.StructType {
  1149  
  1150  	// A.01cf0e2f2f715450.FlowClusterQC.Cluster
  1151  
  1152  	address, _ := common.HexToAddress("01cf0e2f2f715450")
  1153  	location := common.NewAddressLocation(nil, address, "FlowClusterQC")
  1154  
  1155  	return &cadence.StructType{
  1156  		Location:            location,
  1157  		QualifiedIdentifier: "FlowClusterQC.Cluster",
  1158  		Fields: []cadence.Field{
  1159  			{
  1160  				Identifier: "index",
  1161  				Type:       cadence.UInt16Type,
  1162  			},
  1163  			{
  1164  				Identifier: "nodeWeights",
  1165  				Type:       cadence.NewDictionaryType(cadence.StringType, cadence.UInt64Type),
  1166  			},
  1167  			{
  1168  				Identifier: "totalWeight",
  1169  				Type:       cadence.UInt64Type,
  1170  			},
  1171  			{
  1172  				Identifier: "generatedVotes",
  1173  				Type:       cadence.NewDictionaryType(cadence.StringType, newFlowClusterQCVoteStructType()),
  1174  			},
  1175  			{
  1176  				Identifier: "uniqueVoteMessageTotalWeights",
  1177  				Type:       cadence.NewDictionaryType(cadence.StringType, cadence.UInt64Type),
  1178  			},
  1179  		},
  1180  	}
  1181  }