-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authz #2206
Authz #2206
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @vuong177 . Thank you so much for the tests, including on the testnet.
Had some minor comments. Please take a look
x/gamm/types/msgs_test.go
Outdated
@@ -867,3 +872,148 @@ func TestMsgExitSwapShareAmountIn(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
// Test authz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please elaborate elaborate here that this test is meant more so to test the authz than the gamm message
x/gamm/types/msgs_test.go
Outdated
gammMsg sdk.Msg | ||
}{ | ||
{ | ||
expectedGrantSignByteMsg: `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"cosmos-sdk/MsgGrant","value":{"grant":{"authorization":{"type":"cosmos-sdk/GenericAuthorization","value":{"msg":"/osmosis.gamm.v1beta1.MsgExitSwapShareAmountIn"}},"expiration":"0001-01-01T02:01:01.000000001Z"},"grantee":"cosmos1def","granter":"cosmos1abc"}}],"sequence":"1","timeout_height":"1"}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to have this represented in a struct format and the unmarshal to json string if needed?
It's hard to follow this in a string format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to have this represented in a struct format and the unmarshal to json string if needed?
It's hard to follow this in a string format.
I think it's a bit complex. Why we don't use pretty json in expectedGrantSignByteMsg. Like that
expectedGrantSignByteMsg : `{
"account_number":"1",
"chain_id":"foo",
"fee":{
"amount":[
],
"gas":"0"
},
"memo":"memo",
"msgs":[
{
"type":"cosmos-sdk/MsgGrant",
"value":{
"grant":{
"authorization":{
"type":"cosmos-sdk/GenericAuthorization",
"value":{
"msg":"/osmosis.gamm.v1beta1.MsgExitSwapShareAmountIn"
}
},
"expiration":"0001-01-01T02:01:01.000000001Z"
},
"grantee":"cosmos1def",
"granter":"cosmos1abc"
}
}
],
"sequence":"1",
"timeout_height":"1"
}`
instead of use one line string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks for suggesting the alternative
x/gamm/types/msgs_test.go
Outdated
typeURL := sdk.MsgTypeURL(tc.gammMsg) | ||
grant, err := authz.NewGrant(someDate, authz.NewGenericAuthorization(typeURL), someDate.Add(time.Hour)) | ||
require.NoError(t, err) | ||
msgGrant := &authz.MsgGrant{Granter: "cosmos1abc", Grantee: "cosmos1def", Grant: grant} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we extract cosmos1abc
and cosmos1def
to constants instead of hardcoding in multiple places, please?
x/superfluid/types/msg_test.go
Outdated
msg sdk.Msg | ||
}{ | ||
{ | ||
expectedGrantSignByteMsg: `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"cosmos-sdk/MsgGrant","value":{"grant":{"authorization":{"type":"cosmos-sdk/GenericAuthorization","value":{"msg":"/osmosis.superfluid.MsgLockAndSuperfluidDelegate"}},"expiration":"0001-01-01T02:01:01.000000001Z"},"grantee":"cosmos1def","granter":"cosmos1abc"}}],"sequence":"1","timeout_height":"1"}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment about making these structs and unmarshalling, if possible
x/tokenfactory/types/msgs_test.go
Outdated
msg sdk.Msg | ||
}{ | ||
{ | ||
expectedGrantSignByteMsg: `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"cosmos-sdk/MsgGrant","value":{"grant":{"authorization":{"type":"cosmos-sdk/GenericAuthorization","value":{"msg":"/osmosis.tokenfactory.v1beta1.MsgCreateDenom"}},"expiration":"0001-01-01T02:01:01.000000001Z"},"grantee":"cosmos1def","granter":"cosmos1abc"}}],"sequence":"1","timeout_height":"1"}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto: structs instead of strings
Hi @vuong177 . Have you gotten a chance to look at my comments? Would love to help you get this over the finish line as we are prioritizing this feature for the current sprint completion |
@p0mvn sorry for my late response. I'm making this test cleaner. |
No problem and no rush, just making sure that we are making progress here 👍 |
Woah thanks for this PR! I think somethings off about having this many test vectors for authz in every module. Whats the exact authz property were trying to test for every message? What I was hoping would be the case is that we can have a |
@ValarDragon This test is for checking serialize and de-serialize in MsgExec. Example in a gamm msg : Current version:
This PR :
|
What confuses is me is that there should be some generic validation logic for checking this -- if there wasn't, then there wouldn't have been any failures. Can we just re-use that method (or write it), and then ensure |
Oh great idea. I think we can do that. It makes this test more sense. Thank you @ValarDragon ! I'm going to make that. |
Awesome, thank you so much! That will become much more maintainable as well =) |
x/gamm/types/msgs_test.go
Outdated
var ( | ||
mockMsgGrant authz.MsgGrant | ||
mockMsgRevoke authz.MsgRevoke | ||
mockMsgExec authz.MsgExec | ||
) | ||
|
||
// Authz: Grant Msg | ||
typeURL := sdk.MsgTypeURL(tc.gammMsg) | ||
grant, err := authz.NewGrant(someDate, authz.NewGenericAuthorization(typeURL), someDate.Add(time.Hour)) | ||
require.NoError(t, err) | ||
|
||
msgGrant := authz.MsgGrant{Granter: mockGranter, Grantee: mockGrantee, Grant: grant} | ||
msgGrantBytes := json.RawMessage(sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msgGrant))) | ||
err = authzcodec.ModuleCdc.UnmarshalJSON(msgGrantBytes, &mockMsgGrant) | ||
require.NoError(t, err) | ||
|
||
// Authz: Revoke Msg | ||
msgRevoke := authz.MsgRevoke{Granter: mockGranter, Grantee: mockGrantee, MsgTypeUrl: typeURL} | ||
msgRevokeByte := json.RawMessage(sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msgRevoke))) | ||
err = authzcodec.ModuleCdc.UnmarshalJSON(msgRevokeByte, &mockMsgRevoke) | ||
require.NoError(t, err) | ||
|
||
// Authz: Exec Msg | ||
msgAny, _ := cdctypes.NewAnyWithValue(tc.gammMsg) | ||
msgExec := authz.MsgExec{Grantee: mockGrantee, Msgs: []*cdctypes.Any{msgAny}} | ||
execMsgByte := json.RawMessage(sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msgExec))) | ||
err = authzcodec.ModuleCdc.UnmarshalJSON(execMsgByte, &mockMsgExec) | ||
require.NoError(t, err) | ||
require.Equal(t, msgExec.Msgs[0].Value, mockMsgExec.Msgs[0].Value) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this all to apptesting
function, and call it TestMessageSerialization
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I rename package in msg_test.go
from types
to types_test
? This is to avoid import cycle error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah, this makes sense to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty for doing this! Looks good to me!
Note to others, diff is only large due to the _testing package switch, which makes sense
Lets add a changelog and this is good to go?
I added changelog. Thanks for your reviews ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, nice work @vuong177
I'm wondering though if it makes sense to separate the types package name change so that we can backport it to v11.x
. Please let me know what you think
app/apptesting/test_suite.go
Outdated
require.NoError(t, err) | ||
|
||
// Authz: Exec Msg | ||
msgAny, _ := cdctypes.NewAnyWithValue(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's handle the error please
x/gamm/types/msgs_test.go
Outdated
msg.TokenOutMinAmount = sdk.NewInt(0) | ||
return msg | ||
}), | ||
expectPass: false, | ||
}, | ||
{ | ||
name: "negative amount criteria", | ||
msg: createMsg(func(msg MsgSwapExactAmountIn) MsgSwapExactAmountIn { | ||
msg: createMsg(func(msg gammtypes.MsgSwapExactAmountIn) gammtypes.MsgSwapExactAmountIn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Would it make sense to split up pass-through changes into a separate PR so that we can backport it?
Otherwise, backporting other work can get bottlenecked on this later
cc: @ValarDragon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with creating a new PR to change package name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to create it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah thats a great point, should also be a really quick review + merge
Ty for doing that vuong!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x/gamm/types/msgs_test.go
Outdated
appParams.SetAddressPrefixes() | ||
pk1 := ed25519.GenPrivKey().PubKey() | ||
addr1 := sdk.AccAddress(pk1.Address()).String() | ||
coin := sdk.NewCoin("stake", sdk.NewInt(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coin := sdk.NewCoin("stake", sdk.NewInt(1)) | |
coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)) |
Co-authored-by: Roman <[email protected]>
oh rip merge conflicts, can you try git merge main? (Thanks for making the other PR off the osmosis repo, once this is on the repo, we can get these last steps handled with async round trip lol) |
yes. No conflict anymore! |
Thanks for making this!- |
Closes: #2099
What is the purpose of the change
Brief Changelog
(for example:)
RegisterLegacyAminoCodec
in codec.go in every module. This allows thex/authz
module to properly serialize and de-serializeMsgExec
instances using AminoTesting and Verifying