Skip to content

Commit

Permalink
Unify gas adjustment usage for the integration tests. (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil authored May 17, 2024
1 parent 7ac8916 commit 995c66c
Show file tree
Hide file tree
Showing 20 changed files with 362 additions and 171 deletions.
206 changes: 181 additions & 25 deletions integration-tests/ibc/asset_ft_test.go

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions integration-tests/ibc/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestIBCHooksCounterWASMCall(t *testing.T) {

coreumContractAddr, _, err := coreumChain.Wasm.DeployAndInstantiateWASMContract(
ctx,
coreumChain.TxFactory().WithSimulateAndExecute(true),
coreumChain.TxFactoryAuto(),
coreumContractAdmin,
ibcwasm.IBCHooksCounter,
integration.InstantiateConfig{
Expand All @@ -95,7 +95,13 @@ func TestIBCHooksCounterWASMCall(t *testing.T) {

sendToOsmosisCoin := coreumChain.NewCoin(sdkmath.NewInt(10_000_000))
_, err = coreumChain.ExecuteIBCTransfer(
ctx, t, coreumSender, sendToOsmosisCoin, osmosisChain.ChainContext, osmosisHookCaller1,
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumSender,
sendToOsmosisCoin,
osmosisChain.ChainContext,
osmosisHookCaller1,
)
requireT.NoError(err)

Expand All @@ -121,13 +127,13 @@ func TestIBCHooksCounterWASMCall(t *testing.T) {
ibcHookCallerOnCoreumAddr1, err := ibchookskeeper.DeriveIntermediateSender(
coreumToOsmosisChannelID,
osmosisChain.MustConvertToBech32Address(osmosisHookCaller1),
coreumChain.Chain.ChainSettings.AddressPrefix)
coreumChain.ChainSettings.AddressPrefix)
requireT.NoError(err)

ibcHookCallerOnCoreumAddr2, err := ibchookskeeper.DeriveIntermediateSender(
coreumToOsmosisChannelID,
osmosisChain.MustConvertToBech32Address(osmosisHookCaller2),
coreumChain.Chain.ChainSettings.AddressPrefix)
coreumChain.ChainSettings.AddressPrefix)
requireT.NoError(err)

// Verify that hook caller is separate for each sender address.
Expand All @@ -143,6 +149,7 @@ func TestIBCHooksCounterWASMCall(t *testing.T) {
_, err = osmosisChain.ExecuteIBCTransferWithMemo(
ctx,
t,
osmosisChain.TxFactoryAuto(),
osmosisHookCaller1,
sendToCoreumCoin,
coreumChain.ChainContext,
Expand All @@ -164,6 +171,7 @@ func TestIBCHooksCounterWASMCall(t *testing.T) {
_, err = osmosisChain.ExecuteIBCTransferWithMemo(
ctx,
t,
osmosisChain.TxFactoryAuto(),
osmosisHookCaller1,
sendToCoreumCoin,
coreumChain.ChainContext,
Expand All @@ -185,6 +193,7 @@ func TestIBCHooksCounterWASMCall(t *testing.T) {
_, err = osmosisChain.ExecuteIBCTransferWithMemo(
ctx,
t,
osmosisChain.TxFactoryAuto(),
osmosisHookCaller2,
sendOsmosisToCoreumCoin,
coreumChain.ChainContext,
Expand Down Expand Up @@ -239,7 +248,7 @@ func TestIBCHooksCounterWASMCallback(t *testing.T) {

coreumContractAddr, _, err := coreumChain.Wasm.DeployAndInstantiateWASMContract(
ctx,
coreumChain.TxFactory().WithSimulateAndExecute(true),
coreumChain.TxFactoryAuto(),
coreumContractAdmin,
ibcwasm.IBCHooksCounter,
integration.InstantiateConfig{
Expand All @@ -259,9 +268,10 @@ func TestIBCHooksCounterWASMCallback(t *testing.T) {
// For more details check: https://github.com/cosmos/ibc-apps/blob/main/modules/ibc-hooks/wasm_hook.go#L228
ibcCallbackMemo := fmt.Sprintf(`{"ibc_callback": "%s"}`, coreumContractAddr)
sendToOsmosisCoin := coreumChain.NewCoin(sdkmath.NewInt(10_000_000))
_, err = coreumChain.Chain.ExecuteIBCTransferWithMemo(
_, err = coreumChain.ExecuteIBCTransferWithMemo(
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumSender,
sendToOsmosisCoin,
osmosisChain.ChainContext,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/ibc/pfm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestPFMViaCoreum(t *testing.T) {
_, err = osmosisChain.ExecuteIBCTransferWithMemo(
ctx,
t,
osmosisChain.TxFactoryAuto(),
osmosisSender,
sendToGaiaCoin,
coreumChain.ChainContext,
Expand Down
70 changes: 62 additions & 8 deletions integration-tests/ibc/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ func TestIBCTransferFromCoreumToGaiaAndBack(t *testing.T) {
})

txRes, err := coreumChain.ExecuteIBCTransfer(
ctx, t, coreumSender, sendToGaiaCoin, gaiaChain.ChainContext, gaiaRecipient,
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumSender,
sendToGaiaCoin,
gaiaChain.ChainContext,
gaiaRecipient,
)
requireT.NoError(err)
requireT.EqualValues(txRes.GasUsed, coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{}))
Expand All @@ -62,7 +68,13 @@ func TestIBCTransferFromCoreumToGaiaAndBack(t *testing.T) {
)
requireT.NoError(gaiaChain.AwaitForBalance(ctx, t, gaiaRecipient, expectedGaiaRecipientBalance))
_, err = gaiaChain.ExecuteIBCTransfer(
ctx, t, gaiaRecipient, expectedGaiaRecipientBalance, coreumChain.Chain.ChainContext, coreumSender,
ctx,
t,
gaiaChain.TxFactoryAuto(),
gaiaRecipient,
expectedGaiaRecipientBalance,
coreumChain.Chain.ChainContext,
coreumSender,
)
requireT.NoError(err)

Expand Down Expand Up @@ -106,7 +118,13 @@ func TestIBCTransferFromGaiaToCoreumAndBack(t *testing.T) {

// Send from gaiaAccount to coreumToCoreumSender
_, err := gaiaChain.ExecuteIBCTransfer(
ctx, t, gaiaAccount1, sendToCoreumCoin, coreumChain.Chain.ChainContext, coreumToCoreumSender,
ctx,
t,
gaiaChain.TxFactoryAuto(),
gaiaAccount1,
sendToCoreumCoin,
coreumChain.Chain.ChainContext,
coreumToCoreumSender,
)
requireT.NoError(err)

Expand Down Expand Up @@ -140,7 +158,13 @@ func TestIBCTransferFromGaiaToCoreumAndBack(t *testing.T) {

// Send from coreumToGaiaSender back to gaiaAccount
_, err = coreumChain.ExecuteIBCTransfer(
ctx, t, coreumToGaiaSender, expectedBalanceAtCoreum, gaiaChain.ChainContext, gaiaAccount2,
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumToGaiaSender,
expectedBalanceAtCoreum,
gaiaChain.ChainContext,
gaiaAccount2,
)
requireT.NoError(err)
expectedGaiaSenderBalance := sdk.NewCoin(sendToCoreumCoin.Denom, expectedBalanceAtCoreum.Amount)
Expand Down Expand Up @@ -178,7 +202,13 @@ func TestTimedOutTransfer(t *testing.T) {
})

_, err := coreumChain.ExecuteTimingOutIBCTransfer(
ctx, t, coreumSender, sendToOsmosisCoin, osmosisChain.ChainContext, osmosisRecipient,
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumSender,
sendToOsmosisCoin,
osmosisChain.ChainContext,
osmosisRecipient,
)
switch {
case err == nil:
Expand Down Expand Up @@ -276,7 +306,15 @@ func TestRejectedTransfer(t *testing.T) {
Amount: gaiaChain.NewCoin(sdk.NewIntFromUint64(100000)),
})

_, err := coreumChain.ExecuteIBCTransfer(ctx, t, coreumSender, sendToGaiaCoin, gaiaChain.ChainContext, moduleAddress)
_, err := coreumChain.ExecuteIBCTransfer(
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumSender,
sendToGaiaCoin,
gaiaChain.ChainContext,
moduleAddress,
)
requireT.NoError(err)

// funds should be returned to coreum
Expand All @@ -299,11 +337,27 @@ func TestRejectedTransfer(t *testing.T) {
})

sendToCoreumCoin := sdk.NewCoin(ibcGaiaDenom, sendToGaiaCoin.Amount)
_, err = coreumChain.ExecuteIBCTransfer(ctx, t, coreumSender, sendToGaiaCoin, gaiaChain.ChainContext, gaiaRecipient)
_, err = coreumChain.ExecuteIBCTransfer(
ctx,
t,
coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(&ibctransfertypes.MsgTransfer{})),
coreumSender,
sendToGaiaCoin,
gaiaChain.ChainContext,
gaiaRecipient,
)
requireT.NoError(err)
requireT.NoError(gaiaChain.AwaitForBalance(ctx, t, gaiaRecipient, sendToCoreumCoin))

_, err = gaiaChain.ExecuteIBCTransfer(ctx, t, gaiaRecipient, sendToCoreumCoin, coreumChain.ChainContext, moduleAddress)
_, err = gaiaChain.ExecuteIBCTransfer(
ctx,
t,
gaiaChain.TxFactoryAuto(),
gaiaRecipient,
sendToCoreumCoin,
coreumChain.ChainContext,
moduleAddress,
)
requireT.NoError(err)

// funds should be returned to gaia
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/ibc/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestIBCTransferFromSmartContract(t *testing.T) {
// deploy the contract and fund it
contractAddr, _, err := coreumChain.Wasm.DeployAndInstantiateWASMContract(
ctx,
coreumChain.TxFactory().WithSimulateAndExecute(true),
coreumChain.TxFactoryAuto(),
coreumAdmin,
ibcwasm.IBCTransferWASM,
integration.InstantiateConfig{
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestIBCTransferFromSmartContract(t *testing.T) {

_, err = coreumChain.Wasm.ExecuteWASMContract(
ctx,
coreumChain.TxFactory().WithSimulateAndExecute(true),
coreumChain.TxFactoryAuto(),
coreumAdmin,
contractAddr,
transferPayload,
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestIBCCallFromSmartContract(t *testing.T) {

coreumContractAddr, _, err := coreumChain.Wasm.DeployAndInstantiateWASMContract(
ctx,
coreumChain.TxFactory().WithSimulateAndExecute(true),
coreumChain.TxFactoryAuto(),
coreumCaller,
ibcwasm.IBCCallWASM,
integration.InstantiateConfig{
Expand All @@ -209,7 +209,7 @@ func TestIBCCallFromSmartContract(t *testing.T) {

osmosisContractAddr, _, err := osmosisChain.Wasm.DeployAndInstantiateWASMContract(
ctx,
osmosisChain.TxFactory().WithSimulateAndExecute(true),
osmosisChain.TxFactoryAuto(),
osmosisCaller,
ibcwasm.IBCCallWASM,
integration.InstantiateConfig{
Expand Down Expand Up @@ -303,7 +303,7 @@ func executeWasmIncrement(

_, err = chain.Wasm.ExecuteWASMContract(
ctx,
chain.TxFactory().WithSimulateAndExecute(true),
chain.TxFactoryAuto(),
caller,
contractAddr,
incrementPayload,
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) {
require.NoError(t, err)
gaiaSettings := integration.QueryChainSettings(queryCtx, gaiaGRPClient)
gaiaSettings.GasPrice = sdk.MustNewDecFromStr("0.01")
gaiaSettings.GasAdjustment = 1.5
gaiaSettings.CoinType = sdk.CoinType // gaia coin type
gaiaSettings.RPCAddress = gaiaRPCAddress

Expand All @@ -182,7 +181,6 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) {
require.NoError(t, err)
osmosisChainSettings := integration.QueryChainSettings(queryCtx, osmosisGRPClient)
osmosisChainSettings.GasPrice = sdk.MustNewDecFromStr("0.01")
osmosisChainSettings.GasAdjustment = 1.5
osmosisChainSettings.CoinType = sdk.CoinType // osmosis coin type
osmosisChainSettings.RPCAddress = osmosisRPCAddress

Expand Down
Loading

0 comments on commit 995c66c

Please sign in to comment.