Skip to content

Commit

Permalink
Add transaction test and remove isSmartContract detection
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Oct 9, 2023
1 parent a1918a3 commit d133edb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
18 changes: 4 additions & 14 deletions packages/protocol-kit/src/utils/signatures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 => {
Expand Down
16 changes: 10 additions & 6 deletions packages/protocol-kit/tests/e2e/eip1271.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand Down

0 comments on commit d133edb

Please sign in to comment.