Tests for BIP72.
This commit is contained in:
parent
1be9ce39c1
commit
a4ab20abba
2 changed files with 46 additions and 3 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// https://en.bitcoin.it/wiki/BIP_0072
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
angular
|
angular
|
||||||
|
|
@ -17,9 +19,7 @@
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
||||||
|
function generateTestData() {
|
||||||
|
|
||||||
function isValidCashAddr(address, network) {
|
|
||||||
var privateKey = new bch.PrivateKey('testnet');
|
var privateKey = new bch.PrivateKey('testnet');
|
||||||
var address1 = privateKey.toAddress();
|
var address1 = privateKey.toAddress();
|
||||||
console.log('legacy pub:', address1.toString());
|
console.log('legacy pub:', address1.toString());
|
||||||
|
|
@ -28,6 +28,12 @@
|
||||||
//bch.Address.fromString(address1, 'testnet');
|
//bch.Address.fromString(address1, 'testnet');
|
||||||
console.log('generated:', address1.toString('cashaddr'));
|
console.log('generated:', address1.toString('cashaddr'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isValidCashAddr(address, network) {
|
||||||
|
|
||||||
|
|
||||||
var isValid = false;
|
var isValid = false;
|
||||||
|
|
||||||
var prefix = network === 'testnet' ? 'bchtest:' : 'bitcoincash:';
|
var prefix = network === 'testnet' ? 'bchtest:' : 'bitcoincash:';
|
||||||
|
|
@ -220,6 +226,7 @@
|
||||||
parsed.coin = 'bch';
|
parsed.coin = 'bch';
|
||||||
// TODO: Get legacy address
|
// TODO: Get legacy address
|
||||||
|
|
||||||
|
|
||||||
} else if (cashAddrRe.test(address)) {
|
} else if (cashAddrRe.test(address)) {
|
||||||
var cashAddr = 'bitcoincash:' + addressLowerCase;
|
var cashAddr = 'bitcoincash:' + addressLowerCase;
|
||||||
parsed.address = cashAddr;
|
parsed.address = cashAddr;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,42 @@ fdescribe('bitcoinUriService', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
it('Bitcoin Cash BIP72', function() {
|
||||||
|
|
||||||
|
var parsed = bitcoinUriService.parse('bitcoincash:?r=https://bitpay.com/i/SmHdie5dvBnG5kouZzEPzu');
|
||||||
|
|
||||||
|
expect(parsed.isValid).toBe(true);
|
||||||
|
expect(parsed.address).toBeUndefined()
|
||||||
|
expect(parsed.coin).toBe('bch');
|
||||||
|
expect(parsed.legacyAddress).toBeUndefined();
|
||||||
|
expect(parsed.testnet).toBeUndefined();
|
||||||
|
expect(parsed.url).toBe('https://bitpay.com/i/SmHdie5dvBnG5kouZzEPzu');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Bitcoin BIP72', function() {
|
||||||
|
|
||||||
|
var parsed = bitcoinUriService.parse('bitcoin:?r=https://bitpay.com/i/CwzbKP3k3JNgXJBfuoerDr');
|
||||||
|
|
||||||
|
expect(parsed.isValid).toBe(true);
|
||||||
|
expect(parsed.address).toBeUndefined()
|
||||||
|
expect(parsed.coin).toBe('btc');
|
||||||
|
expect(parsed.legacyAddress).toBeUndefined();
|
||||||
|
expect(parsed.testnet).toBeUndefined();
|
||||||
|
expect(parsed.url).toBe('https://bitpay.com/i/CwzbKP3k3JNgXJBfuoerDr');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Bitcoin testnet address', function() {
|
||||||
|
|
||||||
|
var parsed = bitcoinUriService.parse('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
|
||||||
|
expect(parsed.isValid).toBe(true);
|
||||||
|
expect(parsed.address).toBe('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
expect(parsed.coin).toBeUndefined();
|
||||||
|
expect(parsed.legacyAddress).toBe('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
expect(parsed.testnet).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('Bitcoin testnet address', function() {
|
it('Bitcoin testnet address', function() {
|
||||||
|
|
||||||
var parsed = bitcoinUriService.parse('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
var parsed = bitcoinUriService.parse('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue