Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRFelix committed Jun 6, 2024
1 parent 8a48bcf commit 368d228
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe("compare1CTTransactionParams", () => {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

Expand All @@ -38,7 +37,6 @@ describe("compare1CTTransactionParams", () => {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

Expand All @@ -56,7 +54,6 @@ describe("compare1CTTransactionParams", () => {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

Expand All @@ -69,45 +66,24 @@ describe("compare1CTTransactionParams", () => {
expect(changes).toContain("networkFeeLimit");
});

it("should detect changes in resetPeriod", () => {
const prevParams: OneClickTradingTransactionParams = {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

const nextParams: OneClickTradingTransactionParams = {
...prevParams,
resetPeriod: "week",
};

const changes = compare1CTTransactionParams({ prevParams, nextParams });
expect(changes).toContain("resetPeriod");
});

it("should detect multiple changes including sessionPeriod", () => {
const prevParams: OneClickTradingTransactionParams = {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

const nextParams: OneClickTradingTransactionParams = {
...prevParams,
spendLimit: mockPricePretty(7000),
networkFeeLimit: mockCoinPretty(16000),
resetPeriod: "month",
sessionPeriod: { end: "3hours" },
};

const changes = compare1CTTransactionParams({ prevParams, nextParams });
expect(changes).toContain("spendLimit");
expect(changes).toContain("networkFeeLimit");
expect(changes).toContain("resetPeriod");
expect(changes).toContain("sessionPeriod");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jest.mock("~/config", () => ({
describe("isAuthenticatorOneClickTradingSession", () => {
const key = new PrivKeySecp256k1(Buffer.from("key"));
const allowedAmount = "1000";
const resetPeriod = "day";
const allowedMessages: AvailableOneClickTradingMessages[] = [
"/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn",
"/osmosis.poolmanager.v1beta1.MsgSplitRouteSwapExactAmountIn",
Expand All @@ -29,7 +28,6 @@ describe("isAuthenticatorOneClickTradingSession", () => {
const rawAuthenticator = getOneClickTradingSessionAuthenticator({
key,
allowedAmount,
resetPeriod,
allowedMessages,
sessionPeriod,
});
Expand All @@ -46,7 +44,7 @@ describe("isAuthenticatorOneClickTradingSession", () => {
it("should return false for an invalid 1-Click Trading Session authenticator", () => {
const authenticator = {
type: "AllOf",
subAuthenticators: [{ type: "InvalidType" }],
subAuthenticators: [{ type: "Invalidtype" }],
};
expect(
isAuthenticatorOneClickTradingSession({
Expand All @@ -60,7 +58,6 @@ describe("getOneClickTradingSessionAuthenticator", () => {
it("should generate a correct 1-Click Trading Session authenticator", () => {
const key = PrivKeySecp256k1.generateRandomKey();
const allowedAmount = "1000";
const resetPeriod = "day";
const allowedMessages: AvailableOneClickTradingMessages[] = [
"/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn",
"/osmosis.poolmanager.v1beta1.MsgSplitRouteSwapExactAmountIn",
Expand All @@ -70,17 +67,16 @@ describe("getOneClickTradingSessionAuthenticator", () => {
const result = getOneClickTradingSessionAuthenticator({
key,
allowedAmount,
resetPeriod,
allowedMessages,
sessionPeriod,
});

expect(result.type).toEqual("AllOf");
const data = JSON.parse(Buffer.from(result.data).toString());
expect(data).toHaveLength(3);
expect(data[0].Type).toEqual("SignatureVerification");
expect(data[1].Type).toEqual("CosmwasmAuthenticatorV1");
expect(data[2].Type).toEqual("AnyOf");
expect(data[0].type).toEqual("SignatureVerification");
expect(data[1].type).toEqual("CosmwasmAuthenticatorV1");
expect(data[2].type).toEqual("AnyOf");
});
});

Expand Down

0 comments on commit 368d228

Please sign in to comment.