Skip to content

Commit

Permalink
fix: use the deployment by chainId (#2246)
Browse files Browse the repository at this point in the history
* fix: use the deployment by `chainId`

* fix: add test
  • Loading branch information
iamacook authored Jul 20, 2023
1 parent 01135da commit 327b4cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
37 changes: 37 additions & 0 deletions src/components/settings/FallbackHandler/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ describe('FallbackHandler', () => {
})
})

it('should render the Fallback Handler without warning when one that is not a default address is set', async () => {
const OPTIMISM_FALLBACK_HANDLER = '0x69f4D1788e39c87893C980c06EdF4b7f686e2938'

// Optimism is not a "default" address
expect(OPTIMISM_FALLBACK_HANDLER).not.toBe(GOERLI_FALLBACK_HANDLER)

jest.spyOn(useSafeInfoHook, 'default').mockImplementation(
() =>
({
safe: {
version: '1.3.0',
chainId: '10',
fallbackHandler: {
value: OPTIMISM_FALLBACK_HANDLER,
name: 'FallbackHandlerName',
},
},
} as unknown as ReturnType<typeof useSafeInfoHook.default>),
)

const fbHandler = render(<FallbackHandler />)

await waitFor(() => {
expect(
fbHandler.queryByText(
'The fallback handler adds fallback logic for funtionality that may not be present in the Safe contract. Learn more about the fallback handler',
),
).toBeDefined()

expect(fbHandler.getByText(OPTIMISM_FALLBACK_HANDLER)).toBeDefined()

expect(fbHandler.getByText('FallbackHandlerName')).toBeDefined()

expect(fbHandler.queryByText('An unofficial fallback handler is currently set.')).not.toBeInTheDocument()
})
})

it('should use the official deployment name if the address is official but no known name is present', async () => {
jest.spyOn(useSafeInfoHook, 'default').mockImplementation(
() =>
Expand Down
3 changes: 2 additions & 1 deletion src/components/settings/FallbackHandler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const FallbackHandler = (): ReactElement | null => {
return null
}

const isOfficial = !!safe.fallbackHandler && safe.fallbackHandler.value === fallbackHandlerDeployment?.defaultAddress
const isOfficial =
!!safe.fallbackHandler && safe.fallbackHandler.value === fallbackHandlerDeployment?.networkAddresses[safe.chainId]

const tooltip = !safe.fallbackHandler ? (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/coreSDK/safeCoreSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const initSafeSDK = async ({
const safeL1Deployment = getSafeSingletonDeployment({ network: chainId, version: safeVersion })
const safeL2Deployment = getSafeL2SingletonDeployment({ network: chainId, version: safeVersion })

isL1SafeMasterCopy = masterCopy === safeL1Deployment?.defaultAddress
const isL2SafeMasterCopy = masterCopy === safeL2Deployment?.defaultAddress
isL1SafeMasterCopy = masterCopy === safeL1Deployment?.networkAddresses[chainId]
const isL2SafeMasterCopy = masterCopy === safeL2Deployment?.networkAddresses[chainId]

// Unknown deployment, which we do not want to support
if (!isL1SafeMasterCopy && !isL2SafeMasterCopy) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/security/modules/DelegateCallModule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DelegateCallModule implements SecurityModule<DelegateCallModuleRequ
// We need not check for nested delegate calls as we only use MultiSendCallOnly in the UI
const multiSendDeployment = getMultiSendCallOnlyDeployment({ network: chainId, version: safeVersion ?? undefined })

return multiSendDeployment?.defaultAddress !== safeTransaction.data.to
return multiSendDeployment?.networkAddresses[chainId] !== safeTransaction.data.to
}

async scanTransaction(request: DelegateCallModuleRequest): Promise<SecurityResponse<DelegateCallModuleResponse>> {
Expand Down

1 comment on commit 327b4cd

@davidaucoin7377
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/components/settings/FallbackHandler/tests/index.test.tsxsrc/components/settings/FallbackHandler/index.tsxsrc/hooks/coreSDK/src/services/security/modules/DelegateCallModule/index.ts

Please sign in to comment.