Skip to content

Commit

Permalink
fix: throw custom error for empty setupData (#4255)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Sep 26, 2024
1 parent 3361831 commit 2531ac1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
44 changes: 34 additions & 10 deletions src/features/multichain/hooks/__tests__/useSafeCreationData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error for legacy counterfactual Safes', async () => {
it('should throw an error for legacy counterfactual Safes', async () => {
const safeAddress = faker.finance.ethereumAddress()
const chainInfos = [chainBuilder().with({ chainId: '1', l2: false }).build()]
const undeployedSafe = {
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if creation data cannot be found', async () => {
it('should throw an error if creation data cannot be found', async () => {
jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
response: new Response(),
data: undefined,
Expand All @@ -127,7 +127,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if Safe creation data is incomplete', async () => {
it('should throw an error if Safe creation data is incomplete', async () => {
jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
data: {
created: new Date(Date.now()).toISOString(),
Expand All @@ -151,7 +151,31 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if outdated masterCopy is being used', async () => {
it('should throw an error if Safe setupData is empty', async () => {
jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
data: {
created: new Date(Date.now()).toISOString(),
creator: faker.finance.ethereumAddress(),
factoryAddress: faker.finance.ethereumAddress(),
transactionHash: faker.string.hexadecimal({ length: 64 }),
masterCopy: faker.finance.ethereumAddress(),
setupData: '0x',
},
response: new Response(),
})

const safeAddress = faker.finance.ethereumAddress()
const chainInfos = [chainBuilder().with({ chainId: '1', l2: false }).build()]

// Run hook
const { result } = renderHook(() => useSafeCreationData(safeAddress, chainInfos))

await waitFor(() => {
expect(result.current).toEqual([undefined, new Error(SAFE_CREATION_DATA_ERRORS.NO_CREATION_DATA), false])
})
})

it('should throw an error if outdated masterCopy is being used', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down Expand Up @@ -190,7 +214,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if unknown masterCopy is being used', async () => {
it('should throw an error if unknown masterCopy is being used', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down Expand Up @@ -229,7 +253,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if the Safe creation uses reimbursement', async () => {
it('should throw an error if the Safe creation uses reimbursement', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down Expand Up @@ -264,7 +288,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if RPC could not be created', async () => {
it('should throw an error if RPC could not be created', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down Expand Up @@ -301,7 +325,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if RPC cannot find the tx hash', async () => {
it('should throw an error if RPC cannot find the tx hash', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down Expand Up @@ -398,7 +422,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if the setup data does not match', async () => {
it('should throw an error if the setup data does not match', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down Expand Up @@ -463,7 +487,7 @@ describe('useSafeCreationData', () => {
})
})

it('should throw error if the masterCopies do not match', async () => {
it('should throw an error if the masterCopies do not match', async () => {
const setupData = Safe__factory.createInterface().encodeFunctionData('setup', [
[faker.finance.ethereumAddress(), faker.finance.ethereumAddress()],
1,
Expand Down
2 changes: 1 addition & 1 deletion src/features/multichain/hooks/useSafeCreationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const getCreationDataForChain = async (
},
})

if (!creation || !creation.masterCopy || !creation.setupData) {
if (!creation || !creation.masterCopy || !creation.setupData || creation.setupData === '0x') {
throw new Error(SAFE_CREATION_DATA_ERRORS.NO_CREATION_DATA)
}

Expand Down

0 comments on commit 2531ac1

Please sign in to comment.