Skip to content

Commit

Permalink
add additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kc1116 committed Aug 30, 2024
1 parent 435a55d commit 48a491c
Show file tree
Hide file tree
Showing 5 changed files with 619 additions and 154 deletions.
2 changes: 1 addition & 1 deletion contracts/epochs/FlowEpoch.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ access(all) contract FlowEpoch {
// sanity check recovery epoch counter should be the current epoch counter
assert(
recoveryEpochCounter == FlowEpoch.currentEpochCounter,
message: "recovery epoch counter should equal current epoch counter"
message: "recovery epoch counter does not equal current epoch counter"
)
self.stopEpochComponents()

Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

58 changes: 57 additions & 1 deletion lib/go/test/epoch_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
emulator "github.com/onflow/flow-emulator/emulator"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/crypto"
sdkcrypto "github.com/onflow/flow-go-sdk/crypto"
sdktemplates "github.com/onflow/flow-go-sdk/templates"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -588,7 +589,6 @@ func verifyEpochMetadata(

endView := metadataFields["endView"]
assertEqual(t, cadence.NewUInt64(expectedMetadata.endView), endView)

stakingEndView := metadataFields["stakingEndView"]
assertEqual(t, cadence.NewUInt64(expectedMetadata.stakingEndView), stakingEndView)

Expand Down Expand Up @@ -915,3 +915,59 @@ func convertClusterQcsCdc(env templates.Environment, clusters []cadence.Value) [

return qcVoteData
}

type testEpochConfig struct {
startEpochCounter uint64 // start epoch counter
numEpochViews uint64 // num views per epoch
numStakingViews uint64 // num views for staking auction
numDKGViews uint64 // num views for DKG phase
numClusters uint64 // num collector clusters
numEpochAccounts int // num collector clusters
randomSource string // random source
rewardIncreaseFactor string // reward increase factor
}

func runWithDefaultContracts(t *testing.T, config *testEpochConfig, f func(b emulator.Emulator, env templates.Environment, ids []string, idTableAddress flow.Address, IDTableSigner sdkcrypto.Signer, adapter *adapters.SDKAdapter)) {
b, adapter, accountKeys, env := newTestSetup(t)
// Create new keys for the epoch account
idTableAccountKey, IDTableSigner := accountKeys.NewWithSigner()

// Deploys the staking contract, qc, dkg, and epoch lifecycle contract
// staking contract is deployed with default values (1.25M rewards, 8% cut)
idTableAddress, _ := initializeAllEpochContracts(t, b, idTableAccountKey, IDTableSigner, &env,
config.startEpochCounter, // start epoch counter
config.numEpochViews, // num views per epoch
config.numStakingViews, // num views for staking auction
config.numDKGViews, // num views for DKG phase
config.numClusters, // num collector clusters
config.randomSource, // random source
config.rewardIncreaseFactor)

// create new user accounts, mint tokens for them, and register them for staking
addresses, _, signers := registerAndMintManyAccounts(t, b, env, accountKeys, config.numEpochAccounts)
ids, _, _ := generateNodeIDs(config.numEpochAccounts)
// stakingPrivateKeys
_, stakingPublicKeys, _, networkingPublicKeys := generateManyNodeKeys(t, config.numEpochAccounts)
registerNodesForStaking(t, b, env,
addresses,
signers,
stakingPublicKeys,
networkingPublicKeys,
ids)

// Set the approved node list
tx := createTxWithTemplateAndAuthorizer(b, templates.GenerateSetApprovedNodesScript(env), idTableAddress)

approvedNodeIDs := generateCadenceNodeDictionary(ids)
err := tx.AddArgument(approvedNodeIDs)
require.NoError(t, err)

signAndSubmit(
t, b, tx,
[]flow.Address{idTableAddress},
[]sdkcrypto.Signer{IDTableSigner},
false,
)

f(b, env, ids, idTableAddress, IDTableSigner, adapter)
}
Loading

0 comments on commit 48a491c

Please sign in to comment.