citadel-tech / coinswap

Functioning, minimal-viable binaries and libraries to perform a trustless, p2p Maxwell-Belcher Coinswap Protocol

Home Page:https://gist.github.com/chris-belcher/9144bd57a91c194e332fb5ca371d0964

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatically spawn regtest bitcoind node.

rajarshimaitra opened this issue · comments

commented

Our current integration test in integration.rs performs a basic swap. But it requires an already running bitcoins instance with a wallet named teleport loaded with available balance.

This is handled in the CI by downloading and running a bitcoind binary with specific configs and performing the wallet loading part before running the tests.

Check: https://github.com/utxo-teleport/teleport-transactions/blob/96f83ddd4f1e7228737bcd2dc98c0d492da8e291/.github/workflows/coverage.yaml#L25-L42

This can be automated using the bitcoind crate. https://docs.rs/bitcoind/latest/bitcoind/

Create a basic testing framework with bitcoind crate with APIs to control the background node.

struct TestNode {
     bitcoind: Bitcoind
     ...
}

A few important ones are

  • Mine blocks,
  • get transaction in mempool,
  • get transaction in block,
  • broadcast transaction.
  • Reorg blocks.

Use the resulting Bitcoind to connect with the taker and maker wallets. Modify the test_basic_coinswap in /tests/integration.rs to use the TestNode struct. All existing tests should pass.

For reference, check out the BDK lib's testing framework: https://github.com/bitcoindevkit/bdk/blob/78529b6a429e066d5c0290111c9e26f908af5fa4/src/testutils/blockchain_tests.rs#L29-L324