@tunghm/relay-kit
Version:
124 lines • 6.42 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ethers_1 = require("ethers");
const protocol_kit_1 = require("@safe-global/protocol-kit");
const SafeOperation_1 = __importDefault(require("./SafeOperation"));
const fixtures = __importStar(require("./testing-utils/fixtures"));
describe('SafeOperation', () => {
it('should create a SafeOperation from an UserOperation', () => {
const safeOperation = new SafeOperation_1.default(fixtures.USER_OPERATION, {
entryPoint: fixtures.ENTRYPOINTS[0]
});
expect(safeOperation.data).toMatchObject({
safe: fixtures.USER_OPERATION.sender,
nonce: BigInt(fixtures.USER_OPERATION.nonce),
initCode: fixtures.USER_OPERATION.initCode,
callData: fixtures.USER_OPERATION.callData,
callGasLimit: fixtures.USER_OPERATION.callGasLimit,
verificationGasLimit: fixtures.USER_OPERATION.verificationGasLimit,
preVerificationGas: fixtures.USER_OPERATION.preVerificationGas,
maxFeePerGas: fixtures.USER_OPERATION.maxFeePerGas,
maxPriorityFeePerGas: fixtures.USER_OPERATION.maxPriorityFeePerGas,
paymasterAndData: fixtures.USER_OPERATION.paymasterAndData,
validAfter: 0,
validUntil: 0,
entryPoint: fixtures.ENTRYPOINTS[0]
});
expect(safeOperation.signatures.size).toBe(0);
});
it('should add and retrieve signatures', () => {
const safeOperation = new SafeOperation_1.default(fixtures.USER_OPERATION, {
entryPoint: fixtures.ENTRYPOINTS[0]
});
safeOperation.addSignature(new protocol_kit_1.EthSafeSignature('0xSigner', '0xSignature'));
expect(safeOperation.signatures.size).toBe(1);
expect(safeOperation.getSignature('0xSigner')).toMatchObject({
signer: '0xSigner',
data: '0xSignature',
isContractSignature: false
});
});
it('should encode the signatures', () => {
const safeOperation = new SafeOperation_1.default(fixtures.USER_OPERATION, {
entryPoint: fixtures.ENTRYPOINTS[0]
});
safeOperation.addSignature(new protocol_kit_1.EthSafeSignature('0xSigner1', '0xSignature1'));
safeOperation.addSignature(new protocol_kit_1.EthSafeSignature('0xSigner2', '0xSignature2'));
expect(safeOperation.encodedSignatures()).toBe('0xSignature1Signature2');
});
it('should add estimations', () => {
const safeOperation = new SafeOperation_1.default(fixtures.USER_OPERATION, {
entryPoint: fixtures.ENTRYPOINTS[0]
});
safeOperation.addEstimations({
callGasLimit: BigInt(fixtures.GAS_ESTIMATION.callGasLimit),
verificationGasLimit: BigInt(fixtures.GAS_ESTIMATION.verificationGasLimit),
preVerificationGas: BigInt(fixtures.GAS_ESTIMATION.preVerificationGas)
});
expect(safeOperation.data).toMatchObject({
safe: fixtures.USER_OPERATION.sender,
nonce: BigInt(fixtures.USER_OPERATION.nonce),
initCode: fixtures.USER_OPERATION.initCode,
callData: fixtures.USER_OPERATION.callData,
callGasLimit: BigInt(fixtures.GAS_ESTIMATION.callGasLimit),
verificationGasLimit: BigInt(fixtures.GAS_ESTIMATION.verificationGasLimit),
preVerificationGas: BigInt(fixtures.GAS_ESTIMATION.preVerificationGas),
maxFeePerGas: fixtures.USER_OPERATION.maxFeePerGas,
maxPriorityFeePerGas: fixtures.USER_OPERATION.maxPriorityFeePerGas,
paymasterAndData: fixtures.USER_OPERATION.paymasterAndData,
validAfter: 0,
validUntil: 0,
entryPoint: fixtures.ENTRYPOINTS[0]
});
});
it('should convert to UserOperation', () => {
const safeOperation = new SafeOperation_1.default(fixtures.USER_OPERATION, {
entryPoint: fixtures.ENTRYPOINTS[0]
});
safeOperation.addSignature(new protocol_kit_1.EthSafeSignature('0xSigner', '0x000000000000000000000000a397ca32ee7fb5282256ee3465da0843485930b803d747516aac76e152f834051ac18fd2b3c0565590f9d65085538993c85c9bb189c940d15c15402c7c2885821b'));
expect(safeOperation.toUserOperation()).toMatchObject({
sender: safeOperation.data.safe,
nonce: ethers_1.ethers.toBeHex(fixtures.USER_OPERATION.nonce),
initCode: safeOperation.data.initCode,
callData: safeOperation.data.callData,
callGasLimit: safeOperation.data.callGasLimit,
verificationGasLimit: safeOperation.data.verificationGasLimit,
preVerificationGas: safeOperation.data.preVerificationGas,
maxFeePerGas: safeOperation.data.maxFeePerGas,
maxPriorityFeePerGas: safeOperation.data.maxPriorityFeePerGas,
paymasterAndData: safeOperation.data.paymasterAndData,
signature: ethers_1.ethers.solidityPacked(['uint48', 'uint48', 'bytes'], [
safeOperation.data.validAfter,
safeOperation.data.validUntil,
safeOperation.encodedSignatures()
])
});
});
});
//# sourceMappingURL=SafeOperation.test.js.map