Skip to content

Commit 4035778

Browse files
authored
Fee calculation strategies and transaction builders (#116)
* issue #99 - fee calculation strategies and transaction builders * issue #99 - adding ZERO strategy meaning no fees * issue #99 - refactoring + account link transaction * added account link transaction and builder * renamed transaction factory to transaction builder factory * made transaction builder factory available to all e2e tests * removed duplication of aggregate transaction size calculation * issue #99 - updates to account link, aggregate and alias transactions * issue #99 - LockFundsTransaction added * issue #99 - fee calculation is now fully owned by the builder * issue #99 - more transactions added, e2e tests updated, comments * issue #99 - junit test updates * issue #99 - fixed copy-paste error * issue #99 - adding blockchain config/upgrade + modify contract * issue #99 - refactoring tests to match constructors * issue #99 - size adding more transactions + fixes fixes for builder setter names and for size calculation * issue #99 - secret lock and proof + account properties * issue #99 - finished refactoring. e2e tests pass * issue #99 - api cleanup and fixed junit tests * issue #99 - first batch of builder junit tests * issue #99 - wrote tests for builders and couple transactions
1 parent ad7c709 commit 4035778

File tree

103 files changed

+7267
-3024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+7267
-3024
lines changed

src/e2e/java/io/proximax/sdk/E2EAccountLinkTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

21-
import java.math.BigInteger;
2221
import java.util.concurrent.TimeUnit;
2322

2423
import org.junit.jupiter.api.BeforeAll;
@@ -32,7 +31,6 @@
3231
import io.proximax.core.crypto.KeyPair;
3332
import io.proximax.sdk.model.account.Account;
3433
import io.proximax.sdk.model.account.AccountInfo;
35-
import io.proximax.sdk.model.transaction.AccountLinkAction;
3634
import io.proximax.sdk.model.transaction.AccountLinkTransaction;
3735
import io.proximax.sdk.model.transaction.TransactionStatusError;
3836

@@ -59,8 +57,7 @@ void test01linkAccounts() {
5957

6058
@Test
6159
void test02unlinkAccounts() {
62-
AccountLinkTransaction link = new AccountLinkTransaction(remoteAccount.getPublicAccount(),
63-
AccountLinkAction.UNLINK, getNetworkType(), getDeadline(), BigInteger.ZERO);
60+
AccountLinkTransaction link = transact.accountLink().unlink(remoteAccount.getPublicAccount()).build();
6461
transactionHttp.announce(api.sign(link, localAccount)).blockingFirst();
6562
listener.confirmed(localAccount.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
6663

@@ -82,16 +79,14 @@ void test03relinkAccounts() {
8279
@Test
8380
void test04overLinkAccounts() {
8481
Account remoteAccount2 = new Account(new KeyPair(), getNetworkType());
85-
AccountLinkTransaction link = new AccountLinkTransaction(remoteAccount2.getPublicAccount(),
86-
AccountLinkAction.LINK, getNetworkType(), getDeadline(), BigInteger.ZERO);
82+
AccountLinkTransaction link = transact.accountLink().link(remoteAccount2.getPublicAccount()).build();
8783
transactionHttp.announce(api.sign(link, localAccount)).blockingFirst();
8884
TransactionStatusError error = listener.status(localAccount.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
8985
assertEquals("Failure_AccountLink_Link_Already_Exists", error.getStatus());
9086
}
9187

9288
private void linkAndTestAccounts(Account localAccount, Account remoteAccount) {
93-
AccountLinkTransaction link = new AccountLinkTransaction(remoteAccount.getPublicAccount(), AccountLinkAction.LINK,
94-
getNetworkType(), getDeadline(), BigInteger.ZERO);
89+
AccountLinkTransaction link = transact.accountLink().link(remoteAccount.getPublicAccount()).build();
9590
transactionHttp.announce(api.sign(link, localAccount)).blockingFirst();
9691
listener.confirmed(localAccount.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
9792

src/e2e/java/io/proximax/sdk/E2EAccountTest.java

Lines changed: 112 additions & 139 deletions
Large diffs are not rendered by default.

src/e2e/java/io/proximax/sdk/E2EAggregateTest.java

Lines changed: 67 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ public class E2EAggregateTest extends E2EBaseTest {
5757
private final Account bob = new Account(new KeyPair(), getNetworkType());
5858
private final Account mike = new Account(new KeyPair(), getNetworkType());
5959

60-
private final MosaicId mosaicX = new MosaicId(UInt64Utils.fromLongArray(new long[] {481110499,231112638}));
61-
private final MosaicId mosaicY = new MosaicId(UInt64Utils.fromLongArray(new long[] {519256100,642862634}));
62-
63-
60+
private final MosaicId mosaicX = new MosaicId(UInt64Utils.fromLongArray(new long[] { 481110499, 231112638 }));
61+
private final MosaicId mosaicY = new MosaicId(UInt64Utils.fromLongArray(new long[] { 519256100, 642862634 }));
62+
6463
@BeforeAll
6564
void addListener() {
66-
disposables.add(listener.status(alice.getAddress())
67-
.subscribe(err -> logger.error("Operation failed for alice: {}", err), t -> logger.error("exception thrown", t)));
68-
disposables.add(listener.status(bob.getAddress())
69-
.subscribe(err -> logger.error("Operation failed for bob: {}", err), t -> logger.error("exception thrown", t)));
70-
disposables.add(listener.status(mike.getAddress())
71-
.subscribe(err -> logger.error("Operation failed for mike: {}", err), t -> logger.error("exception thrown", t)));
65+
disposables.add(
66+
listener.status(alice.getAddress()).subscribe(err -> logger.error("Operation failed for alice: {}", err),
67+
t -> logger.error("exception thrown", t)));
68+
disposables
69+
.add(listener.status(bob.getAddress()).subscribe(err -> logger.error("Operation failed for bob: {}", err),
70+
t -> logger.error("exception thrown", t)));
71+
disposables
72+
.add(listener.status(mike.getAddress()).subscribe(err -> logger.error("Operation failed for mike: {}", err),
73+
t -> logger.error("exception thrown", t)));
7274
// send funds to alice and bob
7375
logger.info("Mosaic X: {}", mosaicX.getIdAsHex());
7476
logger.info("Mosaic Y: {}", mosaicY.getIdAsHex());
@@ -97,36 +99,28 @@ void escrowBetweenTwoParties() {
9799
sendMosaic(seedAccount, bob.getAddress(), new Mosaic(mosaicY, BigInteger.TEN));
98100
logger.info("Escrow between {} and {}", alice, bob);
99101
// send mosaic X from alice to bob
100-
TransferTransaction aliceToBob = TransferTransaction.create(getDeadline(),
101-
bob.getAddress(),
102-
Arrays.asList(NetworkCurrencyMosaic.ONE),
103-
PlainMessage.Empty,
104-
getNetworkType());
102+
TransferTransaction aliceToBob = transact.transfer().mosaics(NetworkCurrencyMosaic.ONE).to(bob.getAddress())
103+
.build();
105104
// send mosaic Y from bob to alice
106-
TransferTransaction bobToAlice = TransferTransaction.create(getDeadline(),
107-
alice.getAddress(),
108-
Arrays.asList(new Mosaic(mosaicY, BigInteger.TEN)),
109-
PlainMessage.Empty,
110-
getNetworkType());
105+
TransferTransaction bobToAlice = transact.transfer().mosaics(new Mosaic(mosaicY, BigInteger.TEN))
106+
.to(alice.getAddress()).build();
111107
// aggregate bonded with the 2 transactions - escrow
112-
AggregateTransaction escrow = AggregateTransaction.createBonded(getDeadline(),
113-
Arrays.asList(aliceToBob.toAggregate(alice.getPublicAccount()),
114-
bobToAlice.toAggregate(bob.getPublicAccount())),
115-
getNetworkType());
108+
AggregateTransaction escrow = transact.aggregateBonded()
109+
.innerTransactions(aliceToBob.toAggregate(alice.getPublicAccount()),
110+
bobToAlice.toAggregate(bob.getPublicAccount()))
111+
.build();
116112
// alice sign the escrow trans
117113
SignedTransaction signedEscrow = api.sign(escrow, alice);
118114
// lock funds for escrow
119-
LockFundsTransaction lock = LockFundsTransaction.create(getDeadline(),
120-
NetworkCurrencyMosaic.TEN,
121-
BigInteger.valueOf(480),
122-
signedEscrow,
123-
getNetworkType());
115+
LockFundsTransaction lock = transact.lockFunds().mosaic(NetworkCurrencyMosaic.TEN)
116+
.duration(BigInteger.valueOf(480)).signedTransaction(signedEscrow).build();
124117
// alice sign and announce the lock
125118
logger.info("announcing {}", lock);
126119
SignedTransaction signedLock = api.sign(lock, alice);
127120
transactionHttp.announce(signedLock).blockingFirst();
128121
// wait for lock confirmation
129-
logger.info("got confirmation: {}", listener.confirmed(alice.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst());
122+
logger.info("got confirmation: {}",
123+
listener.confirmed(alice.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst());
130124
sleepForAWhile();
131125
// announce escrow
132126
logger.info("announcing {}", escrow);
@@ -135,7 +129,8 @@ void escrowBetweenTwoParties() {
135129
listener.aggregateBondedAdded(alice.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
136130

137131
// bob sign the escrow
138-
AggregateTransaction pendingEscrow = accountHttp.aggregateBondedTransactions(bob.getPublicAccount()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
132+
AggregateTransaction pendingEscrow = accountHttp.aggregateBondedTransactions(bob.getPublicAccount())
133+
.timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
139134
CosignatureSignedTransaction signedCosig = CosignatureTransaction.create(pendingEscrow).signWith(bob);
140135
// bob announce the cosignature
141136
logger.info("announcing escrow");
@@ -166,7 +161,7 @@ void escrowBetweenTwoParties() {
166161
}
167162
});
168163
}
169-
164+
170165
@Test
171166
void escrowBetweenTwoPartiesComplete() {
172167
returnAllToSeed(alice);
@@ -176,22 +171,16 @@ void escrowBetweenTwoPartiesComplete() {
176171
sendMosaic(seedAccount, bob.getAddress(), new Mosaic(mosaicY, BigInteger.TEN));
177172
logger.info("Escrow between {} and {}", alice, bob);
178173
// send mosaic X from alice to bob
179-
TransferTransaction aliceToBob = TransferTransaction.create(getDeadline(),
180-
bob.getAddress(),
181-
Arrays.asList(NetworkCurrencyMosaic.ONE),
182-
PlainMessage.Empty,
183-
getNetworkType());
174+
TransferTransaction aliceToBob = transact.transfer().mosaics(NetworkCurrencyMosaic.ONE).to(bob.getAddress())
175+
.build();
184176
// send mosaic Y from bob to alice
185-
TransferTransaction bobToAlice = TransferTransaction.create(getDeadline(),
186-
alice.getAddress(),
187-
Arrays.asList(new Mosaic(mosaicY, BigInteger.TEN)),
188-
PlainMessage.Empty,
189-
getNetworkType());
177+
TransferTransaction bobToAlice = transact.transfer().mosaics(new Mosaic(mosaicY, BigInteger.TEN))
178+
.to(alice.getAddress()).build();
190179
// aggregate bonded with the 2 transactions - escrow
191-
AggregateTransaction escrow = AggregateTransaction.createComplete(getDeadline(),
192-
Arrays.asList(aliceToBob.toAggregate(alice.getPublicAccount()),
193-
bobToAlice.toAggregate(bob.getPublicAccount())),
194-
getNetworkType());
180+
AggregateTransaction escrow = transact.aggregateComplete()
181+
.innerTransactions(aliceToBob.toAggregate(alice.getPublicAccount()),
182+
bobToAlice.toAggregate(bob.getPublicAccount()))
183+
.build();
195184
// alice sign the escrow trans
196185
SignedTransaction signedEscrow = api.signWithCosigners(escrow, alice, Arrays.asList(bob));
197186
// announce escrow
@@ -223,7 +212,7 @@ void escrowBetweenTwoPartiesComplete() {
223212
}
224213
});
225214
}
226-
215+
227216
@Test
228217
void escrowBetweenThreeParties() {
229218
returnAllToSeed(alice);
@@ -236,38 +225,25 @@ void escrowBetweenThreeParties() {
236225
sleepForAWhile();
237226
logger.info("Escrow between {}, {} and {}", alice, bob, mike);
238227
// send mosaic X from alice to bob
239-
TransferTransaction aliceToBob = TransferTransaction.create(getDeadline(),
240-
bob.getAddress(),
241-
Arrays.asList(NetworkCurrencyMosaic.ONE),
242-
PlainMessage.Empty,
243-
getNetworkType());
228+
TransferTransaction aliceToBob = transact.transfer().mosaics(NetworkCurrencyMosaic.ONE).to(bob.getAddress())
229+
.build();
244230
// send mosaic Y from bob to alice
245-
TransferTransaction bobToAlice = TransferTransaction.create(getDeadline(),
246-
alice.getAddress(),
247-
Arrays.asList(new Mosaic(mosaicY, BigInteger.TEN)),
248-
PlainMessage.Empty,
249-
getNetworkType());
231+
TransferTransaction bobToAlice = transact.transfer().mosaics(new Mosaic(mosaicY, BigInteger.TEN))
232+
.to(alice.getAddress()).build();
250233
// send mosaic Y from bob to alice
251-
TransferTransaction mikeToAlice = TransferTransaction.create(getDeadline(),
252-
alice.getAddress(),
253-
Arrays.asList(NetworkCurrencyMosaic.ONE),
254-
PlainMessage.Empty,
255-
getNetworkType());
234+
TransferTransaction mikeToAlice = transact.transfer().mosaics(NetworkCurrencyMosaic.ONE).to(alice.getAddress())
235+
.build();
256236
// aggregate bonded with the 3 transactions - escrow
257-
AggregateTransaction escrow = AggregateTransaction.createBonded(getDeadline(),
258-
Arrays.asList(
259-
aliceToBob.toAggregate(alice.getPublicAccount()),
237+
AggregateTransaction escrow = transact.aggregateBonded()
238+
.innerTransactions(aliceToBob.toAggregate(alice.getPublicAccount()),
260239
bobToAlice.toAggregate(bob.getPublicAccount()),
261-
mikeToAlice.toAggregate(mike.getPublicAccount())),
262-
getNetworkType());
240+
mikeToAlice.toAggregate(mike.getPublicAccount()))
241+
.build();
263242
// alice sign the escrow trans
264243
SignedTransaction signedEscrow = api.sign(escrow, alice);
265244
// lock funds for escrow
266-
LockFundsTransaction lock = LockFundsTransaction.create(getDeadline(),
267-
NetworkCurrencyMosaic.TEN,
268-
BigInteger.valueOf(480),
269-
signedEscrow,
270-
getNetworkType());
245+
LockFundsTransaction lock = transact.lockFunds().mosaic(NetworkCurrencyMosaic.TEN)
246+
.duration(BigInteger.valueOf(480)).signedTransaction(signedEscrow).build();
271247
// alice sign and announce the lock
272248
logger.info("announcing {}", lock);
273249
SignedTransaction signedLock = api.sign(lock, alice);
@@ -280,18 +256,20 @@ void escrowBetweenThreeParties() {
280256
transactionHttp.announceAggregateBonded(signedEscrow).blockingFirst();
281257
// wait for escrow confirmation
282258
listener.aggregateBondedAdded(alice.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
283-
259+
284260
// bob sign the escrow
285-
AggregateTransaction pendingEscrowBob = accountHttp.aggregateBondedTransactions(bob.getPublicAccount()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
261+
AggregateTransaction pendingEscrowBob = accountHttp.aggregateBondedTransactions(bob.getPublicAccount())
262+
.timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
286263
CosignatureSignedTransaction signedCosigBob = CosignatureTransaction.create(pendingEscrowBob).signWith(bob);
287264
// bob announce the cosignature
288265
logger.info("announcing cosig bob");
289266
transactionHttp.announceAggregateBondedCosignature(signedCosigBob).blockingFirst();
290267
// wait for cosig event
291268
listener.cosignatureAdded(bob.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
292-
269+
293270
// mike sign the escrow
294-
AggregateTransaction pendingEscrowMike = accountHttp.aggregateBondedTransactions(mike.getPublicAccount()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
271+
AggregateTransaction pendingEscrowMike = accountHttp.aggregateBondedTransactions(mike.getPublicAccount())
272+
.timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
295273
CosignatureSignedTransaction signedCosigMike = CosignatureTransaction.create(pendingEscrowMike).signWith(mike);
296274
// mike announce the cosignature
297275
logger.info("announcing cosig mike");
@@ -329,7 +307,7 @@ void escrowBetweenThreeParties() {
329307
List<Mosaic> mikeMosaics = accountHttp.getAccountInfo(mike.getAddress()).blockingFirst().getMosaics();
330308
assertTrue(mikeMosaics.isEmpty());
331309
}
332-
310+
333311
@Test
334312
void askforMoney() {
335313
returnAllToSeed(alice);
@@ -338,30 +316,21 @@ void askforMoney() {
338316
sendMosaic(seedAccount, bob.getAddress(), new Mosaic(mosaicY, BigInteger.TEN));
339317
logger.info("Alice asks for money");
340318
// send mosaic X from alice to bob
341-
TransferTransaction aliceToBob = TransferTransaction.create(getDeadline(),
342-
bob.getAddress(),
343-
Arrays.asList(),
344-
PlainMessage.create("send me 10 Y"),
345-
getNetworkType());
319+
TransferTransaction aliceToBob = transact.transfer().to(bob.getAddress())
320+
.message(PlainMessage.create("send me 10 Y")).build();
346321
// send mosaic Y from bob to alice
347-
TransferTransaction bobToAlice = TransferTransaction.create(getDeadline(),
348-
alice.getAddress(),
349-
Arrays.asList(new Mosaic(mosaicY, BigInteger.TEN)),
350-
PlainMessage.Empty,
351-
getNetworkType());
322+
TransferTransaction bobToAlice = transact.transfer().mosaics(new Mosaic(mosaicY, BigInteger.TEN))
323+
.to(alice.getAddress()).build();
352324
// aggregate bonded with the 2 transactions - escrow
353-
AggregateTransaction escrow = AggregateTransaction.createBonded(getDeadline(),
354-
Arrays.asList(aliceToBob.toAggregate(alice.getPublicAccount()),
355-
bobToAlice.toAggregate(bob.getPublicAccount())),
356-
getNetworkType());
325+
AggregateTransaction escrow = transact.aggregateBonded()
326+
.innerTransactions(aliceToBob.toAggregate(alice.getPublicAccount()),
327+
bobToAlice.toAggregate(bob.getPublicAccount()))
328+
.build();
357329
// alice sign the escrow trans
358330
SignedTransaction signedEscrow = api.sign(escrow, alice);
359331
// lock funds for escrow
360-
LockFundsTransaction lock = LockFundsTransaction.create(getDeadline(),
361-
NetworkCurrencyMosaic.TEN,
362-
BigInteger.valueOf(480),
363-
signedEscrow,
364-
getNetworkType());
332+
LockFundsTransaction lock = transact.lockFunds().mosaic(NetworkCurrencyMosaic.TEN)
333+
.duration(BigInteger.valueOf(480)).signedTransaction(signedEscrow).build();
365334
// alice sign and announce the lock
366335
logger.info("announcing {}", lock);
367336
SignedTransaction signedLock = api.sign(lock, alice);
@@ -375,7 +344,8 @@ void askforMoney() {
375344
// wait for escrow confirmation
376345
listener.aggregateBondedAdded(alice.getAddress()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst();
377346
// bob sign the escrow
378-
AggregateTransaction pendingEscrow = accountHttp.aggregateBondedTransactions(bob.getPublicAccount()).timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
347+
AggregateTransaction pendingEscrow = accountHttp.aggregateBondedTransactions(bob.getPublicAccount())
348+
.timeout(getTimeoutSeconds(), TimeUnit.SECONDS).blockingFirst().get(0);
379349
CosignatureSignedTransaction signedCosig = CosignatureTransaction.create(pendingEscrow).signWith(bob);
380350
// bob announce the cosignature
381351
logger.info("announcing escrow");

0 commit comments

Comments
 (0)