import { describe, expect, test } from "vitest"
import { encode7579Calls } from "./encode7579Calls"

describe("encode7579Calls", () => {
    test("single call", async () => {
        const callData = encode7579Calls({
            mode: {
                type: "call"
            },
            callData: [
                {
                    to: "0x1234567890123456789012345678901234567890",
                    value: BigInt(12345),
                    data: "0x1234567890123456789012345678901234567890"
                }
            ]
        })

        expect(callData).toBe(
            "0xe9ae5c53000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000030391234567890123456789012345678901234567890000000000000000000000000000000000000000000000000"
        )
    })

    test("batch call", async () => {
        const callData = encode7579Calls({
            mode: {
                type: "batchcall"
            },
            callData: [
                {
                    to: "0x1234567890123456789012345678901234567890",
                    value: BigInt(12345),
                    data: "0x1234567890123456789012345678901234567890"
                },
                {
                    to: "0x1234567890123456789012345678901234567890",
                    value: BigInt(12345),
                    data: "0x1234567890123456789012345678901234567890"
                }
            ]
        })

        expect(callData).toBe(
            "0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000303900000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000014123456789012345678901234567890123456789000000000000000000000000000000000000000000000000012345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000003039000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000141234567890123456789012345678901234567890000000000000000000000000"
        )
    })

    test("should throw error for batch call with different mode", async () => {
        expect(() => {
            encode7579Calls({
                mode: {
                    type: "call"
                },
                callData: [
                    {
                        to: "0x1234567890123456789012345678901234567890",
                        value: BigInt(12345),
                        data: "0x1234567890123456789012345678901234567890"
                    },
                    {
                        to: "0x1234567890123456789012345678901234567890",
                        value: BigInt(12345),
                        data: "0x1234567890123456789012345678901234567890"
                    }
                ]
            })
        }).toThrowError("batchcall calldata")
    })
})
