2018-10-04 13:38:59 +00:00
|
|
|
package test;
|
|
|
|
|
2018-10-04 20:58:04 +00:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
2018-10-04 13:38:59 +00:00
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import com.google.common.hash.HashCode;
|
|
|
|
|
Finally syncs with qora1 chain!
ATData no longer needs deploySignature as a link back to DeployATTransaction,
but does need creator and creation [timestamp].
"creation" is critical for ordering ATs when creating/validating blocks.
Similar changes to ATStateData, adding creation, stateHash (for quicker
comparison with blocks received over the network), and fees incurred
by running AT on that block.
Also added more explicit constructors for different scenarios.
BlockData upgraded from simplistic "atBytes" to use ATStateData (above)
which has details on ATs run for that block, fees incurred, and a hash
of the AT's state. atCount added to keep track of how many ATs ran.
ATTransactions essentially reuse the GenesisAccount's publickey as
creator/sender as they're brought into existence by the Qora code
rather than an end user. ATTransactionData updated to reflect this
and the AT's address used as a "sender" field.
Account tidied up with respect to CIYAM ATs and setConfirmedBalance
ensures there is a corresponding record in Accounts (DB table).
Account, and subclasses, don't need "throws DataException" on
constructor any more.
Fixed bug in Asset Order matching where the matching engine
would give up after first potential match instead of trying others.
Lots more work on CIYAM AT, albeit mainly blind importing of old
v1 ATs from static JSON file as they're all dead and new
v2 implementation is not backwards compatible.
More work on Blocks, mostly AT stuff, but also fork-based corruption
prevention using fix from Qora v1.
Payment-related transactions (multipayment, etc.) always expect/use
non-null (albeit maybe empty) list of PaymentData when validating,
processing or orphaning.
Mainly a change in HSQLDBTransactionRepository.getPayments()
Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid)
didn't pass on isZeroAmountValid to called method - whoops!
Lots of work on ATTransactions themselves.
MessageTransactions incorrectly assumed the optional payment was always
in Qora. Now fixed to use the transaction's provided assetId.
Mass of fixes/additions to HSQLDBATRepository, especially fixing
incorrect reference to Assets DB table!
In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8)
to DECIMAL(27,8) to allow for huge asset quantities.
You WILL have to rebuild your database!
2018-10-26 16:47:47 +00:00
|
|
|
import data.at.ATStateData;
|
2018-10-04 13:38:59 +00:00
|
|
|
import data.block.BlockData;
|
|
|
|
import data.block.BlockTransactionData;
|
|
|
|
import data.transaction.DeployATTransactionData;
|
2018-12-03 13:12:52 +00:00
|
|
|
import qora.assets.Asset;
|
2018-10-04 13:38:59 +00:00
|
|
|
import qora.transaction.DeployATTransaction;
|
|
|
|
import repository.DataException;
|
|
|
|
import repository.Repository;
|
|
|
|
import repository.RepositoryManager;
|
|
|
|
import transform.TransformationException;
|
|
|
|
import utils.Base58;
|
|
|
|
|
|
|
|
public class ATTests extends Common {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testATAccount() throws TransformationException, DataException {
|
|
|
|
// 2dZ4megUyNoYYY7qWmuSd4xw1yUKgPPF97yBbeddh8aKuC8PLpz7Xvf3r6Zjv1zwGrR8fEAHuaztCPD4KQp76KdL at height 125598
|
|
|
|
// AT address: AaaUn82XV4YcUtsQ3rHa5ZgqyiK35rVfE3
|
|
|
|
|
|
|
|
String expectedAddress = "AaaUn82XV4YcUtsQ3rHa5ZgqyiK35rVfE3";
|
|
|
|
|
|
|
|
byte[] creatorPublicKey = HashCode.fromString("c74d71ecec6b37890f26573186e634986cc90a507af01749f92aa2c7c95ad05f").asBytes();
|
|
|
|
String name = "QORABURST @ 1.00";
|
|
|
|
String description = "Initiators BURST address: BURST-LKGW-Z2JK-EZ99-E7CUE";
|
|
|
|
String ATType = "acct";
|
|
|
|
String tags = "acct,atomic cross chain tx,initiate,initiator";
|
|
|
|
byte[] creationBytes = HashCode
|
|
|
|
.fromString("010000000100010000000000" + "0094357700" + "000000bf"
|
|
|
|
+ "3501030900000006040000000900000029302009000000040000000f1ab4000000330403090000003525010a000000260a000000320903350703090000003526010a0000001b0a000000cd322801331601000000003317010100000033180102000000331901030000003505020a0000001b0a000000a1320b033205041e050000001833000509000000320a033203041ab400000033160105000000331701060000003318010700000033190108000000320304320b033203041ab7"
|
|
|
|
+ "00000048"
|
|
|
|
+ "5e211280259d2f3130248482c2dfc53be2fd5f9bedc9bc21425f951e8097a21900000000c80000003ac8716ad810191acf270d22e9f47f27806256c10d6ba6144900000000000000")
|
|
|
|
.asBytes();
|
|
|
|
BigDecimal amount = BigDecimal.valueOf(500.0).setScale(8);
|
|
|
|
BigDecimal fee = BigDecimal.valueOf(20.0).setScale(8);
|
|
|
|
long timestamp = 1439997077932L;
|
|
|
|
byte[] reference = Base58.decode("2D3jX1pEgu6irsQ7QzJb85QP1D9M45dNyP5M9a3WFHndU5ZywF4F5pnUurcbzMnGMcTwpAY6H7DuLw8cUBU66ao1");
|
|
|
|
byte[] signature = Base58.decode("2dZ4megUyNoYYY7qWmuSd4xw1yUKgPPF97yBbeddh8aKuC8PLpz7Xvf3r6Zjv1zwGrR8fEAHuaztCPD4KQp76KdL");
|
|
|
|
|
2018-12-03 13:12:52 +00:00
|
|
|
DeployATTransactionData transactionData = new DeployATTransactionData(creatorPublicKey, name, description, ATType, tags, creationBytes, amount,
|
|
|
|
Asset.QORA, fee, timestamp, reference, signature);
|
2018-10-04 13:38:59 +00:00
|
|
|
|
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
|
|
|
repository.getTransactionRepository().save(transactionData);
|
|
|
|
|
|
|
|
DeployATTransaction transaction = new DeployATTransaction(repository, transactionData);
|
|
|
|
|
|
|
|
// Fake entry for this transaction at block height 125598 if it doesn't already exist
|
|
|
|
if (transaction.getHeight() == 0) {
|
|
|
|
byte[] blockSignature = Base58.decode(
|
|
|
|
"2amu634LnAbxeLfDtWdTLiCWtKu1XM2XLK9o6fDM7yGNNoh5Tq2KxSLdx8AS486zUU1wYNGCm8mcGxjMiww979MxdPVB2PQzaKrW2aFn9hpdSNN6Nk7EmeYKwsZdx9tkpHfBt5thSrUUrhzXJju9KYCAP6p3Ty4zccFkaxCP15j332U");
|
|
|
|
byte[] generatorSignature = Arrays.copyOfRange(blockSignature, 0, 64);
|
|
|
|
byte[] transactionsSignature = Arrays.copyOfRange(blockSignature, 64, 128);
|
|
|
|
|
|
|
|
// Check block exists too
|
|
|
|
if (repository.getBlockRepository().fromSignature(blockSignature) == null) {
|
|
|
|
int version = 2;
|
|
|
|
byte[] blockReference = blockSignature;
|
|
|
|
int transactionCount = 0;
|
|
|
|
BigDecimal totalFees = BigDecimal.valueOf(70.0).setScale(8);
|
|
|
|
int height = 125598;
|
|
|
|
long blockTimestamp = 1439997158336L;
|
|
|
|
BigDecimal generatingBalance = BigDecimal.valueOf(1440368826L).setScale(8);
|
|
|
|
byte[] generatorPublicKey = Base58.decode("X4s833bbtghh7gejmaBMbWqD44HrUobw93ANUuaNhFc");
|
Finally syncs with qora1 chain!
ATData no longer needs deploySignature as a link back to DeployATTransaction,
but does need creator and creation [timestamp].
"creation" is critical for ordering ATs when creating/validating blocks.
Similar changes to ATStateData, adding creation, stateHash (for quicker
comparison with blocks received over the network), and fees incurred
by running AT on that block.
Also added more explicit constructors for different scenarios.
BlockData upgraded from simplistic "atBytes" to use ATStateData (above)
which has details on ATs run for that block, fees incurred, and a hash
of the AT's state. atCount added to keep track of how many ATs ran.
ATTransactions essentially reuse the GenesisAccount's publickey as
creator/sender as they're brought into existence by the Qora code
rather than an end user. ATTransactionData updated to reflect this
and the AT's address used as a "sender" field.
Account tidied up with respect to CIYAM ATs and setConfirmedBalance
ensures there is a corresponding record in Accounts (DB table).
Account, and subclasses, don't need "throws DataException" on
constructor any more.
Fixed bug in Asset Order matching where the matching engine
would give up after first potential match instead of trying others.
Lots more work on CIYAM AT, albeit mainly blind importing of old
v1 ATs from static JSON file as they're all dead and new
v2 implementation is not backwards compatible.
More work on Blocks, mostly AT stuff, but also fork-based corruption
prevention using fix from Qora v1.
Payment-related transactions (multipayment, etc.) always expect/use
non-null (albeit maybe empty) list of PaymentData when validating,
processing or orphaning.
Mainly a change in HSQLDBTransactionRepository.getPayments()
Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid)
didn't pass on isZeroAmountValid to called method - whoops!
Lots of work on ATTransactions themselves.
MessageTransactions incorrectly assumed the optional payment was always
in Qora. Now fixed to use the transaction's provided assetId.
Mass of fixes/additions to HSQLDBATRepository, especially fixing
incorrect reference to Assets DB table!
In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8)
to DECIMAL(27,8) to allow for huge asset quantities.
You WILL have to rebuild your database!
2018-10-26 16:47:47 +00:00
|
|
|
int atCount = 1;
|
2018-10-04 13:38:59 +00:00
|
|
|
BigDecimal atFees = BigDecimal.valueOf(50.0).setScale(8);
|
|
|
|
|
|
|
|
BlockData blockData = new BlockData(version, blockReference, transactionCount, totalFees, transactionsSignature, height, blockTimestamp,
|
Finally syncs with qora1 chain!
ATData no longer needs deploySignature as a link back to DeployATTransaction,
but does need creator and creation [timestamp].
"creation" is critical for ordering ATs when creating/validating blocks.
Similar changes to ATStateData, adding creation, stateHash (for quicker
comparison with blocks received over the network), and fees incurred
by running AT on that block.
Also added more explicit constructors for different scenarios.
BlockData upgraded from simplistic "atBytes" to use ATStateData (above)
which has details on ATs run for that block, fees incurred, and a hash
of the AT's state. atCount added to keep track of how many ATs ran.
ATTransactions essentially reuse the GenesisAccount's publickey as
creator/sender as they're brought into existence by the Qora code
rather than an end user. ATTransactionData updated to reflect this
and the AT's address used as a "sender" field.
Account tidied up with respect to CIYAM ATs and setConfirmedBalance
ensures there is a corresponding record in Accounts (DB table).
Account, and subclasses, don't need "throws DataException" on
constructor any more.
Fixed bug in Asset Order matching where the matching engine
would give up after first potential match instead of trying others.
Lots more work on CIYAM AT, albeit mainly blind importing of old
v1 ATs from static JSON file as they're all dead and new
v2 implementation is not backwards compatible.
More work on Blocks, mostly AT stuff, but also fork-based corruption
prevention using fix from Qora v1.
Payment-related transactions (multipayment, etc.) always expect/use
non-null (albeit maybe empty) list of PaymentData when validating,
processing or orphaning.
Mainly a change in HSQLDBTransactionRepository.getPayments()
Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid)
didn't pass on isZeroAmountValid to called method - whoops!
Lots of work on ATTransactions themselves.
MessageTransactions incorrectly assumed the optional payment was always
in Qora. Now fixed to use the transaction's provided assetId.
Mass of fixes/additions to HSQLDBATRepository, especially fixing
incorrect reference to Assets DB table!
In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8)
to DECIMAL(27,8) to allow for huge asset quantities.
You WILL have to rebuild your database!
2018-10-26 16:47:47 +00:00
|
|
|
generatingBalance, generatorPublicKey, generatorSignature, atCount, atFees);
|
2018-10-04 13:38:59 +00:00
|
|
|
|
|
|
|
repository.getBlockRepository().save(blockData);
|
Finally syncs with qora1 chain!
ATData no longer needs deploySignature as a link back to DeployATTransaction,
but does need creator and creation [timestamp].
"creation" is critical for ordering ATs when creating/validating blocks.
Similar changes to ATStateData, adding creation, stateHash (for quicker
comparison with blocks received over the network), and fees incurred
by running AT on that block.
Also added more explicit constructors for different scenarios.
BlockData upgraded from simplistic "atBytes" to use ATStateData (above)
which has details on ATs run for that block, fees incurred, and a hash
of the AT's state. atCount added to keep track of how many ATs ran.
ATTransactions essentially reuse the GenesisAccount's publickey as
creator/sender as they're brought into existence by the Qora code
rather than an end user. ATTransactionData updated to reflect this
and the AT's address used as a "sender" field.
Account tidied up with respect to CIYAM ATs and setConfirmedBalance
ensures there is a corresponding record in Accounts (DB table).
Account, and subclasses, don't need "throws DataException" on
constructor any more.
Fixed bug in Asset Order matching where the matching engine
would give up after first potential match instead of trying others.
Lots more work on CIYAM AT, albeit mainly blind importing of old
v1 ATs from static JSON file as they're all dead and new
v2 implementation is not backwards compatible.
More work on Blocks, mostly AT stuff, but also fork-based corruption
prevention using fix from Qora v1.
Payment-related transactions (multipayment, etc.) always expect/use
non-null (albeit maybe empty) list of PaymentData when validating,
processing or orphaning.
Mainly a change in HSQLDBTransactionRepository.getPayments()
Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid)
didn't pass on isZeroAmountValid to called method - whoops!
Lots of work on ATTransactions themselves.
MessageTransactions incorrectly assumed the optional payment was always
in Qora. Now fixed to use the transaction's provided assetId.
Mass of fixes/additions to HSQLDBATRepository, especially fixing
incorrect reference to Assets DB table!
In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8)
to DECIMAL(27,8) to allow for huge asset quantities.
You WILL have to rebuild your database!
2018-10-26 16:47:47 +00:00
|
|
|
|
|
|
|
byte[] atBytes = HashCode.fromString("17950a6c62d17ff0caa545651c054a105f1c464daca443df846cc6a3d58f764b78c09cff50f0fd9ec2").asBytes();
|
|
|
|
|
|
|
|
String atAddress = Base58.encode(Arrays.copyOfRange(atBytes, 0, 25));
|
|
|
|
byte[] stateHash = Arrays.copyOfRange(atBytes, 25, atBytes.length);
|
|
|
|
|
|
|
|
ATStateData atStateData = new ATStateData(atAddress, height, timestamp, new byte[0], stateHash, atFees);
|
|
|
|
|
|
|
|
repository.getATRepository().save(atStateData);
|
2018-10-04 13:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sequence = 0;
|
|
|
|
|
|
|
|
BlockTransactionData blockTransactionData = new BlockTransactionData(blockSignature, sequence, signature);
|
|
|
|
repository.getBlockRepository().save(blockTransactionData);
|
|
|
|
}
|
|
|
|
|
|
|
|
String actualAddress = transaction.getATAccount().getAddress();
|
|
|
|
|
|
|
|
repository.discardChanges();
|
|
|
|
|
|
|
|
assertEquals(expectedAddress, actualAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|