|
|
@ -16,22 +16,22 @@ describe('URI', function() { |
|
|
|
|
|
|
|
URI.parse.bind(URI, 'badURI').should.throw(TypeError); |
|
|
|
|
|
|
|
uri = URI.parse('bitcoin:'); |
|
|
|
uri = URI.parse('bitcoincash:'); |
|
|
|
expect(uri.address).to.be.undefined(); |
|
|
|
expect(uri.amount).to.be.undefined(); |
|
|
|
expect(uri.otherParam).to.be.undefined(); |
|
|
|
|
|
|
|
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri = URI.parse('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
expect(uri.amount).to.be.undefined(); |
|
|
|
expect(uri.otherParam).to.be.undefined(); |
|
|
|
|
|
|
|
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22'); |
|
|
|
uri = URI.parse('bitcoincash: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:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22' + |
|
|
|
uri = URI.parse('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22' + |
|
|
|
'&other-param=something&req-extra=param'); |
|
|
|
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri.amount.should.equal('123.22'); |
|
|
@ -41,24 +41,24 @@ describe('URI', function() { |
|
|
|
|
|
|
|
// TODO: Split this and explain tests
|
|
|
|
it('URIs can be validated statically (test vector)', function() { |
|
|
|
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk').should.equal(true); |
|
|
|
URI.isValid('bitcoin:mkYY5NRvikVBY1EPtaq9fAFgquesdjqECw').should.equal(true); |
|
|
|
URI.isValid('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk').should.equal(true); |
|
|
|
URI.isValid('bitcoincash:mkYY5NRvikVBY1EPtaq9fAFgquesdjqECw').should.equal(true); |
|
|
|
|
|
|
|
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2') |
|
|
|
URI.isValid('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2') |
|
|
|
.should.equal(true); |
|
|
|
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param') |
|
|
|
URI.isValid('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param') |
|
|
|
.should.equal(true); |
|
|
|
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&req-other=param', |
|
|
|
URI.isValid('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&req-other=param', |
|
|
|
['req-other']).should.equal(true); |
|
|
|
URI.isValid('bitcoin:mmrqEBJxUCf42vdb3oozZtyz5mKr3Vb2Em?amount=0.1&' + |
|
|
|
URI.isValid('bitcoincash:mmrqEBJxUCf42vdb3oozZtyz5mKr3Vb2Em?amount=0.1&' + |
|
|
|
'r=https%3A%2F%2Ftest.bitpay.com%2Fi%2F6DKgf8cnJC388irbXk5hHu').should.equal(true); |
|
|
|
|
|
|
|
URI.isValid('bitcoin:').should.equal(false); |
|
|
|
URI.isValid('bitcoin:badUri').should.equal(false); |
|
|
|
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfk?amount=bad').should.equal(false); |
|
|
|
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfk?amount=1.2&req-other=param') |
|
|
|
URI.isValid('bitcoincash:').should.equal(false); |
|
|
|
URI.isValid('bitcoincash:badUri').should.equal(false); |
|
|
|
URI.isValid('bitcoincash:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfk?amount=bad').should.equal(false); |
|
|
|
URI.isValid('bitcoincash:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfk?amount=1.2&req-other=param') |
|
|
|
.should.equal(false); |
|
|
|
URI.isValid('bitcoin:?r=https%3A%2F%2Ftest.bitpay.com%2Fi%2F6DKgf8cnJC388irbXk5hHu') |
|
|
|
URI.isValid('bitcoincash:?r=https%3A%2F%2Ftest.bitpay.com%2Fi%2F6DKgf8cnJC388irbXk5hHu') |
|
|
|
.should.equal(false); |
|
|
|
}); |
|
|
|
|
|
|
@ -69,7 +69,7 @@ describe('URI', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('do not need new keyword', function() { |
|
|
|
var uri = URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
var uri = URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri.should.be.instanceof(URI); |
|
|
|
}); |
|
|
|
|
|
|
@ -78,26 +78,26 @@ describe('URI', function() { |
|
|
|
var uri; |
|
|
|
|
|
|
|
it('parses address', function() { |
|
|
|
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri = new URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri.address.should.be.instanceof(bitcore.Address); |
|
|
|
uri.network.should.equal(Networks.livenet); |
|
|
|
}); |
|
|
|
|
|
|
|
it('parses amount', function() { |
|
|
|
uri = URI.fromString('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22'); |
|
|
|
uri = URI.fromString('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22'); |
|
|
|
uri.address.toString().should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri.amount.should.equal(12322000000); |
|
|
|
expect(uri.otherParam).to.be.undefined(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('parses a testnet address', function() { |
|
|
|
uri = new URI('bitcoin:mkYY5NRvikVBY1EPtaq9fAFgquesdjqECw'); |
|
|
|
uri = new URI('bitcoincash:mkYY5NRvikVBY1EPtaq9fAFgquesdjqECw'); |
|
|
|
uri.address.should.be.instanceof(bitcore.Address); |
|
|
|
uri.network.should.equal(Networks.testnet); |
|
|
|
}); |
|
|
|
|
|
|
|
it('stores unknown parameters as "extras"', function() { |
|
|
|
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param'); |
|
|
|
uri = new URI('bitcoincash: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:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&req-required=param'); |
|
|
|
return new URI('bitcoincash: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:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&' + |
|
|
|
uri = new URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&' + |
|
|
|
'req-required=param', ['req-required']); |
|
|
|
uri.address.should.be.instanceof(bitcore.Address); |
|
|
|
uri.amount.should.equal(120000000); |
|
|
@ -166,12 +166,12 @@ describe('URI', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should support double slash scheme', function() { |
|
|
|
var uri = new URI('bitcoin://CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
var uri = new URI('bitcoincash://CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
uri.address.toString().should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should input/output String', function() { |
|
|
|
var str = 'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' + |
|
|
|
var str = 'bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' + |
|
|
|
'message=Donation%20for%20project%20xyz&label=myLabel&other=xD'; |
|
|
|
URI.fromString(str).toString().should.equal(str); |
|
|
|
}); |
|
|
@ -187,12 +187,12 @@ describe('URI', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should support numeric amounts', function() { |
|
|
|
var uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=12.10001'); |
|
|
|
var uri = new URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=12.10001'); |
|
|
|
expect(uri.amount).to.be.equal(1210001000); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should support extra arguments', function() { |
|
|
|
var uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' + |
|
|
|
var uri = new URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' + |
|
|
|
'message=Donation%20for%20project%20xyz&label=myLabel&other=xD'); |
|
|
|
|
|
|
|
should.exist(uri.message); |
|
|
@ -209,7 +209,7 @@ describe('URI', function() { |
|
|
|
new URI({ |
|
|
|
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk', |
|
|
|
}).toString().should.equal( |
|
|
|
'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk' |
|
|
|
'bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk' |
|
|
|
); |
|
|
|
|
|
|
|
new URI({ |
|
|
@ -218,27 +218,27 @@ describe('URI', function() { |
|
|
|
message: 'Hello World', |
|
|
|
something: 'else' |
|
|
|
}).toString().should.equal( |
|
|
|
'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.10001&message=Hello%20World&something=else' |
|
|
|
'bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.10001&message=Hello%20World&something=else' |
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
it('should be case insensitive to protocol', function() { |
|
|
|
var uri1 = new URI('bItcOin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
var uri2 = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
var uri1 = new URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
var uri2 = new URI('bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'); |
|
|
|
|
|
|
|
uri1.address.toString().should.equal(uri2.address.toString()); |
|
|
|
}); |
|
|
|
|
|
|
|
it('writes correctly the "r" parameter on string serialization', function() { |
|
|
|
var originalString = 'bitcoin:mmrqEBJxUCf42vdb3oozZtyz5mKr3Vb2Em?amount=0.1&' + |
|
|
|
var originalString = 'bitcoincash:mmrqEBJxUCf42vdb3oozZtyz5mKr3Vb2Em?amount=0.1&' + |
|
|
|
'r=https%3A%2F%2Ftest.bitpay.com%2Fi%2F6DKgf8cnJC388irbXk5hHu'; |
|
|
|
var uri = new URI(originalString); |
|
|
|
uri.toString().should.equal(originalString); |
|
|
|
}); |
|
|
|
|
|
|
|
it('displays nicely on the console (#inspect)', function() { |
|
|
|
var uri = 'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'; |
|
|
|
var uri = 'bitcoincash:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'; |
|
|
|
var instance = new URI(uri); |
|
|
|
instance.inspect().should.equal('<URI: ' + uri + '>'); |
|
|
|
}); |
|
|
|