Skip to content

Commit

Permalink
Merge pull request #151 from gnosis/fix-saltnonce-negative
Browse files Browse the repository at this point in the history
Throw error if saltNonce is a negative integer
  • Loading branch information
germartinez authored Jan 20, 2022
2 parents c7e6490 + 5ea40b1 commit 8661d5c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class GnosisSafeProxyFactoryEthersContract implements GnosisSafeProxyFactoryCont
saltNonce,
options
}: CreateProxyProps): Promise<string> {
if (saltNonce < 0) {
throw new Error('saltNonce must be greater than 0')
}
const txResponse = await this.contract.createProxyWithNonce(
safeMasterCopyAddress,
initializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class GnosisSafeProxyFactoryWeb3Contract implements GnosisSafeProxyFactoryContra
saltNonce,
options
}: CreateProxyProps): Promise<string> {
if (saltNonce < 0) {
throw new Error('saltNonce must be greater than 0')
}
const txResponse = this.contract.methods
.createProxyWithNonce(safeMasterCopyAddress, initializer, saltNonce)
.send(options)
Expand Down
18 changes: 18 additions & 0 deletions packages/safe-core-sdk/tests/safeFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ describe('Safe Proxy Factory', () => {
.rejectedWith('Threshold must be lower than or equal to owners length')
})

it('should fail if the saltNonce is lower than 0', async () => {
const { accounts, contractNetworks } = await setupTests()
const [account1, account2] = accounts
const ethAdapter = await getEthAdapter(account1.signer)
const safeFactory = await SafeFactory.create({
ethAdapter,
safeVersion: safeVersionDeployed,
contractNetworks
})
const owners = [account1.address, account2.address]
const threshold = 2
const safeAccountConfig: SafeAccountConfig = { owners, threshold }
const safeDeploymentConfig: SafeDeploymentConfig = { saltNonce: -1 }
chai
.expect(safeFactory.deploySafe(safeAccountConfig, safeDeploymentConfig))
.rejectedWith('saltNonce must be greater than 0')
})

it('should deploy a new Safe without saltNonce', async () => {
const { accounts, contractNetworks } = await setupTests()
const [account1, account2] = accounts
Expand Down

0 comments on commit 8661d5c

Please sign in to comment.