Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,37 @@ jobs:
strategy:
matrix:
node-version: [20, 'lts/*']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm i
- run: npm ci
- run: npm run unit
coverage:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20, 'lts/*']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm i
- run: npm ci
- run: npm run coverage
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20, 'lts/*']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm i
- run: npm ci
- run: npm run standard
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/coinselect",
"version": "3.1.14",
"version": "3.1.15",
"description": "A transaction input selection module for bitcoin.",
"keywords": [
"coinselect",
Expand Down
91 changes: 91 additions & 0 deletions test/fixtures/witness.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,97 @@ const fixtures = [
outputsPermutation: [0]
},
shouldThrow: false
},
{
description: 'skipUtxoSelection - coin control with specific inputs',
feeRate: 10,
inputs: [
{
txId: 'f46689066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332',
vout: 0,
value: 50000,
amount: '50000',
confirmations: 100,
own: true,
coinbase: false,
address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd',
path: "m/84'/1'/0'/0/0"
},
{
txId: 'a88d1066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332',
vout: 1,
value: 30000,
amount: '30000',
confirmations: 200,
own: true,
coinbase: false,
address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd',
path: "m/84'/1'/0'/0/0"
}
],
outputs: [
{
type: 'payment',
address: 'tb1quawu6eyfuechu3qhdeejnrzne9y7shr08u8zzt',
value: 60000,
amount: '60000'
}
],
network: testnet,
changeAddress: {
address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd',
path: "m/84'/1'/0'/0/0"
},
txType: 'p2wpkh',
skipUtxoSelection: true,
expected: {
type: 'final',
fee: '2090',
feePerByte: '10',
bytes: 209,
max: undefined,
totalSpent: '62090',
inputs: [
{
txId: 'a88d1066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332',
vout: 1,
value: 30000,
confirmations: 200,
own: true,
address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd',
path: "m/84'/1'/0'/0/0",
coinbase: false,
amount: '30000'
},
{
txId: 'f46689066ac0493cc55920c3918163ccda6c64998d6c078c6254e1c00c36a332',
vout: 0,
value: 50000,
confirmations: 100,
own: true,
address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd',
path: "m/84'/1'/0'/0/0",
coinbase: false,
amount: '50000'
}
],
outputs: [
{
type: 'payment',
address: 'tb1quawu6eyfuechu3qhdeejnrzne9y7shr08u8zzt',
value: 60000,
amount: '60000'
},
{
type: 'change',
address: 'tb1qul5mzh5phe7xqyqek0nl42hflfrn7ugxck59jd',
path: "m/84'/1'/0'/0/0",
amount: '17910'
}
],
outputsPermutation: [0, 1]
},
shouldThrow: false
}
]

Expand Down
5 changes: 3 additions & 2 deletions test/witness.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ fixtures.forEach(function (f) {
feeRate: f.feeRate,
network: f.network,
changeAddress: f.changeAddress,
txType: f.txType
txType: f.txType,
skipUtxoSelection: f.skipUtxoSelection
})

const compareOutputs = (actual, expected) => {
Expand Down Expand Up @@ -61,7 +62,7 @@ fixtures.forEach(function (f) {
t.same(actual.bytes, f.expected.bytes)
t.same(actual.max, f.expected.max)
t.same(actual.totalSpent, f.expected.totalSpent)
t.same(actual.inputs, f.expected.inputs)
t.ok(compareOutputs(actual.inputs, f.expected.inputs), 'inputs are the same')
t.ok(compareOutputs(actual.outputs, f.expected.outputs), 'outputs are the same')
t.end()
}
Expand Down
6 changes: 4 additions & 2 deletions witness.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function coinSelect ({
network,
txType,
baseFee = 0,
dustThreshold = 546
dustThreshold = 546,
skipUtxoSelection = false
}) {
const result = composeTx({
utxos,
Expand All @@ -19,7 +20,8 @@ module.exports = function coinSelect ({
dustThreshold,
changeAddress,
network,
baseFee
baseFee,
skipUtxoSelection
})

if (result.type === 'error') {
Expand Down