Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/infrastructure/transaction/CreateTransactionFromDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,25 @@ const extractTransactionMeta = (meta: any, id: string): TransactionInfo | Aggreg
return undefined;
}
if (meta.aggregateHash || meta.aggregateId) {
return new AggregateTransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id, meta.aggregateHash, meta.aggregateId);
return new AggregateTransactionInfo(
UInt64.fromNumericString(meta.height),
meta.index,
id,
UInt64.fromNumericString(meta.timestamp),
meta.feeMultiplier,
meta.aggregateHash,
meta.aggregateId,
);
}
return new TransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id, meta.hash, meta.merkleComponentHash);
return new TransactionInfo(
UInt64.fromNumericString(meta.height),
meta.index,
id,
UInt64.fromNumericString(meta.timestamp),
meta.feeMultiplier,
meta.hash,
meta.merkleComponentHash,
);
};
/**
* @internal
Expand Down
6 changes: 5 additions & 1 deletion src/model/transaction/AggregateTransactionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ export class AggregateTransactionInfo extends TransactionInfo {
* @param id
* @param aggregateHash
* @param aggregateId
* @param timestamp
* @param feeMultiplier
*/
constructor(
height: UInt64,
index: number,
id: string,
timestamp: UInt64,
feeMultiplier: number,
/**
* The hash of the aggregate transaction.
*/
Expand All @@ -41,6 +45,6 @@ export class AggregateTransactionInfo extends TransactionInfo {
*/
public readonly aggregateId: string,
) {
super(height, index, id);
super(height, index, id, timestamp, feeMultiplier);
}
}
10 changes: 10 additions & 0 deletions src/model/transaction/TransactionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class TransactionInfo {
* @param height
* @param index
* @param id
* @param timestamp
* @param feeMultiplier
* @param hash
* @param merkleComponentHash
*/
Expand All @@ -40,6 +42,14 @@ export class TransactionInfo {
* The transaction db id.
*/
public readonly id: string,
/**
* The transaction timestamp.
*/
public readonly timestamp?: UInt64,
/**
* The transaction fee multiplier.
*/
public readonly feeMultiplier?: number,
/**
* The transaction hash.
*/
Expand Down
37 changes: 26 additions & 11 deletions test/infrastructure/Listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('Listener', () => {
);
const transferTransactionDTO = transferTransaction.toJSON();
const hash = 'abc';
transferTransactionDTO.meta = { height: '1', hash: hash };
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };

const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMultisigMock, multisigRepo);
listener.open();
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('Listener', () => {
);
const transferTransactionDTO = transferTransaction.toJSON();
const hash = 'abc';
transferTransactionDTO.meta = { height: '1', hash: hash };
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };

const reportedTransactions: Transaction[] = [];
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMockAlias);
Expand All @@ -334,7 +334,10 @@ describe('Listener', () => {
listener.handleMessage(
{
topic: name.toString(),
data: { meta: { height: '2', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
data: {
meta: { height: '2', hash: 'new hash', timestamp: '2', feeMultiplier: 1 },
transaction: transferTransactionDTO.transaction,
},
},
null,
);
Expand All @@ -360,7 +363,7 @@ describe('Listener', () => {
const transferTransactionDTO = transferTransaction.toJSON();
const hash = 'abc';
const hash2 = 'abc2';
transferTransactionDTO.meta = { height: '1', hash: hash };
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };

const reportedTransactions: Transaction[] = [];
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMock);
Expand All @@ -379,7 +382,10 @@ describe('Listener', () => {
listener.handleMessage(
{
topic: name.toString(),
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
data: {
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
transaction: transferTransactionDTO.transaction,
},
},
null,
);
Expand All @@ -399,7 +405,7 @@ describe('Listener', () => {
);
const transferTransactionDTO = transferTransaction.toJSON();
const hash = 'abc';
transferTransactionDTO.meta = { height: '1', hash: hash };
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };

const reportedTransactions: Transaction[] = [];
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMockAlias);
Expand All @@ -418,7 +424,10 @@ describe('Listener', () => {
listener.handleMessage(
{
topic: name.toString(),
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
data: {
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
transaction: transferTransactionDTO.transaction,
},
},
null,
);
Expand All @@ -438,7 +447,7 @@ describe('Listener', () => {
);
const transferTransactionDTO = transferTransaction.toJSON();
const hash = 'abc';
transferTransactionDTO.meta = { height: '1', hash: hash };
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };

const reportedTransactions: Transaction[] = [];

Expand All @@ -458,7 +467,10 @@ describe('Listener', () => {
listener.handleMessage(
{
topic: name.toString(),
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
data: {
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
transaction: transferTransactionDTO.transaction,
},
},
null,
);
Expand Down Expand Up @@ -487,7 +499,7 @@ describe('Listener', () => {
);
const transferTransactionDTO = transferTransaction.toJSON();
const hash = 'abc';
transferTransactionDTO.meta = { height: '1', hash: hash };
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };

const reportedTransactions: Transaction[] = [];

Expand All @@ -507,7 +519,10 @@ describe('Listener', () => {
listener.handleMessage(
{
topic: name.toString(),
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
data: {
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
transaction: transferTransactionDTO.transaction,
},
},
null,
);
Expand Down
15 changes: 14 additions & 1 deletion test/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ describe('TransactionHttp', () => {
metaDto.hash = 'hash';
metaDto.height = '1';
metaDto.index = 0;
metaDto.timestamp = '0';
metaDto.feeMultiplier = 0;
metaDto.merkleComponentHash = 'merkleHash';

const transactionDto = {} as TransferTransactionDTO;
Expand Down Expand Up @@ -186,6 +188,8 @@ describe('TransactionHttp', () => {
expect(((transactions.data[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
expect(transactions.data[0].transactionInfo?.id).to.be.equal('id');
expect(transactions.data[0].transactionInfo?.hash).to.be.equal('hash');
expect(transactions.data[0].transactionInfo?.timestamp?.toString()).to.be.equal('0');
expect(transactions.data[0].transactionInfo?.feeMultiplier).to.be.equal(0);

expect(transactions.pageNumber).to.be.equal(1);
expect(transactions.pageSize).to.be.equal(1);
Expand Down Expand Up @@ -219,6 +223,8 @@ describe('TransactionHttp', () => {
metaDto.hash = 'hash';
metaDto.height = '1';
metaDto.index = 0;
metaDto.timestamp = '0';
metaDto.feeMultiplier = 0;
metaDto.merkleComponentHash = 'merkleHash';

const transactionDto = {} as TransferTransactionDTO;
Expand All @@ -245,14 +251,15 @@ describe('TransactionHttp', () => {
expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
expect(transaction.transactionInfo?.id).to.be.equal('id');
expect(transaction.transactionInfo?.hash).to.be.equal('hash');
expect(transaction.transactionInfo?.timestamp?.toString()).to.be.equal('0');
expect(transaction.transactionInfo?.feeMultiplier).to.be.equal(0);

transaction = await firstValueFrom(transactionHttp.getTransaction(generationHash, TransactionGroup.Partial));

expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf());
expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
expect(transaction.transactionInfo?.id).to.be.equal('id');
expect(transaction.transactionInfo?.hash).to.be.equal('hash');

transaction = await firstValueFrom(transactionHttp.getTransaction(generationHash, TransactionGroup.Unconfirmed));

expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf());
Expand All @@ -267,6 +274,8 @@ describe('TransactionHttp', () => {
metaDto.hash = 'hash';
metaDto.height = '1';
metaDto.index = 0;
metaDto.timestamp = '0';
metaDto.feeMultiplier = 0;
metaDto.merkleComponentHash = 'merkleHash';

const transactionDto = {} as TransferTransactionDTO;
Expand Down Expand Up @@ -309,6 +318,8 @@ describe('TransactionHttp', () => {
expect(((transactionConfirmed[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
expect(transactionConfirmed[0].transactionInfo?.id).to.be.equal('id');
expect(transactionConfirmed[0].transactionInfo?.hash).to.be.equal('hash');
expect(transactionConfirmed[0].transactionInfo?.timestamp?.toString()).to.be.equal('0');
expect(transactionConfirmed[0].transactionInfo?.feeMultiplier).to.be.equal(0);

expect(transactionUnconfirmed.length).to.be.equal(1);
expect(transactionUnconfirmed[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf());
Expand All @@ -330,6 +341,8 @@ describe('TransactionHttp', () => {
metaDto.height = '1';
metaDto.index = 0;
metaDto.merkleComponentHash = 'merkleHash';
metaDto.timestamp = '0';
metaDto.feeMultiplier = 0;

const transactionDto = {} as TransferTransactionDTO;
transactionDto.deadline = '1';
Expand Down
Loading