Commit ea379135 authored by Zhenzhen Zhan's avatar Zhenzhen Zhan
Browse files

Address conversion

parent c8f65827
......@@ -659,20 +659,20 @@ describe('Script', function() {
});
describe('#buildPublicKeyHashOut', function() {
it('should create script from livenet address', function() {
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
var address = Address.fromString('CRWZYSpVnfL4zN3QmCxP9vqEZvHmX8gbhNJm');
var s = Script.buildPublicKeyHashOut(address);
should.exist(s);
s.toString().should.equal('OP_DUP OP_HASH160 20 0xecae7d092947b7ee4998e254aa48900d26d2ce1d OP_EQUALVERIFY OP_CHECKSIG');
s.isPublicKeyHashOut().should.equal(true);
s.toAddress().toString().should.equal('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
s.toAddress().toString().should.equal('CRWZYSpVnfL4zN3QmCxP9vqEZvHmX8gbhNJm');
});
it('should create script from testnet address', function() {
var address = Address.fromString('mxRN6AQJaDi5R6KmvMaEmZGe3n5ScV9u33');
var address = Address.fromString('tCRWVtnuieRvecQGx4XiBGNC2du1mJ7xyNbUM');
var s = Script.buildPublicKeyHashOut(address);
should.exist(s);
s.toString().should.equal('OP_DUP OP_HASH160 20 0xb96b816f378babb1fe585b7be7a2cd16eb99b3e4 OP_EQUALVERIFY OP_CHECKSIG');
s.isPublicKeyHashOut().should.equal(true);
s.toAddress().toString().should.equal('mxRN6AQJaDi5R6KmvMaEmZGe3n5ScV9u33');
s.toAddress().toString().should.equal('tCRWVtnuieRvecQGx4XiBGNC2du1mJ7xyNbUM');
});
it('should create script from public key', function() {
var pubkey = new PublicKey('022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da');
......@@ -739,14 +739,14 @@ describe('Script', function() {
});
it('inherits network property from other script', function() {
var s1 = new Script.fromAddress(new Address('1FSMWkjVPAxzUNjbxT52p3mVKC971rfW3S'));
var s1 = new Script.fromAddress(new Address('CRWSQLqJzwVmemza6EB2epHT3hctkmjuYRQK'));
var s2 = Script.buildScriptHashOut(s1);
should.exist(s1._network);
s1._network.should.equal(s2._network);
});
it('inherits network property form an address', function() {
var address = new Address('CUTW3oos5yjeeBBcqU1oQ6vZPz5jk9Q1AN');
var address = new Address('CRMYXL8wAuhZFdGhZuq4wedEbSETpEt3zhCM');
var script = Script.buildScriptHashOut(address);
should.exist(script._network);
script._network.should.equal(address.network);
......@@ -821,12 +821,12 @@ describe('Script', function() {
data.should.deep.equal(new Buffer(0));
});
it('for a P2PKH address', function() {
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
var address = Address.fromString('CRWZYSpVnfL4zN3QmCxP9vqEZvHmX8gbhNJm');
var script = Script.buildPublicKeyHashOut(address);
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.true();
});
it('for a P2SH address', function() {
var address = Address.fromString('CVyuProFiaWMNphLZESddgeS9WajA3nBKB');
var address = Address.fromString('CRMa3jUzAJLA2L1M5dYqNUrpKJyzKEJGvgbU');
var script = new Script(address);
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.true();
});
......@@ -862,13 +862,13 @@ describe('Script', function() {
script.toAddress().network.should.equal(Networks.defaultNetwork);
});
it('for a P2PKH address', function() {
var stringAddress = '1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14';
var stringAddress = 'CRWZYSpVnfL4zN3QmCxP9vqEZvHmX8gbhNJm';
var address = new Address(stringAddress);
var script = new Script(address);
script.toAddress().toString().should.equal(stringAddress);
});
it('for a P2SH address', function() {
var stringAddress = 'CVyuProFiaWMNphLZESddgeS9WajA3nBKB';
var stringAddress = 'CRMa3jUzAJLA2L1M5dYqNUrpKJyzKEJGvgbU';
var address = new Address(stringAddress);
var script = new Script(address);
script.toAddress().toString().should.equal(stringAddress);
......@@ -881,26 +881,26 @@ describe('Script', function() {
// taken from tx 7e519caca256423320b92e3e17be5701f87afecbdb3f53af598032bfd8d164f5
var script = new Script('OP_DUP OP_HASH160 20 ' +
'0xc8e11b0eb0d2ad5362d894f048908341fa61b6e1 OP_EQUALVERIFY OP_CHECKSIG');
script.toAddress().toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc');
script.toAddress().toString().should.equal('CRWWH98YL3MspPY5SxzJGUkz5eXyZhzUXuh9');
});
it('works for p2pkh input', function() {
// taken from tx 7e519caca256423320b92e3e17be5701f87afecbdb3f53af598032bfd8d164f5
var script = new Script('72 0x3045022100eff96230ca0f55b1e8c7a63e014f48611ff1af40875ecd33dee9062d7a6f5e2002206320405b5f6992c756e03e66b21a05a812b60996464ac6af815c2638b930dd7a01 65 0x04150defa035a2c7d826d7d5fc8ab2154bd1bb832f1a5c8ecb338f436362ad232e428b57db44677c5a8bd42c5ed9e2d7e04e742c59bee1b40080cfd57dec64b23a');
script.toAddress().toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc');
script.toAddress().toString().should.equal('CRWWH98YL3MspPY5SxzJGUkz5eXyZhzUXuh9');
// taken from tx 7f8f95752a59d715dae9e0008a42e7968d2736741591bbfc6685f6e1649c21ed
var s2 = new Script('71 0x3044022017053dad84aa06213749df50a03330cfd24d6b8e7ddbb6de66c03697b78a752a022053bc0faca8b4049fb3944a05fcf7c93b2861734d39a89b73108f605f70f5ed3401 33 0x0225386e988b84248dc9c30f784b06e02fdec57bbdbd443768eb5744a75ce44a4c');
s2.toAddress().toString().should.equal('17VArX6GRE6i6MVscBUZoXwi6NhnHa68B7');
s2.toAddress().toString().should.equal('CRWJTAB5MiXpnVcYrVpm4MGwDvQ5KSuDgsPP');
});
it('works for p2sh output', function() {
// taken from tx fe1f764299dc7f3b5a8fae912050df2b633bf99554c68bf1c456edb9c2b63585
var script = new Script('OP_HASH160 20 0x99d29051af0c29adcb9040034752bba7dde33e35 OP_EQUAL');
script.toAddress().toString().should.equal('CWVECcjWvowBKEHHxks44t7MGi7w9Ci5XS');
script.toAddress().toString().should.equal('CRMaZ4Hk6ZYPT9wkfaxMnuJ1nE7BrSFQq5uZ');
});
it('works for p2sh input', function() {
// taken from tx fe1f764299dc7f3b5a8fae912050df2b633bf99554c68bf1c456edb9c2b63585
var script = new Script('OP_FALSE 72 0x3045022100e824fbe979fac5834d0062dd5a4e82a898e00ac454bd254cd708ad28530816f202206251ff0fa4dd70c0524c690d4e4deb2bd167297e7bbdf6743b4a8050d681555001 37 0x512102ff3ae0aaa4679ea156d5581dbe6695cc0c311df0aa42af76670d0debbd8f672951ae');
script.toAddress().toString().should.equal('CXKbFtoqG1z5QGyYvpqyfdT95wpxeANeV2');
script.toAddress().toString().should.equal('CRMbPRM2AssbW42oMqvRmptm81vRZTmqK7gk');
});
// no address scripts
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment