-
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.
Merge pull request #1 from MalteHerrmann/make-more-variable
imp: use variable keys and proposal ID from current chain state
- Loading branch information
Showing
8 changed files
with
236 additions
and
25 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
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
module github.com/MalteHerrmann/upgrade-local-node-go | ||
|
||
go 1.20 | ||
|
||
require github.com/stretchr/testify v1.8.4 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,10 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
// getKeys returns the list of keys from the current running local node | ||
func getKeys() ([]string, error) { | ||
out, err := executeShellCommand([]string{"keys", "list"}, evmosdHome, "", false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return parseKeysFromOut(out) | ||
} | ||
|
||
func parseKeysFromOut(out string) ([]string, error) { | ||
// Define the regular expression pattern | ||
pattern := `\s+name:\s*(\w+)` | ||
|
||
// Compile the regular expression | ||
re := regexp.MustCompile(pattern) | ||
|
||
matches := re.FindAllStringSubmatch(out, -1) | ||
if len(matches) == 0 { | ||
return nil, fmt.Errorf("no keys found in output") | ||
} | ||
|
||
var keys []string | ||
for _, match := range matches { | ||
keys = append(keys, match[1]) | ||
} | ||
|
||
return keys, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseKeysFromOut(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
out string | ||
expKeys []string | ||
expError bool | ||
}{ | ||
{ | ||
name: "pass", | ||
out: ` - address: evmos19mx9kcksequm4m4xume5h0k9fquwgmea3yvu89 | ||
name: dev0 | ||
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"AmquZBW+CPcgHKx6D4YRDICzr0MNcRvl9Wm/jJn8wJxs"}' | ||
type: local | ||
- address: evmos18z7xfs864u49jcv6gkgajpteesjl5d7krpple6 | ||
name: dev1 | ||
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"AtY/rqJrmhKbXrQ02xSxq/t9JGgbP2T7HPGTZJIbuT8I"}' | ||
type: local | ||
- address: evmos12rrt7vcnxvhxad6gzz0vt5psdlnurtldety57n | ||
name: dev2 | ||
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"A544btlGjv4zB/qpWT8dQqlAHrcmgZEvrFSgJnp7Yjt4"}' | ||
type: local | ||
- address: evmos1dln2gjtsfd2sny6gwdxzyxcsr0uu8sh5nwajun | ||
name: testKey1 | ||
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"Amja5pRiVw+5vPkozo6Eo20AEbYVVBqOKBi5yP7EbxyJ"}' | ||
type: local | ||
- address: evmos1qdxgxz9g2la8g9eyjdq4srlpxgrmuqd6ty88zm | ||
name: testKey2 | ||
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"A+ytKfWmkQiW0c6iOCXSL71e4b5njmJVUd1msONsPEnA"}' | ||
type: local | ||
- address: evmos1hduvvhjvu0pqu7m97pajymdsupqx3us3ntey9a | ||
name: testKey3 | ||
pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"AsdAPndEVttzhUz5iSm0/FoFxkzB0oZE7DuKf3NjzXkS"}' | ||
type: local`, | ||
expKeys: []string{"dev0", "dev1", "dev2", "testKey1", "testKey2", "testKey3"}, | ||
}, | ||
{ | ||
name: "fail - no keys", | ||
out: "invalid output", | ||
expError: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
keys, err := parseKeysFromOut(tc.out) | ||
if tc.expError { | ||
require.Error(t, err, "expected error parsing keys") | ||
} else { | ||
require.NoError(t, err, "unexpected error parsing keys") | ||
require.Equal(t, tc.expKeys, keys) | ||
} | ||
}) | ||
} | ||
} |
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
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,65 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetProposalID(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
out string | ||
expID int | ||
expError bool | ||
}{ | ||
{ | ||
name: "pass", | ||
out: `gas estimate: 850456 | ||
code: 0 | ||
codespace: "" | ||
data: 12330A2D2F636F736D6F732E676F762E763162657461312E4D73675375626D697450726F706F73616C526573706F6E736512020804 | ||
events: | ||
logs: | ||
- events: | ||
- attributes: | ||
- key: amount | ||
value: 1000000000000aevmos | ||
- key: proposal_id | ||
value: "4" | ||
type: proposal_deposit | ||
- attributes: | ||
- key: proposal_id | ||
value: "4" | ||
- key: proposal_messages | ||
value: ',/cosmos.gov.v1.MsgExecLegacyContent' | ||
- key: voting_period_start | ||
value: "4" | ||
type: submit_proposal | ||
type: transfer | ||
log: "" | ||
msg_index: 0 | ||
timestamp: "" | ||
tx: null | ||
txhash: A505158FF9EFB4E939CD4A9A94F731E0E34AEEF50C7E53A723226EEF33A1A89B`, | ||
expID: 4, | ||
}, | ||
{ | ||
name: "fail - no proposal ID", | ||
out: "invalid output", | ||
expError: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
id, err := getProposalID(tc.out) | ||
if tc.expError { | ||
require.Error(t, err, "expected error parsing proposal ID") | ||
} else { | ||
require.NoError(t, err, "unexpected error parsing proposal ID") | ||
require.Equal(t, tc.expID, id, "expected different proposal ID") | ||
} | ||
}) | ||
} | ||
} |