Added PresenceTestTransaction, to allow SerializationTests.testTransactions() to be unblocked

This commit is contained in:
CalDescent 2021-11-03 19:18:26 +00:00
parent 6f07dc7852
commit fe79119809
2 changed files with 26 additions and 2 deletions

View File

@ -38,7 +38,6 @@ public class SerializationTests extends Common {
} }
@Test @Test
@Ignore(value = "Doesn't work, to be fixed later")
public void testTransactions() throws DataException, TransformationException { public void testTransactions() throws DataException, TransformationException {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
PrivateKeyAccount signingAccount = Common.getTestAccount(repository, "alice"); PrivateKeyAccount signingAccount = Common.getTestAccount(repository, "alice");
@ -174,4 +173,4 @@ public class SerializationTests extends Common {
assertEqualBigDecimals("Deserialized BigDecimal has incorrect value", amount, newAmount); assertEqualBigDecimals("Deserialized BigDecimal has incorrect value", amount, newAmount);
} }
} }

View File

@ -0,0 +1,25 @@
package org.qortal.test.common.transaction;
import com.google.common.primitives.Longs;
import org.qortal.account.PrivateKeyAccount;
import org.qortal.data.transaction.PresenceTransactionData;
import org.qortal.data.transaction.TransactionData;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.transaction.PresenceTransaction.PresenceType;
import org.qortal.utils.NTP;
public class PresenceTestTransaction extends TestTransaction {
public static TransactionData randomTransaction(Repository repository, PrivateKeyAccount account, boolean wantValid) throws DataException {
final int nonce = 0;
byte[] tradePrivateKey = new byte[32];
PrivateKeyAccount tradeNativeAccount = new PrivateKeyAccount(repository, tradePrivateKey);
long timestamp = NTP.getTime();
byte[] timestampSignature = tradeNativeAccount.sign(Longs.toByteArray(timestamp));
return new PresenceTransactionData(generateBase(account), nonce, PresenceType.TRADE_BOT, timestampSignature);
}
}