RestAssured -> Error handling on QueryParameters - java

// I am using RestAssured with Java.
// I want to validate if my No 1 service fails and can't get the account number how can i use my hard //coded account number from no 2. Can someone help me on what error condition or strategy i can use?
// Basically if No 1 fails then user No 2.
// No 1 Getting the account number from other class by calling another api
acct= otherclass.getaccountNumber();
queryParamerters.put("accountnumber",acct);
// No 2 Hard coded account number
queryParamerters.put("accountnumber","123456");

create a flag, set it to 0 if No1 doesnt fails, if flag is 0, then use No2

Related

Why am I getting "Error processing transaction request: intrinsic gas too low" error when trying to add tUSDT to a particular account?

I am trying to send test USDT to a particular account in Java using the following code:
final Web3j web3 = createWeb3If(ethNetworkUrl);
final Credentials credentials = Credentials.create(privateKey);
final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
The last statement results in the following exception:
java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
TestGasProvider is defined as:
public class TestGasProvider extends StaticGasProvider {
public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
public TestGasProvider() {
super(GAS_PRICE, GAS_LIMIT);
}
}
usdtContract was deployed using this script, which calls deploy.js:
async function main() {
const USDT = await ethers.getContractFactory("USDT");
const usdt = await USDT.deploy(1000000000000000);
console.log("USDT contract deployed to:", usdt.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
This contract is running on a local testnet set up as described here.
What do I need to change in any of these components (testnet, contract, deploy scripts, Java code) in order to send any amount of USDT to a particular address (without any errors)?
Update 1: If I change TestGasProvider to
public class TestGasProvider extends StaticGasProvider {
public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
public TestGasProvider() {
super(GAS_PRICE, GAS_LIMIT);
}
}
I get another error:
java.lang.RuntimeException: Error processing transaction request: exceeds block gas limit
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
Update 1
I am looking to submit a set of code changes to the branch i16 of the minimal-crypto-exchange project which passes the following test:
Step 1
Set up the environment as described here.
Step 2
Set a breakpoint on line usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); in TransferUsdtToExchangeAccount class:
Step 3
Start the process engine application in debug mode. Its Java main method is located here.
Wait until you see the message starting to acquire jobs in the console output:
11:59:16.031 [JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor]] INFO org.camunda.bpm.engine.jobexecutor - ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs
Step 4
Login with the credentials demo/demo at http://localhost:8080.
After login you should see a page like this:
Step 5
Click on the tasklist link. You should see a page that looks like this:
Press the "Start process" link. Following screen will appear:
Click on Send USDT to the exchange account process link. Following dialog box will appear:
Enter an arbitrary value into the "business key" field and press the "Start" button.
Step 6
After a couple of seconds, the breakpoint from step 2 will activate.
The problem will be solved if usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send() is executed without errors.
Notes
You are allowed to modify the amount in usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); from 10 to something else.
You can also modify the parameters of the Ethereum testnet specified in docker-compose.yml and genesis.json, as well as those of the USDT smart contract which is deployed using this script.
Your solution must work in this controlled environment (i. e. no faucets must be used).
Update 2
I made following changes:
The set-up tutorial now contains step 7 in which ETH is added to the exchange account.
Now a new version of the ETH testnet is being used, major changes being that log output is more verbose and the gas price is set to 1 (see --miner.gasprice 1 in entrypoint.sh).
Modified the code in TransferUsdtToExchangeAccount so that now USDT is transferred not from the exchange account (which has zero balance), but from the buffer account.
Now I am receiving the error
org.web3j.protocol.exceptions.TransactionException: Transaction 0x4bce379a2673c4564b2eb6080607b00d1a8ac232fbddf903f353f4eeda566cae
has failed with status: 0x0. Gas used: 32767.
Revert reason: 'ERC20: transfer amount exceeds allowance'.
My skills with Ethereum are still not sharp enough to give you a proper answer, but I hope you get some guidance.
The error states that you are trying to transfer by a party A certain quantity in the name of another party B, to a third one C, but the amount you are trying to transfer, using transferFrom, is greater than the one party B approved party A to send.
You can check the actual allowance between to parties using the method with the same name of your contract.
Please, consider review this integration test from the web3j library in Github. It is different than yours but I think it could be helpful.
Especially, it states that the actual transferFrom operation should be performed by the beneficiary of the allowance. Please, see the relevant code:
final String aliceAddress = ALICE.getAddress();
final String bobAddress = BOB.getAddress();
ContractGasProvider contractGasProvider = new DefaultGasProvider();
HumanStandardToken contract =
HumanStandardToken.deploy(
web3j,
ALICE,
contractGasProvider,
aliceQty,
"web3j tokens",
BigInteger.valueOf(18),
"w3j$")
.send();
//...
// set an allowance
assertEquals(contract.allowance(aliceAddress, bobAddress).send(), (BigInteger.ZERO));
transferQuantity = BigInteger.valueOf(50);
TransactionReceipt approveReceipt =
contract.approve(BOB.getAddress(), transferQuantity).send();
HumanStandardToken.ApprovalEventResponse approvalEventValues =
contract.getApprovalEvents(approveReceipt).get(0);
assertEquals(approvalEventValues._owner, (aliceAddress));
assertEquals(approvalEventValues._spender, (bobAddress));
assertEquals(approvalEventValues._value, (transferQuantity));
assertEquals(contract.allowance(aliceAddress, bobAddress).send(), (transferQuantity));
// perform a transfer as Bob
transferQuantity = BigInteger.valueOf(25);
// Bob requires his own contract instance
HumanStandardToken bobsContract =
HumanStandardToken.load(
contract.getContractAddress(), web3j, BOB, STATIC_GAS_PROVIDER);
TransactionReceipt bobTransferReceipt =
bobsContract.transferFrom(aliceAddress, bobAddress, transferQuantity).send();
HumanStandardToken.TransferEventResponse bobTransferEventValues =
contract.getTransferEvents(bobTransferReceipt).get(0);
assertEquals(bobTransferEventValues._from, (aliceAddress));
assertEquals(bobTransferEventValues._to, (bobAddress));
assertEquals(bobTransferEventValues._value, (transferQuantity));
//...
This fact is also indicated in this OpenZeppelin forum post.

Using SmartyStreets and nothing is working

I am using the SmartyStreets API to verify valid street addresses in New York City.
I downloaded their example code file and I tried running it with a variety of different values. I tried my address, the address of Apples HQ, and even the stock address they had preloaded and nothing is working. This is the Example class and it is the shortest template of them all.
public class Example {
public static void main(String[] args) throws IOException, SmartyException {
// This keypair will have been deleted by the time you are watching this video...
String authId = "d418a4cc-69da-e48f-bc9d-ee7357b30d61";
String authToken = "clDiwTlcW5YTFjEl5mp1";
System.out.println("Step 0. Wire up the client with your keypair.");
Client client = new ClientBuilder(authId, authToken).buildUsStreetApiClient();
System.out.println("Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)");
Lookup lookup = new Lookup();
lookup.setStreet("1 Rosedale");
lookup.setLastline("Baltimore MD");
lookup.setMaxCandidates(10);
System.out.println("Step 2. Send the lookup.");
client.send(lookup);
System.out.println("Step 3. Show the resulting candidate addresses:");
int index = 0;
for (Candidate candidate : lookup.getResult()) {
System.out.printf("- %d: %s, %s\n", index, candidate.getDeliveryLine1(), candidate.getLastLine());
index++;
}
}
The message I am supposed to get after running this main method is:
Step 0. Wire up the client with your keypair.
Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)
Step 2. Send the lookup.
Step 3. Show the resulting candidate addresses:
- 0: 1 N Rosedale St, Baltimore MD 21229-3737
- 1: 1 S Rosedale St, Baltimore MD 21229-3739
But instead I am getting this and an error code:
Step 0. Wire up the client with your keypair.
Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)
Step 2. Send the lookup.
Exception in thread "main" com.smartystreets.api.exceptions.BadCredentialsException: Unauthorized: The credentials were provided incorrectly or did not match any existing, active credentials.
at com.smartystreets.api.StatusCodeSender.send(StatusCodeSender.java:21)
at com.smartystreets.api.SigningSender.send(SigningSender.java:18)
at com.smartystreets.api.URLPrefixSender.send(URLPrefixSender.java:19)
at com.smartystreets.api.RetrySender.trySend(RetrySender.java:34)
at com.smartystreets.api.RetrySender.send(RetrySender.java:23)
at com.smartystreets.api.us_street.Client.send(Client.java:48)
at com.smartystreets.api.us_street.Client.send(Client.java:27)
at examples.Example.main(Example.java:25)
Process finished with exit code 1
SOLUTION:
I received the following solution for my problem privately with whom I assume is a developer for the program.
Go to the following link
https://account.smartystreets.com/#keys
Login and scroll to the bottom of the page where it says auto-generated.
You must take the auth-id and auth-token values from here and use them to replace the dummy values in the Example class.
At this point you are able to test out whatever addresses you want in USA.
For rulings on what combinations and parts of addresses are required check this link:
https://smartystreets.com/docs/cloud/us-street-api#root

Metrics logging in Springboot to Signalfx using management.metrics.export.signalfx

I am calling a third party API using the
org.springframework.web.client.RestTemplate
in my application.yml file
management.metrics.export.signalfx.enabled:true
we have 2 type of api call
/api/users/update
/api/users/byUserId/123
in the signalFX the first one is showing the count of call correctly but for the second one as the URI has the last 3 digit which changes based on the ID i count is not proper what we want is that irrespective of the ID the count should show the the number of time the second URI is called. we want some metrics customisation that we can apply.
The change that we did for this is that instead of call the restTemplate method with the URI having the ID we actually used
restTemplate.delete("/api/users/byUserId/{id}", Collections.singletonMap("id", id));
using this we were able to group the metrics with the URI /api/users/byUserId/{id}.

Twilio - Page number out of range Exception

I have an application that interacts with Twilio. My Twilio account has 2000+ numbers and my app tries to retrieve them all. This is required and there is no way around this.
I use the following snippet of code to iterate across all numbers,
try {
// Initiate Twilio RESTful session
TwilioRestClient client = new TwilioRestClient(/* sid */, /* token */);
IncomingPhoneNumberList numbers = client.getAccount().getIncomingPhoneNumbers();
LogMsg.info("Attempting to retrieve phone numbers", "Phone Numbers");
// Loop over numbers and print out a property for each one.
for (IncomingPhoneNumber number : numbers) {
// Twilio Phone number
String twilioNumber = number.getPhoneNumber();
/*
* ...
*/
}
}
I keep getting,
java.lang.RuntimeException: com.twilio.sdk.TwilioRestException: Page number out of range
From what I see, I'm usually at the 1400th number when this happens. Since I'm not doing anything specific with pages, I don't understand why I'm getting this error. Is there anything I can do to be able to iterate across all my numbers?
Thanks
This turned out to be something wrong on Twilio's end. I have not since received that error.

JMeter go back to previous sampler

I am quite new to jmeter, I am using it to load test an application. My current setup is good if running few threads at a time but gets problems when more users get connected.
Here's the scenario,
sample_1: request table data
sample_2: set table row with empty user column as used by current user
|
'-->post_process_beanshell: check if have error message
sample_3: do other stuff
Currently I am able to check if the 2nd sample has an error message, the question is how do I tell beanshell to go back to 1st sample when the 2nd sample has an error message?
I would recommend put your "sample_3" under If Controller like:
Loop Controller (define maximum number of n-tries)
sample_1
sample_2
post_process_beanshell
If Controller: condition ${JMeterThread.last_sample_ok}
sample_3
JMeterThread.last_sample_ok - is a pre-defined variable which returns "true" if previous sampler was successful and "false" if not so if your "sample_2" will fail - "sample_3" won't be executed and the whole sequence will start over
Assuming you want to keep going back to sampler1 until sampler2 beanshell returns true, use a While controller.
Stick both sampler1 and sampler2 in a while controller which is conditional on the result of your error check.

Categories

Resources