Skip to content

Commit

Permalink
test: tests for enoughRouterLiquidity
Browse files Browse the repository at this point in the history
  • Loading branch information
just-a-node committed Apr 24, 2024
1 parent 2cb1822 commit bc18006
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions packages/agents/sdk/test/sdkUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ describe("SdkUtils", () => {

stub(ConfigFns, "getConfig").resolves({ nxtpConfig: config, chainData: mockChainData });
stub(SharedFns, "domainToChainId").returns(chainId);
stubAxiosGetRequest = stub(SharedFns, 'axiosGetRequest').resolves([
{ "address": mkAddress("0x1") }
]);

nxtpUtils = await SdkUtils.create(mockConfig, undefined, mockChainData);
});

Expand All @@ -48,6 +44,12 @@ describe("SdkUtils", () => {
});

describe("#getRoutersData", () => {
beforeEach(async () => {
stubAxiosGetRequest = stub(SharedFns, 'axiosGetRequest').resolves([
{ "address": mkAddress("0x1") }
]);
});

it("happy: should work", async () => {
(nxtpUtils as any).config.cartographerUrl = config.cartographerUrl;

Expand Down Expand Up @@ -166,11 +168,14 @@ describe("SdkUtils", () => {
});

describe("#enoughRouterLiquidity", () => {
beforeEach(async () => {
stubAxiosGetRequest = stub(SharedFns, 'axiosGetRequest');
});

it("should be true when enough liquidity between <N routers", async () => {
(nxtpUtils as any).config.cartographerUrl = config.cartographerUrl;

restore();
stub(SharedFns, 'axiosGetRequest').resolves([
stubAxiosGetRequest.resolves([
{
"balance": "100",
"local": mock.asset.A.address,
Expand All @@ -182,6 +187,7 @@ describe("SdkUtils", () => {
"domain": mock.domain.A,
}
]);

const res = await nxtpUtils.enoughRouterLiquidity(
mock.domain.A,
mock.asset.A.address,
Expand All @@ -195,19 +201,21 @@ describe("SdkUtils", () => {
it("happy: should be true when enough liquidity between N routers", async () => {
(nxtpUtils as any).config.cartographerUrl = config.cartographerUrl;

restore();
stub(SharedFns, 'axiosGetRequest').resolves([
{
"balance": "100",
"local": mock.asset.A.address,
"domain": mock.domain.A,
},
{
"balance": "200",
"local": mock.asset.A.address,
"domain": mock.domain.A,
}
]);
stubAxiosGetRequest.resolves(
[
{
"balance": "100",
"local": mock.asset.A.address,
"domain": mock.domain.A,
},
{
"balance": "200",
"local": mock.asset.A.address,
"domain": mock.domain.A,
}
]
);

const res = await nxtpUtils.enoughRouterLiquidity(
mock.domain.A,
mock.asset.A.address,
Expand All @@ -221,8 +229,7 @@ describe("SdkUtils", () => {
it("happy: should be false when not enough liquidity between <N routers", async () => {
(nxtpUtils as any).config.cartographerUrl = config.cartographerUrl;

restore();
stub(SharedFns, 'axiosGetRequest').resolves([
stubAxiosGetRequest.resolves([
{
"balance": "100",
"local": mock.asset.A.address,
Expand All @@ -242,8 +249,7 @@ describe("SdkUtils", () => {
it("happy: should be false when not enough liquidity between N routers", async () => {
(nxtpUtils as any).config.cartographerUrl = config.cartographerUrl;

restore();
stub(SharedFns, 'axiosGetRequest').resolves([
stubAxiosGetRequest.resolves([
{
"balance": "100",
"local": mock.asset.A.address,
Expand Down

0 comments on commit bc18006

Please sign in to comment.