Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ An '!' indicates a state machine breaking change.

### Bug Fixes

- ! [#163](https://github.com/bcp-innovations/hyperlane-cosmos/pull/163) Fix warp payload length check
- [#157](https://github.com/bcp-innovations/hyperlane-cosmos/pull/157) Fix Amino JSON signing for ISM `MsgSetRoutingIsmDomain`, warp `MsgEnrollRemoteRouter`, and post_dispatch `MsgSetDestinationGasConfig`.
- ! [#164](https://github.com/bcp-innovations/hyperlane-cosmos/pull/164) Fix MsgPayForGas to account for the IGP quote.
- ! [#163](https://github.com/bcp-innovations/hyperlane-cosmos/pull/163) Fix warp payload length check.
- ! [#157](https://github.com/bcp-innovations/hyperlane-cosmos/pull/157) Fix Amino JSON signing for ISM `MsgSetRoutingIsmDomain`, warp `MsgEnrollRemoteRouter`, and post_dispatch `MsgSetDestinationGasConfig`.
- ! [#148](https://github.com/bcp-innovations/hyperlane-cosmos/pull/148) Fix Amino name typos in warp.
- ! [#153](https://github.com/bcp-innovations/hyperlane-cosmos/pull/153) Fix SetDomain for RoutingISM.
- ! [#123](https://github.com/bcp-innovations/hyperlane-cosmos/pull/123) Fix Amino name typos in core.
Expand Down
65 changes: 54 additions & 11 deletions x/core/02_post_dispatch/keeper/logic_gas_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TEST CASES - logic_gas_payment.go
* PayForGas (invalid) with zero amount
* PayForGas (invalid) with an invalid sender
* PayForGas (invalid) with a non-funded sender
* PayForGas (invalid) insufficient amount
* PayForGas (valid)
* Claim (invalid) for non-existing IGP
* Claim (invalid) from non-owner address
Expand Down Expand Up @@ -90,8 +91,8 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {
IgpId: nonExistingIgp,
MessageId: messageIdTest,
DestinationDomain: 1,
GasLimit: math.NewInt(1),
Amount: sdk.NewCoin(denom, math.NewInt(10)),
GasLimit: math.NewInt(50000),
Amount: sdk.NewCoin(denom, math.NewInt(250000)),
})

// Assert
Expand Down Expand Up @@ -132,14 +133,56 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {
IgpId: igpId,
MessageId: messageIdTest,
DestinationDomain: 1,
GasLimit: math.NewInt(1),
GasLimit: math.NewInt(50000),
Amount: sdk.NewCoin(denom, math.ZeroInt()),
})

// Assert
Expect(err.Error()).To(Equal("amount must be greater than zero"))
})

It("PayForGas (invalid) insufficient amount", func() {
// NOTE: Negative amount panics at sdk.NewCoins()
// Arrange
res, err := s.RunTx(&types.MsgCreateIgp{
Owner: creator.Address,
Denom: denom,
})
Expect(err).To(BeNil())

var response types.MsgCreateIgpResponse
err = proto.Unmarshal(res.MsgResponses[0].Value, &response)
Expect(err).To(BeNil())
igpId := response.Id

_, err = s.RunTx(&types.MsgSetDestinationGasConfig{
Owner: creator.Address,
IgpId: igpId,
DestinationGasConfig: &types.DestinationGasConfig{
RemoteDomain: 1,
GasOracle: &types.GasOracle{
TokenExchangeRate: math.NewInt(1e10),
GasPrice: math.NewInt(1),
},
GasOverhead: math.NewInt(200000),
},
})
Expect(err).To(BeNil())

// Act
_, err = s.RunTx(&types.MsgPayForGas{
Sender: gasPayer.Address,
IgpId: igpId,
MessageId: messageIdTest,
DestinationDomain: 1,
GasLimit: math.NewInt(50000),
Amount: sdk.NewCoin(denom, math.NewInt(5)),
})

// Assert
Expect(err.Error()).To(Equal("required payment exceeds max hyperlane fee: 250000acoin"))
})

It("PayForGas (invalid) with an invalid sender", func() {
// Arrange
res, err := s.RunTx(&types.MsgCreateIgp{
Expand Down Expand Up @@ -174,7 +217,7 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {
MessageId: messageIdTest,
DestinationDomain: 1,
GasLimit: math.NewInt(50000),
Amount: sdk.NewCoin(denom, math.NewInt(10)),
Amount: sdk.NewCoin(denom, math.NewInt(250000)),
})

// Assert
Expand Down Expand Up @@ -215,16 +258,16 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {
MessageId: messageIdTest,
DestinationDomain: 1,
GasLimit: math.NewInt(50000),
Amount: sdk.NewCoin(denom, math.NewInt(10)),
Amount: sdk.NewCoin(denom, math.NewInt(250000)),
})

// Assert
Expect(err.Error()).To(Equal("spendable balance 0acoin is smaller than 10acoin: insufficient funds"))
Expect(err.Error()).To(Equal("spendable balance 0acoin is smaller than 250000acoin: insufficient funds"))
})

It("PayForGas (valid)", func() {
// Arrange
gasAmount := math.NewInt(10)
gasAmount := math.NewInt(250000)

err := s.MintBaseCoins(gasPayer.Address, 1_000_000)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -263,7 +306,7 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {
MessageId: messageIdTest,
DestinationDomain: 1,
GasLimit: math.NewInt(50000),
Amount: sdk.NewCoin(denom, math.NewInt(10)),
Amount: sdk.NewCoin(denom, math.NewInt(250000)),
})

// Assert
Expand Down Expand Up @@ -293,7 +336,7 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {

It("Claim (invalid) from non-owner address", func() {
// Arrange
gasAmount := math.NewInt(10)
gasAmount := math.NewInt(200000)

err := s.MintBaseCoins(gasPayer.Address, 1_000_000)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -355,7 +398,7 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {

It("Claim (invalid) with invalid address", func() {
// Arrange
gasAmount := math.NewInt(10)
gasAmount := math.NewInt(250000)

err := s.MintBaseCoins(gasPayer.Address, 1_000_000)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -445,7 +488,7 @@ var _ = Describe("logic_gas_payment.go", Ordered, func() {

It("Claim (valid)", func() {
// Arrange
gasAmount := math.NewInt(10)
gasAmount := math.NewInt(250000)

err := s.MintBaseCoins(gasPayer.Address, 1_000_000)
Expect(err).To(BeNil())
Expand Down
4 changes: 3 additions & 1 deletion x/core/02_post_dispatch/keeper/msg_igp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func (ms msgServer) PayForGas(ctx context.Context, req *types.MsgPayForGas) (*ty

handler := InterchainGasPaymasterHookHandler{*ms.k}

return &types.MsgPayForGasResponse{}, handler.PayForGasWithoutQuote(ctx, req.IgpId, req.Sender, req.MessageId, req.DestinationDomain, req.GasLimit, sdk.NewCoins(req.Amount))
_, err := handler.PayForGas(ctx, req.IgpId, req.Sender, req.MessageId, req.DestinationDomain, req.GasLimit, sdk.NewCoins(req.Amount))

return &types.MsgPayForGasResponse{}, err
}

func (ms msgServer) SetDestinationGasConfig(ctx context.Context, req *types.MsgSetDestinationGasConfig) (*types.MsgSetDestinationGasConfigResponse, error) {
Expand Down