forked from hyperledger-web3j/web3j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Added FastRawTransactionManager and associated integration test.
2. Cleaned up imports.
- Loading branch information
Showing
1,133 changed files
with
1,688 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/integration-test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.web3j.protocol.scenarios; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.concurrent.Future; | ||
|
||
import org.junit.Test; | ||
|
||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
import org.web3j.tx.FastRawTransactionManager; | ||
import org.web3j.tx.Transfer; | ||
import org.web3j.utils.Convert; | ||
|
||
import static junit.framework.TestCase.assertFalse; | ||
import static junit.framework.TestCase.assertTrue; | ||
|
||
public class FastRawTransactionManagerIT extends Scenario { | ||
|
||
private static final int COUNT = 1; // don't set too high if using a real Ethereum network | ||
|
||
@Test | ||
public void testTransaction() throws Exception { | ||
|
||
List<Future<TransactionReceipt>> transactionReceipts = new LinkedList<>(); | ||
|
||
FastRawTransactionManager transactionManager = new FastRawTransactionManager( | ||
parity, ALICE); | ||
|
||
// We need to explicitly reset the nonce here, due to a race condition is taking place in | ||
// this test, where we experience deadlock in the entry point of the | ||
// RawTransactionManager.getNonce() method called within the | ||
// FastRawTransactionManager.getNonce() method. Using a sync call to getNonce() instead | ||
// of async as is currently the case also stops the issue from occurring. | ||
// | ||
// Bizarrely this issue does not occur when the gas price is not set on the transaction, | ||
// and getGasPrice() is called on prior to sending each transaction. i.e. instead we use: | ||
// | ||
// Future<TransactionReceipt> transactionReceiptFuture = transfer.sendFundsAsync( | ||
// BOB.getAddress(), BigDecimal.valueOf(0.1), Convert.Unit.ETHER); | ||
// | ||
// One fix would be to migrate to synchronous calls throughout the | ||
// ManagedTransaction parent and child classes. | ||
transactionManager.resetNonce(); | ||
|
||
Transfer transfer = new Transfer(parity, transactionManager); | ||
|
||
BigInteger gasPrice = transfer.getGasPrice(); | ||
|
||
for (int i = 0; i < COUNT; i++) { | ||
|
||
Future<TransactionReceipt> transactionReceiptFuture = transfer.sendFundsAsync( | ||
BOB.getAddress(), BigDecimal.valueOf(1.0), Convert.Unit.ETHER, | ||
gasPrice, Transfer.GAS_LIMIT); | ||
transactionReceipts.add(transactionReceiptFuture); | ||
} | ||
|
||
for (int i = 0; i < transfer.getAttempts() && !transactionReceipts.isEmpty(); i++) { | ||
Thread.sleep(transfer.getSleepDuration()); | ||
|
||
for (Iterator<Future<TransactionReceipt>> iterator = transactionReceipts.iterator(); iterator.hasNext(); ) { | ||
Future<TransactionReceipt> transactionReceiptFuture = iterator.next(); | ||
|
||
if (transactionReceiptFuture.isDone()) { | ||
TransactionReceipt transactionReceipt = transactionReceiptFuture.get(); | ||
System.out.println(transactionReceipt.getBlockHash()); | ||
assertFalse(transactionReceipt.getBlockHash().isEmpty()); | ||
iterator.remove(); | ||
} | ||
} | ||
} | ||
|
||
assertTrue(transactionReceipts.isEmpty()); | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
src/integration-test/java/org/web3j/protocol/scenarios/FunctionWrappersIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.