0

I have some JUnit test that assert some values returned from the blockchain deployed smart-contract. But the assert return me a error because the assertEqual call is done when the transaction has not been validated yet.

In Web3j 4.0.6 and a Quorum 2.2.3 version envyroment is ther a wey to make callbacks?

Im using the generated Web3j wrapper, the web3j quorum version is the following 4.0.6

  • 1
    can you provide more infos, are you using the smartcontract-wrappers to send the transaction? which java version? can you wait for events and then call the assertEqual() ? – Majd TL May 7 at 15:26
  • I edit the question – UnexpectedCharacter May 13 at 6:59
1

Maybe this could help you if you are stuck here, It is not the solution but you can do something like this. (worked for me with web3 "idk about Quorum")

For example if you have a transfer(..) function to send tokens in your smartcontract, then write another function balanceOf(...) to get the balance

And in your Unit-Test, send a transfer-transaction and then wait with a simple loop for about 10 second, and then call the method balanceOf(..) from your wrapper

I did something like this:

in my serviceClass i implemented a getBalance() method (same for transfer)

public int getBalanceOf(...) {
    TokenContract tokenContract = new TokenContract(<contract-address>, <web3j/quorum>, <credentials>, ....);
    return tokenContract.balanceOf(...);
}

In my Unit-Test class

@Test
void testTransferTokenContract() { 
    MyService service = new MyService();
    service.transfer(100,.....);
    ..wait about 10 seconds ..
    assertEquals(100, service.getBalanceOf(....));
}
  • Thank you for the answer. So nowadays Web3j doesn't have promise to check when a transaction is confirmed. We have to manage this manually? – UnexpectedCharacter May 13 at 9:45
  • 1
    There is a transaction manager in web3j but (for me it was not very well documented and i couldn't find a lot of examples). Java has an awesome thing called CompletableFuture<..> , and with web3j it will look something like this CompletableFuture<TransactionReceipt> ... maybe this will be usefull for you – Majd TL May 13 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.