|
| 1 | +/* |
| 2 | + * Copyright 2019 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 {Recipient} from '../../../src/model/account/Recipient'; |
| 21 | +import {Id} from '../../../src/model/Id'; |
| 22 | +import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; |
| 23 | + |
| 24 | +describe('Recipient', () => { |
| 25 | + it('should be created with address given Address value', () => { |
| 26 | + const recipient = new Recipient(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC')); |
| 27 | + expect(recipient.value).to.be.instanceof(Address); |
| 28 | + expect((recipient.value as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should be created with namespaceId given NamespaceId value', () => { |
| 32 | + const recipient = new Recipient(new NamespaceId('nem')); |
| 33 | + expect(recipient.value).to.be.instanceof(NamespaceId); |
| 34 | + expect((recipient.value as NamespaceId).toHex()).to.be.equal('84b3552d375ffa4b'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should be created with address given encoded address recipient', () => { |
| 38 | + const recipient = Recipient.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); |
| 39 | + const expectAddress = 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'; |
| 40 | + |
| 41 | + expect(recipient.value).to.be.instanceof(Address); |
| 42 | + expect((recipient.value as Address).plain()).to.be.equal(expectAddress); |
| 43 | + }); |
| 44 | + |
| 45 | + const ns_vectors = [ |
| 46 | + {name: 'nem', encoded: '914BFA5F372D55B38400000000000000000000000000000000'}, |
| 47 | + {name: 'nem.owner', encoded: '9151776168D24257D800000000000000000000000000000000'}, |
| 48 | + ]; |
| 49 | + |
| 50 | + it('should be created with namespaceId given encoded namespaceId recipient', () => { |
| 51 | + ns_vectors.map(({name, encoded}) => { |
| 52 | + const recipient = Recipient.createFromEncoded(encoded); |
| 53 | + const expectNamespaceId = new NamespaceId(name); |
| 54 | + |
| 55 | + expect(recipient.value).to.be.instanceof(NamespaceId); |
| 56 | + expect((recipient.value as NamespaceId).toHex()).to.be.equal(expectNamespaceId.toHex()); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + const addr_vectors = [ |
| 61 | + { |
| 62 | + address: 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC', |
| 63 | + encoded: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', |
| 64 | + }, |
| 65 | + { |
| 66 | + address: 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDFG', |
| 67 | + encoded: '6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6', |
| 68 | + }, |
| 69 | + ]; |
| 70 | + |
| 71 | + it('should be created with namespaceId given encoded namespaceId recipient', () => { |
| 72 | + addr_vectors.map(({address, encoded}) => { |
| 73 | + const recipient = Recipient.createFromEncoded(encoded); |
| 74 | + const expectAddress = Address.createFromRawAddress(address); |
| 75 | + |
| 76 | + expect(recipient.value).to.be.instanceof(Address); |
| 77 | + expect((recipient.value as Address).plain()).to.be.equal(expectAddress.plain()); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should compare and return false for equals with different types', () => { |
| 82 | + const recipient1 = Recipient.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); |
| 83 | + const recipient2 = Recipient.createFromEncoded('914BFA5F372D55B38400000000000000000000000000000000'); |
| 84 | + expect(recipient1.equals(recipient2)).to.be.equal(false); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should compare and return false for equals with different values of type address', () => { |
| 88 | + const recipient1 = Recipient.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); |
| 89 | + const recipient2 = Recipient.createFromEncoded('6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6'); |
| 90 | + expect(recipient1.value).to.be.instanceof(Address); |
| 91 | + expect(recipient2.value).to.be.instanceof(Address); |
| 92 | + expect(recipient1.equals(recipient2)).to.be.equal(false); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should compare and return false for equals with different values of type namespaceId', () => { |
| 96 | + const recipient1 = Recipient.createFromEncoded('914BFA5F372D55B38400000000000000000000000000000000'); |
| 97 | + const recipient2 = Recipient.createFromEncoded('9151776168D24257D800000000000000000000000000000000'); |
| 98 | + expect(recipient1.value).to.be.instanceof(NamespaceId); |
| 99 | + expect(recipient2.value).to.be.instanceof(NamespaceId); |
| 100 | + expect(recipient1.equals(recipient2)).to.be.equal(false); |
| 101 | + }); |
| 102 | +}); |
0 commit comments