-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into
issue/106-test-coverage Conflicts: src/main/java/io/proximax/sdk/infrastructure/TransactionMapping.java
- Loading branch information
Showing
7 changed files
with
108 additions
and
17 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
48 changes: 48 additions & 0 deletions
48
src/main/java/io/proximax/sdk/model/transaction/DeadlineRaw.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,48 @@ | ||
/* | ||
* Copyright 2019 ProximaX Limited. All rights reserved. | ||
* Use of this source code is governed by the Apache 2.0 | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
package io.proximax.sdk.model.transaction; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Date; | ||
|
||
/** | ||
* Raw deadline implementation working directly with milliseconds. Consider using {@link Deadline} or {@link DeadlineBP} | ||
*/ | ||
public class DeadlineRaw implements TransactionDeadline { | ||
|
||
/** milliseconds since epoch */ | ||
private final long deadline; | ||
|
||
/** | ||
* @param deadline in milliseconds since epoch | ||
*/ | ||
public DeadlineRaw(BigInteger deadline) { | ||
this.deadline = deadline.longValue(); | ||
} | ||
|
||
/** | ||
* create new deadline instance specifying duration since current time | ||
* | ||
* @param duration duration after current time | ||
* @return deadline representing specified time | ||
*/ | ||
public static TransactionDeadline startNow(BigInteger duration) { | ||
return new DeadlineRaw(BigInteger | ||
.valueOf(System.currentTimeMillis() - TransactionDeadline.NETWORK_EPOCH_START_MILLIS).add(duration)); | ||
} | ||
|
||
@Override | ||
public long getInstant() { | ||
return deadline; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DeadlineRaw [deadline=" + new Date(deadline + TransactionDeadline.NETWORK_EPOCH_START_MILLIS) + "]"; | ||
} | ||
|
||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/io/proximax/sdk/model/transaction/DeadlineRawTest.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,50 @@ | ||
/* | ||
* Copyright 2019 ProximaX Limited. All rights reserved. | ||
* Use of this source code is governed by the Apache 2.0 | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
package io.proximax.sdk.model.transaction; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.math.BigInteger; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* {@link DeadlineRaw} tests | ||
*/ | ||
class DeadlineRawTest { | ||
private static final long HOUR_MILLIS = 3_600_000l; | ||
private static final long ACCEPTABLE_THRESHOLD = 500l; | ||
@Test | ||
void constructor() { | ||
DeadlineRaw rawDeadline = new DeadlineRaw(BigInteger.valueOf(HOUR_MILLIS)); | ||
assertEquals(HOUR_MILLIS, rawDeadline.getInstant()); | ||
} | ||
|
||
@Test | ||
void startNow() { | ||
Deadline deadline = new Deadline(1, ChronoUnit.HOURS); | ||
TransactionDeadline rawDeadline = DeadlineRaw.startNow(BigInteger.valueOf(HOUR_MILLIS)); | ||
long diff = Math.abs(deadline.getInstant() - rawDeadline.getInstant()); | ||
assertTrue(diff < ACCEPTABLE_THRESHOLD); | ||
} | ||
|
||
@Test | ||
void compareWithDeadline() { | ||
Deadline deadline = new Deadline(BigInteger.valueOf(HOUR_MILLIS)); | ||
DeadlineRaw rawDeadline = new DeadlineRaw(BigInteger.valueOf(HOUR_MILLIS)); | ||
|
||
long diff = Math.abs(deadline.getInstant() - rawDeadline.getInstant()); | ||
assertTrue(diff < ACCEPTABLE_THRESHOLD, "difference was "+diff); | ||
} | ||
|
||
@Test | ||
void toStringPasses() { | ||
DeadlineRaw rawDeadline = new DeadlineRaw(BigInteger.valueOf(HOUR_MILLIS)); | ||
assertTrue(rawDeadline.toString().startsWith("DeadlineRaw")); | ||
} | ||
} |