Skip to content

Commit

Permalink
add index BTC,BCH,LTC,ETH,TRX test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wang committed Jul 23, 2020
1 parent ff81662 commit 0cacc6b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 49 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
let Address = {
BTC: require("./lib/btc.address"),
BTC: require("./lib/btc.series.address"),
BCH: require("./lib/btc.series.address"),
LTC: require("./lib/btc.series.address"),
ETH: require("./lib/eth.address"),
TRX: require("./lib/trx.address")
}

module.exports = class ChainAddress {
constructor(coin, networkType) {
networkType = networkType || coin
this.address = new Address[coin](coin, networkType)
}

Expand Down
70 changes: 30 additions & 40 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,55 @@
'use strict';

let Address = require("../index")
let addrValid = require("./benchmark/address.valid")
let hdData = require("./lib/base/data").hd
let hdIndex = hdData.index

let getKeyPairTest = async (coinSymbol) => {
let chain = new Address(coinSymbol)
let {address, pri, pub} = await chain.getKeyPair(hdIndex)
let validAddress = addrValid(chain.address.coin, address)
console.assert(validAddress, "address invalid")
console.assert(address == hdData[coinSymbol], "address is diff")

let userId = 123456
let priAddr = await chain.address.getAddressByPrivateKey(pri)
console.assert(priAddr.address == hdData[coinSymbol], "address is diff")

// 0x833F5230f7443761AfC8282829989E25f0Fc0A71
it("ETH getAddress and ", async () => {
let chain = new Address("ETH")
let {address} = await chain.address.getAddress(userId)
let pubAddr = await chain.address.getAddressByPublicKey(pub)
console.assert(pubAddr.address == hdData[coinSymbol], "address is diff")
}

let foo = await chain.address.isAddress(address)
console.log(foo)
it("BTC getKeyPair", async () => {
let ok =await getKeyPairTest("BTC")
})


it("BTC TEST getKeyPair", async () => {
let chain = new Address("BTC", "TEST")
let foo = await chain.getKeyPair(userId)
console.log(foo)
let {address} = await chain.getKeyPair(hdIndex)
let validAddress = addrValid(chain.address.coin, address, "TEST")
console.assert(validAddress, "address invalid")
console.assert(address == hdData.BTC_TEST, "address is diff")
})

it("BTC getAddressEx", async () => {
let chain = new Address("BTC", "TEST")
let foo = await chain.getAddressEx(userId)
console.log(foo)
it("BCH getKeyPair", async () => {
let ok =await getKeyPairTest("BCH")
})


it("BTC getKeyPair", async () => {
let chain = new Address("BTC", "BTC")
let foo = await chain.getKeyPair(userId)
it("LTC getKeyPair", async () => {
let ok =await getKeyPairTest("LTC")
})

console.log(foo.address)
let priAddr = await chain.address.getAddressByPrivateKey(foo.pri)
console.log(priAddr.address)
let pubAddr = await chain.address.getAddressByPublicKey(foo.pub)
console.log(pubAddr.address)

})

it("ETH getKeyPair", async () => {
let chain = new Address("ETH")
let foo = await chain.getKeyPair(userId)
console.log(foo.address)
let priAddr = await chain.address.getAddressByPrivateKey(foo.pri)
console.log(priAddr.address)
let pubAddr = await chain.address.getAddressByPublicKey(foo.pub)
console.log(pubAddr.address)
it("ETH getKeyPair ", async () => {
let ok =await getKeyPairTest("ETH")

console.assert(pubAddr.address == "0x833F5230f7443761AfC8282829989E25f0Fc0A71")
})


it("TRX getKeyPair", async () => {
let chain = new Address("TRX")
let foo = await chain.getKeyPair(userId)
console.log(foo.address)
let priAddr = await chain.address.getAddressByPrivateKey(foo.pri)
console.log(priAddr.address)
let pubAddr = await chain.address.getAddressByPublicKey(foo.pub)
console.log(pubAddr.address)
console.assert(pubAddr.address == "TDmpo4ZwgpJ5aMfuqiK4mKcbY131STyybh")
//
let ok =await getKeyPairTest("TRX")
})

3 changes: 2 additions & 1 deletion test/lib/base/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let authData = require("./auth.data")
let starData = require("./star.6677.data")

module.exports = {
hd: authData.hd
hd: starData.hd
}
14 changes: 7 additions & 7 deletions test/lib/base/star.6677.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
"hd": {
"mnemonic": "star star star star star star",
"index": 6677,
"BTC": "1HthGRdzxunKAiMSazDdL8PZhE4qWpeBNK",
"BTC_TEST": "mxQeZUiymwDZwpq4JZC1A3btZDfYRhqRwS",
"BCH": "12owPGh3cXLk8HevCEx5fZAMPqZPBgvgmX",
"LTC": "LchXCPCtYTKUvksjf5RvkZhCwvYQrYewaa",
"ETH": "0x4E04823FDF08E862201a4cfA595dc1Ec72AdF3Ab",
"TRX": "TZFH9KReZpsWZZ9Q2bVyXGQtmvVL3PV8gE",
},
"BTC": "1442MZYQMh17ZoWdLMferxM4U9ppqGQbuK",
"BTC_TEST": "miZyecdPAiSNLuzF3ve2gsZPL9RXjA51JS",
"BCH": "12Ut7DckjmdzU4Kx8cZeCfsyqufcrTFkFq",
"LTC": "LbspHRvEu8PpyMq2EpR7rJNN5D3kzzsk9a",
"ETH": "0xe4fa4CEFEa4ebfB79f4527a71EEF983700119d58",
"TRX": "TQawSTYUsWvibpQURRUxJhUcLZdEbuFdGT",
}
}

0 comments on commit 0cacc6b

Please sign in to comment.