From 5ea40b150feee9fca75ac2ecd80f5b320d2aa2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Thu, 20 Jan 2022 03:47:39 +0100 Subject: [PATCH] Throw error if saltNonce is a negative number --- .../GnosisSafeProxyFactoryEthersContract.ts | 3 +++ .../GnosisSafeProxyFactoryWeb3Contract.ts | 3 +++ .../safe-core-sdk/tests/safeFactory.test.ts | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryEthersContract.ts b/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryEthersContract.ts index 58ebce738..3b5fb77be 100644 --- a/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryEthersContract.ts +++ b/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryEthersContract.ts @@ -16,6 +16,9 @@ class GnosisSafeProxyFactoryEthersContract implements GnosisSafeProxyFactoryCont saltNonce, options }: CreateProxyProps): Promise { + if (saltNonce < 0) { + throw new Error('saltNonce must be greater than 0') + } const txResponse = await this.contract.createProxyWithNonce( safeMasterCopyAddress, initializer, diff --git a/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryWeb3Contract.ts b/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryWeb3Contract.ts index cd9664f9d..11c30edf6 100644 --- a/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryWeb3Contract.ts +++ b/packages/safe-core-sdk/src/contracts/GnosisSafeProxyFactory/GnosisSafeProxyFactoryWeb3Contract.ts @@ -16,6 +16,9 @@ class GnosisSafeProxyFactoryWeb3Contract implements GnosisSafeProxyFactoryContra saltNonce, options }: CreateProxyProps): Promise { + if (saltNonce < 0) { + throw new Error('saltNonce must be greater than 0') + } const txResponse = this.contract.methods .createProxyWithNonce(safeMasterCopyAddress, initializer, saltNonce) .send(options) diff --git a/packages/safe-core-sdk/tests/safeFactory.test.ts b/packages/safe-core-sdk/tests/safeFactory.test.ts index f84b2249c..3505a06c4 100644 --- a/packages/safe-core-sdk/tests/safeFactory.test.ts +++ b/packages/safe-core-sdk/tests/safeFactory.test.ts @@ -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