Skip to content

Commit

Permalink
isKakarotTransaction tests (#1129)
Browse files Browse the repository at this point in the history
* tests for each branching

* removed unused import

* fix
  • Loading branch information
stevencartavia authored May 29, 2024
1 parent 09ad0ae commit 454eda3
Showing 1 changed file with 86 additions and 2 deletions.
88 changes: 86 additions & 2 deletions indexer/src/utils/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
assert,
assertFalse,
assertEquals
} from "https://deno.land/[email protected]/assert/mod.ts";
import { ethValidationFailed } from "./filter.ts";
import { Event } from "../deps.ts";
import { ethValidationFailed, isKakarotTransaction } from "./filter.ts";
import { Event, Transaction } from "../deps.ts";

const event = (data: `0x${string}`[]) => {
return {
Expand Down Expand Up @@ -71,3 +72,86 @@ Deno.test("ethValidationFailed: incorrect data length", () => {
const failed = ethValidationFailed(x);
assertFalse(failed);
});

Deno.test("isKakarotTransaction: no calldata", () => {
const transaction: Transaction = {
invokeV1: {
senderAddress: "0x01",
calldata: []
},
meta: {
hash: "0x01",
maxFee: "0x01",
nonce: "0x01",
signature: ["0x1", "0x2", "0x3", "0x4", "0x32"],
version: "1",
},
};
const failed = isKakarotTransaction(transaction);
assertFalse(failed);
});

Deno.test("isKakarotTransaction: no `to` field in calldata", () => {
const starknetTxCalldata: `0x${string}`[] = [
"0x1"
];
const transaction: Transaction = {
invokeV1: {
senderAddress: "0x01",
calldata: starknetTxCalldata
},
meta: {
hash: "0x01",
maxFee: "0x01",
nonce: "0x01",
signature: ["0x1", "0x2", "0x3", "0x4", "0x32"],
version: "1",
},
};
const failed = isKakarotTransaction(transaction);
assertFalse(failed);
});

Deno.test("isKakarotTransaction: `to` address not matching KAKAROT_ADDRESS", () => {
const starknetTxCalldata: `0x${string}`[] = [
"0x1",
"0x2",
];
const transaction: Transaction = {
invokeV1: {
senderAddress: "0x01",
calldata: starknetTxCalldata
},
meta: {
hash: "0x02",
maxFee: "0x02",
nonce: "0x02",
signature: ["0x2"],
version: "1",
},
};
const failed = isKakarotTransaction(transaction);
assertEquals(failed, false);
});

Deno.test("isKakarotTransaction: `to` address matching KAKAROT_ADDRESS", () => {
const starknetTxCalldata: `0x${string}`[] = [
"0x1",
"0x1"
];
const transaction: Transaction = {
invokeV1: {
senderAddress: "0x01",
calldata: starknetTxCalldata
},
meta: {
hash: "0x01",
maxFee: "0x01",
nonce: "0x01",
signature: ["0x1", "0x2", "0x3", "0x4", "0x1"],
version: "1",
},
};
const success = isKakarotTransaction(transaction);
assertEquals(success, true);
});

0 comments on commit 454eda3

Please sign in to comment.