-
Notifications
You must be signed in to change notification settings - Fork 0
feat: PoC implementation of scanning for nBTC txs logic #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f6abcf
PoC implementation of scanning for nBTC txs logic
sczembor 7580389
Merge branch 'master' into stan/scan_for_nbtc_tx
sczembor aafb5ee
finish the discovery logic; unit test
sczembor 96d6c44
remove sender address
sczembor b201ad4
lint
sczembor 3ec2d9c
Apply suggestions from code review
sczembor 07d1ff9
apply code review suggestions
sczembor cd2b8a8
disable lint rule
sczembor 1ee4b9e
linter
sczembor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,51 @@ | ||
| import { expect, test } from "vitest"; | ||
| import { describe, it, assert } from "vitest"; | ||
| import { Indexer } from "../src/btcindexer"; | ||
| import { Block, networks } from "bitcoinjs-lib"; | ||
|
|
||
| import { Indexer } from "./btcindexer"; | ||
| // generated using bitcoin-cli --regtest | ||
| const REGTEST_DATA = { | ||
| DEPOSIT_ADDR: "bcrt1qfnyeg7dd5vqs2mtc4rekwm8mgpxkj647p39zhw", | ||
| SUI_ADDR: "0x123456789", | ||
| BLOCK_HEIGHT: 303, | ||
| BLOCK_ID: "39d7c49ae129865f3aca615bc222b185fdff0ff61385b838bbbf00da8cbbea9d", | ||
| TX_ID: "2060dfd3cdbffb7db6c968357f3c9df91b52a4cef5c02fad0b0836b0f25cc4ca", | ||
| DEPOSIT_AMOUNT_SATS: 50000000, | ||
| RAW_BLOCK_HEX: | ||
| "000000305c2f30d99ad69f247638613dcca7f455159e252878ea6fe10bbc4574a0076914d98ada655d950ac6507d14584fa679d12fb5203c384e52ef292d063fe29b1b645c4b6d68ffff7f200200000002020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04022f0100ffffffff02de82814a0000000016001477174bfb906c0e52d750eac4b40fd86746ad50550000000000000000266a24aa21a9ed27611410788b35b819e10a0227f40f9bbc70df824e3a30879552f004b48451210120000000000000000000000000000000000000000000000000000000000000000000000000020000000001017fec0755f3524b89ad45383343f992a0d5cb797a695b59e30f2fc80794f001050000000000fdffffff032202089200000000160014b125723e78c2d779e3e299dfd95d72e9a067a0b780f0fa02000000001600144cc99479ada301056d78a8f3676cfb404d696abe00000000000000000d6a0b3078313233343536373839024730440220755610ff6b6fdea530c20d11b7765816beb75e16ce78fa200a7da25e251a7eb9022078e78bed1cc38822cd5dce3982e23c3cd401415ae72050b00c5f8b3441a2c178012103ef55b72bddf4960ddbb12a9a04f61f91fb613aa99b472115f25a5f8686e6c3f200000000", | ||
| }; | ||
| const SUI_FALLBACK_ADDRESS = "0xFALLBACK"; | ||
|
|
||
| test("nbtc add tx", async () => { | ||
| const i = new Indexer({} as Env, "todo"); | ||
| expect(await i.putNbtcTx()).toBe(true); | ||
| const mkMockEnv = () => ({ | ||
| DB: {} as D1Database, | ||
| btc_blocks: {} as KVNamespace, | ||
| nbtc_txs: {} as KVNamespace, | ||
| }); | ||
|
|
||
| describe("Indexer.findNbtcDeposits", () => { | ||
| it("should correctly parse the real regtest transaction", () => { | ||
| const mockEnv = mkMockEnv(); | ||
| const indexer = new Indexer( | ||
| mockEnv, | ||
| REGTEST_DATA.DEPOSIT_ADDR, | ||
| SUI_FALLBACK_ADDRESS, | ||
| networks.regtest, | ||
| ); | ||
|
|
||
| const block = Block.fromHex(REGTEST_DATA.RAW_BLOCK_HEX); | ||
| const targetTx = block.transactions?.find((tx) => tx.getId() === REGTEST_DATA.TX_ID); | ||
|
|
||
| assert(targetTx, "Setup error"); | ||
|
|
||
| const deposits = indexer.findNbtcDeposits(targetTx); | ||
| assert.equal(deposits.length, 1); | ||
| assert.equal(deposits[0].amountSats, REGTEST_DATA.DEPOSIT_AMOUNT_SATS); | ||
| assert.equal(deposits[0].suiRecipient, REGTEST_DATA.SUI_ADDR); | ||
| assert.equal(deposits[0].vout, 1); | ||
| }); | ||
| }); | ||
|
|
||
| describe.skip("Indexer.scanNewBlocks", () => { | ||
| it("should be tested later", () => { | ||
| // TODO: add a test for the scanNewBlocks using the same data | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 @@ | ||
| export const OP_RETURN = 0x6a; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.