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

feat(axelarnet)!: release lock check #1972

Merged
merged 2 commits into from
Jul 26, 2023
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
4 changes: 2 additions & 2 deletions x/axelarnet/keeper/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (c Coin) Lock(bankK types.BankKeeper, depositAddr sdk.AccAddress) error {
return err
}

if !ics20.Equal(bankK.GetBalance(c.ctx, depositAddr, ics20.GetDenom())) {
return fmt.Errorf("balance does not match expected %s", ics20)
if bankK.GetBalance(c.ctx, depositAddr, ics20.GetDenom()).IsLT(ics20) {
return fmt.Errorf("coin %s to lock is greater than account balance", ics20)
}

// lock tokens in escrow address
Expand Down
42 changes: 32 additions & 10 deletions x/axelarnet/keeper/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestCoin(t *testing.T) {
ibcK keeper.IBCKeeper
chain nexus.Chain
coin keeper.Coin
trace ibctypes.DenomTrace
)

givenAKeeper := Given("a keeper", func() {
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestCoin(t *testing.T) {
// setup
path := testutils.RandomIBCPath()
chain = nexustestutils.RandomChain()
trace := ibctypes.DenomTrace{
trace = ibctypes.DenomTrace{
Path: path,
BaseDenom: rand.Denom(5, 10),
}
Expand All @@ -89,8 +90,11 @@ func TestCoin(t *testing.T) {

coin = funcs.Must(keeper.NewCoin(ctx, ibcK, nexusK, sdk.NewCoin(trace.IBCDenom(), sdk.NewInt(rand.PosI64()))))

bankK.GetBalanceFunc = func(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
return sdk.NewCoin(trace.IBCDenom(), coin.Amount)
nexusK.GetChainFunc = func(sdk.Context, nexus.ChainName) (nexus.Chain, bool) {
return chain, true
}
nexusK.GetChainByNativeAssetFunc = func(sdk.Context, string) (nexus.Chain, bool) {
return chain, true
}
})

Expand All @@ -109,16 +113,34 @@ func TestCoin(t *testing.T) {
assert.Len(t, bankK.SendCoinsFromAccountToModuleCalls(), 1)
assert.Len(t, bankK.BurnCoinsCalls(), 1)
}),

whenCoinIsICS20.
Then("should Lock ICS20 coin in escrow account", func(t *testing.T) {
nexusK.GetChainFunc = func(sdk.Context, nexus.ChainName) (nexus.Chain, bool) {
return chain, true
When("coin is greater than bank balance", func() {
bankK.GetBalanceFunc = func(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
return sdk.NewCoin(trace.IBCDenom(), coin.Amount.Sub(sdk.OneInt()))
}
nexusK.GetChainByNativeAssetFunc = func(sdk.Context, string) (nexus.Chain, bool) {
return chain, true
}).
Then("should return error", func(t *testing.T) {
err := coin.Lock(bankK, rand.AccAddr())
assert.ErrorContains(t, err, "is greater than account balance")
}),
whenCoinIsICS20.
When("coin equals to bank balance", func() {
bankK.GetBalanceFunc = func(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
return sdk.NewCoin(trace.IBCDenom(), coin.Amount)
}

}).
Then("should Lock ICS20 coin in escrow account", func(t *testing.T) {
err := coin.Lock(bankK, rand.AccAddr())
assert.NoError(t, err)
assert.Len(t, bankK.SendCoinsCalls(), 1)
}),
whenCoinIsICS20.
When("coin is less than bank balance", func() {
bankK.GetBalanceFunc = func(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
return sdk.NewCoin(trace.IBCDenom(), coin.Amount.Add(sdk.OneInt()))
}
}).
Then("should Lock ICS20 coin in escrow account", func(t *testing.T) {
err := coin.Lock(bankK, rand.AccAddr())
assert.NoError(t, err)
assert.Len(t, bankK.SendCoinsCalls(), 1)
Expand Down
Loading