Is there a way to stub out block.timestamp in a Solidity unit test. Current using hardhat for unit tests

Dec 10, 2021, 5:18 PM
Need to simulate time passing in my contract for unit testing purposes
Dec 10, 2021, 5:18 PM
Import openzeppelin test helper
It have evm simulation like mine block, increase timestamp...
Dec 10, 2021, 5:26 PM
I thought it was only for web3
Dec 10, 2021, 5:26 PM
Ooh he said hardhat.
Dec 10, 2021, 5:27 PM
Yes, it's hardhat
Dec 10, 2021, 5:27 PM
Wait so test helper doesn't work on ethers?
Dec 10, 2021, 5:27 PM
I don't know
I'm gonna look into it now, thanks, @grimreaper619 !!
Dec 10, 2021, 5:28 PM
Yeah it works with web3 only. The npm docs says install hardhat web3
https://www.npmjs.com/package/@openzeppelin/test-helpers
Dec 10, 2021, 5:31 PM
is it good practice to use web3 and ethers at the same time ?
Dec 10, 2021, 5:32 PM
No idea tbh. Been using only web3 or ethers, not both at same time
Dec 10, 2021, 5:33 PM
I find ethers more intuitive and more powerful. I'll have to use both, then :(
Dec 10, 2021, 5:35 PM
Found this https://ethereum.stackexchange.com/questions/86633/time-dependent-tests-with-hardhat/92906#92906
Dec 10, 2021, 5:36 PM
web3 deprecated for Metamask. On frontend you need to use ethers or another lib.
I faced with this problem a week ago. And now I need to migrate my code to Ethers
Dec 10, 2021, 5:37 PM
I'm writing tests, I'm not doing frontend in this project
Dec 10, 2021, 5:37 PM
This is what test helper also is doing, just being a wrapper for these functions
Dec 10, 2021, 5:38 PM
But I don't know how to read a param of an emitted event
Dec 10, 2021, 5:39 PM
Okay. But as I understood web3 does not maintained now.
It will be more correctly to start from ethers.
I also have web3 on server side and Ethers on client
Dec 10, 2021, 5:39 PM
In a js "getPastEvent "
Dec 10, 2021, 5:40 PM
Where is that property, @davidjohn_crypto_dev ?
Dec 10, 2021, 5:40 PM
It will get the last event of our contract
When we execute the contract function then it will get tha
Or you will get the transaction hash logs event
Dec 10, 2021, 5:43 PM
But the code is emitting an event explicitly
Is it part of ethers ?
Dec 10, 2021, 5:44 PM
Yes
Dec 10, 2021, 5:44 PM
Okay, I'm gonna search in the docs, many thanks, @davidjohn_crypto_dev !!
Dec 10, 2021, 5:45 PM
It's ok
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#getpastevents
Dec 10, 2021, 5:49 PM
That's not ethers :(
Dec 10, 2021, 5:50 PM
Dm
Ohh yeah
Dec 10, 2021, 5:50 PM
They are both just libraries so I imagine you can use them both concurrently. Haven’t considered doing that myself before but now that I’m thinking abiht it seems useful
Why not just use test apis to trigger fake mined blocks?
Well it’s not for trading
It’s for data querying, results aren’t real time from what I understand. But I don’t know the details so it might be a useful trading tool?
Dec 10, 2021, 8:24 PM
Yes for watching the pending txns and also submitting txs, that should be a lot faster than using 3rd party services for that no
I run a bot from my local computer that use 3rd party services to buy new listings, my txn lands in the same block but im usually the 4-5th
Dec 10, 2021, 8:27 PM
Yeah. Send amounts below 0.01 bnb and see if that remains
My case, they didn't care and I was able to get my staked cake out
Dec 10, 2021, 9:52 PM
First thought - if you are using 3rd parry service you will never be first. They (people running the service) will always be first. Second thought - if you want to monitor mempool I don’t think you can use the subgraph stuff, don’t think it’s for real time monitoring.
Any competent dev should never need someone else’s private key or seed phrase
Hey, welcome!
Dec 11, 2021, 12:59 AM
ah so web3 completely doesnt work with emtamask anymore
found different infos but cant seem to get it going
May 28, 2022, 5:58 PM
O.o?
Just use ethers.js and you're good to go
May 28, 2022, 5:59 PM
damn ok
yea omg i wasted so much time with web3 wtf
May 28, 2022, 11:53 PM
all training :P
May 28, 2022, 11:54 PM
in their documentation it says its still possible and on metamask website they describe this so bad but whatever
yea
May 28, 2022, 11:54 PM
Both are pretty poorly documented. At least ethers' documentation isn't actively wrong, and ethers doesn't need an RPC connection for things that can be done without one, whereas web3 requires one in some cases
May 29, 2022, 7:03 AM

© 2024 Draquery.com All rights reserved.