-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
473208b
commit 4f93ce5
Showing
4 changed files
with
107 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gov | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/MalteHerrmann/upgrade-local-node-go/utils" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// DepositForProposal deposits the given amount of Evmos for the proposal with the given proposalID | ||
// from the given account. | ||
func DepositForProposal(bin *utils.Binary, proposalID int, sender string, amount int) (string, error) { | ||
out, err := utils.ExecuteBinaryCmd(bin, utils.BinaryCmdArgs{ | ||
Subcommand: []string{ | ||
"tx", "gov", "deposit", strconv.Itoa(proposalID), strconv.Itoa(amount) + "aevmos", | ||
}, | ||
From: sender, | ||
UseDefaults: true, | ||
Quiet: true, | ||
}) | ||
if err != nil { | ||
return out, errors.Wrap(err, fmt.Sprintf("failed to deposit for proposal %d", proposalID)) | ||
} | ||
|
||
return out, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package gov | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/MalteHerrmann/upgrade-local-node-go/utils" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// SubmitAllVotesForProposal submits a vote for the given proposal ID using all testing accounts. | ||
func SubmitAllVotesForProposal(bin *utils.Binary, proposalID int) error { | ||
accsWithDelegations, err := utils.FilterAccountsWithDelegations(bin) | ||
if err != nil { | ||
return errors.Wrap(err, "error filtering accounts") | ||
} | ||
|
||
if len(accsWithDelegations) == 0 { | ||
return errors.New("no accounts with delegations found") | ||
} | ||
|
||
utils.Wait(1) | ||
log.Printf("Voting for proposal %d...\n", proposalID) | ||
|
||
var out string | ||
|
||
for _, acc := range accsWithDelegations { | ||
out, err = VoteForProposal(bin, proposalID, acc.Name) | ||
if err != nil { | ||
if strings.Contains(out, fmt.Sprintf("%d: unknown proposal", proposalID)) { | ||
return fmt.Errorf("no proposal with ID %d found", proposalID) | ||
} | ||
|
||
if strings.Contains(out, fmt.Sprintf("%d: inactive proposal", proposalID)) { | ||
return fmt.Errorf("proposal with ID %d is inactive", proposalID) | ||
} | ||
|
||
log.Printf(" - could NOT vote using key: %s\n", acc.Name) | ||
} else { | ||
log.Printf(" - voted using key: %s\n", acc.Name) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// VoteForProposal votes for the proposal with the given ID using the given account. | ||
func VoteForProposal(bin *utils.Binary, proposalID int, sender string) (string, error) { | ||
out, err := utils.ExecuteBinaryCmd(bin, utils.BinaryCmdArgs{ | ||
Subcommand: []string{"tx", "gov", "vote", strconv.Itoa(proposalID), "yes"}, | ||
From: sender, | ||
UseDefaults: true, | ||
Quiet: true, | ||
}) | ||
if err != nil { | ||
return out, errors.Wrap(err, fmt.Sprintf("failed to vote for proposal %d", proposalID)) | ||
} | ||
|
||
return out, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters