Browse Source

fix uri tests

master
matiu 7 years ago
parent
commit
d5f287fc6b
  1. 26
      test/script/script.js
  2. 68
      test/uri.js

26
test/script/script.js

@ -659,12 +659,12 @@ describe('Script', function() {
});
describe('#buildPublicKeyHashOut', function() {
it('should create script from livenet address', function() {
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
var address = Address.fromString('Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU');
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('Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU');
});
it('should create script from testnet address', function() {
var address = Address.fromString('mxRN6AQJaDi5R6KmvMaEmZGe3n5ScV9u33');
@ -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('CWuF5o5ZGDwXNWe2eCPxPZPWwKMWuiixY2'));
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('34Nn91aTGaULqWsZiunrBPHzFBDrZ3B8XS');
var address = new Address('H9Ctbp1Y7th1TgkbabT19mpXGqEsTXggJE');
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('Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU');
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('3GhtMmAbWrUf6Y8vDxn9ETB14R6V7Br3mt');
var address = Address.fromString('HMXzpZbgNAhKii1x5eSJCqhY657VyZgNb5');
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 = 'Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU';
var address = new Address(stringAddress);
var script = new Script(address);
script.toAddress().toString().should.equal(stringAddress);
});
it('for a P2SH address', function() {
var stringAddress = '3GhtMmAbWrUf6Y8vDxn9ETB14R6V7Br3mt';
var stringAddress = 'HMXzpZbgNAhKii1x5eSJCqhY657VyZgNb5';
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('Can3P2Qf8L78v1zmTU1cs6RTrQATGLYZY4');
});
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('Can3P2Qf8L78v1zmTU1cs6RTrQATGLYZY4');
// taken from tx 7f8f95752a59d715dae9e0008a42e7968d2736741591bbfc6685f6e1649c21ed
var s2 = new Script('71 0x3044022017053dad84aa06213749df50a03330cfd24d6b8e7ddbb6de66c03697b78a752a022053bc0faca8b4049fb3944a05fcf7c93b2861734d39a89b73108f605f70f5ed3401 33 0x0225386e988b84248dc9c30f784b06e02fdec57bbdbd443768eb5744a75ce44a4c');
s2.toAddress().toString().should.equal('17VArX6GRE6i6MVscBUZoXwi6NhnHa68B7');
s2.toAddress().toString().should.equal('CNx4RZSLJH5EzVQJHvoVP3ZjiVvCC6Eog1');
});
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('3FiMZ7stbfH2WG5JQ7CiuzrFo7CEnGUcAP');
script.toAddress().toString().should.equal('HLYU1vJySyVh8RxLFnrstPNnpmDFe7fiir');
});
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('3GYicPxCvsKvbJmZNBBeWkC3cLuGFhtrQi');
script.toAddress().toString().should.equal('HMNq5CPHnBYbDUebDrqoV8iadzvHBw7bJP');
});
// no address scripts

68
test/uri.js

@ -21,19 +21,19 @@ describe('URI', function() {
expect(uri.amount).to.be.undefined();
expect(uri.otherParam).to.be.undefined();
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
expect(uri.amount).to.be.undefined();
expect(uri.otherParam).to.be.undefined();
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22');
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.amount.should.equal('123.22');
expect(uri.otherParam).to.be.undefined();
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22' +
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22' +
'&other-param=something&req-extra=param');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.amount.should.equal('123.22');
uri['other-param'].should.equal('something');
uri['req-extra'].should.equal('param');
@ -41,14 +41,14 @@ describe('URI', function() {
// TODO: Split this and explain tests
it('URIs can be validated statically (test vector)', function() {
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj').should.equal(true);
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk').should.equal(true);
URI.isValid('bitcoin:mkYY5NRvikVBY1EPtaq9fAFgquesdjqECw').should.equal(true);
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2')
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2')
.should.equal(true);
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param')
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param')
.should.equal(true);
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&req-other=param',
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&req-other=param',
['req-other']).should.equal(true);
URI.isValid('bitcoin:mmrqEBJxUCf42vdb3oozZtyz5mKr3Vb2Em?amount=0.1&' +
'r=https%3A%2F%2Ftest.bitpay.com%2Fi%2F6DKgf8cnJC388irbXk5hHu').should.equal(true);
@ -69,7 +69,7 @@ describe('URI', function() {
});
it('do not need new keyword', function() {
var uri = URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
var uri = URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.should.be.instanceof(URI);
});
@ -78,14 +78,14 @@ describe('URI', function() {
var uri;
it('parses address', function() {
uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.address.should.be.instanceof(bitcore.Address);
uri.network.should.equal(Networks.livenet);
});
it('parses amount', function() {
uri = URI.fromString('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22');
uri.address.toString().should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri = URI.fromString('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22');
uri.address.toString().should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.amount.should.equal(12322000000);
expect(uri.otherParam).to.be.undefined();
});
@ -97,7 +97,7 @@ describe('URI', function() {
});
it('stores unknown parameters as "extras"', function() {
uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param');
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param');
uri.address.should.be.instanceof(bitcore.Address);
expect(uri.other).to.be.undefined();
uri.extras.other.should.equal('param');
@ -105,12 +105,12 @@ describe('URI', function() {
it('throws error when a required feature is not supported', function() {
(function() {
return new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param&req-required=param');
return new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&req-required=param');
}).should.throw(Error);
});
it('has no false negative when checking supported features', function() {
uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param&' +
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&' +
'req-required=param', ['req-required']);
uri.address.should.be.instanceof(bitcore.Address);
uri.amount.should.equal(120000000);
@ -125,7 +125,7 @@ describe('URI', function() {
var uri;
uri = new URI({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj'
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'
});
uri.address.should.be.instanceof(bitcore.Address);
uri.network.should.equal(Networks.livenet);
@ -137,7 +137,7 @@ describe('URI', function() {
uri.network.should.equal(Networks.testnet);
uri = new URI({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
amount: 120000000,
other: 'param'
});
@ -148,13 +148,13 @@ describe('URI', function() {
(function() {
return new URI({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
'req-required': 'param'
});
}).should.throw(Error);
uri = new URI({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
amount: 120000000,
other: 'param',
'req-required': 'param'
@ -166,19 +166,19 @@ describe('URI', function() {
});
it('should support double slash scheme', function() {
var uri = new URI('bitcoin://1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.toString().should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
var uri = new URI('bitcoin://CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.address.toString().should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
});
it('should input/output String', function() {
var str = 'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?' +
var str = 'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' +
'message=Donation%20for%20project%20xyz&label=myLabel&other=xD';
URI.fromString(str).toString().should.equal(str);
});
it('should input/output JSON', function() {
var json = JSON.stringify({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
message: 'Donation for project xyz',
label: 'myLabel',
other: 'xD'
@ -187,12 +187,12 @@ describe('URI', function() {
});
it('should support numeric amounts', function() {
var uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=12.10001');
var uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=12.10001');
expect(uri.amount).to.be.equal(1210001000);
});
it('should support extra arguments', function() {
var uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?' +
var uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' +
'message=Donation%20for%20project%20xyz&label=myLabel&other=xD');
should.exist(uri.message);
@ -207,25 +207,25 @@ describe('URI', function() {
it('should generate a valid URI', function() {
new URI({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
}).toString().should.equal(
'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj'
'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'
);
new URI({
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
amount: 110001000,
message: 'Hello World',
something: 'else'
}).toString().should.equal(
'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.10001&message=Hello%20World&something=else'
'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.10001&message=Hello%20World&something=else'
);
});
it('should be case insensitive to protocol', function() {
var uri1 = new URI('bItcOin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
var uri2 = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
var uri1 = new URI('bItcOin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
var uri2 = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri1.address.toString().should.equal(uri2.address.toString());
});
@ -238,7 +238,7 @@ describe('URI', function() {
});
it('displays nicely on the console (#inspect)', function() {
var uri = 'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj';
var uri = 'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk';
var instance = new URI(uri);
instance.inspect().should.equal('<URI: ' + uri + '>');
});

Loading…
Cancel
Save