-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add long asset checker * chore: update invariant check function and unit tests * fix: minor fix TOTO to TODO --------- Co-authored-by: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com>
- Loading branch information
1 parent
8dc11ac
commit b880472
Showing
12 changed files
with
574 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/elys-network/elys/x/margin/types" | ||
ptypes "github.com/elys-network/elys/x/parameter/types" | ||
) | ||
|
||
func (k Keeper) CheckLongingAssets(ctx sdk.Context, collateralAsset string, borrowAsset string) error { | ||
if borrowAsset == ptypes.USDC { | ||
return sdkerrors.Wrap(types.ErrInvalidBorrowingAsset, "invalid borrowing asset") | ||
} | ||
|
||
if collateralAsset == borrowAsset && collateralAsset == ptypes.USDC { | ||
return sdkerrors.Wrap(types.ErrInvalidBorrowingAsset, "invalid borrowing asset") | ||
} | ||
|
||
if collateralAsset != borrowAsset && collateralAsset != ptypes.USDC { | ||
return sdkerrors.Wrap(types.ErrInvalidBorrowingAsset, "invalid borrowing asset") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/elys-network/elys/x/margin/keeper" | ||
"github.com/elys-network/elys/x/margin/types" | ||
"github.com/elys-network/elys/x/margin/types/mocks" | ||
"github.com/stretchr/testify/assert" | ||
|
||
ptypes "github.com/elys-network/elys/x/parameter/types" | ||
) | ||
|
||
func TestCheckLongAssets_InvalidAssets(t *testing.T) { | ||
// Setup the mock checker | ||
mockChecker := new(mocks.OpenLongChecker) | ||
|
||
// Create an instance of Keeper with the mock checker | ||
k := keeper.Keeper{ | ||
OpenLongChecker: mockChecker, | ||
} | ||
|
||
ctx := sdk.Context{} // mock or setup a context | ||
|
||
err := k.CheckLongingAssets(ctx, ptypes.USDC, ptypes.USDC) | ||
assert.True(t, errors.Is(err, sdkerrors.Wrap(types.ErrInvalidBorrowingAsset, "invalid borrowing asset"))) | ||
|
||
err = k.CheckLongingAssets(ctx, ptypes.ATOM, ptypes.USDC) | ||
assert.True(t, errors.Is(err, sdkerrors.Wrap(types.ErrInvalidBorrowingAsset, "invalid borrowing asset"))) | ||
|
||
// Expect no error | ||
mockChecker.AssertExpectations(t) | ||
} | ||
|
||
func TestCheckLongAssets_ValidAssets(t *testing.T) { | ||
// Setup the mock checker | ||
mockChecker := new(mocks.OpenLongChecker) | ||
|
||
// Create an instance of Keeper with the mock checker | ||
k := keeper.Keeper{ | ||
OpenLongChecker: mockChecker, | ||
} | ||
|
||
ctx := sdk.Context{} // mock or setup a context | ||
|
||
err := k.CheckLongingAssets(ctx, ptypes.USDC, ptypes.ATOM) | ||
assert.Nil(t, err) | ||
|
||
err = k.CheckLongingAssets(ctx, ptypes.ATOM, ptypes.ATOM) | ||
assert.Nil(t, err) | ||
|
||
// Expect an error about max open positions | ||
assert.Nil(t, err) | ||
mockChecker.AssertExpectations(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.