How to simulate real uniswap v2 slippage without actually send transaction? - web3js

Some erc20 tokens will burn percentage of tokens as tax on transaction. In this situation, a dry call using Web3.eth.Contract with proper minAmountOut of swapExactETHForTokens will not be reverted even token recieved will be significantly smaller than minAmountOut. But uniswap, pancake and many other dex tools can successfully simulate this behavior, and show PancakeRouter: INSUFFICIENT_OUTPUT_AMOUNT accordingly.
By the way, I'm relying on metamask for the call.

I find out there is an swapExactTokensForTokensSupportingFeeOnTransferTokens to do that.

Related

How to have a constant in feature scenarios in Behave

Is there a way to set a global variable/constant in .feature files in Behave?
For an analytical service, I have many scenarios like this one
Scenario: Some scenario
Given do some action
And wait for 90 seconds while the action results are ready
Then verifying some result
And recently the requirements has updated and the service can wait for a longer time. This requirement may be changed in future. Is there a way not to find and replace all the "wait for 90 seconds" but have some constant in a feature file that I can update in one place?
My current approach is to refactor the step into wait for a reasonable time while the action results are ready and set the constant of reasonable time in Python. But in this approach, it's not clear from the tests logs what is the reasonable time for a specific run.
Waiting a constant amount of time is bad practice
Correct scenario defininition should be:
Scenario: Some scenario
Given do some action
And wait for the action results are ready
Then verifying some result
In the step implementation of "wait for the action results are ready" an active wait must be made that will end when results are ready

Alexa: How to know where large responses are interrupted?

My skill has some intents which give out very large reponses (text). So there is a good chance the user might want to interrupt it and listen to the remaining part of the response later. I want to make the intent continue from where it left off (I guess I will have to use user state management). Is there a way for the backend to know where it was interupted? or even better, is there a way to send the response line by line so that the backend exactly knows which line was read out last?
Currently there is no way to find where the speech was interrupted nor you can send multiple responses line by line. However, you could calculate the time difference between when the response was sent and the interrupted request was received. And based on the time difference you could roughly determine where was it interrupted. Again, this is not an accurate way, it just a hack and you should keep in mind the network latency.
When you send the response, include response generated timestamp in sessionAttributes, so that you can use it to verify time difference.

pre-emptive refresh of expired JWT token

All of the solutions I've found while searching react to a 401 response from an API call before triggering logic to refresh the expired token. In my case, I'm using react-cognito which puts the expiry time in the redux store under cognito.user.signInUserSession.idToken.payload.exp (integer representing unix time).
I would like to try and implement a scheme where expiry is pre-empted and I'd like to keep this logic separated from my API call code, if practical.
One option I explored is setting a timeout for currentTime - expiryTime - someBuffer, but this may be 50 minutes long or more and I've read that long-running timeouts can often be unreliable, having strange performance especially when the browser tab is not in-focus.
Another option I considered was a saga that runs in a loop, initiated by the LOGGED_IN action and ended by the LOGGED_OUT action, that checks for an almost expired token and refreshes it. On mobile, my understanding is that code execution is paused while the browser is in the background - as such this approach would have an edge case where if the user foregrounds the browser just after token expiry then there's a window of time equal to the loop interval where API calls will 401. The loop interval can be made smaller but the edge condition could never be eliminated.
Is there some scheme that can reliably fire an event/action just before token expiry or, in the case of mobile browsers, fire immediately upon execution-resume if foregrounding happens after the desired refresh time?
Thanks!
David
There is no need for long lived timeouts, simply check each second or so if the token has expired.
while(true){
yield delay(5000);
if(yield call(checkExpiring)){
yield relogin();
}
}
There will be a lot of checks, but they don't have any real performance impact.
That said, I usually write a fetch middleware which checks if the server replies with 401/402 and than reauthenticate and resubmit with the new token.

Sending request each n seconds with libcurl in c

I am trying to figure out how to make a request in c each n seconds. I want it to be asynchronous, meaning the requests are made even if the previous ones have not been responded.
I want to achieve this in order to test a server.
Any ideas?
Thank you.
Use the multi interface. Add a new handle and start a new request every N seconds and let it take its time. It'll handle "any" amount of simultaneous transfers for you. "any" because there's probably a limit in number of open sockets a process is allowed to use (depending on the environment you want this for).

How to abandon a long-running search in System.DirectoryServices.Protocols

I've been trying to work out how to cancel a long-running AD search in System.DirectoryServices.Protocols. Can anyone help?
I've looked at the supportControl/supportedCapabilities attributes on RootDSE and they don't contain the 1.3.6.1.1.8 OID so I think that means it doesn't support the LDAP CANCEL extended operation as defined here: https://www.rfc-editor.org/rfc/rfc3909
That leaves the original LDAP ABANDON command (see here for list). But there doesn't seem to be a matching DirectoryRequest Class.
Anyone have any ideas?
I think I've found my answer: whilst I was reading around your suggestion, Martin, I came across the Abort method on the LdapConnection class. I didn't expect to find it there: starting out from the LDAP documentation I'd expected to find it as just another LDAPMessage but the MS guys seem to have treated it as a special case. If anyone is familiar with a non-MS implementation of LDAP and can comment on whether the MS approach is typical, I'd appreciate it to improve my understanding.
I think, but I'm not positive, there is no asynch query with a cancel. It has an asynch property but it's to allow a collection to be filled, nothing to do with cancelling. The best I can offer is to put your query in a background worker thread and put an asynch callback that will deal with the answer when it comes back. If the user decides to cancel, you can just cancel the background worker thread. You'll free your app up, even if you haven't freed the ldap server up until it finishes it's query. You can find info on background worker threads at http://www.c-sharpcorner.com/UploadFile/LivMic/BGWorker07032007000515AM/BGWorker.aspx
Don't forget to call .Dispose() when cleaning up your active directory objects to prevent memory leaks.
If the query will produce many data also, you can abandon them through paging. Specify a PageResultRequestControl option in the query, giving a fairly low page size (IIUC, 1000 is the default page size). IIUC, you'll send new requests every time you got a page (passing cookies from one response into the next request). When you choose to cancel the query, send another request with zero expected results.

Resources