Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multichain] Fix: precise counterfactual safes #4191

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@ import { JsonRpcProvider } from 'ethers'
import { EMPTY_DATA, ZERO_ADDRESS } from '@safe-global/protocol-kit/dist/src/utils/constants'
import { waitFor } from '@testing-library/react'
import { type EIP1193Provider } from '@web3-onboard/core'
import { type ReplayedSafeProps } from '@/store/slices'
import { faker } from '@faker-js/faker'

const mockProps = {
owners: [],
threshold: 1,
saltNonce: 1,
const mockProps: ReplayedSafeProps = {
safeAccountConfig: {
owners: [faker.finance.ethereumAddress()],
threshold: 1,
data: EMPTY_DATA,
to: ZERO_ADDRESS,
fallbackHandler: faker.finance.ethereumAddress(),
paymentReceiver: ZERO_ADDRESS,
},
factoryAddress: faker.finance.ethereumAddress(),
masterCopy: faker.finance.ethereumAddress(),
saltNonce: '0',
safeVersion: '1.3.0',
}

describe('useEstimateSafeCreationGas', () => {
Expand All @@ -28,7 +39,7 @@ describe('useEstimateSafeCreationGas', () => {
jest
.spyOn(safeContracts, 'getReadOnlyProxyFactoryContract')
.mockResolvedValue({ getAddress: () => ZERO_ADDRESS } as unknown as SafeProxyFactoryContractImplementationType)
jest.spyOn(sender, 'encodeSafeCreationTx').mockReturnValue(Promise.resolve(EMPTY_DATA))
jest.spyOn(sender, 'encodeSafeCreationTx').mockReturnValue(EMPTY_DATA)
jest.spyOn(wallet, 'default').mockReturnValue({} as ConnectedWallet)
})

Expand Down
51 changes: 42 additions & 9 deletions src/components/new-safe/create/logic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { JsonRpcProvider } from 'ethers'
import * as contracts from '@/services/contracts/safeContracts'
import type { SafeProvider } from '@safe-global/protocol-kit'
import type { CompatibilityFallbackHandlerContractImplementationType } from '@safe-global/protocol-kit/dist/src/types'
import { ZERO_ADDRESS } from '@safe-global/protocol-kit/dist/src/utils/constants'
import { EMPTY_DATA, ZERO_ADDRESS } from '@safe-global/protocol-kit/dist/src/utils/constants'
import * as web3 from '@/hooks/wallets/web3'
import * as sdkHelpers from '@/services/tx/tx-sender/sdk'
import { SAFE_TO_L2_SETUP_INTERFACE, relaySafeCreation, getRedirect } from '@/components/new-safe/create/logic/index'
import { relaySafeCreation, getRedirect } from '@/components/new-safe/create/logic/index'
import { relayTransaction } from '@safe-global/safe-gateway-typescript-sdk'
import { toBeHex } from 'ethers'
import {
Expand All @@ -21,8 +21,8 @@ import * as gateway from '@safe-global/safe-gateway-typescript-sdk'
import { FEATURES, getLatestSafeVersion } from '@/utils/chains'
import { type FEATURES as GatewayFeatures } from '@safe-global/safe-gateway-typescript-sdk'
import { chainBuilder } from '@/tests/builders/chains'
import { getSafeL2SingletonDeployment } from '@safe-global/safe-deployments'
import { SAFE_TO_L2_SETUP_ADDRESS } from '@/config/constants'
import { type ReplayedSafeProps } from '@/store/slices'
import { faker } from '@faker-js/faker'

const provider = new JsonRpcProvider(undefined, { name: 'ethereum', chainId: 1 })

Expand Down Expand Up @@ -70,13 +70,29 @@ describe('createNewSafeViaRelayer', () => {
const safeContractAddress = await (
await getReadOnlyGnosisSafeContract(mockChainInfo, latestSafeVersion)
).getAddress()
const l2Deployment = getSafeL2SingletonDeployment({ version: latestSafeVersion, network: mockChainInfo.chainId })

const undeployedSafeProps: ReplayedSafeProps = {
safeAccountConfig: {
owners: [owner1, owner2],
threshold: 1,
data: EMPTY_DATA,
to: ZERO_ADDRESS,
fallbackHandler: await readOnlyFallbackHandlerContract.getAddress(),
paymentReceiver: ZERO_ADDRESS,
payment: 0,
paymentToken: ZERO_ADDRESS,
},
safeVersion: latestSafeVersion,
factoryAddress: proxyFactoryAddress,
masterCopy: safeContractAddress,
saltNonce: '69',
}

const expectedInitializer = Gnosis_safe__factory.createInterface().encodeFunctionData('setup', [
[owner1, owner2],
expectedThreshold,
SAFE_TO_L2_SETUP_ADDRESS,
SAFE_TO_L2_SETUP_INTERFACE.encodeFunctionData('setupToL2', [l2Deployment?.defaultAddress]),
ZERO_ADDRESS,
EMPTY_DATA,
await readOnlyFallbackHandlerContract.getAddress(),
ZERO_ADDRESS,
0,
Expand All @@ -89,7 +105,7 @@ describe('createNewSafeViaRelayer', () => {
expectedSaltNonce,
])

const taskId = await relaySafeCreation(mockChainInfo, [owner1, owner2], expectedThreshold, expectedSaltNonce)
const taskId = await relaySafeCreation(mockChainInfo, undeployedSafeProps)

expect(taskId).toEqual('0x123')
expect(relayTransaction).toHaveBeenCalledTimes(1)
Expand All @@ -104,7 +120,24 @@ describe('createNewSafeViaRelayer', () => {
const relayFailedError = new Error('Relay failed')
jest.spyOn(gateway, 'relayTransaction').mockRejectedValue(relayFailedError)

expect(relaySafeCreation(mockChainInfo, [owner1, owner2], 1, 69)).rejects.toEqual(relayFailedError)
const undeployedSafeProps: ReplayedSafeProps = {
safeAccountConfig: {
owners: [owner1, owner2],
threshold: 1,
data: EMPTY_DATA,
to: ZERO_ADDRESS,
fallbackHandler: faker.finance.ethereumAddress(),
paymentReceiver: ZERO_ADDRESS,
payment: 0,
paymentToken: ZERO_ADDRESS,
},
safeVersion: latestSafeVersion,
factoryAddress: faker.finance.ethereumAddress(),
masterCopy: faker.finance.ethereumAddress(),
saltNonce: '69',
}

expect(relaySafeCreation(mockChainInfo, undeployedSafeProps)).rejects.toEqual(relayFailedError)
})

describe('getRedirect', () => {
Expand Down
Loading
Loading