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

EpochRecover service event and transaction #420

Merged
merged 163 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
c97e2f0
update to view functions for stable cadence
joshuahannan Nov 2, 2022
e39f87c
Update to newest Stable Cadence Preview (#371)
dsainati1 Jul 5, 2023
309e602
remove casting and fix conflicts
joshuahannan Jul 10, 2023
08c37b8
integrate ft and nft stable cadence changes, use access, view, and en…
joshuahannan Jul 18, 2023
345c81b
use v2 ft and nft
joshuahannan Jul 18, 2023
2de1c22
use string for nft import
joshuahannan Jul 18, 2023
d70590b
update token deps
joshuahannan Jul 18, 2023
861a1c4
update token deps
joshuahannan Jul 18, 2023
6c7e2e5
update nft dependecy
joshuahannan Jul 18, 2023
9005af3
update nft dep
joshuahannan Jul 18, 2023
34953f6
update ft dep
joshuahannan Jul 18, 2023
6044078
add more view
joshuahannan Jul 19, 2023
bcdf82c
update FlowToken contract getter to explicitly use metadata views
joshuahannan Jul 19, 2023
b1cdfb9
implement new standard methods
joshuahannan Jul 19, 2023
5c9dbc1
update nft dependency
joshuahannan Jul 19, 2023
b8f0e9e
update ft dep
joshuahannan Jul 19, 2023
15d02eb
fix FungibleToken.Vault types and imports
joshuahannan Jul 19, 2023
46b6929
remove view from copy
joshuahannan Jul 19, 2023
a9f8e5f
add correct vault type
joshuahannan Jul 19, 2023
492674f
remove views and update balances
joshuahannan Jul 19, 2023
971b709
use vault interface type
joshuahannan Jul 19, 2023
f1f8764
remove restricted types
joshuahannan Jul 26, 2023
3e8c398
remove AnyStruct
joshuahannan Jul 26, 2023
9fd65f4
remove type restrictions
joshuahannan Jul 26, 2023
b977889
fix view modifiers in epoch contracts
joshuahannan Jul 27, 2023
f16eaec
use setter methods in QC
joshuahannan Jul 27, 2023
70bc6fd
remove pub from QC
joshuahannan Jul 27, 2023
57ec160
remove restricted types from flow epoch
joshuahannan Jul 27, 2023
692c1cf
use setters in FlowEpoch
joshuahannan Jul 27, 2023
47187b3
correct metadata types
joshuahannan Jul 27, 2023
1fc8536
use UInt64 in NodeVersionBeacon
joshuahannan Jul 27, 2023
02c1131
replace addresses and fix transactions and scripts
joshuahannan Aug 2, 2023
f2fe0ac
fixes to epoch tests
joshuahannan Aug 8, 2023
da1b7b5
update to latest token standards and update locked tokens transactions
joshuahannan Aug 22, 2023
c7e0170
Update contracts
SupunS Sep 8, 2023
722ec7b
Update more contracts
SupunS Sep 11, 2023
9564e5d
Update contracts
SupunS Sep 11, 2023
81aa739
Update contarcts and transactions
SupunS Sep 12, 2023
4c50f6c
go mod tidy
SupunS Sep 12, 2023
d052c5c
Update flow-sdk
SupunS Sep 12, 2023
bf077d0
Update more contracts
SupunS Sep 12, 2023
fb8fc84
Update ft/nft deps
SupunS Sep 13, 2023
2334795
Generate assets
SupunS Sep 13, 2023
82a613c
Update more cadence codes
SupunS Sep 13, 2023
6401295
Fix typo
SupunS Sep 14, 2023
370407f
Replace get()+borrow() with borrow()
SupunS Sep 14, 2023
6a99037
Refactor code
SupunS Sep 14, 2023
fd33ce2
Update go-sdk and flow-nft versions
SupunS Sep 15, 2023
1cf8b4c
Fix publish_voter transaction
SupunS Sep 18, 2023
0aef25b
Update to Cadence v1.0.0-preview.1
SupunS Sep 21, 2023
448d648
Apply suggestions from code review
SupunS Sep 21, 2023
d49fd04
Refactor code
SupunS Sep 22, 2023
ce228e8
fix and improve syntax
turbolent Sep 22, 2023
3b4c47c
use optional chaining and nil-coaelescing instead of force-unwrapping
turbolent Sep 22, 2023
19a5688
Update get_total_balance.cdc
SupunS Sep 26, 2023
b373ce8
make sure epoch contracts work with capability controllers and entitl…
joshuahannan Nov 22, 2023
298f47d
update dependencies and add public burn tokens method
joshuahannan Dec 4, 2023
20e6057
remove view from getRandomSourceHistoryPage and use account.storage
joshuahannan Dec 11, 2023
99ff402
remove custom destructors and fix entitlement usage
joshuahannan Dec 12, 2023
761f879
get all go tests passing for cadence 1.0
joshuahannan Jan 2, 2024
3f33ef0
make ci
joshuahannan Jan 2, 2024
6edd0e3
make ci
joshuahannan Jan 2, 2024
40e8ef0
update cli version for CI
joshuahannan Jan 2, 2024
c4d2acb
update go version
joshuahannan Jan 3, 2024
8094b24
update Withdrawable and createEmptyVault
joshuahannan Jan 23, 2024
0c5bccb
Update Cadence version (#406)
SupunS Jan 23, 2024
6430730
update createEmpty in staking
joshuahannan Jan 24, 2024
1376f64
use Burner and update dependencies
joshuahannan Jan 25, 2024
c4cacb0
update to SDK v1.0.0-M1
turbolent Jan 25, 2024
b0d86ba
update NFT contracts, remove replace statements
turbolent Jan 25, 2024
762d6d2
update to Cadence v1.0.0-M3
turbolent Jan 25, 2024
ad07d0e
update to Cadence v1.0.0-M3 and SDK v1.0.0-M1
turbolent Jan 25, 2024
04dae1a
remove getBalance, add isAvailableToWithdraw
joshuahannan Jan 25, 2024
61d01ea
update ft and nft deps
joshuahannan Feb 1, 2024
9974772
update emulator dependencies and get tests passing
joshuahannan Feb 1, 2024
639f419
use FungibleToken.Balance instead of FlowToken.Vault
joshuahannan Feb 1, 2024
5c18b63
use correct public path types
joshuahannan Feb 5, 2024
23e5224
update imports
joshuahannan Feb 6, 2024
9f926bf
go mod tidy
joshuahannan Feb 6, 2024
d795124
add fungible token switchboard
joshuahannan Feb 6, 2024
d9617df
fix switchboard
joshuahannan Feb 6, 2024
006447b
update error messages for ledger transactions
joshuahannan Feb 7, 2024
47f3354
add updated manifests with new account, FT, and NFT transactions and …
joshuahannan Feb 9, 2024
b56d319
update account transactions to use simple arguments
joshuahannan Feb 12, 2024
1533936
update manifest to include both styles of token transfer transactions:
joshuahannan Feb 13, 2024
96d94e2
use string args for NFT contracts
joshuahannan Feb 14, 2024
59a36e0
update collection machine account transactions to not use keylist entry
joshuahannan Feb 15, 2024
426ec6e
Update contract getter methods to use env (#410)
joshuahannan Feb 27, 2024
594be1e
get address replacement working in tests and add event emission restr…
joshuahannan Feb 27, 2024
9fab58a
update to latest emulator, cadence, and token standards versions
joshuahannan Mar 5, 2024
aecc7fb
Update README
joshuahannan Mar 7, 2024
5c41345
Don't copy dictionary in getEpochMetadata (#413)
janezpodhostnik Mar 22, 2024
12c392c
update NFT contracts
joshuahannan Mar 26, 2024
26f74bc
update ft dependency
joshuahannan Mar 27, 2024
e100822
update token standard dependencies
joshuahannan Apr 2, 2024
02924cc
make ci
joshuahannan Apr 2, 2024
c53fc79
fix algorithm typo and test names
joshuahannan Apr 8, 2024
9eaaa39
update nft transactions
joshuahannan Apr 9, 2024
7abc82a
update FlowEpoch contract
kc1116 Apr 12, 2024
7fe14e1
generate assets
kc1116 Apr 12, 2024
5791ea4
happy path tests
kc1116 Apr 12, 2024
4fa05d5
Update flow_epoch_test.go
kc1116 Apr 12, 2024
c256d3c
upgrade changes to be compliant with cadence 1.0
kc1116 Apr 15, 2024
11e2b2d
generate assets
kc1116 Apr 12, 2024
836e726
happy path tests
kc1116 Apr 12, 2024
cb277e5
remove unused stakingEndView param
kc1116 Apr 26, 2024
500fb52
cant use timing config in epoch recover
kc1116 Apr 26, 2024
4fbd4aa
add epoch counter comment
kc1116 Apr 26, 2024
ad2df49
move save epoch metadata to ending of recover func add comment
kc1116 Apr 26, 2024
505a371
Update FlowEpoch.cdc
kc1116 Apr 26, 2024
f2818d8
Update contracts/epochs/FlowEpoch.cdc
kc1116 Apr 25, 2024
5e2f861
Update contracts/epochs/FlowEpoch.cdc
kc1116 Apr 26, 2024
dfd8e2f
update assets
kc1116 Apr 26, 2024
5d5fb6e
Apply suggestions from code review
kc1116 May 13, 2024
5b92b6e
reuse old var names
kc1116 May 15, 2024
6a2bdb5
remove RecoverEpochMetadata
kc1116 May 15, 2024
caa0040
use named parameters
kc1116 May 15, 2024
a667862
use separate var for long lines, remove casts
kc1116 May 15, 2024
97baba8
generate assets
kc1116 May 15, 2024
926626a
use common.AddressLocation
kc1116 May 15, 2024
8ae7e38
add separate funcs recover new epoch and recover current epoch
kc1116 May 28, 2024
3ce24c2
- dont generate a new random source when overwriting the epoch metadata
kc1116 Jun 20, 2024
548f22f
fix typos in transactions
joshuahannan Apr 15, 2024
66a7ba9
update nft dependencies
joshuahannan Apr 15, 2024
ac40215
Add entitlement for locked account creator (#423)
joshuahannan Apr 24, 2024
677b20d
update ft dependencies
joshuahannan Apr 24, 2024
d289b84
update nft imports and remove unnecessary Burner import from FlowToken
joshuahannan Apr 29, 2024
fed5e86
update dependencies
joshuahannan May 7, 2024
46a4cac
address PR comments and add entitlements to LockedTokens.TokenManager
joshuahannan May 9, 2024
81b3d68
remove UseTokens entitlement
joshuahannan May 9, 2024
0f711ea
use view more and update nft deps
joshuahannan May 17, 2024
99b721f
make ci
joshuahannan May 17, 2024
63df092
merge master
kc1116 Jun 20, 2024
b912dae
update assets
kc1116 Jun 20, 2024
20115f7
merge master
kc1116 Jun 20, 2024
4d826d5
update changes from master
kc1116 Jun 20, 2024
59905bb
update changes from master
kc1116 Jun 20, 2024
f893516
Update random_beacon_history_test.cdc
kc1116 Jun 20, 2024
52f8c36
fix whitespace
kc1116 Jun 20, 2024
3e09ba0
Update ci.yml
kc1116 Jun 20, 2024
3da8cf5
update assets
kc1116 Jun 20, 2024
967aae8
update test helpers
kc1116 Jun 20, 2024
88f0a28
reference event from parent scope
kc1116 Jun 22, 2024
d8135eb
use aggregatedSignature
kc1116 Jul 10, 2024
c15443c
Update contracts/epochs/FlowClusterQC.cdc
kc1116 Jul 22, 2024
71ef9e2
Apply suggestions from code review
kc1116 Jul 22, 2024
118967a
Merge branch 'feature/efm-recovery' into khalil/5639-epoch-recovery-t…
jordanschalm Jul 25, 2024
6d88321
make generate
jordanschalm Jul 25, 2024
4a4524c
Merge branch 'feature/efm-recovery' into khalil/5639-epoch-recovery-t…
jordanschalm Jul 28, 2024
5aafe7f
tidy
jordanschalm Jul 28, 2024
66fa3f4
document TestEpochRecover
kc1116 Jul 29, 2024
61f07b6
remove unused dkg qc txs
kc1116 Jul 29, 2024
a78b7d7
add sanity check to ensure we receive vote data for each cluster
kc1116 Jul 29, 2024
614f489
ensure curEpochCounter = startEpochCounter+1
kc1116 Jul 29, 2024
8b5087d
check counter and epoch metadata after second recover transaction
kc1116 Jul 29, 2024
1e41ecf
provide recovery epoch counter in recover epoch transaction
kc1116 Jul 29, 2024
ec8c94d
Update contracts/epochs/FlowEpoch.cdc
kc1116 Jul 29, 2024
88d6cda
Update contracts/epochs/FlowEpoch.cdc
kc1116 Jul 29, 2024
19a3795
add new line
kc1116 Jul 29, 2024
d342f4e
Update flow_epoch_test.go
kc1116 Jul 29, 2024
d332997
Merge branch 'khalil/5639-epoch-recovery-transaction' of github.com:o…
kc1116 Jul 29, 2024
802d828
remove state changes from prechecks func add new func stop epoch comp…
kc1116 Jul 29, 2024
1f63515
use access self on admin commands
kc1116 Jul 29, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Run tests
run: export GOPATH=$HOME/go && make ci
run: export GOPATH=$HOME/go && make ci
15 changes: 15 additions & 0 deletions contracts/epochs/FlowClusterQC.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ access(all) contract FlowClusterQC {
}
}

/// Represents the quorum certificate vote data for a signer
/// of the certificate.
access(all) struct ClusterQCVoteData {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to match the current util command output, I think this structure needs to have the form:

struct ClusterQCVoteData {
  voteData: String // hex-encoded aggregated signature
  voterIDs: [String]
}

/// The aggregated signature, hex-encoded, encompasses all individual vote signatures contributed by nodes across the cluster
access(all) let aggregatedSignature: String

/// The node IDs that contributed their vote to the aggregated signature
access(all) let voterIDs: [String]

init(aggregatedSignature: String, voterIDs: [String]) {
self.aggregatedSignature = aggregatedSignature
self.voterIDs = voterIDs
}
}

/// The Voter resource is generated for each collection node after they register.
/// Each resource instance is good for all future potential epochs, but will
/// only be valid if the node operator has been confirmed as a collector node for the next epoch.
Expand Down
316 changes: 303 additions & 13 deletions contracts/epochs/FlowEpoch.cdc

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions lib/go/templates/epoch_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
updateRewardPercentageFilename = "epoch/admin/update_reward.cdc"
advanceViewFilename = "epoch/admin/advance_view.cdc"
resetEpochFilename = "epoch/admin/reset_epoch.cdc"
recoverEpochFilename = "epoch/admin/recover_epoch.cdc"
epochCalculateSetRewardsFilename = "epoch/admin/calculate_rewards.cdc"
epochPayRewardsFilename = "epoch/admin/pay_rewards.cdc"
epochSetAutoRewardsFilename = "epoch/admin/set_automatic_rewards.cdc"
Expand Down Expand Up @@ -114,6 +115,12 @@ func GenerateResetEpochScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

func GenerateRecoverEpochScript(env Environment) []byte {
code := assets.MustAssetString(recoverEpochFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateEpochCalculateSetRewardsScript(env Environment) []byte {
code := assets.MustAssetString(epochCalculateSetRewardsFilename)

Expand Down
23 changes: 23 additions & 0 deletions lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

187 changes: 184 additions & 3 deletions lib/go/test/epoch_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/cadence/runtime/common"
cdcCommon "github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/onflow/flow-core-contracts/lib/go/templates"
Expand Down Expand Up @@ -130,6 +132,82 @@ type EpochCommit struct {
dkgPubKeys []string
}

// EpochRecover used to verify EpochRecover event fields in tests.
type EpochRecover struct {
counter uint64
nodeInfoLength int
firstView uint64
finalView uint64
collectorClusters []cadence.Value
randomSource string
dkgPhase1FinalView uint64
dkgPhase2FinalView uint64
dkgPhase3FinalView uint64
targetDuration uint64
targetEndTime uint64
clusterQCVoteDataLength int
dkgPubKeys []string
}

type EpochRecoverEvent flow.Event

// Counter returns counter field in EpochRecover event.
func (evt EpochRecoverEvent) Counter() cadence.UInt64 {
return cadence.SearchFieldByName(evt.Value, "counter").(cadence.UInt64)
}

// NodeInfo returns nodeInfo field in EpochRecover event.
func (evt EpochRecoverEvent) NodeInfo() cadence.Array {
return cadence.SearchFieldByName(evt.Value, "nodeInfo").(cadence.Array)
}

// FirstView returns firstView field in EpochRecover event.
func (evt EpochRecoverEvent) FirstView() cadence.UInt64 {
return cadence.SearchFieldByName(evt.Value, "firstView").(cadence.UInt64)
}

// FinalView returns finalView field in EpochRecover event.
func (evt EpochRecoverEvent) FinalView() cadence.UInt64 {
return cadence.SearchFieldByName(evt.Value, "finalView").(cadence.UInt64)
}

// CollectorClusters returns clusterAssignments field in EpochRecover event.
func (evt EpochRecoverEvent) CollectorClusters() cadence.Array {
return cadence.SearchFieldByName(evt.Value, "clusterAssignments").(cadence.Array)
}

// RandomSource returns randomSource field in EpochRecover event.
func (evt EpochRecoverEvent) RandomSource() cadence.String {
return cadence.SearchFieldByName(evt.Value, "randomSource").(cadence.String)
}

// DKGFinalViews returns dkgFinalViews field in EpochRecover event.
func (evt EpochRecoverEvent) DKGFinalViews() (cadence.UInt64, cadence.UInt64, cadence.UInt64) {
return cadence.SearchFieldByName(evt.Value, "DKGPhase1FinalView").(cadence.UInt64),
cadence.SearchFieldByName(evt.Value, "DKGPhase2FinalView").(cadence.UInt64),
cadence.SearchFieldByName(evt.Value, "DKGPhase3FinalView").(cadence.UInt64)
}

// TargetDuration returns targetDuration field in EpochRecover event.
func (evt EpochRecoverEvent) TargetDuration() cadence.UInt64 {
return cadence.SearchFieldByName(evt.Value, "targetDuration").(cadence.UInt64)
}

// TargetEndTime returns targetEndTime field in EpochRecover event.
func (evt EpochRecoverEvent) TargetEndTime() cadence.UInt64 {
return cadence.SearchFieldByName(evt.Value, "targetEndTime").(cadence.UInt64)
}

// ClusterQCVoteData returns clusterQCVoteData field in EpochRecover event.
func (evt EpochRecoverEvent) ClusterQCVoteData() cadence.Array {
return cadence.SearchFieldByName(evt.Value, "clusterQCVoteData").(cadence.Array)
}

// DKGPubKeys returns dkgPubKeys field in EpochRecover event.
func (evt EpochRecoverEvent) DKGPubKeys() cadence.Array {
return cadence.SearchFieldByName(evt.Value, "dkgPubKeys").(cadence.Array)
}

// Go event definitions for the epoch events
// Can be used with the SDK to retreive and parse epoch events

Expand Down Expand Up @@ -495,10 +573,9 @@ func verifyEpochMetadata(
env templates.Environment,
expectedMetadata EpochMetadata) {

result := executeScriptAndCheck(t, b, templates.GenerateGetEpochMetadataScript(env), [][]byte{jsoncdc.MustEncode(cadence.UInt64(expectedMetadata.counter))})
metadataFields := cadence.FieldsMappedByName(result.(cadence.Struct))

metadataFields := getEpochMetadata(t, b, env, cadence.UInt64(expectedMetadata.counter))
counter := metadataFields["counter"]

assertEqual(t, cadence.NewUInt64(expectedMetadata.counter), counter)

if len(expectedMetadata.seed) != 0 {
Expand Down Expand Up @@ -714,6 +791,15 @@ func verifyEpochCommit(

}

// verifyCollectorClusters verifies both collector clusters are equal.
func verifyCollectorClusters(t *testing.T, expected, got []cadence.Value) {
for i, cluster := range got {
for j, node := range cluster.(cadence.Array).Values {
assertEqual(t, expected[i].(cadence.Array).Values[j], node)
}
}
}

// expectedTargetEndTime returns the expected `targetEndTime` for the given target epoch,
// as a second-precision Unix time.
func expectedTargetEndTime(timingConfig cadence.Value, targetEpoch uint64) uint64 {
Expand All @@ -724,3 +810,98 @@ func expectedTargetEndTime(timingConfig cadence.Value, targetEpoch uint64) uint6

return refTimestamp + duration*(targetEpoch-refCounter)
}

// verifyEpochRecover verifies that an emitted EpochRecover event is equal to the provided `expectedRecover`.
// Assumptions:
// - only one `EpochRecover` is emitted (otherwise, only the first is verified)
// - the `EpochRecover` is emitted within the first 1000 blocks
func verifyEpochRecover(
t *testing.T,
adapter *adapters.SDKAdapter,
epochAddress flow.Address,
expectedRecover EpochRecover,
) {
var emittedEvent EpochRecoverEvent
addrLocation := common.NewAddressLocation(nil, common.Address(epochAddress), "FlowEpoch")
evtTypeID := string(addrLocation.TypeID(nil, "FlowEpoch.EpochRecover"))
for i := uint64(0); i < 1000; i++ {
results, _ := adapter.GetEventsForHeightRange(context.Background(), evtTypeID, i, i)

for _, result := range results {
for _, event := range result.Events {

if event.Type == evtTypeID {
emittedEvent = EpochRecoverEvent(event)
}
}
}
}

assertEqual(t, cadence.NewUInt64(expectedRecover.counter), emittedEvent.Counter())
assertEqual(t, expectedRecover.nodeInfoLength, len(emittedEvent.NodeInfo().Values))
assertEqual(t, cadence.NewUInt64(expectedRecover.firstView), emittedEvent.FirstView())
assertEqual(t, cadence.NewUInt64(expectedRecover.finalView), emittedEvent.FinalView())
verifyCollectorClusters(t, expectedRecover.collectorClusters, emittedEvent.CollectorClusters().Values)
assertEqual(t, cadence.String(expectedRecover.randomSource), emittedEvent.RandomSource())
dkgPhase1FinalView, dkgPhase2FinalView, dkgPhase3FinalView := emittedEvent.DKGFinalViews()
assertEqual(t, cadence.NewUInt64(expectedRecover.dkgPhase1FinalView), dkgPhase1FinalView)
assertEqual(t, cadence.NewUInt64(expectedRecover.dkgPhase2FinalView), dkgPhase2FinalView)
assertEqual(t, cadence.NewUInt64(expectedRecover.dkgPhase3FinalView), dkgPhase3FinalView)
assertEqual(t, cadence.NewUInt64(expectedRecover.targetDuration), emittedEvent.TargetDuration())
assertEqual(t, cadence.NewUInt64(expectedRecover.targetEndTime), emittedEvent.TargetEndTime())
assertEqual(t, expectedRecover.clusterQCVoteDataLength, len(emittedEvent.ClusterQCVoteData().Values))
assertEqual(t, len(expectedRecover.dkgPubKeys), len(emittedEvent.DKGPubKeys().Values))
}

func getEpochMetadata(t *testing.T, b emulator.Emulator, env templates.Environment, counter cadence.Value) map[string]cadence.Value {
result := executeScriptAndCheck(t, b, templates.GenerateGetEpochMetadataScript(env), [][]byte{jsoncdc.MustEncode(counter)})
return cadence.FieldsMappedByName(result.(cadence.Struct))
}

func getCurrentEpochCounter(t *testing.T, b emulator.Emulator, env templates.Environment) cadence.UInt64 {
result := executeScriptAndCheck(t, b, templates.GenerateGetCurrentEpochCounterScript(env), [][]byte{})
return result.(cadence.UInt64)
}

// newClusterQCVoteDataCdcType returns the FlowClusterQC cadence struct type.
func newClusterQCVoteDataCdcType(clusterQcAddress string) *cadence.StructType {

// FlowClusterQC.ClusterQCVoteData
address, _ := cdcCommon.HexToAddress(clusterQcAddress)
location := cdcCommon.NewAddressLocation(nil, address, "FlowClusterQC")

return &cadence.StructType{
Location: location,
QualifiedIdentifier: "FlowClusterQC.ClusterQCVoteData",
Fields: []cadence.Field{
{
Identifier: "aggregatedSignature",
Type: cadence.StringType,
},
{
Identifier: "voterIDs",
Type: cadence.NewVariableSizedArrayType(cadence.StringType),
},
},
}
}

func convertClusterQcsCdc(env templates.Environment, clusters []cadence.Value) []cadence.Value {
voteDataType := newClusterQCVoteDataCdcType(env.QuorumCertificateAddress)
qcVoteData := make([]cadence.Value, len(clusters))
for i, cluster := range clusters {
clusterCdc := cluster.(cadence.Array)
cdcVoterIds := make([]cadence.Value, len(clusterCdc.Values))
for i, id := range clusterCdc.Values {
cdcVoterIds[i] = cadence.String(id.String())
}
qcVoteData[i] = cadence.NewStruct([]cadence.Value{
// aggregatedSignature
cadence.String(fmt.Sprintf("signature_%d", i)),
// Node IDs of signers
cadence.NewArray(cdcVoterIds).WithType(cadence.NewVariableSizedArrayType(cadence.StringType)),
}).WithType(voteDataType)
}

return qcVoteData
}
Loading
Loading