Skip to content

Commit

Permalink
Merge #4286
Browse files Browse the repository at this point in the history
4286: Remove payout flag, arg from resetEpoch cmd r=jordanschalm a=jordanschalm

In onflow/flow-core-contracts#365, we removed the payout argument from the resetEpoch transaction and function. Here, we update the CLI tool which generates arguments for this transaction accordingly.

Co-authored-by: Jordan Schalm <[email protected]>
  • Loading branch information
bors[bot] and jordanschalm authored May 1, 2023
2 parents 6a911be + 601ba43 commit 0fc9b05
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 59 deletions.
1 change: 0 additions & 1 deletion cmd/util/cmd/epochs/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
var (
flagBootDir string

flagPayout string
flagBucketNetworkName string

flagFlowSupplyIncreasePercentage string
Expand Down
23 changes: 2 additions & 21 deletions cmd/util/cmd/epochs/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -44,7 +43,6 @@ func init() {
}

func addResetCmdFlags() {
resetCmd.Flags().StringVar(&flagPayout, "payout", "", "the payout eg. 10000.0")
resetCmd.Flags().StringVar(&flagBucketNetworkName, "bucket-network-name", "", "when retrieving the root snapshot from a GCP bucket, the network name portion of the URL (eg. \"mainnet-13\")")
}

Expand Down Expand Up @@ -132,7 +130,7 @@ func extractResetEpochArgs(snapshot *inmem.Snapshot) []cadence.Value {
log.Fatal().Err(err).Msg("could not get final view from epoch")
}

return convertResetEpochArgs(epochCounter, randomSource, flagPayout, firstView, stakingEndView, finalView)
return convertResetEpochArgs(epochCounter, randomSource, firstView, stakingEndView, finalView)
}

// getStakingAuctionEndView determines the staking auction end view from the
Expand Down Expand Up @@ -169,7 +167,7 @@ func getStakingAuctionEndView(epoch protocol.Epoch) (uint64, error) {
// convertResetEpochArgs converts the arguments required by `resetEpoch` to cadence representations
// Contract Method: https://github.com/onflow/flow-core-contracts/blob/master/contracts/epochs/FlowEpoch.cdc#L413
// Transaction: https://github.com/onflow/flow-core-contracts/blob/master/transactions/epoch/admin/reset_epoch.cdc
func convertResetEpochArgs(epochCounter uint64, randomSource []byte, payout string, firstView, stakingEndView, finalView uint64) []cadence.Value {
func convertResetEpochArgs(epochCounter uint64, randomSource []byte, firstView, stakingEndView, finalView uint64) []cadence.Value {

args := make([]cadence.Value, 0)

Expand All @@ -183,23 +181,6 @@ func convertResetEpochArgs(epochCounter uint64, randomSource []byte, payout stri
}
args = append(args, cdcRandomSource)

// add payout
var cdcPayout cadence.Value
if payout != "" {
index := strings.Index(payout, ".")
if index == -1 {
log.Fatal().Msg("invalid --payout, eg: 10000.0")
}

cdcPayout, err = cadence.NewUFix64(payout)
if err != nil {
log.Fatal().Err(err).Msg("could not convert payout to cadence type")
}
} else {
cdcPayout = cadence.NewOptional(nil)
}
args = append(args, cdcPayout)

// add first view
args = append(args, cadence.NewUInt64(firstView))

Expand Down
37 changes: 0 additions & 37 deletions cmd/util/cmd/epochs/cmd/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,6 @@ func TestReset_LocalSnapshot(t *testing.T) {

// set initial flag values
flagBootDir = bootDir
flagPayout = ""

// run command with overwritten stdout
stdout := bytes.NewBuffer(nil)
resetCmd.SetOut(stdout)
resetRun(resetCmd, nil)

// read output from stdout
var outputTxArgs []interface{}
err = json.NewDecoder(stdout).Decode(&outputTxArgs)
require.NoError(t, err)

// compare to expected values
expectedArgs := extractResetEpochArgs(rootSnapshot)
verifyArguments(t, expectedArgs, outputTxArgs)
})
})

// tests that given the root snapshot file and payout, the command
// writes the expected arguments to stdout.
t.Run("with payout flag set", func(t *testing.T) {
unittest.RunWithTempDir(t, func(bootDir string) {

// create a root snapshot
rootSnapshot := unittest.RootSnapshotFixture(unittest.IdentityListFixture(10, unittest.WithAllRoles()))

// write snapshot to correct path in bootDir
err := writeRootSnapshot(bootDir, rootSnapshot)
require.NoError(t, err)

// set initial flag values
flagBootDir = bootDir
flagPayout = "10.0"

// run command with overwritten stdout
stdout := bytes.NewBuffer(nil)
Expand Down Expand Up @@ -97,7 +64,6 @@ func TestReset_LocalSnapshot(t *testing.T) {

// set initial flag values
flagBootDir = bootDir
flagPayout = ""

// run command
resetRun(resetCmd, nil)
Expand All @@ -117,7 +83,6 @@ func TestReset_BucketSnapshot(t *testing.T) {
t.Run("happy path", func(t *testing.T) {
// set initial flag values
flagBucketNetworkName = "mainnet-13"
flagPayout = ""

// run command with overwritten stdout
stdout := bytes.NewBuffer(nil)
Expand All @@ -140,7 +105,6 @@ func TestReset_BucketSnapshot(t *testing.T) {
t.Run("happy path - with payout", func(t *testing.T) {
// set initial flag values
flagBucketNetworkName = "mainnet-13"
flagPayout = "10.0"

// run command with overwritten stdout
stdout := bytes.NewBuffer(nil)
Expand All @@ -167,7 +131,6 @@ func TestReset_BucketSnapshot(t *testing.T) {

// set initial flag values
flagBucketNetworkName = "not-a-real-network-name"
flagPayout = ""

// run command
resetRun(resetCmd, nil)
Expand Down

0 comments on commit 0fc9b05

Please sign in to comment.