UNPKG

@uniswap/smart-wallet-sdk

Version:

⚒️ An SDK for building applications with smart wallets on Uniswap

84 lines 4.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const viem_1 = require("viem"); const callPlanner_1 = require("./callPlanner"); const testConstants_1 = require("./testConstants"); describe('CallPlanner', () => { describe('constructor', () => { it('should initialize with an empty array of calls', () => { const planner = new callPlanner_1.CallPlanner(); expect(planner.calls).toEqual([]); }); it('should initialize with a provided array of calls', () => { const calls = [ { to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_1, value: testConstants_1.TEST_VALUE_1 }, { to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_2, value: testConstants_1.TEST_VALUE_2 } ]; const planner = new callPlanner_1.CallPlanner(calls); expect(planner.calls).toEqual(calls); }); }); describe('value', () => { it('should return 0 when no calls are present', () => { const planner = new callPlanner_1.CallPlanner(); expect(planner.value.toString()).toBe('0'); }); it('should sum the values of all calls', () => { const planner = new callPlanner_1.CallPlanner([ { to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_1, value: testConstants_1.TEST_VALUE_1 }, { to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_2, value: testConstants_1.TEST_VALUE_2 } ]); expect(planner.value.toString()).toBe('300'); }); it('should handle undefined values as 0', () => { const planner = new callPlanner_1.CallPlanner([ { to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_1, value: testConstants_1.TEST_VALUE_1 }, { to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_2, value: undefined } ]); expect(planner.value.toString()).toBe('100'); }); }); describe('encode', () => { it('should correctly abi encode the calls', () => { const planner = new callPlanner_1.CallPlanner([ { to: testConstants_1.TEST_ADDRESS_1, value: testConstants_1.TEST_VALUE_1, data: testConstants_1.TEST_DATA_1 } ]); const encoded = planner.encode(); // decode the encoded data const decoded = (0, viem_1.decodeAbiParameters)(callPlanner_1.CALL_ABI_PARAMS, encoded); expect(decoded).toEqual([[{ to: testConstants_1.TEST_ADDRESS_1, value: testConstants_1.TEST_VALUE_1, data: testConstants_1.TEST_DATA_1 }]]); }); it('should throw an error if there are no calls to encode', () => { const planner = new callPlanner_1.CallPlanner(); expect(() => planner.encode()).toThrow("No calls to encode"); }); }); describe('add', () => { it('should add a new call to the calls array', () => { const planner = new callPlanner_1.CallPlanner(); planner.add(testConstants_1.TEST_ADDRESS_1, testConstants_1.TEST_VALUE_1, testConstants_1.TEST_DATA_1); expect(planner.calls).toEqual([{ to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_1, value: testConstants_1.TEST_VALUE_1 }]); }); it('should add a new call with bigint value', () => { const planner = new callPlanner_1.CallPlanner(); planner.add(testConstants_1.TEST_ADDRESS_1, 100n, testConstants_1.TEST_DATA_1); expect(planner.calls).toEqual([{ to: testConstants_1.TEST_ADDRESS_1, data: testConstants_1.TEST_DATA_1, value: 100n }]); }); it('should return the planner instance for chaining', () => { const planner = new callPlanner_1.CallPlanner(); const result = planner.add(testConstants_1.TEST_ADDRESS_1, testConstants_1.TEST_VALUE_1, testConstants_1.TEST_DATA_1); expect(result).toBe(planner); }); it('should allow chaining multiple add calls', () => { const planner = new callPlanner_1.CallPlanner(); planner .add(testConstants_1.TEST_ADDRESS_1, testConstants_1.TEST_VALUE_1, testConstants_1.TEST_DATA_1) .add(testConstants_1.TEST_ADDRESS_1, testConstants_1.TEST_VALUE_2, testConstants_1.TEST_DATA_2); expect(planner.calls).toEqual([ { to: testConstants_1.TEST_ADDRESS_1, value: testConstants_1.TEST_VALUE_1, data: testConstants_1.TEST_DATA_1 }, { to: testConstants_1.TEST_ADDRESS_1, value: testConstants_1.TEST_VALUE_2, data: testConstants_1.TEST_DATA_2 } ]); }); }); }); //# sourceMappingURL=callPlanner.test.js.map