From d133edb15ac4454bf1942f3fb0fe8ea753db178d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Mon, 9 Oct 2023 13:25:41 +0200 Subject: [PATCH] Add transaction test and remove isSmartContract detection --- .../protocol-kit/src/utils/signatures/utils.ts | 18 ++++-------------- .../protocol-kit/tests/e2e/eip1271.test.ts | 16 ++++++++++------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/protocol-kit/src/utils/signatures/utils.ts b/packages/protocol-kit/src/utils/signatures/utils.ts index 7c3082d9d..40e000a14 100644 --- a/packages/protocol-kit/src/utils/signatures/utils.ts +++ b/packages/protocol-kit/src/utils/signatures/utils.ts @@ -100,15 +100,10 @@ export async function generateSignature( throw new Error('EthAdapter must be initialized with a signer to use this method') } - const isSmartContract = await ethAdapter.isContractDeployed(signerAddress) let signature = await ethAdapter.signMessage(hash) - if (!isSmartContract) { - signature = adjustVInSignature('eth_sign', signature, hash, signerAddress) - return new EthSafeSignature(signerAddress, signature) - } - - return new EthSafeSignature(signerAddress, signature, true) + signature = adjustVInSignature('eth_sign', signature, hash, signerAddress) + return new EthSafeSignature(signerAddress, signature) } export async function generateEIP712Signature( @@ -121,15 +116,10 @@ export async function generateEIP712Signature( throw new Error('EthAdapter must be initialized with a signer to use this method') } - const isSmartContract = await ethAdapter.isContractDeployed(signerAddress) let signature = await ethAdapter.signTypedData(safeEIP712Args, methodVersion) - if (!isSmartContract) { - signature = adjustVInSignature('eth_signTypedData', signature) - return new EthSafeSignature(signerAddress, signature) - } - - return new EthSafeSignature(signerAddress, signature, true) + signature = adjustVInSignature('eth_signTypedData', signature) + return new EthSafeSignature(signerAddress, signature) } export const buildSignature = (signatures: SafeSignature[]): string => { diff --git a/packages/protocol-kit/tests/e2e/eip1271.test.ts b/packages/protocol-kit/tests/e2e/eip1271.test.ts index 4cc4ccc79..dafb48eae 100644 --- a/packages/protocol-kit/tests/e2e/eip1271.test.ts +++ b/packages/protocol-kit/tests/e2e/eip1271.test.ts @@ -11,7 +11,7 @@ import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' import { itif } from './utils/helpers' import { BigNumber, ethers } from 'ethers' -import { buildSignature } from '@safe-global/protocol-kit/utils' +import { EthSafeSignature, buildSignature } from '@safe-global/protocol-kit/utils' import { soliditySha3, utf8ToHex } from 'web3-utils' chai.use(chaiAsPromised) @@ -231,9 +231,9 @@ describe.only('EIP1271', () => { ) it.only('should allow to use a sign transactions using smart contracts', async () => { - const { safe, accounts, safeSdk1, safeSdk2 } = await setupTests() + const { safe, accounts, safeSdk1, safeSdk3, signerSafe } = await setupTests() - const [account1, account2] = accounts + const [account1] = accounts await account1.signer.sendTransaction({ to: safe.address, @@ -251,13 +251,17 @@ describe.only('EIP1271', () => { const tx = await safeSdk1.createTransaction({ safeTransactionData }) - const signature1 = await safeSdk1.signTypedData(tx) - const signature2 = await safeSdk2.signTypedData(tx) + const signature1 = await safeSdk1.signTransactionHash(await safeSdk1.getTransactionHash(tx)) + let signature2 = await safeSdk3.signTypedData(tx) + signature2 = new EthSafeSignature(signerSafe.address, signature2.data, true) tx.addSignature(signature1) tx.addSignature(signature2) - const execResponse = await safeSdk1.executeTransaction(tx) + console.log('OWNER 1: ', signature1.signer) + console.log('OWNER 2: ', signature2.signer) + + const execResponse = await safeSdk1.executeTransaction(tx, { gasLimit: 1000000 }) await waitSafeTxReceipt(execResponse)