From 9198be6558588b8e4e3e65c47e3495994e14442f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 30 Oct 2019 12:19:33 +0000 Subject: [PATCH 1/2] Fixed #323 --- src/model/transaction/SecretLockTransaction.ts | 18 ++++++++++-------- .../transaction/SecretProofTransaction.ts | 12 +++++++----- src/service/MetadataTransactionService.ts | 4 +++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index e95d1b40a4..2472e5d93b 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import { Convert, Convert as convert, RawAddress } from '../../core/format'; +import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -30,6 +31,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; import { MosaicId } from '../mosaic/MosaicId'; +import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; @@ -49,7 +51,7 @@ export class SecretLockTransaction extends Transaction { * @param duration - The funds lock duration. * @param hashType - The hash algorithm secret is generated with. * @param secret - The proof hashed. - * @param recipientAddress - The recipient address of the funds. + * @param recipientAddress - The unresolved recipient address of the funds. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender * @@ -60,7 +62,7 @@ export class SecretLockTransaction extends Transaction { duration: UInt64, hashType: HashType, secret: string, - recipientAddress: Address, + recipientAddress: Address | NamespaceId, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): SecretLockTransaction { return new SecretLockTransaction( @@ -111,9 +113,9 @@ export class SecretLockTransaction extends Transaction { */ public readonly secret: string, /** - * The recipientAddress of the funds. + * The unresolved recipientAddress of the funds. */ - public readonly recipientAddress: Address, + public readonly recipientAddress: Address | NamespaceId, signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { @@ -139,13 +141,13 @@ export class SecretLockTransaction extends Transaction { isEmbedded ? Deadline.create() : Deadline.createFromDTO( (builder as SecretLockTransactionBuilder).getDeadline().timestamp), new Mosaic( - new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + UnresolvedMapping.toUnresolvedMosaic(new UInt64(builder.getMosaic().mosaicId.unresolvedMosaicId).toHex()), new UInt64(builder.getMosaic().amount.amount), ), new UInt64(builder.getDuration().blockDuration), builder.getHashAlgorithm().valueOf(), Convert.uint8ToHex(builder.getSecret().hash256), - Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)), + UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretLockTransactionBuilder).fee.amount), ); @@ -204,7 +206,7 @@ export class SecretLockTransaction extends Transaction { new BlockDurationDto(this.duration.toDTO()), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), ); return transactionBuilder.serialize(); } @@ -223,7 +225,7 @@ export class SecretLockTransaction extends Transaction { new BlockDurationDto(this.duration.toDTO()), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), ); return transactionBuilder.serialize(); } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 60a365616a..9700eb2dee 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -15,6 +15,7 @@ */ import { Convert, Convert as convert, RawAddress } from '../../core/format'; +import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; @@ -26,6 +27,7 @@ import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedA import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; +import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; @@ -53,7 +55,7 @@ export class SecretProofTransaction extends Transaction { public static create(deadline: Deadline, hashType: HashType, secret: string, - recipientAddress: Address, + recipientAddress: Address | NamespaceId, proof: string, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): SecretProofTransaction { @@ -88,7 +90,7 @@ export class SecretProofTransaction extends Transaction { maxFee: UInt64, public readonly hashType: HashType, public readonly secret: string, - public readonly recipientAddress: Address, + public readonly recipientAddress: Address | NamespaceId, public readonly proof: string, signature?: string, signer?: PublicAccount, @@ -116,7 +118,7 @@ export class SecretProofTransaction extends Transaction { (builder as SecretProofTransactionBuilder).getDeadline().timestamp), builder.getHashAlgorithm().valueOf(), Convert.uint8ToHex(builder.getSecret().hash256), - Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)), + UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)), Convert.uint8ToHex(builder.getProof()), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretProofTransactionBuilder).fee.amount), @@ -181,7 +183,7 @@ export class SecretProofTransaction extends Transaction { new TimestampDto(this.deadline.toDTO()), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), this.getProofByte(), ); return transactionBuilder.serialize(); @@ -198,7 +200,7 @@ export class SecretProofTransaction extends Transaction { TransactionType.SECRET_PROOF.valueOf(), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), this.getProofByte(), ); return transactionBuilder.serialize(); diff --git a/src/service/MetadataTransactionService.ts b/src/service/MetadataTransactionService.ts index 557c07f72a..17d31b6448 100644 --- a/src/service/MetadataTransactionService.ts +++ b/src/service/MetadataTransactionService.ts @@ -55,6 +55,7 @@ export class MetadataTransactionService { * @param senderPublicAccount - sender (signer) public account * @param targetId - Target Id (MosaicId | NamespaceId) * @param maxFee - Max fee + * @return {AccountMetadataTransaction | MosaicMetadataTransaction | NamespaceMetadataTransaction} */ public createMetadataTransaction(deadline: Deadline, networkType: NetworkType, @@ -64,7 +65,8 @@ export class MetadataTransactionService { value: string, senderPublicAccount: PublicAccount, targetId?: MosaicId | NamespaceId, - maxFee: UInt64 = new UInt64([0, 0])): Observable { + maxFee: UInt64 = new UInt64([0, 0])): + Observable { switch (metadataType) { case MetadataType.Account: return this.createAccountMetadataTransaction( From e51d7043297e9009b2803d053fa0c1c4c6ec890e Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 30 Oct 2019 14:07:34 +0000 Subject: [PATCH 2/2] updated transaction mapping --- .../transaction/CreateTransactionFromDTO.ts | 9 +-- .../transaction/SerializeTransactionToJSON.ts | 2 +- .../transaction/SecretLockTransaction.ts | 4 +- .../transaction/SecretProofTransaction.ts | 4 +- test/core/utils/TransactionMapping.spec.ts | 73 ++++++++++++++++++- test/core/utils/UnresolvedMapping.spec.ts | 2 +- .../transaction/SecretLockTransaction.spec.ts | 21 ++++++ .../SecretProofTransaction.spec.ts | 18 +++++ 8 files changed, 120 insertions(+), 13 deletions(-) diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 33511e4437..2085ede09a 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -218,17 +218,17 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr ); } else if (transactionDTO.type === TransactionType.SECRET_LOCK) { const recipientAddress = transactionDTO.recipientAddress; + const mosaicId = UnresolvedMapping.toUnresolvedMosaic(transactionDTO.mosaicId); return new SecretLockTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), - new Mosaic(new MosaicId(transactionDTO.mosaicId), UInt64.fromNumericString(transactionDTO.amount)), + new Mosaic(mosaicId, UInt64.fromNumericString(transactionDTO.amount)), UInt64.fromNumericString(transactionDTO.duration), transactionDTO.hashAlgorithm, transactionDTO.secret, - typeof recipientAddress === 'object' && recipientAddress.hasOwnProperty('address') ? - Address.createFromRawAddress(recipientAddress.address) : Address.createFromEncoded(recipientAddress), + extractRecipient(recipientAddress), transactionDTO.signature, transactionDTO.signerPublicKey ? PublicAccount.createFromPublicKey(transactionDTO.signerPublicKey, extractNetworkType(transactionDTO.version)) : undefined, @@ -243,8 +243,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.hashAlgorithm, transactionDTO.secret, - typeof recipientAddress === 'object' && recipientAddress.hasOwnProperty('address') ? - Address.createFromRawAddress(recipientAddress.address) : Address.createFromEncoded(recipientAddress), + extractRecipient(recipientAddress), transactionDTO.proof, transactionDTO.signature, transactionDTO.signerPublicKey ? PublicAccount.createFromPublicKey(transactionDTO.signerPublicKey, diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 5e6a824385..cad83dfd6a 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -144,7 +144,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { return jsonObject; case TransactionType.SECRET_LOCK: return { - mosaicId: (transaction as SecretLockTransaction).mosaic.id.id, + mosaicId: (transaction as SecretLockTransaction).mosaic.id.id.toHex(), amount: (transaction as SecretLockTransaction).mosaic.amount.toString(), duration: (transaction as SecretLockTransaction).duration.toString(), hashAlgorithm: (transaction as SecretLockTransaction).hashType, diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 2472e5d93b..8c0ec0c49e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -206,7 +206,7 @@ export class SecretLockTransaction extends Transaction { new BlockDurationDto(this.duration.toDTO()), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), ); return transactionBuilder.serialize(); } @@ -225,7 +225,7 @@ export class SecretLockTransaction extends Transaction { new BlockDurationDto(this.duration.toDTO()), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), ); return transactionBuilder.serialize(); } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 9700eb2dee..dd78629485 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -183,7 +183,7 @@ export class SecretProofTransaction extends Transaction { new TimestampDto(this.deadline.toDTO()), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), this.getProofByte(), ); return transactionBuilder.serialize(); @@ -200,7 +200,7 @@ export class SecretProofTransaction extends Transaction { TransactionType.SECRET_PROOF.valueOf(), this.hashType.valueOf(), new Hash256Dto(this.getSecretByte()), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)), + new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), this.getProofByte(), ); return transactionBuilder.serialize(); diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d47d1de640..3eaf17ebe5 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -66,6 +66,7 @@ import { TransactionType } from '../../../src/model/transaction/TransactionType' import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; +import { Mosaic } from '../../../src/model/model'; describe('TransactionMapping - createFromPayload', () => { let account: Account; @@ -361,7 +362,7 @@ describe('TransactionMapping - createFromPayload', () => { expect(transaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(transaction.hashType).to.be.equal(0); expect(transaction.secret).to.be.equal('9B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E'); - expect(transaction.recipientAddress.plain()).to.be.equal(recipientAddress.plain()); + expect((transaction.recipientAddress as Address).plain()).to.be.equal(recipientAddress.plain()); }); @@ -382,7 +383,7 @@ describe('TransactionMapping - createFromPayload', () => { expect(secretProofTransaction.hashType).to.be.equal(0); expect(secretProofTransaction.secret).to.be.equal('9b3155b37159da50aa52d5967c509b410f5a36a3b1e31ecb5ac76675d79b4a5e' ); expect(secretProofTransaction.proof).to.be.equal(proof); - expect(secretProofTransaction.recipientAddress.plain()).to.be.equal(account.address.plain()); + expect((secretProofTransaction.recipientAddress as Address).plain()).to.be.equal(account.address.plain()); }); @@ -902,6 +903,51 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => }); + it('should create SecretLockTransaction - Address alias', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipientAddress = new NamespaceId('test'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + NetworkCurrencyMosaic.createAbsolute(10), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(Convert.hexToUint8(proof)).hex(), + recipientAddress, + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(secretLockTransaction.toJSON()) as SecretLockTransaction; + + expect(transaction.type).to.be.equal(TransactionType.SECRET_LOCK); + expect(transaction.hashType).to.be.equal(HashType.Op_Sha3_256); + expect((transaction.recipientAddress as NamespaceId).id.toHex()).to.be.equal(recipientAddress.toHex()); + + }); + + it('should create SecretLockTransaction - resolved Mosaic', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const mosaicId = new NamespaceId('test'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + new Mosaic(new MosaicId([1, 1]), UInt64.fromUint(10)), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(Convert.hexToUint8(proof)).hex(), + recipientAddress, + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(secretLockTransaction.toJSON()) as SecretLockTransaction; + + expect(transaction.type).to.be.equal(TransactionType.SECRET_LOCK); + expect(transaction.hashType).to.be.equal(HashType.Op_Sha3_256); + expect(transaction.mosaic.id.toHex()).to.be.equal((new MosaicId([1, 1])).toHex()); + + }); + it('should create SecretProofTransaction', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; const secretProofTransaction = SecretProofTransaction.create( @@ -924,6 +970,29 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => }); + it('should create SecretProofTransaction - Address alias', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipientAddress = new NamespaceId('test'); + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Sha3_256, + sha3_256.create().update(Convert.hexToUint8(proof)).hex(), + recipientAddress, + proof, + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(secretProofTransaction.toJSON()) as SecretProofTransaction; + + expect(transaction.type).to.be.equal(TransactionType.SECRET_PROOF); + expect(transaction.hashType).to.be.equal(HashType.Op_Sha3_256); + expect(transaction.secret).to.be.equal(sha3_256.create().update(Convert.hexToUint8(proof)).hex()); + expect(transaction.proof).to.be.equal(proof); + expect((transaction.recipientAddress as NamespaceId).id.toHex()).to.be.equal(recipientAddress.toHex()); + + }); + it('should create ModifyMultiSigTransaction', () => { const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( Deadline.create(), diff --git a/test/core/utils/UnresolvedMapping.spec.ts b/test/core/utils/UnresolvedMapping.spec.ts index adad2f7098..19b64d1373 100644 --- a/test/core/utils/UnresolvedMapping.spec.ts +++ b/test/core/utils/UnresolvedMapping.spec.ts @@ -17,9 +17,9 @@ import { expect } from 'chai'; import { Convert, RawAddress } from '../../../src/core/format'; import { UnresolvedMapping } from '../../../src/core/utils/UnresolvedMapping'; import { Address } from '../../../src/model/account/Address'; +import { NetworkType } from "../../../src/model/blockchain/NetworkType"; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; -import { NetworkType } from "../../../src/model/blockchain/NetworkType"; describe('UnresolvedMapping', () => { let mosaicId: MosaicId; diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index e6ce810ca8..2b9aebd2ab 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -22,6 +22,7 @@ import { Account } from '../../../src/model/account/Account'; import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashType} from '../../../src/model/transaction/HashType'; import {SecretLockTransaction} from '../../../src/model/transaction/SecretLockTransaction'; @@ -245,4 +246,24 @@ describe('SecretLockTransaction', () => { expect(Convert.hexToUint8(secretLockTransaction.serialize()).length).to.be.equal(secretLockTransaction.size); }); }); + + it('should be created with alias address', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipientAddress = new NamespaceId('test'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + NetworkCurrencyMosaic.createAbsolute(10), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + recipientAddress, + NetworkType.MIJIN_TEST, + ); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); + expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); + expect(secretLockTransaction.hashType).to.be.equal(0); + expect(secretLockTransaction.secret).to.be.equal('9b3155b37159da50aa52d5967c509b410f5a36a3b1e31ecb5ac76675d79b4a5e'); + expect(secretLockTransaction.recipientAddress).to.be.equal(recipientAddress); + }); }); diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index b2170b4b50..1e3f401629 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -19,6 +19,7 @@ import {keccak_256, sha3_256} from 'js-sha3'; import {Convert, Convert as convert} from '../../../src/core/format'; import { Account } from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashType} from '../../../src/model/transaction/HashType'; import {SecretProofTransaction} from '../../../src/model/transaction/SecretProofTransaction'; @@ -212,4 +213,21 @@ describe('SecretProofTransaction', () => { '009B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E90A75B6B63D31BDA938' + '08727940F24699AECDDF17C568508BA2000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'); }); + + it('should be created with alias address', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipientAddress = new NamespaceId('test'); + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + recipientAddress, + proof, + NetworkType.MIJIN_TEST, + ); + expect(secretProofTransaction.hashType).to.be.equal(0); + expect(secretProofTransaction.secret).to.be.equal('9b3155b37159da50aa52d5967c509b410f5a36a3b1e31ecb5ac76675d79b4a5e' ); + expect(secretProofTransaction.proof).to.be.equal(proof); + expect(secretProofTransaction.recipientAddress).to.be.equal(recipientAddress); + }); });