Skip to content

Commit e7cb3d2

Browse files
authored
Merge pull request #21 from gnosis/fix-gas-limit
Remove default gas limit equal to block limit when using Web3
2 parents 042c126 + 13e8418 commit e7cb3d2

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,8 @@ const CPK = class CPK {
319319
let encodeMultiSendCalldata;
320320

321321
if (this.apiType === 'web3') {
322-
const blockGasLimit = (await this.web3.eth.getBlock(this.web3.eth.defaultBlock)).gasLimit;
323322
const sendOptions = {
324323
from: ownerAccount,
325-
gas: blockGasLimit,
326324
...(options || {}),
327325
};
328326
const promiEventToPromise = (promiEvent) => new Promise(

test/contract-proxy-kit.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const MultiSend = artifacts.require('MultiSend');
2020
const DefaultCallbackHandler = artifacts.require('DefaultCallbackHandler');
2121
const ProxyFactory = artifacts.require('ProxyFactory');
2222
const zeroAddress = `0x${'0'.repeat(40)}`;
23+
// TODO: remove requirement to put this parameter in the test cases:
24+
// should estimate gas when gas is not provided to CPK
25+
const defaultGasLimit = '0x100000';
2326

2427
const toConfirmationPromise = (promiEvent) => new Promise(
2528
(resolve, reject) => promiEvent.on('confirmation',
@@ -98,7 +101,7 @@ function shouldSupportDifferentTransactions({
98101
to: multiStep.address,
99102
value: 0,
100103
data: multiStep.contract.methods.doStep(1).encodeABI(),
101-
}]);
104+
}], { gasLimit: defaultGasLimit });
102105
(await multiStep.lastStepFinished(cpk.address)).toNumber().should.equal(1);
103106
});
104107

@@ -117,7 +120,7 @@ function shouldSupportDifferentTransactions({
117120
value: 0,
118121
data: multiStep.contract.methods.doStep(2).encodeABI(),
119122
},
120-
]);
123+
], { gasLimit: defaultGasLimit });
121124
(await multiStep.lastStepFinished(cpk.address)).toNumber().should.equal(2);
122125
});
123126

@@ -149,7 +152,7 @@ function shouldSupportDifferentTransactions({
149152
value: 0,
150153
data: multiStep.contract.methods.doERC20Step(2, erc20.address).encodeABI(),
151154
},
152-
]);
155+
], { gasLimit: defaultGasLimit });
153156

154157
(await multiStep.lastStepFinished(cpk.address)).toNumber().should.equal(2);
155158

@@ -201,7 +204,7 @@ function shouldSupportDifferentTransactions({
201204
`${1e18}`,
202205
).encodeABI(),
203206
},
204-
]);
207+
], { gasLimit: defaultGasLimit });
205208

206209
if (cpk.address === proxyOwner) {
207210
fromWei(await erc20.balanceOf(cpk.address)).should.equal(99);
@@ -222,7 +225,7 @@ function shouldSupportDifferentTransactions({
222225
to: multiStep.address,
223226
value: 0,
224227
data: multiStep.contract.methods.doStep(2).encodeABI(),
225-
}]).should.be.rejectedWith(/must do the next step/);
228+
}], { gasLimit: defaultGasLimit }).should.be.rejectedWith(/must do the next step/);
226229

227230
(await multiStep.lastStepFinished(cpk.address)).toNumber().should.equal(0);
228231
await getTransactionCount(ownerAccount)
@@ -248,7 +251,7 @@ function shouldSupportDifferentTransactions({
248251
value: 0,
249252
data: multiStep.contract.methods.doStep(3).encodeABI(),
250253
},
251-
]).should.be.rejectedWith(/(proxy creation and )?transaction execution expected to fail/);
254+
], { gasLimit: defaultGasLimit }).should.be.rejectedWith(/(proxy creation and )?transaction execution expected to fail/);
252255

253256
(await multiStep.lastStepFinished(cpk.address)).toNumber().should.equal(0);
254257
await getTransactionCount(ownerAccount)
@@ -261,7 +264,7 @@ function shouldSupportDifferentTransactions({
261264
to: multiStep.address,
262265
value: 0,
263266
data: multiStep.contract.methods.doStep(1).encodeABI(),
264-
}]));
267+
}], { gasLimit: defaultGasLimit }));
265268
});
266269

267270
it('can execute a single transaction with a specific gas price', async () => {
@@ -278,7 +281,7 @@ function shouldSupportDifferentTransactions({
278281
value: 0,
279282
data: multiStep.contract.methods.doStep(1).encodeABI(),
280283
}],
281-
{ gasPrice },
284+
{ gasPrice, gasLimit: defaultGasLimit },
282285
);
283286
const gasUsed = await getGasUsed(txObj);
284287

@@ -311,7 +314,7 @@ function shouldSupportDifferentTransactions({
311314
data: multiStep.contract.methods.doStep(2).encodeABI(),
312315
},
313316
],
314-
{ gasPrice },
317+
{ gasPrice, gasLimit: defaultGasLimit },
315318
);
316319
const gasUsed = await getGasUsed(txObj);
317320

@@ -386,7 +389,7 @@ function shouldWorkWithWeb3(Web3, defaultAccount, safeOwner, gnosisSafeProviderB
386389
to: idPrecompile,
387390
value: 0,
388391
data: '0x',
389-
}]);
392+
}], { gasLimit: defaultGasLimit });
390393
});
391394

392395
shouldSupportDifferentTransactions({
@@ -515,7 +518,7 @@ function shouldWorkWithEthers(ethers, defaultAccount, safeOwner, gnosisSafeProvi
515518
to: idPrecompile,
516519
value: 0,
517520
data: '0x',
518-
}]);
521+
}], { gasLimit: defaultGasLimit });
519522
});
520523

521524
shouldSupportDifferentTransactions({

0 commit comments

Comments
 (0)