|
| 1 | +/* |
| 2 | + * Copyright 2018 NEM |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import {deepEqual} from 'assert'; |
| 18 | +import {expect} from 'chai'; |
| 19 | +import {Address} from '../../../src/model/account/Address'; |
| 20 | +import {NetworkType} from '../../../src/model/blockchain/NetworkType'; |
| 21 | +import {MosaicId} from '../../../src/model/mosaic/MosaicId'; |
| 22 | +import {AddressAlias} from '../../../src/model/namespace/AddressAlias'; |
| 23 | +import {Alias} from '../../../src/model/namespace/Alias'; |
| 24 | +import {AliasType} from '../../../src/model/namespace/AliasType'; |
| 25 | +import {EmptyAlias} from '../../../src/model/namespace/EmptyAlias'; |
| 26 | +import {MosaicAlias} from '../../../src/model/namespace/MosaicAlias'; |
| 27 | +import {UInt64} from '../../../src/model/UInt64'; |
| 28 | + |
| 29 | +describe('Alias', () => { |
| 30 | + let emptyAliasDTO; |
| 31 | + let addressAliasDTO; |
| 32 | + let mosaicAliasDTO; |
| 33 | + let address; |
| 34 | + let address2; |
| 35 | + |
| 36 | + before(() => { |
| 37 | + address = Address.createFromRawAddress('SCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPRLIKCF2'); |
| 38 | + address2 = Address.createFromRawAddress('SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP'); |
| 39 | + emptyAliasDTO = { |
| 40 | + type: 0, |
| 41 | + }; |
| 42 | + mosaicAliasDTO = { |
| 43 | + type: AliasType.Mosaic, |
| 44 | + mosaicId: new MosaicId([481110499, 231112638]), |
| 45 | + }; |
| 46 | + addressAliasDTO = { |
| 47 | + type: AliasType.Address, |
| 48 | + address, |
| 49 | + }; |
| 50 | + }); |
| 51 | + |
| 52 | + it('should create an EmptyAlias object', () => { |
| 53 | + const alias = new EmptyAlias(); |
| 54 | + expect(alias.type).to.be.equal(AliasType.None); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should create a AddressAlias object', () => { |
| 58 | + const alias = new AddressAlias(addressAliasDTO.type, addressAliasDTO.address); |
| 59 | + expect(alias.type).to.be.equal(AliasType.Address); |
| 60 | + expect(alias.address).to.be.equal(addressAliasDTO.address); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should create a MosaicAlias object', () => { |
| 64 | + const alias = new MosaicAlias(mosaicAliasDTO.type, mosaicAliasDTO.mosaicId); |
| 65 | + expect(alias.type).to.be.equal(AliasType.Mosaic); |
| 66 | + expect(alias.mosaicId).to.be.equal(mosaicAliasDTO.mosaicId); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should compare addresses in AddressAlias.equals()', () => { |
| 70 | + const alias1 = new AddressAlias(addressAliasDTO.type, addressAliasDTO.address); |
| 71 | + const alias2 = new AddressAlias(addressAliasDTO.type, addressAliasDTO.address); |
| 72 | + const alias3 = new AddressAlias(addressAliasDTO.type, address2); |
| 73 | + |
| 74 | + expect(alias1.equals(alias2)).to.be.equal(true); |
| 75 | + expect(alias1.equals(alias3)).to.be.equal(false); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should compare mosaicIds in MosaicAlias.equals()', () => { |
| 79 | + const alias1 = new MosaicAlias(mosaicAliasDTO.type, mosaicAliasDTO.mosaicId); |
| 80 | + const alias2 = new MosaicAlias(mosaicAliasDTO.type, mosaicAliasDTO.mosaicId); |
| 81 | + const alias3 = new MosaicAlias(mosaicAliasDTO.type, new MosaicId([481110498, 231112637])); |
| 82 | + |
| 83 | + expect(alias1.equals(alias2)).to.be.equal(true); |
| 84 | + expect(alias1.equals(alias3)).to.be.equal(false); |
| 85 | + }); |
| 86 | +}); |
0 commit comments