github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/cmdvotetestsetup.go (about) 1 // Copyright (c) 2020-2021 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 ) 10 11 // cmdVoteTestSetup starts a batch of proposal votes. 12 type cmdVoteTestSetup struct { 13 Args struct { 14 AdminEmail string `positional-arg-name:"adminemail"` 15 AdminPassword string `positional-arg-name:"adminpassword"` 16 } `positional-args:"true" required:"true"` 17 18 // Votes is the number of DCR ticket votes that will be started. 19 Votes uint32 `long:"votes"` 20 21 // Duration is the duration, in blocks of the DCR ticket votes. 22 Duration uint32 `long:"duration"` 23 24 // Quorum is the percent of total votes required for a quorum. This is a 25 // pointer so that a value of 0 can be provided. A quorum of zero allows 26 // for the vote to be approved or rejected using a single DCR ticket. 27 Quorum *uint32 `long:"quorum"` 28 29 // Passing is the percent of cast votes required for a vote options to be 30 // considered as passing. 31 Passing uint32 `long:"passing"` 32 } 33 34 // Execute executes the cmdVoteTestSetup command. 35 // 36 // This function satisfies the go-flags Commander interface. 37 func (c *cmdVoteTestSetup) Execute(args []string) error { 38 // Setup vote parameters 39 var ( 40 votes uint32 = 10 41 duration = defaultDuration 42 quorum = defaultQuorum 43 passing = defaultPassing 44 ) 45 if c.Votes > 0 { 46 votes = c.Votes 47 } 48 if c.Duration > 0 { 49 duration = c.Duration 50 } 51 if c.Quorum != nil { 52 quorum = *c.Quorum 53 } 54 if c.Passing != 0 { 55 passing = c.Passing 56 } 57 58 // We don't want the output of individual commands printed. 59 cfg.Verbose = false 60 cfg.RawJSON = false 61 cfg.Silent = true 62 63 // Verify the the provided login credentials are for an admin. 64 admin := user{ 65 Email: c.Args.AdminEmail, 66 Password: c.Args.AdminPassword, 67 } 68 err := userLogin(admin) 69 if err != nil { 70 return fmt.Errorf("failed to login admin: %v", err) 71 } 72 lr, err := client.Me() 73 if err != nil { 74 return err 75 } 76 if !lr.IsAdmin { 77 return fmt.Errorf("provided user is not an admin") 78 } 79 admin.Username = lr.Username 80 81 // Verify that the paywall is disabled 82 policyWWW, err := client.Policy() 83 if err != nil { 84 return err 85 } 86 if policyWWW.PaywallEnabled { 87 fmt.Printf("WARN: politeiawww paywall is not disabled\n") 88 } 89 90 // Setup votes 91 for i := 0; i < int(votes); i++ { 92 s := fmt.Sprintf("Starting voting period on proposal %v/%v", i+1, votes) 93 printInPlace(s) 94 95 // Create a public proposal 96 r, err := proposalPublic(admin, admin, &proposalOpts{ 97 Random: true, 98 RandomImages: false, 99 }) 100 if err != nil { 101 return err 102 } 103 token := r.CensorshipRecord.Token 104 105 // Authorize vote 106 err = voteAuthorize(admin, token) 107 if err != nil { 108 return err 109 } 110 111 // Start vote 112 err = voteStart(admin, token, duration, quorum, passing, false) 113 if err != nil { 114 return err 115 } 116 } 117 fmt.Printf("\n") 118 119 return nil 120 } 121 122 // voteTestSetupHelpMsg is the printed to stdout by the help command. 123 const voteTestSetupHelpMsg = `votetestsetup [flags] "adminemail" "adminpassword" 124 125 Start batch of proposal votes. This command submits the specified number of 126 proposals, makes them public, then starts the voting period on each one. 127 128 Arguments: 129 1. adminemail (string, required) Email for admin account. 130 2. adminpassword (string, required) Password for admin account. 131 132 Flags 133 --votes (uint32) Number of votes to start. 134 (default: 10) 135 --duration (uint32) Duration, in blocks, of the vote. 136 (default: 6) 137 --quorum (uint32) Percent of total votes required to reach a quorum. A 138 quorum of 0 means that the vote can be approved or 139 rejected using a single DCR ticket. 140 (default: 0) 141 --passing (uint32) Percent of cast votes required for a vote option to be 142 considered as passing. 143 (default: 60) 144 `