Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
add post-withdraw bitcoin balance assertion to integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
keppel committed Sep 2, 2019
1 parent b030571 commit 82b7ac0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class Relay {
signatoryKeys,
this.network
)
let result = await rpc.sendRawTransaction(finalizedTx.toHex())
}
// TODO: not properly tracking processed transactions on state.
// Relay deposit transactions to the peg chain
Expand Down
5 changes: 0 additions & 5 deletions src/reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,3 @@ export function createOutput(
network: networks[network === 'mainnet' ? 'bitcoin' : network]
}).output as Buffer
}

function resolveNetwork(network: string) {
if (network === 'mainnet') {
}
}
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,6 @@ export interface BitcoinRPC {
rescan?: boolean,
p2sh?: boolean
): void

sendRawTransaction(txHex: string): string
}
14 changes: 13 additions & 1 deletion test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import getPort = require('get-port')
import { commitPubkey, signDisbursal } from '../src/signatory'
let seed = require('random-bytes-seed')
import { Relay } from '../src/relay'
import * as bitcoin from 'bitcoinjs-lib'
let RPCClient = require('bitcoin-core')
let { genValidator } = require('tendermint-node')
let ed = require('ed25519-supercop')
Expand Down Expand Up @@ -250,10 +251,15 @@ test('deposit / send / withdraw', async function(t) {
// Bob submits a withdrawal transaction.
let signingTx = await lc.state.bitcoin.signingTx
t.is(signingTx, null)
let bobBtcAddress = await ctx.bobRpc.getNewAddress()
let outputScript = bitcoin.address.toOutputScript(
bobBtcAddress,
bitcoin.networks.regtest
)
await ctx.bobWallet.send({
type: 'bitcoin',
amount: 5e8,
script: Buffer.from([1, 2, 3, 4])
script: outputScript
})
signingTx = await lc.state.bitcoin.signingTx
t.is(signingTx.outputs[0].amount, 5e8)
Expand All @@ -265,7 +271,13 @@ test('deposit / send / withdraw', async function(t) {
t.is(signingTx, null)
let signedTx: SignedTx | null = await lc.state.bitcoin.signedTx

// The signed tx gets broadcast to the Bitcoin network by the relayer:
await ctx.relay.step()
await ctx.minerRpc.generateToAddress(1, minerBtcAddress)

// Now bob has some Bitcoin.
let bobBtcBalance = await ctx.bobRpc.getBalance()
t.is(bobBtcBalance, 4.99999)
})

function formatHeader(header: RPCHeader) {
Expand Down

0 comments on commit 82b7ac0

Please sign in to comment.