Skip to content
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

refactor(nexus)!: distinguish locking of bank coin vs nexus assets #2197

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s msgServer) CallContract(c context.Context, req *types.CallContractReques
})

if req.Fee != nil {
lockableAsset, err := s.nexus.NewLockableAsset(ctx, s.ibcK, s.bank, req.Fee.Amount)
lockableAsset, err := s.nexus.NewLockableAssetFromCosmosCoin(ctx, s.ibcK, s.bank, req.Fee.Amount)
if err != nil {
return nil, sdkerrors.Wrap(err, "unrecognized fee denom")
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (s msgServer) ConfirmDeposit(c context.Context, req *types.ConfirmDepositRe
return nil, fmt.Errorf("recipient chain '%s' is not activated", recipient.Chain.Name)
}

lockableAsset, err := s.nexus.NewLockableAsset(ctx, s.ibcK, s.bank, coin)
lockableAsset, err := s.nexus.NewLockableAssetFromCosmosCoin(ctx, s.ibcK, s.bank, coin)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/axelarnet/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func extractTokenFromPacketData(ctx sdk.Context, ibcK keeper.IBCKeeper, n types.
denom = denomTrace.IBCDenom()
}

return n.NewLockableAsset(ctx, ibcK, b, sdk.NewCoin(denom, amount))
return n.NewLockableAssetFromCosmosCoin(ctx, ibcK, b, sdk.NewCoin(denom, amount))
}

// deductFee pays the fee and returns the updated transfer amount with the fee deducted
Expand All @@ -416,7 +416,7 @@ func deductFee(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK types.IB
// subtract fee from transfer value
coinAfterFee := token.GetCoin(ctx).Sub(feeCoin)

return funcs.Must(n.NewLockableAsset(ctx, ibcK, b, coinAfterFee)), b.SendCoins(ctx, types.AxelarIBCAccount, recipient, sdk.NewCoins(feeCoin))
return funcs.Must(n.NewLockableAssetFromCosmosCoin(ctx, ibcK, b, coinAfterFee)), b.SendCoins(ctx, types.AxelarIBCAccount, recipient, sdk.NewCoins(feeCoin))
}

// validateReceiver rejects uppercase GMP account address
Expand Down
14 changes: 7 additions & 7 deletions x/axelarnet/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestHandleMessage(t *testing.T) {
}))
channelK.SendPacketFunc = func(sdk.Context, *captypes.Capability, ibcexported.PacketI) error { return nil }
n = &mock.NexusMock{
NewLockableAssetFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
NewLockableAssetFromCosmosCoinFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
lockableAsset = &nexusmock.LockableAssetMock{
GetAssetFunc: func() sdk.Coin { return coin },
GetCoinFunc: func(_ sdk.Context) sdk.Coin { return coin },
Expand Down Expand Up @@ -496,7 +496,7 @@ func TestHandleMessageWithToken(t *testing.T) {
GetCoinFunc: func(_ sdk.Context) sdk.Coin { return sdk.NewCoin(denom, funcs.MustOk(sdk.NewIntFromString(amount))) },
}
n = &mock.NexusMock{
NewLockableAssetFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
NewLockableAssetFromCosmosCoinFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
return lockableAsset, nil
},
SetNewMessageFunc: func(ctx sdk.Context, msg nexus.GeneralMessage) error {
Expand Down Expand Up @@ -677,9 +677,9 @@ func TestHandleMessageWithToken(t *testing.T) {
Then("should return ack success", func(t *testing.T) {
assert.True(t, axelarnet.OnRecvMessage(ctx, k, ibcK, n, b, r, packet).Success())
assert.Equal(t, genMsg.Status, nexus.Approved)
assert.Len(t, n.NewLockableAssetCalls(), 2)
assert.Equal(t, n.NewLockableAssetCalls()[0].Coin.Amount, funcs.MustOk(sdk.NewIntFromString(amount)))
assert.Equal(t, n.NewLockableAssetCalls()[1].Coin.Amount, sdk.OneInt())
assert.Len(t, n.NewLockableAssetFromCosmosCoinCalls(), 2)
assert.Equal(t, n.NewLockableAssetFromCosmosCoinCalls()[0].Coin.Amount, funcs.MustOk(sdk.NewIntFromString(amount)))
assert.Equal(t, n.NewLockableAssetFromCosmosCoinCalls()[1].Coin.Amount, sdk.OneInt())
}).
Run(t)
}
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestHandleSendToken(t *testing.T) {
GetCoinFunc: func(_ sdk.Context) sdk.Coin { return sdk.NewCoin(denom, funcs.MustOk(sdk.NewIntFromString(amount))) },
}
n = &mock.NexusMock{
NewLockableAssetFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
NewLockableAssetFromCosmosCoinFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
return lockableAsset, nil
},
SetNewMessageFunc: func(sdk.Context, nexus.GeneralMessage) error { return nil },
Expand Down Expand Up @@ -929,7 +929,7 @@ func TestTokenAndDestChainNotFound(t *testing.T) {
channelK.SendPacketFunc = func(sdk.Context, *captypes.Capability, ibcexported.PacketI) error { return nil }
lockableAsset = &nexusmock.LockableAssetMock{}
n = &mock.NexusMock{
NewLockableAssetFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
NewLockableAssetFromCosmosCoinFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
return lockableAsset, nil
},
SetNewMessageFunc: func(ctx sdk.Context, msg nexus.GeneralMessage) error {
Expand Down
2 changes: 1 addition & 1 deletion x/axelarnet/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestIBCModule(t *testing.T) {
transferK := ibctransferkeeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("transfer"), transferSubspace, &mock.ChannelKeeperMock{}, &mock.ChannelKeeperMock{}, &mock.PortKeeperMock{}, accountK, bankK, scopedTransferK)
lockableAsset = &nexusmock.LockableAssetMock{}
n = &mock.NexusMock{
NewLockableAssetFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
NewLockableAssetFromCosmosCoinFunc: func(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error) {
return lockableAsset, nil
},
}
Expand Down
1 change: 1 addition & 0 deletions x/axelarnet/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Nexus interface {
GenerateMessageID(ctx sdk.Context) (string, []byte, uint64)
ValidateAddress(ctx sdk.Context, address nexus.CrossChainAddress) error
NewLockableAsset(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error)
NewLockableAssetFromCosmosCoin(ctx sdk.Context, ibc nexustypes.IBCKeeper, bank nexustypes.BankKeeper, coin sdk.Coin) (nexus.LockableAsset, error)
}

// BankKeeper defines the expected interface contract the vesting module requires
Expand Down
148 changes: 105 additions & 43 deletions x/axelarnet/types/mock/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading