ethers.js/tests/test-icap-address.js

35 lines
982 B
JavaScript
Raw Normal View History

2016-07-27 00:58:17 +03:00
'use strict';
var Wallet = require('../index.js');
var ethereumUtil = require('ethereumjs-util');
var iban = require('../node_modules/web3/lib/web3/iban.js');
var utils = require('./utils.js');
module.exports = function(test) {
function testAddress(address) {
var officialIban = (iban.fromAddress(address))._iban;
var ethersAddress = Wallet.getAddress(officialIban);
var officialAddress = ethereumUtil.toChecksumAddress(address)
var ethersIban = Wallet.getIcapAddress(address);
test.equal(ethersAddress, officialAddress, 'wrong address');
test.equal(ethersIban, officialIban, 'wrong ICAP address');
}
test.expect(2 * (2 + 10000));
testAddress('0x0000000000000000000000000000000000000000');
testAddress('0xffffffffffffffffffffffffffffffffffffffff');
for (var i = 0; i < 10000; i++) {
testAddress(utils.randomHexString(20));
}
test.done();
};
2016-08-02 01:34:12 +03:00
module.exports.testSelf = module.exports;