-
Notifications
You must be signed in to change notification settings - Fork 83
chore: use ethers for ethereum-storage #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
282f6df
to
05815f8
Compare
2cb737f
to
8122ecc
Compare
05815f8
to
441f044
Compare
c8c8e33
to
6035e98
Compare
2a21082
to
ff6608f
Compare
const url = config.getStorageWeb3ProviderUrl(); | ||
if (url.match('^wss?://.+')) { | ||
provider = new providers.WebSocketProvider(url); | ||
// FIXME previous WS config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexandre-abrioux any idea what we should do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this:
provider = new providers.Web3Provider(
new Web3WsProvider(url, {
// previous WS config
}),
)
; or, if we want to completely remove web3js dependencies, I can take care of it in another PR, for now just remove the if (wss)
block or throw an "unsupported" error in the block, as ethers.js
does not handle auto-reconnect, cf. ethers-io/ethers.js#1053
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the point is to remove web3 completely yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use this solution then: ethers-io/ethers.js#1053 (comment) , we just need to abstract the provider in it's own module.
@@ -494,6 +495,31 @@ describe('Request client using a request node', () => { | |||
const requests = await badRequestNetwork.fromTopic(myRandomTopic); | |||
expect(requests).toHaveLength(0); | |||
}); | |||
|
|||
it('can create multiple requests in parallel', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this test because it seemed that the node wouldn't accespt multiple transactions at once.
} else { | ||
provider = new HDWalletProvider(mnemonic, config.getStorageWeb3ProviderUrl()); | ||
provider = new providers.StaticJsonRpcProvider(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a StaticJsonRpcProvider allows to reduce the number of calls (eth_chainId for instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered it with ct. I should have told you so.
LENGTH_BYTES32_STRING, | ||
const feesParametersAsBytes = utils.hexZeroPad( | ||
utils.hexlify(feesParameters.contentSize), | ||
LENGTH_BYTES32_STRING / 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of the way hexZeroPad works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR ! Well done!
} else { | ||
provider = new HDWalletProvider(mnemonic, config.getStorageWeb3ProviderUrl()); | ||
provider = new providers.StaticJsonRpcProvider(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered it with ct. I should have told you so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not easy to review but everything looks good to me, nice move !
// Keep the transaction hash for future needs | ||
let transactionHash = ''; | ||
const transactionParameters = { | ||
// This boolean is set to true once the ethereum metadata has been created and the promise has been resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
expect(events[0].returnValues.feesParameters).toEqual(realSizeBytes32Hex); | ||
expect(events[0].args.hash).toEqual(hashStr); | ||
expect(events[0].args.hashSubmitter.toLowerCase()).toEqual(addressRequestHashSubmitter); | ||
expect(events[0].args.feesParameters).toEqual(realSizeBytes32Hex); | ||
}); | ||
|
||
// TODO since the migration to jest, this test fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO since the migration to jest, this test fails. |
Good one :)
jest | ||
.spyOn(smartContractManager.ethereumBlocks.provider, 'getBlockNumber') | ||
.mockImplementation(() => Promise.resolve(9)); | ||
// TODO ? smartContractManager.ethereumBlocks = new EthereumBlocks(mockEth, 1, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reminder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
big good job 👍
I wondered if renaming eth as provider would make it more confusing later because it's more generic word but it's also the word used by etherjs so it's good for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing refacto 💯
@@ -103,34 +104,30 @@ const mockBlocksEthereum = [ | |||
9807, | |||
9906, | |||
]; | |||
const provider = new providers.JsonRpcProvider('http://localhost:8545'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Idea for later, to think about) We could do this to not depend on any external service for unit tests
(but this would reintroduce some web3 dependencies 😆)
import ganache from "ganache";
const provider = new ethers.providers.Web3Provider(ganache.provider());
Is this PR still relevant? |
Motivations
ethers
is used everywhere in the codebaseAdditionally, this allows to remove hd-wallet-provider which limits the number of dependencies to maintain