Skip to content

Commit

Permalink
misc: update dev deps (#41)
Browse files Browse the repository at this point in the history
Update the dev dependencies and improve tests.
  • Loading branch information
rllola authored Nov 16, 2024
1 parent 6e33222 commit 2aa7ab1
Show file tree
Hide file tree
Showing 9 changed files with 13,060 additions and 8,423 deletions.
21,400 changes: 13,011 additions & 8,389 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"package-lock.json"
],
"devDependencies": {
"ava": "^3.12.1",
"bitcoinjs-lib": "^5.2.0",
"ava": "6.2.0",
"bitcoinjs-lib": "6.1.6",
"caxa": "^1.0.0",
"dockerode": "^3.3.4",
"nodemon": "^2.0.12",
"nyc": "^15.1.0",
"standard": "^16.0.3",
"vuepress": "^1.8.2"
"dockerode": "4.0.2",
"nodemon": "3.1.7",
"nyc": "17.1.0",
"standard": "17.1.2",
"vuepress": "1.9.10"
},
"dependencies": {
"axios": "^0.24.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getVersion (ip, port) {
remote: {
services: 1n,
host: ip,
port: port
port
},
local: {
services: 4n,
Expand Down
2 changes: 0 additions & 2 deletions src/wallet/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,3 @@ module.exports = {
extractPubkeyHashFromP2PKH,
extractScriptHashFromP2SH
}

// 41049464205950188c29d377eebca6535e0f3699ce4069ecd77ffebfbd0bcf95e3c134cb7d2742d800a12df41413a09ef87a80516353a2f0a280547bb5512dc03da8ac
12 changes: 5 additions & 7 deletions test/integration/issue4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const { decodeTxMessage } = require('../../src/commands/tx')
const { setup, close, regtest } = require('./util.js')
const { ECPair } = require('bitcoinjs-lib')
const { setup, close } = require('./util.js')

test.before(setup)
test.after.always(close)
Expand Down Expand Up @@ -32,14 +31,13 @@ test.serial('generate new pubkey that is not part of the filter (see issue #4)',
}

// Get bob public key
const bobKey = ECPair.fromPrivateKey(Buffer.from('3b187fd3a10960efe5753c9851c174c05bcdb30db22fd9deab981fe1f0ec7b00', 'hex'), {
compressed: true,
network: regtest
})
// TODO: generate key at every test
// const bobPrivateKey = Buffer.from('3b187fd3a10960efe5753c9851c174c05bcdb30db22fd9deab981fe1f0ec7b00', 'hex')
const bobPublicKey = Buffer.from('02695c71925215f8a23d9880fc52811c77aac00a259876046c8ad92731d8c2c172', 'hex')

// create payment channel
t.log('Initiate payment channel')
const pctx = await wallet.initiatePaymentChannel(100n, bobKey.publicKey.toString('hex'), 1n, 200)
const pctx = await wallet.initiatePaymentChannel(100n, bobPublicKey.toString('hex'), 1n, 200)

execSync(`docker exec ${containerName} dogecoin-cli -conf=/mnt/dogecoin.conf sendrawtransaction ${pctx.rawTransaction.toString('hex')}`)
execSync(`docker exec ${containerName} dogecoin-cli -conf=/mnt/dogecoin.conf generate 150`)
Expand Down
10 changes: 3 additions & 7 deletions test/integration/paymentchannel.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const test = require('ava')
const fs = require('fs')
const path = require('path')
const { ECPair } = require('bitcoinjs-lib')
const { setup, close, regtest } = require('./util.js')
const { setup, close } = require('./util.js')
const { execSync } = require('child_process')
const { decodeTxMessage } = require('../../src/commands/tx')

Expand All @@ -14,10 +13,7 @@ let pctx
test.serial('should create and send a p2sh transaction', async t => {
const { wallet, container } = t.context
const address = await wallet.getAddress()
const bobKey = ECPair.fromPrivateKey(Buffer.from('3b187fd3a10960efe5753c9851c174c05bcdb30db22fd9deab981fe1f0ec7b00', 'hex'), {
compressed: true,
network: regtest
})
const bobPublicKey = Buffer.from('02695c71925215f8a23d9880fc52811c77aac00a259876046c8ad92731d8c2c172', 'hex')

const containerName = (await container.inspect()).Name

Expand All @@ -33,7 +29,7 @@ test.serial('should create and send a p2sh transaction', async t => {
await wallet.addTxToWallet(tx)

t.log('Initiate payment channel')
pctx = await wallet.initiatePaymentChannel(100n, bobKey.publicKey.toString('hex'), 1n, 200)
pctx = await wallet.initiatePaymentChannel(100n, bobPublicKey.toString('hex'), 1n, 200)

execSync(`docker exec ${containerName} dogecoin-cli -conf=/mnt/dogecoin.conf sendrawtransaction ${pctx.rawTransaction.toString('hex')}`)
execSync(`docker exec ${containerName} dogecoin-cli -conf=/mnt/dogecoin.conf generate 150`)
Expand Down
29 changes: 25 additions & 4 deletions test/integration/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const Docker = require('dockerode')
const path = require('path')
const fs = require('fs')
const { execSync } = require('child_process')
const { scheduler } = require('node:timers/promises')

const SPVNode = require('../../src/spvnode')
const networks = require('../../src/network')
Expand Down Expand Up @@ -78,10 +80,25 @@ async function setup (t) {
settings.DEFAULT_PORT = (await container.inspect()).NetworkSettings.Ports['18444/tcp'][0].HostPort

t.log('container started')

// Wait 5 seconds
// Needed otherwise we try to connect when node is not ready
await new Promise(resolve => setTimeout(resolve, 5000))
// still need to wait after starting...
await scheduler.wait(2000)

const containerName = (await container.inspect()).Name.replace('/', '')
await new Promise(function (resolve, reject) {
// timeout after 10 seconds
setTimeout(reject, 10000)

// check health on the node every second
setInterval(function () {
const result = execSync(`docker exec ${containerName} dogecoin-cli -conf=/mnt/dogecoin.conf getbalance`)
if (!result.toString().includes('error code: -28')) {
t.log(`container ${containerName} is up`)

clearInterval(this)
resolve()
}
}, 1000)
})

t.context = { spvnode, settings, container, wallet }
}
Expand All @@ -93,7 +110,11 @@ async function close (t) {
// Clean after
fs.rmSync(settings.DATA_FOLDER, { recursive: true })

const containerName = (await container.inspect()).Name.replace('/', '')

t.log(`stopping ${containerName}`)
await container.stop()
t.log(`removing ${containerName}`)
await container.remove()
}

Expand Down
1 change: 0 additions & 1 deletion test/unit/wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ test.serial('should save the tx', async t => {

await wallet.addTxToWallet(tx)

// return wallet.db.txs.get('da4cfccc4abb6c417b1225e29881ac1f00e08ad1f2f1ed4e0f4c311b56de934500000000')
return wallet.db.txs.get('da4cfccc4abb6c417b1225e29881ac1f00e08ad1f2f1ed4e0f4c311b56de9345')
.then(function (value) { t.pass() })
.catch(function (error) { t.fail(error.message) })
Expand Down
13 changes: 8 additions & 5 deletions test/unit/wallet.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ bitcoinjs.networks.dogecoin_testnet = {
wif: 0xef
}

const keyPairA = bitcoinjs.ECPair.fromPrivateKey(Buffer.from('3b187fd3a10960efe5753c9851c174c05bcdb30db22fd9deab981fe1f0ec7b00', 'hex'))
const keyPairB = bitcoinjs.ECPair.fromPrivateKey(Buffer.from('5cdc1bf38cd77f6a0f130d50e6e37b1d1e3eb59b78f3fde6c1572f44e7f709ed', 'hex'))
// const privatekeyPairA = Buffer.from('3b187fd3a10960efe5753c9851c174c05bcdb30db22fd9deab981fe1f0ec7b00', 'hex')
// const privatekeyPairB = Buffer.from('5cdc1bf38cd77f6a0f130d50e6e37b1d1e3eb59b78f3fde6c1572f44e7f709ed', 'hex')

const publickeyPairA = Buffer.from('02695c71925215f8a23d9880fc52811c77aac00a259876046c8ad92731d8c2c172', 'hex')
const publickeyPairB = Buffer.from('033018856019108336a67b29f4cf9612b9b83953a92a5ef8472b6822f78d850477', 'hex')

/*
pubkeyToAddress
Expand All @@ -49,14 +52,14 @@ test('successfully convert public key hash to address', t => {
test('successfully serialize a pay to multisig with time lock script', t => {
const blocksLock = 500

const multisigScript = serializePayToMultisigWithTimeLockScript([keyPairA.publicKey.toString('hex'), keyPairB.publicKey.toString('hex')], blocksLock)
const multisigScript = serializePayToMultisigWithTimeLockScript([publickeyPairA.toString('hex'), publickeyPairB.toString('hex')], blocksLock)

const locktime = Buffer.from(bip65.encode({ blocks: blocksLock }).toString(16), 'hex').reverse().toString('hex')

const multisigScriptExecpected = bitcoinjs.script.fromASM('OP_IF ' +
locktime + '00' + ' OP_CHECKLOCKTIMEVERIFY OP_DROP ' +
keyPairA.publicKey.toString('hex') + ' OP_CHECKSIGVERIFY OP_ELSE OP_2 OP_ENDIF ' +
keyPairA.publicKey.toString('hex') + ' ' + keyPairB.publicKey.toString('hex') + ' OP_2 OP_CHECKMULTISIG')
publickeyPairA.toString('hex') + ' OP_CHECKSIGVERIFY OP_ELSE OP_2 OP_ENDIF ' +
publickeyPairA.toString('hex') + ' ' + publickeyPairB.toString('hex') + ' OP_2 OP_CHECKMULTISIG')

t.is(multisigScript.toString('hex'), multisigScriptExecpected.toString('hex'))
})
Expand Down

0 comments on commit 2aa7ab1

Please sign in to comment.