Skip to content

Commit

Permalink
fix extra / in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Oct 18, 2024
1 parent 043d5c0 commit c481969
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 147 deletions.
27 changes: 11 additions & 16 deletions lib/go/test/epoch_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import (
*
*/

// / Used to verify the values of the clusters in the smart contract
// Used to verify the values of the clusters in the smart contract
type Cluster struct {
index uint16
totalWeight uint64
size uint16
}

// / Used to verify epoch metadata in tests
// Used to verify epoch metadata in tests
type EpochMetadata struct {
counter uint64
seed string
Expand All @@ -53,7 +53,7 @@ type EpochMetadata struct {
dkgKeys []string
}

// / Used to verify the configurable Epoch metadata in tests
// Used to verify the configurable Epoch metadata in tests
type ConfigMetadata struct {
currentEpochCounter uint64
proposedEpochCounter uint64
Expand All @@ -72,7 +72,7 @@ type EpochTimingConfig struct {
refTimestamp uint64
}

// / Used to verify the EpochStart event fields in tests
// Used to verify the EpochStart event fields in tests
type EpochStart struct {
counter uint64
firstView uint64
Expand Down Expand Up @@ -113,7 +113,7 @@ func (evt EpochStartEvent) rewards() cadence.UFix64 {
return cadence.SearchFieldByName(evt.Value, "totalRewards").(cadence.UFix64)
}

// / Used to verify the EpochSetup event fields in tests
// Used to verify the EpochSetup event fields in tests
type EpochSetup struct {
counter uint64
nodeInfoLength int
Expand Down Expand Up @@ -510,8 +510,7 @@ func registerNodesForEpochs(
}
}

// / Verifies that the clusters provided are the same as the expected clusters
// /
// Verifies that the clusters provided are the same as the expected clusters
func verifyClusters(
t *testing.T,
expectedClusters []Cluster,
Expand Down Expand Up @@ -544,8 +543,7 @@ func verifyClusters(

}

// / Verifies that the cluster quorum certificates are equal to the provided expected values
// /
// Verifies that the cluster quorum certificates are equal to the provided expected values
func verifyClusterQCs(
t *testing.T,
expectedQCs [][]string,
Expand Down Expand Up @@ -663,7 +661,7 @@ func verifyEpochTimingConfig(
assert.InDelta(t, expectedConfig.refTimestamp, uint64(timingConfigFields["refTimestamp"].(cadence.UInt64)), 30)
}

// / Verifies that the configurable epoch metadata is equal to the provided values
// Verifies that the configurable epoch metadata is equal to the provided values
func verifyConfigMetadata(
t *testing.T,
b emulator.Emulator,
Expand Down Expand Up @@ -728,7 +726,7 @@ func verifyEpochStart(

}

// / Verifies that the epoch setup event values are equal to the provided expected values
// Verifies that the epoch setup event values are equal to the provided expected values
func verifyEpochSetup(
t *testing.T,
b emulator.Emulator,
Expand Down Expand Up @@ -773,8 +771,7 @@ func verifyEpochSetup(
assertEqual(t, cadence.NewUInt64(expectedSetup.targetEndTime), emittedEvent.targetEndTime())
}

// / Verifies that the EpochCommit event values are equal to the provided expected values
// /
// Verifies that the EpochCommit event values are equal to the provided expected values
func verifyEpochCommit(
t *testing.T,
b emulator.Emulator,
Expand Down Expand Up @@ -835,9 +832,7 @@ func expectedTargetEndTime(timingConfig cadence.Value, targetEpoch uint64) uint6
}

// 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
// CAUTION: Assumes that only one such event was emitted, and that it was emitted in the first 1000 blocks.
func verifyEpochRecover(
t *testing.T,
adapter *adapters.SDKAdapter,
Expand Down
250 changes: 125 additions & 125 deletions lib/go/test/flow_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1744,151 +1744,151 @@ func TestEpochRecover_OverwriteEpoch_Failure(t *testing.T) {
}
}

func TestEpoch_others(t *testing.T) {
t.Run("Can recover the epoch during the staking auction with automatic rewards enabled", func(t *testing.T) {
epochConfig := &testEpochConfig{
startEpochCounter: startEpochCounter,
numEpochViews: numEpochViews,
numStakingViews: numStakingViews,
numDKGViews: numDKGViews,
numClusters: numClusters,
numEpochAccounts: numEpochAccounts,
randomSource: randomSource,
rewardIncreaseFactor: rewardIncreaseFactor,
}
runWithDefaultContracts(t, epochConfig, func(b emulator.Emulator, env templates.Environment, ids []string, idTableAddress flow.Address, IDTableSigner sdkcrypto.Signer, adapter *adapters.SDKAdapter) {
tx := createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochSetAutomaticRewardsScript(env), idTableAddress)
tx.AddArgument(cadence.NewBool(true))
signAndSubmit(
t, b, tx,
[]flow.Address{idTableAddress},
[]sdkcrypto.Signer{IDTableSigner},
false,
)
// TestEpochRecover_StakingPhase tests EFM recovery during the staking phase with automatic rewards enabled.
func TestEpochRecover_StakingPhase(t *testing.T) {
epochConfig := &testEpochConfig{
startEpochCounter: startEpochCounter,
numEpochViews: numEpochViews,
numStakingViews: numStakingViews,
numDKGViews: numDKGViews,
numClusters: numClusters,
numEpochAccounts: numEpochAccounts,
randomSource: randomSource,
rewardIncreaseFactor: rewardIncreaseFactor,
}
runWithDefaultContracts(t, epochConfig, func(b emulator.Emulator, env templates.Environment, ids []string, idTableAddress flow.Address, IDTableSigner sdkcrypto.Signer, adapter *adapters.SDKAdapter) {
// Enable automatic rewards
tx := createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochSetAutomaticRewardsScript(env), idTableAddress)
tx.AddArgument(cadence.NewBool(true))
signAndSubmit(
t, b, tx,
[]flow.Address{idTableAddress},
[]sdkcrypto.Signer{IDTableSigner},
false,
)

advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "EPOCHSETUP", false)
epochTimingConfigResult := executeScriptAndCheck(t, b, templates.GenerateGetEpochTimingConfigScript(env), nil)
var (
startView uint64 = 100
stakingEndView uint64 = 120
endView uint64 = 160
targetDuration uint64 = numEpochViews
epochCounter uint64 = startEpochCounter + 1
targetEndTime uint64 = expectedTargetEndTime(epochTimingConfigResult, epochCounter)
)
args := getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter)
advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "EPOCHSETUP", false)
epochTimingConfigResult := executeScriptAndCheck(t, b, templates.GenerateGetEpochTimingConfigScript(env), nil)
var (
startView uint64 = 100
stakingEndView uint64 = 120
endView uint64 = 160
targetDuration uint64 = numEpochViews
epochCounter uint64 = startEpochCounter + 1
targetEndTime uint64 = expectedTargetEndTime(epochTimingConfigResult, epochCounter)
)
args := getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter)

tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
for _, arg := range args {
tx.AddArgument(arg)
}
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
for _, arg := range args {
tx.AddArgument(arg)
}

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

advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "BLOCK", false)
advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "BLOCK", false)

verifyEpochRecoverGovernanceTx(t, b, env, ids,
startView,
stakingEndView,
endView,
targetDuration,
targetEndTime,
epochCounter,
// The calculation of the total rewards should have happened
// because automatic rewards are enabled
// (total supply + current payount amount - bonus tokens) * reward increase factor
// (7000000000 + 1250000 - 0) * 0.00093871 = 6,571,204.6775
"6572143.38750000",
idTableAddress,
adapter,
args,
)
verifyEpochRecoverGovernanceTx(t, b, env, ids,
startView,
stakingEndView,
endView,
targetDuration,
targetEndTime,
epochCounter,
// The calculation of the total rewards should have happened
// because automatic rewards are enabled
// (total supply + current payount amount - bonus tokens) * reward increase factor
// (7000000000 + 1250000 - 0) * 0.00093871 = 6,571,204.6775
"6572143.38750000",
idTableAddress,
adapter,
args,
)

args = getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter+1)
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
for _, arg := range args {
tx.AddArgument(arg)
}
args = getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter+1)
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
for _, arg := range args {
tx.AddArgument(arg)
}

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

advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "BLOCK", false)
advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "BLOCK", false)

tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochPayRewardsScript(env), idTableAddress)
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochPayRewardsScript(env), idTableAddress)

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

// Verifies that the rewards from the previous epoch does not include the new epoch's amount
verifyEpochTotalRewardsPaid(t, b, idTableAddress,
EpochTotalRewardsPaid{
total: "6572143.38750000",
fromFees: "0.0",
minted: "6572143.38750000",
feesBurned: "0.01500000"})
// Verifies that the rewards from the previous epoch does not include the new epoch's amount
verifyEpochTotalRewardsPaid(t, b, idTableAddress,
EpochTotalRewardsPaid{
total: "6572143.38750000",
fromFees: "0.0",
minted: "6572143.38750000",
feesBurned: "0.01500000"})

result := executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(ids[0]))})
assertEqual(t, CadenceUFix64("1314428.67450000"), result)
result := executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(ids[0]))})
assertEqual(t, CadenceUFix64("1314428.67450000"), result)

// Rewards have already been paid, so this should not do anything
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochPayRewardsScript(env), idTableAddress)
// Rewards have already been paid, so this should not do anything
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochPayRewardsScript(env), idTableAddress)

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

// The nodes rewards should not have increased
result = executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(ids[0]))})
assertEqual(t, CadenceUFix64("1314428.67450000"), result)

// overwrite current epoch with a recover transaction, rewards should not be paid out
args = getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter+1)
// set unsafe overwrite to true
args[len(args)-1] = cadence.NewBool(true)
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
for _, arg := range args {
tx.AddArgument(arg)
}
// The nodes rewards should not have increased
result = executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(ids[0]))})
assertEqual(t, CadenceUFix64("1314428.67450000"), result)

signAndSubmit(
t, b, tx,
[]flow.Address{idTableAddress},
[]sdkcrypto.Signer{IDTableSigner},
false,
)
// overwrite current epoch with a recover transaction, rewards should not be paid out
args = getRecoveryTxArgs(env, ids, startView, stakingEndView, endView, targetDuration, targetEndTime, epochCounter+1)
// set unsafe overwrite to true
args[len(args)-1] = cadence.NewBool(true)
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateRecoverEpochScript(env), idTableAddress)
for _, arg := range args {
tx.AddArgument(arg)
}

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

advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "BLOCK", false)
advanceView(t, b, env, idTableAddress, IDTableSigner, 1, "BLOCK", false)

tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochPayRewardsScript(env), idTableAddress)
tx = createTxWithTemplateAndAuthorizer(b, templates.GenerateEpochPayRewardsScript(env), idTableAddress)

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

// The nodes rewards should not have increased
result = executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(ids[0]))})
assertEqual(t, CadenceUFix64("1314428.67450000"), result)
})
// The nodes rewards should not have increased
result = executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(ids[0]))})
assertEqual(t, CadenceUFix64("1314428.67450000"), result)
})
}

Expand Down
Loading

0 comments on commit c481969

Please sign in to comment.