Skip to content

Commit

Permalink
Used Hex in mocked bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Oct 20, 2023
1 parent c3213f0 commit b471fe5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
7 changes: 4 additions & 3 deletions typescript/test/data/redemption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export interface RedemptionProofTestData {
redemptionTx: BitcoinRawTxVectors
redemptionProof: BitcoinSpvProof
mainUtxo: BitcoinUtxo
walletPublicKey: string
walletPublicKey: Hex
}
}

Expand Down Expand Up @@ -720,8 +720,9 @@ export const redemptionProof: RedemptionProofTestData = {
outputIndex: 1,
value: BigNumber.from(1429580),
},
walletPublicKey:
"03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9",
walletPublicKey: Hex.from(
"03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9"
),
},
}

Expand Down
2 changes: 1 addition & 1 deletion typescript/test/services/maintenance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,7 @@ describe("Maintenance", () => {
const bridgeLog = tbtcContracts.bridge.redemptionProofLog
expect(bridgeLog.length).to.equal(1)
expect(bridgeLog[0].mainUtxo).to.equal(mainUtxo)
expect(bridgeLog[0].walletPublicKey).to.equal(
expect(bridgeLog[0].walletPublicKey).to.deep.equal(
redemptionProof.expectedRedemptionProof.walletPublicKey
)
expect(bridgeLog[0].redemptionTx).to.deep.equal(
Expand Down
13 changes: 7 additions & 6 deletions typescript/test/services/redemptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ describe("Redemptions", () => {
>()

const key = MockBridge.buildRedemptionKey(
walletPublicKeyHash.toString(),
redeemerOutputScript.toString()
walletPublicKeyHash,
redeemerOutputScript
)

pendingRedemptions.set(
Expand Down Expand Up @@ -465,13 +465,14 @@ describe("Redemptions", () => {
>()

const pendingRedemption1 = MockBridge.buildRedemptionKey(
walletPublicKeyHash.toString(),
redeemerOutputScript.toString()
walletPublicKeyHash,
redeemerOutputScript
)

const pendingRedemption2 = MockBridge.buildRedemptionKey(
findWalletForRedemptionData.liveWallet.event.walletPublicKeyHash.toString(),
redeemerOutputScript.toString()
findWalletForRedemptionData.liveWallet.event
.walletPublicKeyHash,
redeemerOutputScript
)

pendingRedemptions.set(
Expand Down
38 changes: 19 additions & 19 deletions typescript/test/utils/mock-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ interface RevealDepositLogEntry {
}

interface RequestRedemptionLogEntry {
walletPublicKey: string
walletPublicKey: Hex
mainUtxo: BitcoinUtxo
redeemerOutputScript: string
redeemerOutputScript: Hex
amount: BigNumber
}

interface RedemptionProofLogEntry {
redemptionTx: BitcoinRawTxVectors
redemptionProof: BitcoinSpvProof
mainUtxo: BitcoinUtxo
walletPublicKey: string
walletPublicKey: Hex
}

interface NewWalletRegisteredEventsLog {
Expand All @@ -55,7 +55,7 @@ interface NewWalletRegisteredEventsLog {
}

interface WalletLog {
walletPublicKeyHash: string
walletPublicKeyHash: Hex
}

/**
Expand Down Expand Up @@ -229,7 +229,7 @@ export class MockBridge implements Bridge {
redemptionTx,
redemptionProof,
mainUtxo,
walletPublicKey: walletPublicKey.toString(),
walletPublicKey,
})
return new Promise<void>((resolve, _) => {
resolve()
Expand All @@ -243,9 +243,9 @@ export class MockBridge implements Bridge {
amount: BigNumber
) {
this._requestRedemptionLog.push({
walletPublicKey: walletPublicKey.toString(),
walletPublicKey,
mainUtxo,
redeemerOutputScript: redeemerOutputScript.toString(),
redeemerOutputScript,
amount,
})
return new Promise<void>((resolve, _) => {
Expand All @@ -266,8 +266,8 @@ export class MockBridge implements Bridge {
return new Promise<RedemptionRequest>((resolve, _) => {
resolve(
this.redemptions(
walletPublicKey.toString(),
redeemerOutputScript.toString(),
walletPublicKey,
redeemerOutputScript,
this._pendingRedemptions
)
)
Expand All @@ -281,21 +281,21 @@ export class MockBridge implements Bridge {
return new Promise<RedemptionRequest>((resolve, _) => {
resolve(
this.redemptions(
walletPublicKey.toString(),
redeemerOutputScript.toString(),
walletPublicKey,
redeemerOutputScript,
this._timedOutRedemptions
)
)
})
}

private redemptions(
walletPublicKey: string,
redeemerOutputScript: string,
walletPublicKey: Hex,
redeemerOutputScript: Hex,
redemptionsMap: Map<BigNumberish, RedemptionRequest>
): RedemptionRequest {
const redemptionKey = MockBridge.buildRedemptionKey(
BitcoinHashUtils.computeHash160(Hex.from(walletPublicKey)).toString(),
BitcoinHashUtils.computeHash160(walletPublicKey),
redeemerOutputScript
)

Expand All @@ -314,12 +314,12 @@ export class MockBridge implements Bridge {
}

static buildRedemptionKey(
walletPublicKeyHash: string,
redeemerOutputScript: string
walletPublicKeyHash: Hex,
redeemerOutputScript: Hex
): string {
const prefixedWalletPublicKeyHash = `0x${walletPublicKeyHash}`
const prefixedWalletPublicKeyHash = walletPublicKeyHash.toPrefixedString()

const rawOutputScript = Buffer.from(redeemerOutputScript, "hex")
const rawOutputScript = redeemerOutputScript.toBuffer()

const prefixedOutputScript = `0x${Buffer.concat([
Buffer.from([rawOutputScript.length]),
Expand Down Expand Up @@ -353,7 +353,7 @@ export class MockBridge implements Bridge {

async wallets(walletPublicKeyHash: Hex): Promise<Wallet> {
this._walletsLog.push({
walletPublicKeyHash: walletPublicKeyHash.toPrefixedString(),
walletPublicKeyHash,
})
const wallet = this._wallets.get(walletPublicKeyHash.toPrefixedString())
return wallet!
Expand Down

0 comments on commit b471fe5

Please sign in to comment.