Skip to content
Snippets Groups Projects
Commit 2d091226 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Add unit test for multi dest transfer

parent c12571e6
No related branches found
No related tags found
No related merge requests found
Pipeline #15530 failed
......@@ -67,6 +67,7 @@ public class TransactionRemoteServiceImpl extends BaseRemoteServiceImpl implemen
private CryptoService cryptoService;
private BlockchainRemoteService blockchainService;
public TransactionRemoteServiceImpl() {
super();
......@@ -76,6 +77,7 @@ public class TransactionRemoteServiceImpl extends BaseRemoteServiceImpl implemen
public void afterPropertiesSet() {
super.afterPropertiesSet();
cryptoService = ServiceLocator.instance().getCryptoService();
blockchainService = ServiceLocator.instance().getBlockchainRemoteService();
}
......@@ -106,14 +108,15 @@ public class TransactionRemoteServiceImpl extends BaseRemoteServiceImpl implemen
Preconditions.checkArgument(peer != null || wallet.getCurrency() != null);
peer = peer != null ? peer : peerService.getActivePeerByCurrency(wallet.getCurrency());
// Get current block
BlockchainBlock currentBlock = httpService.executeRequest(peer, BlockchainRemoteServiceImpl.URL_BLOCK_CURRENT, BlockchainBlock.class);
BlockchainBlock currentBlock = blockchainService.getCurrentBlock(peer, true);
// http post /tx/process
HttpPost httpPost = new HttpPost(httpService.getPath(peer, URL_TX_PROCESS));
// compute transaction
String transaction = getSignedTransaction(peer, wallet, currentBlock,mapPubkeyAmount , 0,
String transaction = getSignedTransaction(peer, wallet, currentBlock, mapPubkeyAmount , 0,
comment);
if (log.isDebugEnabled()) {
......
......@@ -28,6 +28,8 @@ import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.duniter.core.client.TestResource;
import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.model.bma.BlockchainBlock;
import org.duniter.core.client.model.bma.BlockchainBlocks;
import org.duniter.core.client.model.bma.TxSource;
import org.duniter.core.client.model.local.Peer;
import org.duniter.core.client.model.local.Wallet;
......@@ -48,6 +50,8 @@ public class TransactionRemoteServiceTest {
public static final TestResource resource = TestResource.create();
private TransactionRemoteService service;
private int unitbase;
@Before
public void setUp() {
......@@ -57,6 +61,12 @@ public class TransactionRemoteServiceTest {
Assume.assumeTrue(
"Invalid currencies in test fixtures",
Objects.equals(resource.getFixtures().getDefaultCurrency(), resource.getFixtures().getCurrency()));
// Get the current unit base
BlockchainBlock currentBlock = ServiceLocator.instance().getBlockchainRemoteService()
.getCurrentBlock(resource.getFixtures().getDefaultCurrency());
Assume.assumeNotNull(currentBlock);
this.unitbase = currentBlock.getUnitbase();
}
@Test
......@@ -64,12 +74,12 @@ public class TransactionRemoteServiceTest {
try {
service.transfer(
createTestWallet(),
resource.getFixtures().getOtherUserPublicKey(0),
1,
"my comments" + System.currentTimeMillis());
createTestWallet(),
resource.getFixtures().getOtherUserPublicKey(0),
BlockchainBlocks.powBase(1, unitbase),
"Unit test Duniter4j at " + System.currentTimeMillis());
} catch (InsufficientCreditException e) {
// OK continue
Assume.assumeNoException(String.format("No credit on the test wallet '%s'", resource.getFixtures().getUserPublicKey().substring(0,8)), e);
}
}
......@@ -77,17 +87,17 @@ public class TransactionRemoteServiceTest {
public void transferMulti() throws Exception {
Map<String, Long> destPubkeyAmount = ImmutableMap.<String, Long>builder()
.put(resource.getFixtures().getOtherUserPublicKey(0), 1l)
.put(resource.getFixtures().getOtherUserPublicKey(1), 2l)
.put(resource.getFixtures().getOtherUserPublicKey(0), BlockchainBlocks.powBase(1, unitbase))
.put(resource.getFixtures().getOtherUserPublicKey(1), BlockchainBlocks.powBase(2, unitbase))
.build();
try {
service.transfer(
createTestWallet(),
destPubkeyAmount,
"my comments" + System.currentTimeMillis());
"Unit test Duniter4j at " + System.currentTimeMillis());
} catch (InsufficientCreditException e) {
// OK continue
Assume.assumeNoException(String.format("No credit on the test wallet '%s'", resource.getFixtures().getUserPublicKey().substring(0,8)), e);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment