Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ run-demo-regtest-replenisher-very-small-coins: packages/fastbtc-node/version.jso
.PHONY: run-demo-regtest-replenisher-limits
run-demo-regtest-replenisher-limits: packages/fastbtc-node/version.json
@export TEST_REPLENISHER_LIMITS=true && make run-demo-regtest
.PHONY: run-demo-regtest-cpfp
run-demo-regtest-cpfp: packages/fastbtc-node/version.json
@export TEST_CPFP=true && make run-demo-regtest

.PHONY: show-node-logs
show-node-logs:
@docker-compose -f docker-compose-base.yml -f docker-compose-regtest.yml logs -f node1 node2 node3

# This is very hacky :P We grep for a message only sent by the initiator and parse the node id from there
.PHONY: show-initiator-logs
show-initiator-logs:
docker-compose -f docker-compose-base.yml -f docker-compose-regtest.yml logs -f $$( \
docker-compose -f docker-compose-base.yml -f docker-compose-regtest.yml logs --no-color \
| grep -e 'stored batches in total' | tail -1 | cut -d_ -f 1)

.PHONY: build-regtest-bitcoin
build-regtest-bitcoin:
@(cd integration_test/bitcoind-regtest \
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,37 @@ $ make test-transfers-big-amounts

Observe the output, quit with Ctrl-C if wanted (though it quits automatically on success).

#### Automatic bumping of slow transfers with CPFP

This test tests the case when a bitcoin transfer is slow and requires a CPFP (child-pays-for-parent)
transaction to speed it up.

This is notoriously hard to test in a regtest environment. The test case will validate
that the code for creating a CPFP transaction works, but it will not actually test that
it will actually bump the parent transaction.

```
# In one tab:
$ make run-demo-regtest-cpfp
# In another tab
$ make test-transfers
```

Observe the output, quit with Ctrl-C if wanted (though it quits automatically on success).

You should see the lines:
```
TEST_CPFP is true, only sleeping for 100 ms
```
and
```
CPFP transaction successfully sent to bitcoin
```
in the output.

This test will also take ~10 minutes to run.


### Advanced details

The test setup (launched with `make run-demo-regtest`) will expose the Hardhat RPC server at `http://localhost:18545`
Expand Down
4 changes: 4 additions & 0 deletions docker-compose-regtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
# Extra test vars
- TEST_VERY_SMALL_REPLENISHER_COINS
- TEST_REPLENISHER_LIMITS
- TEST_CPFP

ports:
- 18443:18443
Expand All @@ -55,6 +56,7 @@ services:
- FASTBTC_RSK_RPC_URL=http://hardhat:8545
- FASTBTC_BTC_RPC_URL=http://bitcoin-regtest:18443/wallet/multisig
- FASTBTC_REPLENISHER_RPC_URL=http://bitcoin-regtest:18443/wallet/replenisher
- TEST_CPFP
depends_on:
- bitcoin-regtest
- hardhat
Expand All @@ -64,6 +66,7 @@ services:
- FASTBTC_RSK_RPC_URL=http://hardhat:8545
- FASTBTC_BTC_RPC_URL=http://bitcoin-regtest:18443/wallet/multisig
- FASTBTC_REPLENISHER_RPC_URL=http://bitcoin-regtest:18443/wallet/replenisher
- TEST_CPFP
depends_on:
- bitcoin-regtest
- hardhat
Expand All @@ -81,6 +84,7 @@ services:
- FASTBTC_RSK_RPC_URL=http://hardhat:8545
- FASTBTC_BTC_RPC_URL=http://bitcoin-regtest:18443/wallet/multisig
- FASTBTC_REPLENISHER_RPC_URL=http://bitcoin-regtest:18443/wallet/replenisher
- TEST_CPFP
depends_on:
- bitcoin-regtest
- hardhat
Expand Down
18 changes: 17 additions & 1 deletion integration_test/bitcoind-regtest/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ echo "done"
# triggered (as long as the number matches the one configured in the backend) -- and the rest to the replenisher
# wallet. This is meant to test the case where a new TransferBatch cannot be created because the multisig doesn't
# have enough funds, but the replenisher doesn't trigger either because the balance is over the threshold.
# - If TEST_CPFP is true, we wait a crapton of time between mining new blocks. This is very slow, but
# it enables us to actually send a CPFP transaction and test that the code does not fail.
# Caveat: It does not actually test that the CPFP transaction does a CPFP.
#
# Ugh.
echo "Test settings:"
echo "TEST_VERY_SMALL_REPLENISHER_COINS=$TEST_VERY_SMALL_REPLENISHER_COINS"
echo "TEST_REPLENISHER_LIMITS=$TEST_REPLENISHER_LIMITS"
echo "TEST_CPFP=$TEST_CPFP"

# We need a temporary address for both of these cases, because we need to send amounts smaller than the block reward.
if [[ "$TEST_VERY_SMALL_REPLENISHER_COINS" = "true" || "$TEST_REPLENISHER_LIMITS" = "true" ]]
Expand Down Expand Up @@ -107,6 +111,12 @@ then
echo "Sending 5.5 BTC to the multisig (should be just over the threshold)..."
bitcoin-cli -rpcwallet=temporary sendtoaddress "$MULTISIG_ADDRESS" 5.5 > /dev/null
else
if [[ "$TEST_CPFP" = "true" ]]
then
echo "Generating 101 blocks (sending balance to multisig because we are testing CPFP)..."
bitcoin-cli -rpcwallet=replenisher generatetoaddress 101 "$MULTISIG_ADDRESS" > /dev/null
fi

echo "Generating 101+ blocks (sending balance to replenisher wallet, not directly to multisig)..."
echo "Init replenisher funds"
for i in $(bitcoin-cli deriveaddresses "$REPLENISHER_SOURCE_DESCRIPTOR" '[5,10]'|cut -f 2 -d '"'|grep bc)
Expand Down Expand Up @@ -147,7 +157,13 @@ do
# sending to replenisher here, not multisig
bitcoin-cli -rpcwallet=replenisher generatetoaddress 1 "$i" > /dev/null
fi
sleep 1

if [[ "$TEST_CPFP" = "true" ]]
then
sleep 300
else
sleep 1
fi
done
done

35 changes: 34 additions & 1 deletion packages/fastbtc-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ task("show-transfer", "Show transfer details")

});


task("ispaused", "Check if the bridge is paused")
.addPositionalParam('btcAddressOrTransferId')
.addOptionalPositionalParam('nonce')
.addOptionalParam("bridgeAddress", "FastBTCBridge contract address (if empty, use deployment)")
.setAction(async ({ btcAddressOrTransferId, nonce, bridgeAddress }, hre) => {
const contract = await hre.ethers.getContractAt(
'FastBTCBridge',
await getDeploymentAddress(bridgeAddress, hre, 'FastBTCBridge'),
);

let transferId;
if (nonce === undefined) {
console.log('Nonce not given, treat', btcAddressOrTransferId, 'as transferId');
transferId = btcAddressOrTransferId;
} else {
console.log('Nonce given, treat', btcAddressOrTransferId, 'as btcAddress');
transferId = await contract.getTransferId(btcAddressOrTransferId, nonce);
}

console.log('transferId', transferId);

const transfer = await contract.getTransferByTransferId(transferId);
for (let [key, value] of transfer.entries()) {
console.log(
key,
BigNumber.isBigNumber(value) ? value.toString() : value
);
}
console.log(transfer);

});

task("free-money", "Sends free money to address")
.addPositionalParam("address", "Address to send free money to")
.addPositionalParam("rbtcAmount", "RBTC amount to send", "1.0")
Expand Down Expand Up @@ -276,7 +309,7 @@ task('roles', 'Manage roles')
await getDeploymentAddress(undefined, hre, 'FastBTCAccessControl'),
signer,
);

console.log('fastBTCBridge address', await getDeploymentAddress(undefined, hre, 'FastBTCBridge'));
console.log(`${action} role ${role}`, account ? `for ${account}` : '');
const roleHash = await accessControl[`ROLE_${role}`]();
console.log('role hash:', roleHash);
Expand Down
Loading