Skip to content

Commit e95ab1f

Browse files
authored
Minting roundtrip system tests scenario (#497)
Here we add a new system test scenario that leverages the TBTCVault contract. The scenario consists of several steps: 1. Initiate minting of TBTC tokens by creating a deposit pointing to the TBTCVault 2. Sweep the deposit on the BTC side and submit the SPV proof of the sweep to the Bridge 3. Unmint the minted TBTC tokens and request redemption using the token's approve-and-call mechanism 4. Redeem on the BTC side and submit the SPV proof of redemption to the Bridge Apart from that, this PR: - Bumps the tbtc-v2.ts dependency to pull recent changes and adjusts the existing system tests code accordingly - Adds the new minting scenario to the existing system tests CI workflow
2 parents 44998d5 + eb86680 commit e95ab1f

File tree

7 files changed

+1122
-365
lines changed

7 files changed

+1122
-365
lines changed

.github/workflows/system-tests.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,59 @@ jobs:
6161
DEPOSITOR_BITCOIN_WIF: ${{ secrets.SYSTEM_TESTS_DEPOSITOR_PRIVATE_KEY_WIF }}
6262
run: |
6363
yarn test ./test/deposit-redemption.test.ts --network $ETH_NETWORK
64+
65+
system-tests-minting-unminting:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v3
69+
70+
- uses: actions/setup-node@v3
71+
with:
72+
node-version: "14.x"
73+
cache: "yarn"
74+
cache-dependency-path: system-tests/yarn.lock
75+
76+
- name: Configure git to not use unauthenticated protocol
77+
run: git config --global url."https://".insteadOf git://
78+
79+
- name: Install solidity dependencies
80+
working-directory: ./solidity
81+
run: yarn install
82+
83+
- name: Run ethereum node
84+
working-directory: ./solidity
85+
run: |
86+
npx hardhat node --no-deploy &
87+
HH_NODE_PID=$!
88+
while ! lsof -n -Fn -p $HH_NODE_PID | grep -q '^n.*:8545$'; do sleep 10; done
89+
90+
- name: Deploy contracts
91+
working-directory: ./solidity
92+
env:
93+
ETH_NETWORK: system_tests
94+
run: |
95+
USE_EXTERNAL_DEPLOY=true npx hardhat deploy --network $ETH_NETWORK --export export.json
96+
97+
- name: Setup scenario prerequisites
98+
working-directory: ./solidity
99+
env:
100+
WALLET_PUBLIC_KEY: ${{ secrets.SYSTEM_TESTS_WALLET_PUBLIC_KEY }}
101+
ETH_NETWORK: system_tests
102+
run: |
103+
npx hardhat test-utils:register-operators --network $ETH_NETWORK
104+
npx hardhat test-utils:create-wallet --wallet-public-key $WALLET_PUBLIC_KEY --network $ETH_NETWORK
105+
106+
- name: Install system tests dependencies
107+
working-directory: ./system-tests
108+
run: yarn install
109+
110+
- name: Run scenario
111+
working-directory: ./system-tests
112+
env:
113+
ETH_NETWORK: system_tests
114+
ELECTRUM_URL: ${{ secrets.SYSTEM_TESTS_ELECTRUM_URL }}
115+
CONTRACTS_DEPLOYMENT_EXPORT_FILE_PATH: ../solidity/export.json
116+
WALLET_BITCOIN_WIF: ${{ secrets.SYSTEM_TESTS_WALLET_PRIVATE_KEY_WIF }}
117+
DEPOSITOR_BITCOIN_WIF: ${{ secrets.SYSTEM_TESTS_DEPOSITOR_PRIVATE_KEY_WIF }}
118+
run: |
119+
yarn test ./test/minting-unminting.test.ts --network $ETH_NETWORK

system-tests/test/deposit-redemption.test.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,24 @@ import {
33
SpvMaintainer,
44
ElectrumClient,
55
EthereumBridge,
6-
} from "@keep-network/tbtc-v2.ts"
7-
import {
8-
computeHash160,
9-
TransactionHash,
10-
} from "@keep-network/tbtc-v2.ts/dist/bitcoin"
6+
BitcoinTransactionHash,
7+
} from "@keep-network/tbtc-v2.ts/dist/src"
8+
import { computeHash160 } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
119
import { BigNumber, constants, Contract } from "ethers"
1210
import chai, { expect } from "chai"
13-
import { submitDepositTransaction } from "@keep-network/tbtc-v2.ts/dist/deposit"
14-
import { submitDepositSweepTransaction } from "@keep-network/tbtc-v2.ts/dist/deposit-sweep"
15-
import { submitRedemptionTransaction } from "@keep-network/tbtc-v2.ts/dist/redemption"
11+
import { submitDepositTransaction } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
12+
import { submitDepositSweepTransaction } from "@keep-network/tbtc-v2.ts/dist/src/deposit-sweep"
13+
import { submitRedemptionTransaction } from "@keep-network/tbtc-v2.ts/dist/src/redemption"
1614
import chaiAsPromised from "chai-as-promised"
1715

1816
import { setupSystemTestsContext } from "./utils/context"
1917
import { generateDeposit } from "./utils/deposit"
2018
import { fakeRelayDifficulty, waitTransactionConfirmed } from "./utils/bitcoin"
2119

22-
import type { UnspentTransactionOutput } from "@keep-network/tbtc-v2.ts/dist/bitcoin"
20+
import type { UnspentTransactionOutput } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
2321
import type { SystemTestsContext } from "./utils/context"
24-
import type { RedemptionRequest } from "@keep-network/tbtc-v2.ts/dist/redemption"
25-
import type { Deposit } from "@keep-network/tbtc-v2.ts/dist/deposit"
22+
import type { RedemptionRequest } from "@keep-network/tbtc-v2.ts/dist/src/redemption"
23+
import type { Deposit } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
2624

2725
chai.use(chaiAsPromised)
2826

@@ -72,12 +70,12 @@ describe("System Test - Deposit and redemption", () => {
7270

7371
maintainerBridgeHandle = new EthereumBridge({
7472
address: bridgeAddress,
75-
signer: maintainer,
73+
signerOrProvider: maintainer,
7674
})
7775

7876
depositorBridgeHandle = new EthereumBridge({
7977
address: bridgeAddress,
80-
signer: depositor,
78+
signerOrProvider: depositor,
8179
})
8280

8381
const bankDeploymentInfo = deployedContracts.Bank
@@ -188,7 +186,7 @@ describe("System Test - Deposit and redemption", () => {
188186
// This is the first sweep of the given wallet so there is no main UTXO.
189187
{
190188
// The function expects an unprefixed hash.
191-
transactionHash: TransactionHash.from(constants.HashZero),
189+
transactionHash: BitcoinTransactionHash.from(constants.HashZero),
192190
outputIndex: 0,
193191
value: BigNumber.from(0),
194192
},
@@ -274,6 +272,16 @@ describe("System Test - Deposit and redemption", () => {
274272
)
275273
})
276274

275+
it("should transfer depositor's bank balance to the Bridge", async () => {
276+
expect(
277+
await bank.balanceOf(systemTestsContext.depositor.address)
278+
).to.be.equal(0)
279+
280+
expect(await bank.balanceOf(bridgeAddress)).to.be.equal(
281+
requestedAmount
282+
)
283+
})
284+
277285
it("should register the redemption request on the bridge", async () => {
278286
expect(redemptionRequest.requestedAt).to.be.greaterThan(0)
279287
expect(redemptionRequest.requestedAmount).to.be.equal(requestedAmount)
@@ -285,7 +293,7 @@ describe("System Test - Deposit and redemption", () => {
285293
context(
286294
"when redemption is made and redemption proof submitted",
287295
() => {
288-
let redemptionTxHash: TransactionHash
296+
let redemptionTxHash: BitcoinTransactionHash
289297

290298
before(
291299
"make the redemption and submit redemption proof",
@@ -345,10 +353,8 @@ describe("System Test - Deposit and redemption", () => {
345353
)
346354
})
347355

348-
it("should decrease depositor's balance in the bank", async () => {
349-
const actualBalance = await bank.balanceOf(
350-
systemTestsContext.depositor.address
351-
)
356+
it("should decrease Bridge's balance in the bank", async () => {
357+
const actualBalance = await bank.balanceOf(bridgeAddress)
352358

353359
expect(actualBalance).to.be.equal(0)
354360
})

0 commit comments

Comments
 (0)