Skip to content

Commit

Permalink
chore: add tests for connectors (#138)
Browse files Browse the repository at this point in the history
* chore: add tests for connectors

* chore: enable test workflow

* Create perfect-teachers-agree.md
  • Loading branch information
slavastartsev authored Jan 6, 2025
1 parent 41e282b commit e37daf3
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/perfect-teachers-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gobob/sats-wagmi": patch
---

chore: add tests for connectors
1 change: 0 additions & 1 deletion .github/workflows/QA.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
tests:
name: Tests
runs-on: ubuntu-latest
if: false
steps:
- name: Checkout branch
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions packages/sats-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"clean": "rimraf dist .turbo",
"typecheck": "tsc --noEmit",
"build": "tsup src/index.ts --dts",
"test": "jest",
"prepack": "clean-package",
"postpack": "clean-package restore"
},
Expand Down
64 changes: 64 additions & 0 deletions packages/sats-wagmi/src/connectors/test/okx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Network } from 'bitcoin-address-validation';

import { OKXConnector } from '../okx';

// @ts-ignore
global.okxwallet = {
bitcoin: {
signPsbt: jest.fn()
}
};

describe('OKX connector', () => {
it('should specify correct parameters when signing psbt', async () => {
const okxConnector = new OKXConnector(Network.mainnet);

okxConnector.publicKey = 'test_public_key';
// p2tr
okxConnector.paymentAddress = 'bc1p9u077kplyqud8qyc404l2t5ud8jerwph6t77cd8xqvnan30lef5sqxfjhm';
const psbtHex = '76a914602ba26f38a2f38a0d60b38d2ab5f7ab1562c8e588ac';

const signingIndexes = [1, 2, 3];

await okxConnector.signPsbt(psbtHex, [
{
signingIndexes,
address: 'bc1qqfnxscmxnfhy2ek5uvp6u9wjd9xhs95ksydtnt_test'
}
]);

// @ts-ignore
expect(global.okxwallet.bitcoin.signPsbt).toHaveBeenCalledWith(psbtHex, {
autoFinalized: false,
toSignInputs: expect.arrayContaining(
signingIndexes.map((index) => ({
index,
address: okxConnector.paymentAddress,
disableTweakSigner: false
}))
)
});

// segwit
okxConnector.paymentAddress = 'bc1qqfnxscmxnfhy2ek5uvp6u9wjd9xhs95ksydtnt';

await okxConnector.signPsbt(psbtHex, [
{
signingIndexes,
address: 'bc1qqfnxscmxnfhy2ek5uvp6u9wjd9xhs95ksydtnt_test'
}
]);

// @ts-ignore
expect(global.okxwallet.bitcoin.signPsbt).toHaveBeenCalledWith(psbtHex, {
autoFinalized: false,
toSignInputs: expect.arrayContaining(
signingIndexes.map((index) => ({
index,
publicKey: okxConnector.publicKey,
disableTweakSigner: true
}))
)
});
});
});
65 changes: 65 additions & 0 deletions packages/sats-wagmi/src/connectors/test/unisat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Network } from 'bitcoin-address-validation';

import { UnisatConnector } from '../unisat';

// @ts-ignore
global.unisat = {
signPsbt: jest.fn()
};

describe('Unisat connector', () => {
it('should specify correct parameters when signing psbt', async () => {
// @ts-ignore
global.unisat.signPsbt = jest.fn();

const unisatConnector = new UnisatConnector(Network.mainnet, 'unisat');

unisatConnector.publicKey = 'test_public_key';
// p2tr
unisatConnector.paymentAddress = 'bc1p9u077kplyqud8qyc404l2t5ud8jerwph6t77cd8xqvnan30lef5sqxfjhm';
const psbtHex = '76a914602ba26f38a2f38a0d60b38d2ab5f7ab1562c8e588ac';

const signingIndexes = [1, 2, 3];

await unisatConnector.signPsbt(psbtHex, [
{
signingIndexes,
address: 'bc1qqfnxscmxnfhy2ek5uvp6u9wjd9xhs95ksydtnt_test'
}
]);

// @ts-ignore
expect(global.unisat.signPsbt).toHaveBeenCalledWith(psbtHex, {
autoFinalized: false,
toSignInputs: expect.arrayContaining(
signingIndexes.map((index) => ({
index,
publicKey: unisatConnector.publicKey,
disableTweakSigner: false
}))
)
});

// segwit
unisatConnector.paymentAddress = 'bc1qqfnxscmxnfhy2ek5uvp6u9wjd9xhs95ksydtnt';

await unisatConnector.signPsbt(psbtHex, [
{
signingIndexes,
address: 'bc1qqfnxscmxnfhy2ek5uvp6u9wjd9xhs95ksydtnt_test'
}
]);

// @ts-ignore
expect(global.unisat.signPsbt).toHaveBeenCalledWith(psbtHex, {
autoFinalized: false,
toSignInputs: expect.arrayContaining(
signingIndexes.map((index) => ({
index,
publicKey: unisatConnector.publicKey,
disableTweakSigner: true
}))
)
});
});
});

0 comments on commit e37daf3

Please sign in to comment.