From 96cf752aa8479544e49be70cb79e74be4d468932 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Wed, 25 Oct 2023 12:08:46 -0500 Subject: [PATCH] ibc-go/v7 v7.3.1 & regen mocks --- middleware/packet-forward-middleware/go.mod | 2 +- middleware/packet-forward-middleware/go.sum | 4 +-- .../packetforward/keeper/keeper.go | 12 +++++++++ .../packetforward/types/expected_keepers.go | 2 ++ .../test/mock/transfer_keeper.go | 26 +++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/middleware/packet-forward-middleware/go.mod b/middleware/packet-forward-middleware/go.mod index 61480a92..be0e8c73 100644 --- a/middleware/packet-forward-middleware/go.mod +++ b/middleware/packet-forward-middleware/go.mod @@ -12,7 +12,7 @@ require ( github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-sdk v0.47.5 github.com/cosmos/gogoproto v1.4.10 - github.com/cosmos/ibc-go/v7 v7.3.0 + github.com/cosmos/ibc-go/v7 v7.3.1 github.com/golang/protobuf v1.5.3 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 diff --git a/middleware/packet-forward-middleware/go.sum b/middleware/packet-forward-middleware/go.sum index 98a9773d..6de67449 100644 --- a/middleware/packet-forward-middleware/go.sum +++ b/middleware/packet-forward-middleware/go.sum @@ -340,8 +340,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= -github.com/cosmos/ibc-go/v7 v7.3.0 h1:QtGeVMi/3JeLWuvEuC60sBHpAF40Oenx/y+bP8+wRRw= -github.com/cosmos/ibc-go/v7 v7.3.0/go.mod h1:mUmaHFXpXrEdcxfdXyau+utZf14pGKVUiXwYftRZZfQ= +github.com/cosmos/ibc-go/v7 v7.3.1 h1:bil1IjnHdyWDASFYKfwdRiNtFP6WK3osW7QFEAgU4I8= +github.com/cosmos/ibc-go/v7 v7.3.1/go.mod h1:wvx4pPBofe5ZdMNV3OFRxSI4auEP5Qfqf8JXLLNV04g= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= diff --git a/middleware/packet-forward-middleware/packetforward/keeper/keeper.go b/middleware/packet-forward-middleware/packetforward/keeper/keeper.go index fbac42f2..edf5e8b7 100644 --- a/middleware/packet-forward-middleware/packetforward/keeper/keeper.go +++ b/middleware/packet-forward-middleware/packetforward/keeper/keeper.go @@ -182,6 +182,10 @@ func (k *Keeper) WriteAcknowledgementForForwardedPacket( panic(fmt.Sprintf("cannot burn coins after a successful send from escrow account to module account: %v", err)) } } + + // We move funds from the escrowAddress in both cases, + // update the total escrow amount for the denom. + k.unescrowToken(ctx, token) } } @@ -197,6 +201,14 @@ func (k *Keeper) WriteAcknowledgementForForwardedPacket( }, ack) } +// unescrowToken will update the total escrow by deducting the unescrowed token +// from the current total escrow. +func (k *Keeper) unescrowToken(ctx sdk.Context, token sdk.Coin) { + currentTotalEscrow := k.transferKeeper.GetTotalEscrowForDenom(ctx, token.GetDenom()) + newTotalEscrow := currentTotalEscrow.Sub(token) + k.transferKeeper.SetTotalEscrowForDenom(ctx, newTotalEscrow) +} + func (k *Keeper) ForwardTransferPacket( ctx sdk.Context, inFlightPacket *types.InFlightPacket, diff --git a/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go b/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go index b9bf9fb2..97575175 100644 --- a/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go +++ b/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go @@ -14,6 +14,8 @@ import ( type TransferKeeper interface { Transfer(ctx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) DenomPathFromHash(ctx sdk.Context, denom string) (string, error) + GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin + SetTotalEscrowForDenom(ctx sdk.Context, coin sdk.Coin) } // ChannelKeeper defines the expected IBC channel keeper diff --git a/middleware/packet-forward-middleware/test/mock/transfer_keeper.go b/middleware/packet-forward-middleware/test/mock/transfer_keeper.go index a49c96d8..a583ec4a 100644 --- a/middleware/packet-forward-middleware/test/mock/transfer_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/transfer_keeper.go @@ -51,6 +51,32 @@ func (mr *MockTransferKeeperMockRecorder) DenomPathFromHash(arg0, arg1 interface return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DenomPathFromHash", reflect.TypeOf((*MockTransferKeeper)(nil).DenomPathFromHash), arg0, arg1) } +// GetTotalEscrowForDenom mocks base method. +func (m *MockTransferKeeper) GetTotalEscrowForDenom(arg0 types.Context, arg1 string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTotalEscrowForDenom", arg0, arg1) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// GetTotalEscrowForDenom indicates an expected call of GetTotalEscrowForDenom. +func (mr *MockTransferKeeperMockRecorder) GetTotalEscrowForDenom(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTotalEscrowForDenom", reflect.TypeOf((*MockTransferKeeper)(nil).GetTotalEscrowForDenom), arg0, arg1) +} + +// SetTotalEscrowForDenom mocks base method. +func (m *MockTransferKeeper) SetTotalEscrowForDenom(arg0 types.Context, arg1 types.Coin) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetTotalEscrowForDenom", arg0, arg1) +} + +// SetTotalEscrowForDenom indicates an expected call of SetTotalEscrowForDenom. +func (mr *MockTransferKeeperMockRecorder) SetTotalEscrowForDenom(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTotalEscrowForDenom", reflect.TypeOf((*MockTransferKeeper)(nil).SetTotalEscrowForDenom), arg0, arg1) +} + // Transfer mocks base method. func (m *MockTransferKeeper) Transfer(arg0 context.Context, arg1 *types0.MsgTransfer) (*types0.MsgTransferResponse, error) { m.ctrl.T.Helper()