Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Fix e2e (#2379)
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin authored Feb 3, 2022
1 parent e7feb5d commit d1119ca
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const TEST_ADDRESS_NEVER_USE_SHORTENED = `${TEST_ADDRESS_NEVER_USE.substr
6
)}...${TEST_ADDRESS_NEVER_USE.substr(-4, 4)}`

// Redefined bridge to fix a supper annoying issue making some contract calls to fail
// See https://github.com/ethers-io/ethers.js/issues/1683
class CustomizedBridge extends Eip1193Bridge {
chainId = 4

Expand All @@ -41,6 +43,7 @@ class CustomizedBridge extends Eip1193Bridge {
method = args[0]
params = args[1]
}
// Mock out request accounts and chainId
if (method === 'eth_requestAccounts' || method === 'eth_accounts') {
if (isCallbackForm) {
callback({ result: [TEST_ADDRESS_NEVER_USE] })
Expand All @@ -56,14 +59,41 @@ class CustomizedBridge extends Eip1193Bridge {
}
}
try {
const result = await super.send(method, params)
// If from is present on eth_call it errors, removing it makes the library set
// from as the connected wallet which works fine
if (params && params.length && params[0].from && method === 'eth_call') delete params[0].from
let result
// For sending a transaction if we call send it will error
// as it wants gasLimit in sendTransaction but hexlify sets the property gas
// to gasLimit which makes sensd transaction error.
// This have taken the code from the super method for sendTransaction and altered
// it slightly to make it work with the gas limit issues.
if (params && params.length && params[0].from && method === 'eth_sendTransaction') {
// Hexlify will not take gas, must be gasLimit, set this property to be gasLimit
params[0].gasLimit = params[0].gas
delete params[0].gas
// If from is present on eth_sendTransaction it errors, removing it makes the library set
// from as the connected wallet which works fine
delete params[0].from
const req = ethers.providers.JsonRpcProvider.hexlifyTransaction(params[0])
// Hexlify sets the gasLimit property to be gas again and send transaction requires gasLimit
req.gasLimit = req.gas
delete req.gas
// Send the transaction
const tx = await this.signer.sendTransaction(req)
result = tx.hash
} else {
// All other transactions the base class works for
result = await super.send(method, params)
}
console.debug('result received', method, params, result)
if (isCallbackForm) {
callback(null, { result })
} else {
return result
}
} catch (error) {
console.log(error)
if (isCallbackForm) {
callback(error, null)
} else {
Expand Down

0 comments on commit d1119ca

Please sign in to comment.