Skip to content

Commit

Permalink
dep-up: bump node-dlc & add tx builder validation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjablack committed Mar 16, 2024
1 parent 06792b4 commit 8c28dfc
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 71 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
],
"devDependencies": {
"@changesets/cli": "^2.22.0",
"@node-dlc/bitcoin": "0.23.0",
"@node-dlc/core": "0.23.0",
"@node-dlc/messaging": "0.23.0",
"@node-dlc/bitcoin": "0.23.1",
"@node-dlc/core": "0.23.1",
"@node-dlc/messaging": "0.23.1",
"@swc/cli": "^0.1.57",
"@swc/core": "^1.2.172",
"@swc/register": "^0.1.10",
Expand Down
28 changes: 25 additions & 3 deletions tests/integration/dlc/custom-oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import 'mocha';

import { Value } from '@node-dlc/bitcoin';
import {
BatchDlcTxBuilder,
buildCustomStrategyOrderOffer,
buildRoundingIntervalsFromIntervals,
DualFundingTxFinalizer,
LinearPayout,
} from '@node-dlc/core';
import {
CetAdaptorSignaturesV0,
ContractDescriptorV0,
ContractDescriptorV1,
ContractInfoV0,
DigitDecompositionEventDescriptorV0,
Expand All @@ -18,16 +21,21 @@ import {
DlcParty,
DlcSign,
DlcTransactions,
EnumEventDescriptorV0,
FundingInputV0,
NegotiationFields,
NegotiationFieldsV0,
OracleAnnouncementV0,
OracleAttestationV0,
OracleEventV0,
OracleInfoV0,
PayoutFunctionV0,
RoundingIntervalsV0,
} from '@node-dlc/messaging';
import { Tx, TxOut } from '@node-lightning/bitcoin';
import { HashByteOrder, Sequence, Tx, TxOut } from '@node-lightning/bitcoin';
import { sha256 } from '@node-lightning/crypto';
import { math } from 'bip-schnorr';
import { BitcoinNetworks } from 'bitcoin-networks';
import { BitcoinNetworks, chainHashFromNetwork } from 'bitcoin-networks';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';

Expand Down Expand Up @@ -1250,10 +1258,13 @@ describe('Custom Strategy Oracle POC numdigits=21 split trades', () => {
expect(cetTx._raw.vin.length).to.equal(1);
});

it('should succeed in creating batch dlc transaction', async () => {
it.only('should succeed in creating batch dlc transaction', async () => {
const aliceInput = await getInput(alice);
const bobInput = await getInput(bob);

console.log('aliceInput', aliceInput);
console.log('bobInput', bobInput);

oracle = new Oracle('olivia', numDigits);

const { contractInfo } = generateContractInfoCustomStrategyOracle(
Expand Down Expand Up @@ -1315,11 +1326,22 @@ describe('Custom Strategy Oracle POC numdigits=21 split trades', () => {
dlcTxsList,
);

const txBuilder = new BatchDlcTxBuilder(
dlcOffers as DlcOfferV0[],
dlcAccepts.map((dlcAccept) => (dlcAccept as DlcAcceptV0).withoutSigs()),
);

// Ensure node-dlc tx builder builds identical transaction to cfd-dlc C++ implementation
const fundTxIdNodeDlc = txBuilder
.buildFundingTransaction()
.txId.toString(HashByteOrder.RPC);

const fundTxId = await bob.chain.sendRawTransaction(
fundTx.serialize().toString('hex'),
);

expect(fundTxId).to.be.a('string');
expect(fundTxId).to.equal(fundTxIdNodeDlc); // validates that node-dlc tx builder built identical tx

oracleAttestation = generateOracleAttestation(
outcome,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"transpileOnly": true,
"swc": true,
},
"exclude": ["node_modules", "**/*.spec.ts", "dist"]
"exclude": ["node_modules", "**/*.spec.ts", "dist"],
}
Loading

0 comments on commit 8c28dfc

Please sign in to comment.