Skip to content

Commit

Permalink
fix authz deterministic gas (#935)
Browse files Browse the repository at this point in the history
* Changed gas for authz MsgGrant and MsgExec

* fixed one of tests

* removed unused var
  • Loading branch information
miladz68 authored Aug 29, 2024
1 parent 4250e1b commit 8c55c4b
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 196 deletions.
3 changes: 1 addition & 2 deletions integration-tests/modules/assetft_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,14 +1488,13 @@ func TestAssetFTExtensionMintingAndSendingOnBehalfOfIssuingSmartContractIsPossib
Amount: sdk.NewInt(3 * 500_000),
})

res, err := client.BroadcastTx(
_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
requireT.NotEqualValues(chain.GasLimitByMsgs(&execMsg), res.GasUsed)

// check balances

Expand Down
107 changes: 35 additions & 72 deletions integration-tests/modules/assetft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1683,15 +1683,13 @@ func TestAssetFTFeesAreNotChargedWhenTokensAreTransferredFromSmartContractUsingA
}})

chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down Expand Up @@ -3682,15 +3680,13 @@ func TestAuthzWithAssetFT(t *testing.T) {

execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgFreeze, msgWhitelist})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(40_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down Expand Up @@ -3727,10 +3723,9 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) {
chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
&authztypes.MsgGrant{},
&authztypes.MsgGrant{},
},
Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount,
Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount.
Add(sdk.NewInt(40_000)),
})

// mint and grant authorization
Expand Down Expand Up @@ -3777,15 +3772,13 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) {

execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand All @@ -3812,15 +3805,13 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) {

execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactory().WithGas(200_000),
&execMsg,
)
requireT.Error(err)
Expand All @@ -3834,15 +3825,13 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) {

execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down Expand Up @@ -3877,10 +3866,7 @@ func TestAuthzMintAuthorizationLimit_GrantFromNonIssuer(t *testing.T) {
})

chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{
Messages: []sdk.Msg{
&authztypes.MsgGrant{},
&authztypes.MsgGrant{},
},
Amount: sdk.NewInt(40_000),
})

// issue and grant authorization
Expand Down Expand Up @@ -3938,15 +3924,13 @@ func TestAuthzMintAuthorizationLimit_GrantFromNonIssuer(t *testing.T) {

execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactory().WithGas(200_000),
&execMsg,
)
requireT.Error(err)
Expand All @@ -3971,9 +3955,9 @@ func TestAuthzMintAuthorizationLimit_MultipleCoins(t *testing.T) {
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
&assetfttypes.MsgIssue{},
&authztypes.MsgGrant{},
},
Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount.Mul(sdk.NewInt(2)),
Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount.Mul(sdk.NewInt(2)).
Add(sdk.NewInt(20_000)),
})

// issue and grant authorization
Expand Down Expand Up @@ -4042,15 +4026,13 @@ func TestAuthzMintAuthorizationLimit_MultipleCoins(t *testing.T) {

execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down Expand Up @@ -4084,10 +4066,8 @@ func TestAuthzBurnAuthorizationLimit(t *testing.T) {
chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
&authztypes.MsgGrant{},
&authztypes.MsgGrant{},
},
Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount,
Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount.Add(sdk.NewInt(40_000)),
})

// grant authorization
Expand Down Expand Up @@ -4132,15 +4112,13 @@ func TestAuthzBurnAuthorizationLimit(t *testing.T) {

execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgBurn})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand All @@ -4167,15 +4145,13 @@ func TestAuthzBurnAuthorizationLimit(t *testing.T) {

execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgBurn})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactory().WithGas(200_000),
&execMsg,
)
requireT.Error(err)
Expand All @@ -4189,15 +4165,13 @@ func TestAuthzBurnAuthorizationLimit(t *testing.T) {

execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgBurn})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down Expand Up @@ -4239,10 +4213,7 @@ func TestAuthzBurnAuthorizationLimit_GrantFromNonIssuer(t *testing.T) {
})

chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{
Messages: []sdk.Msg{
&authztypes.MsgGrant{},
&authztypes.MsgGrant{},
},
Amount: sdk.NewInt(40_000),
})

// issue and grant authorization
Expand Down Expand Up @@ -4330,15 +4301,13 @@ func TestAuthzBurnAuthorizationLimit_GrantFromNonIssuer(t *testing.T) {

execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgBurn})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand All @@ -4351,15 +4320,13 @@ func TestAuthzBurnAuthorizationLimit_GrantFromNonIssuer(t *testing.T) {

execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgBurn})
chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactory().WithGas(200_000),
&execMsg,
)
requireT.Error(err)
Expand Down Expand Up @@ -4925,15 +4892,13 @@ func TestAssetFTAminoMultisigWithAuthz(t *testing.T) {
execMsg := authztypes.NewMsgExec(multisigGranteeAddress, []sdk.Msg{issueMsg})

chain.FundAccountWithOptions(ctx, t, multisigGranteeAddress, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(20_000),
})

_, err = chain.SignAndBroadcastMultisigTx(
ctx,
chain.ClientContext.WithFromAddress(multisigGranteeAddress),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
granteeSigner1KeyName, granteeSigner2KeyName)
requireT.NoError(err)
Expand Down Expand Up @@ -5662,15 +5627,13 @@ func TestAssetFTMintingAndSendingOnBehalfOfIssuingSmartContractIsPossibleEvenIfS
})

chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: sdk.NewInt(40_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down
21 changes: 8 additions & 13 deletions integration-tests/modules/assetnft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1902,16 +1902,14 @@ func TestAssetNFTAuthZ(t *testing.T) {
execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{freezeMsg})

chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
},
Amount: chain.QueryAssetNFTParams(ctx, t).MintFee.Amount,
Amount: chain.QueryAssetNFTParams(ctx, t).MintFee.Amount.
Add(sdk.NewInt(20_000)),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down Expand Up @@ -2389,9 +2387,9 @@ func TestAssetNFTSendAuthorization(t *testing.T) {
Messages: []sdk.Msg{
&assetnfttypes.MsgIssueClass{},
&assetnfttypes.MsgMint{},
&authztypes.MsgGrant{},
},
Amount: chain.QueryAssetNFTParams(ctx, t).MintFee.Amount,
Amount: chain.QueryAssetNFTParams(ctx, t).MintFee.Amount.
Add(sdk.NewInt(20_000)), // added 20k for the grant msg
})

chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Expand Down Expand Up @@ -2433,16 +2431,13 @@ func TestAssetNFTSendAuthorization(t *testing.T) {
execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{sendMsg})

chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{
Messages: []sdk.Msg{
&execMsg,
&execMsg,
},
Amount: sdk.NewInt(40_000),
})

_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactory().WithGas(200_000),
&execMsg,
)
requireT.Error(err)
Expand Down Expand Up @@ -2485,7 +2480,7 @@ func TestAssetNFTSendAuthorization(t *testing.T) {
_, err = client.BroadcastTx(
ctx,
chain.ClientContext.WithFromAddress(grantee),
chain.TxFactory().WithGas(chain.GasLimitByMsgs(&execMsg)),
chain.TxFactoryAuto(),
&execMsg,
)
requireT.NoError(err)
Expand Down
Loading

0 comments on commit 8c55c4b

Please sign in to comment.