Skip to content

Commit

Permalink
[explorer] fix: Added mosaic names, and unresolved mosaic map params …
Browse files Browse the repository at this point in the history
…in CreateTransaction method
  • Loading branch information
AnthonyLaw committed Jul 25, 2024
1 parent 02243ad commit b28d0d4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
70 changes: 68 additions & 2 deletions __tests__/infrastructure/TransactionService.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Helper from '../../src/helper';
import { LockService, TransactionService } from '../../src/infrastructure';
import { CreateTransaction, LockService, TransactionService } from '../../src/infrastructure';
import http from '../../src/infrastructure/http';
import TestHelper from '../TestHelper';
import { restore, stub } from 'sinon';
import { MosaicId, TransactionGroup, UInt64 } from 'symbol-sdk';
import { Account, MosaicId, NetworkType, TransactionGroup, UInt64 } from 'symbol-sdk';

describe('Transaction Service', () => {
afterEach(restore);
Expand Down Expand Up @@ -321,4 +321,70 @@ describe('Transaction Service', () => {
});
});
});

describe('createStandaloneTransactionFromSDK', () => {
const commonTransactionDTO = {
deadline: {
adjustedValue: 8266897456
},
maxFee: UInt64.fromUint(1000000),
signer: {
address: Account.generateNewAccount(NetworkType.TEST_NET).address
},
transactionInfo: {}
};

const assertTransactionCreation = async (transactionType, transactionTypeName, expectedParams) => {
// Arrange:
const mockTransactionDTO = {
...commonTransactionDTO,
type: transactionType
};

jest.spyOn(CreateTransaction, transactionTypeName).mockResolvedValue();

// Act:
await TransactionService.createStandaloneTransactionFromSDK(mockTransactionDTO, {
mosaicInfos: [],
mosaicNames: [],
unresolvedMosaicsMap: {}
});

// Assert:
expect(CreateTransaction[transactionTypeName]).toHaveBeenCalledWith({
deadline: 1646115744,
maxFee: '1.000000',
signer: mockTransactionDTO.signer.address.plain(),
transactionInfo: {},
transactionType: transactionType,
type: transactionType
}, expectedParams);
};

it('called mosaic definition', async () => {
await assertTransactionCreation(16717, 'mosaicDefinition', {
unresolvedMosaicsMap: {}
});
});

it('called mosaic supply change', async () => {
await assertTransactionCreation(16973, 'mosaicSupplyChange', {
unresolvedMosaicsMap: {}
});
});

it('called mosaic address restriction', async () => {
await assertTransactionCreation(16977, 'mosaicAddressRestriction', {
mosaicNames: [],
unresolvedMosaicsMap: {}
});
});

it('called mosaic metadata', async () => {
await assertTransactionCreation(16964, 'mosaicMetadata', {
mosaicNames: [],
unresolvedMosaicsMap: {}
});
});
});
});
22 changes: 16 additions & 6 deletions src/infrastructure/TransactionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,13 @@ class TransactionService {
case TransactionType.MOSAIC_ALIAS:
return CreateTransaction.mosaicAlias(transactionObj);
case TransactionType.MOSAIC_DEFINITION:
return CreateTransaction.mosaicDefinition(transactionObj);
return CreateTransaction.mosaicDefinition(transactionObj, {
unresolvedMosaicsMap
});
case TransactionType.MOSAIC_SUPPLY_CHANGE:
return CreateTransaction.mosaicSupplyChange(transactionObj);
return CreateTransaction.mosaicSupplyChange(transactionObj, {
unresolvedMosaicsMap
});
case TransactionType.MOSAIC_SUPPLY_REVOCATION:
return CreateTransaction.mosaicSupplyRevocation(transactionObj, {
mosaicInfos,
Expand Down Expand Up @@ -713,13 +717,19 @@ class TransactionService {
case TransactionType.ACCOUNT_OPERATION_RESTRICTION:
return CreateTransaction.accountOperationRestriction(transactionObj);
case TransactionType.MOSAIC_ADDRESS_RESTRICTION:
return CreateTransaction.mosaicAddressRestriction(transactionObj);
return CreateTransaction.mosaicAddressRestriction(transactionObj, {
mosaicNames,
unresolvedMosaicsMap
});
case TransactionType.MOSAIC_GLOBAL_RESTRICTION:
return CreateTransaction.mosaicGlobalRestriction(transactionObj);
case TransactionType.ACCOUNT_METADATA:
return CreateTransaction.accountMetadata(transactionObj);
case TransactionType.MOSAIC_METADATA:
return CreateTransaction.mosaicMetadata(transactionObj);
return CreateTransaction.mosaicMetadata(transactionObj, {
mosaicNames,
unresolvedMosaicsMap
});
case TransactionType.NAMESPACE_METADATA:
return CreateTransaction.namespaceMetadata(transactionObj);
case TransactionType.VOTING_KEY_LINK:
Expand All @@ -746,7 +756,7 @@ class TransactionService {
transactionDTO.type === TransactionType.AGGREGATE_COMPLETE
) {
const { mosaicInfos, mosaicNames, unresolvedMosaicsMap } =
await helper.getTransactionMosaicInfoAndNamespace(transactionDTO.innerTransactions);
await helper.getTransactionMosaicInfoAndNamespace(transactionDTO);

const innerTransactions = transactionDTO.innerTransactions
? await Promise.all(transactionDTO.innerTransactions.map(async (transaction, index) => {
Expand Down Expand Up @@ -783,7 +793,7 @@ class TransactionService {
};
} else {
const { mosaicInfos, mosaicNames, unresolvedMosaicsMap } =
await helper.getTransactionMosaicInfoAndNamespace([transactionDTO]);
await helper.getTransactionMosaicInfoAndNamespace(transactionDTO);

return this.createStandaloneTransactionFromSDK(transactionDTO, {
mosaicInfos,
Expand Down

0 comments on commit b28d0d4

Please sign in to comment.