-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent recovery with same setup
- Loading branch information
Showing
4 changed files
with
151 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/components/tx-flow/flows/RecoverAccount/__tests__/RecoverAccountFlowSetup.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { faker } from '@faker-js/faker' | ||
import { shuffle } from 'lodash' | ||
import type { AddressEx } from '@safe-global/safe-gateway-typescript-sdk' | ||
|
||
import { _isSameSetup } from '../RecoverAccountFlowSetup' | ||
|
||
describe('RecoverAccountFlowSetup', () => { | ||
describe('isSameSetup', () => { | ||
it('should return true if the owners and threshold are the same', () => { | ||
const oldOwners: Array<AddressEx> = [ | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
] | ||
const oldThreshold = faker.number.int({ min: 1, max: oldOwners.length }) | ||
|
||
const newOwners = shuffle(oldOwners) | ||
|
||
expect( | ||
_isSameSetup({ | ||
oldOwners, | ||
oldThreshold, | ||
newOwners, | ||
newThreshold: oldThreshold, | ||
}), | ||
).toBe(true) | ||
}) | ||
|
||
it('should return false if the owners are the same but the threshold is different', () => { | ||
const oldOwners: Array<AddressEx> = [ | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
] | ||
const oldThreshold = 1 | ||
|
||
const newOwners = shuffle(oldOwners) | ||
const newThreshold = 2 | ||
|
||
expect( | ||
_isSameSetup({ | ||
oldOwners, | ||
oldThreshold, | ||
newOwners, | ||
newThreshold, | ||
}), | ||
).toBe(false) | ||
}) | ||
|
||
it('should return false if the threshold is the same but the owners are different', () => { | ||
const oldOwners: Array<AddressEx> = [ | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
] | ||
const oldThreshold = 2 | ||
|
||
const newOwners = [ | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
{ value: faker.finance.ethereumAddress() }, | ||
] | ||
|
||
expect( | ||
_isSameSetup({ | ||
oldOwners, | ||
oldThreshold, | ||
newOwners, | ||
newThreshold: oldThreshold, | ||
}), | ||
).toBe(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.