-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge branch main into jouzo/spv_listhtlcoutputs
- Loading branch information
Showing
41 changed files
with
1,087 additions
and
66 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
packages/jellyfish-api-core/__tests__/category/spv/getHtlcSeed.test.ts
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,66 @@ | ||
import { /** GenesisKeys, */ MasterNodeRegTestContainer /** ContainerGroup */ } from '@defichain/testcontainers' | ||
import { RpcApiError } from '@defichain/jellyfish-api-core' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
|
||
describe('Spv', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.call('spv_fundaddress', [await container.call('spv_getnewaddress')]) // Funds 1 BTC | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should getHtlcSeed', async () => { | ||
const pubKeyA = await container.call('spv_getaddresspubkey', [await container.call('spv_getnewaddress')]) | ||
const pubKeyB = await container.call('spv_getaddresspubkey', [await container.call('spv_getnewaddress')]) | ||
const htlc = await container.call('spv_createhtlc', [pubKeyA, pubKeyB, '10']) | ||
|
||
await container.call('spv_sendtoaddress', [htlc.address, 0.1]) // Funds HTLC address | ||
await container.call('spv_claimhtlc', [htlc.address, await container.call('spv_getnewaddress'), htlc.seed]) // claim HTLC | ||
|
||
const secret = await client.spv.getHtlcSeed(htlc.address) | ||
expect(secret).toStrictEqual(htlc.seed) | ||
}) | ||
|
||
it('should getHtlcSeed with empty secret before spv_claimhtlc', async () => { | ||
const pubKeyA = await container.call('spv_getaddresspubkey', [await container.call('spv_getnewaddress')]) | ||
const pubKeyB = await container.call('spv_getaddresspubkey', [await container.call('spv_getnewaddress')]) | ||
const htlc = await container.call('spv_createhtlc', [pubKeyA, pubKeyB, '10']) | ||
|
||
const secret = await client.spv.getHtlcSeed(htlc.address) | ||
expect(secret).toStrictEqual('') | ||
}) | ||
|
||
it('should not getHtlcSeed with invalid public key as receiverPubKey', async () => { | ||
const promise = client.spv.getHtlcSeed('XXXX') | ||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow("RpcApiError: 'Error: Invalid address', code: -5, method: spv_gethtlcseed") | ||
}) | ||
}) | ||
|
||
describe('Spv with ContainerGroup', () => { | ||
// const group = new ContainerGroup([ | ||
// new MasterNodeRegTestContainer(GenesisKeys[0]), | ||
// new MasterNodeRegTestContainer(GenesisKeys[1]) | ||
// ]) | ||
// const client0 = new ContainerAdapterClient(group.get(0)) | ||
// const client1 = new ContainerAdapterClient(group.get(1)) | ||
|
||
// beforeAll(async () => { | ||
// // await group.start() | ||
// // await group.get(0).call('spv_fundaddress', [await group.get(0).call('spv_getnewaddress')]) // Funds 1 BTC | ||
// }) | ||
|
||
// afterAll(async () => { | ||
// // await group.stop() | ||
// }) | ||
|
||
it.skip('should getHtlcSeed in multi node setup', async () => { | ||
// TODO | ||
}) | ||
}) |
Oops, something went wrong.