-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for connectors (#138)
* chore: add tests for connectors * chore: enable test workflow * Create perfect-teachers-agree.md
- Loading branch information
1 parent
41e282b
commit e37daf3
Showing
5 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@gobob/sats-wagmi": patch | ||
--- | ||
|
||
chore: add tests for connectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
})) | ||
) | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
})) | ||
) | ||
}); | ||
}); | ||
}); |