mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Added PoW to MESSAGE (for zero fee). DB and tx layout changes.
This commit is contained in:
@@ -29,7 +29,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class MessageTests extends Common {
|
||||
|
||||
private static final int version = 3;
|
||||
private static final int version = 4;
|
||||
private static final String recipient = Common.getTestAccount(null, "bob").getAddress();
|
||||
|
||||
|
||||
@@ -69,6 +69,26 @@ public class MessageTests extends Common {
|
||||
assertFalse(isValid(newGroupId, null, 0L, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noFeeNoNonce() throws DataException {
|
||||
testFeeNonce(false, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withFeeNoNonce() throws DataException {
|
||||
testFeeNonce(true, false, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noFeeWithNonce() throws DataException {
|
||||
testFeeNonce(false, true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withFeeWithNonce() throws DataException {
|
||||
testFeeNonce(true, true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withRecipentNoAmount() throws DataException {
|
||||
testMessage(Group.NO_GROUP, recipient, 0L, null);
|
||||
@@ -105,8 +125,13 @@ public class MessageTests extends Common {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TestAccount alice = Common.getTestAccount(repository, "alice");
|
||||
|
||||
int nonce = 0;
|
||||
byte[] data = new byte[1];
|
||||
boolean isText = false;
|
||||
boolean isEncrypted = false;
|
||||
|
||||
MessageTransactionData transactionData = new MessageTransactionData(TestTransaction.generateBase(alice, txGroupId),
|
||||
version, recipient, amount, assetId, new byte[1], false, false);
|
||||
version, nonce, recipient, amount, assetId, data, isText, isEncrypted);
|
||||
|
||||
Transaction transaction = new MessageTransaction(repository, transactionData);
|
||||
|
||||
@@ -114,12 +139,51 @@ public class MessageTests extends Common {
|
||||
}
|
||||
}
|
||||
|
||||
private void testFeeNonce(boolean withFee, boolean withNonce, boolean isValid) throws DataException {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TestAccount alice = Common.getTestAccount(repository, "alice");
|
||||
|
||||
int txGroupId = 0;
|
||||
int nonce = 0;
|
||||
long amount = 0;
|
||||
long assetId = Asset.QORT;
|
||||
byte[] data = new byte[1];
|
||||
boolean isText = false;
|
||||
boolean isEncrypted = false;
|
||||
|
||||
MessageTransactionData transactionData = new MessageTransactionData(TestTransaction.generateBase(alice, txGroupId),
|
||||
version, nonce, recipient, amount, assetId, data, isText, isEncrypted);
|
||||
|
||||
MessageTransaction transaction = new MessageTransaction(repository, transactionData);
|
||||
|
||||
if (withFee)
|
||||
transactionData.setFee(transaction.calcRecommendedFee());
|
||||
else
|
||||
transactionData.setFee(0L);
|
||||
|
||||
if (withNonce) {
|
||||
transaction.computeNonce();
|
||||
} else {
|
||||
transactionData.setNonce(-1);
|
||||
}
|
||||
|
||||
transaction.sign(alice);
|
||||
|
||||
assertEquals(isValid, transaction.isSignatureValid());
|
||||
}
|
||||
}
|
||||
|
||||
private void testMessage(int txGroupId, String recipient, long amount, Long assetId) throws DataException {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TestAccount alice = Common.getTestAccount(repository, "alice");
|
||||
|
||||
int nonce = 0;
|
||||
byte[] data = new byte[1];
|
||||
boolean isText = false;
|
||||
boolean isEncrypted = false;
|
||||
|
||||
MessageTransactionData transactionData = new MessageTransactionData(TestTransaction.generateBase(alice, txGroupId),
|
||||
version, recipient, amount, assetId, new byte[1], false, false);
|
||||
version, nonce, recipient, amount, assetId, data, isText, isEncrypted);
|
||||
|
||||
TransactionUtils.signAndMint(repository, transactionData, alice);
|
||||
|
||||
@@ -131,8 +195,13 @@ public class MessageTests extends Common {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TestAccount alice = Common.getTestAccount(repository, "alice");
|
||||
|
||||
int nonce = 0;
|
||||
byte[] data = new byte[1];
|
||||
boolean isText = false;
|
||||
boolean isEncrypted = false;
|
||||
|
||||
MessageTransactionData expectedTransactionData = new MessageTransactionData(TestTransaction.generateBase(alice),
|
||||
version, recipient, amount, assetId, new byte[1], false, false);
|
||||
version, nonce, recipient, amount, assetId, data, isText, isEncrypted);
|
||||
|
||||
Transaction transaction = new MessageTransaction(repository, expectedTransactionData);
|
||||
transaction.sign(alice);
|
||||
|
@@ -473,11 +473,13 @@ public class AtTests extends Common {
|
||||
}
|
||||
|
||||
Long fee = null;
|
||||
int version = 4;
|
||||
int nonce = 0;
|
||||
long amount = 0;
|
||||
Long assetId = null; // because amount is zero
|
||||
|
||||
BaseTransactionData baseTransactionData = new BaseTransactionData(txTimestamp, Group.NO_GROUP, lastReference, sender.getPublicKey(), fee, null);
|
||||
TransactionData messageTransactionData = new MessageTransactionData(baseTransactionData, 4, recipient, amount, assetId, data, false, false);
|
||||
TransactionData messageTransactionData = new MessageTransactionData(baseTransactionData, version, nonce, recipient, amount, assetId, data, false, false);
|
||||
|
||||
MessageTransaction messageTransaction = new MessageTransaction(repository, messageTransactionData);
|
||||
|
||||
|
@@ -11,7 +11,8 @@ import org.qortal.utils.Amounts;
|
||||
public class MessageTestTransaction extends TestTransaction {
|
||||
|
||||
public static TransactionData randomTransaction(Repository repository, PrivateKeyAccount account, boolean wantValid) throws DataException {
|
||||
final int version = 3;
|
||||
final int version = 4;
|
||||
final int nonce = 0;
|
||||
String recipient = account.getAddress();
|
||||
final long assetId = Asset.QORT;
|
||||
long amount = 123L * Amounts.MULTIPLIER;
|
||||
@@ -19,7 +20,7 @@ public class MessageTestTransaction extends TestTransaction {
|
||||
final boolean isText = true;
|
||||
final boolean isEncrypted = false;
|
||||
|
||||
return new MessageTransactionData(generateBase(account), version, recipient, amount, assetId, data, isText, isEncrypted);
|
||||
return new MessageTransactionData(generateBase(account), version, nonce, recipient, amount, assetId, data, isText, isEncrypted);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user