-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathExplorerWallet.test.js
113 lines (111 loc) · 4.07 KB
/
ExplorerWallet.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { floTestnet } from '../../../../src/config'
import { ExplorerWallet } from '../../../../src/modules/wallets'
import floTx from 'fcoin/lib/primitives/tx'
const wif = 'cRVa9rNx5N1YKBw8PhavegJPFCiYCfC4n8cYmdc3X1Y6TyFZGG4B'
describe(`ExplorerWallet`, () => {
describe('Transaction Builder', () => {
it('fetch UTXO | getUTXO', async () => {
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let utxo = await wallet.getUTXO()
// console.log(utxo)
expect(utxo).toBeDefined()
expect(Array.isArray(utxo)).toBeTruthy()
})
it(`build Inputs and Outputs | buildInputsAndOutputs`, async () => {
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let { inputs, outputs, fee } = await wallet.buildInputsAndOutputs('floData')
expect(inputs).toBeDefined()
expect(outputs).toBeDefined()
expect(fee).toBeDefined()
})
it('build tx hex | buildTXHex', async () => {
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let hex = await wallet.buildTXHex('floData')
let ftx = floTx.fromRaw(hex, 'hex')
// console.log(ftx)
// ToDo: Test signature validation
expect(ftx.strFloData).toEqual('floData')
})
// it.skip('test insight api update time', async (done) => {
// let wallet = new ExplorerWallet({ wif, network: "testnet" })
//
// for (let i = 0; i < 5; i++) {
// let txid = await wallet.sendDataToChain('11:22')
// console.log(txid)
// let start = Date.now(), finish;
// // console.log(utxo)
// const slam = async () => {
// // console.log('slam')
// let utxo
// try {
// utxo = await wallet.getUTXO()
//
// } catch(err) {console.log('err', err)}
// for (let u of utxo) {
// if (u.txid === txid) {
// finish = Date.now()
// }
// }
// }
// while (!finish) {
// await slam()
// }
// console.log(finish - start)
// }
// done()
// }, 250 * 100 * 100)
it('build and broadcast TX hex | sendDataToChain', async () => {
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let txid = await wallet.sendDataToChain(`RC`)
expect(typeof txid === 'string').toBeTruthy()
// console.log(txid)
})
it('flotx w custom output | sendTx', async () => {
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let output = {
address: 'oNAydz5TjkhdP3RPuu3nEirYQf49Jrzm4S',
value: Math.floor(0.0001 * floTestnet.satPerCoin)
}
let txid = await wallet.sendTx(output, 'to testnet')
// console.log(txid)
expect(txid).toBeDefined()
expect(typeof txid === 'string').toBeTruthy()
})
it('flotx w multiple custom output | sendTx', async () => {
jest.setTimeout(10000)
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let outputs = [
{
address: 'oNAydz5TjkhdP3RPuu3nEirYQf49Jrzm4S',
value: Math.floor(0.0001 * floTestnet.satPerCoin)
},
{
address: 'ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4',
value: Math.floor(0.0001 * floTestnet.satPerCoin)
},
{
address: 'oV5qwoq9CSaXersHk4DQVHhoMTDjRNWRF2',
value: Math.floor(0.0001 * floTestnet.satPerCoin)
}
]
let txid = await wallet.sendTx(outputs, 'to testnet')
console.log(txid)
expect(txid).toBeDefined()
expect(typeof txid === 'string').toBeTruthy()
})
it('add and remove spent transaction from utxo', async () => {
let wallet = new ExplorerWallet({ wif, network: 'testnet' })
let utxo = await wallet.getUTXO()
// console.log(utxo)
let [firstUTXO] = utxo
let txid = firstUTXO.txid
wallet.addSpentTransaction(txid)
let filtedUtxos = wallet.removeSpent(utxo)
for (let tx of filtedUtxos) {
expect(tx.txid).not.toEqual(txid)
}
let spentTx = wallet.getSpentTransactions()[wallet.getSpentTransactions().length - 1]
expect(txid).toEqual(spentTx)
})
})
})