From b471fe5cbbb7ccf340413aedca2b7ef505ff595d Mon Sep 17 00:00:00 2001 From: Tomasz Slabon Date: Fri, 20 Oct 2023 18:17:13 +0200 Subject: [PATCH] Used Hex in mocked bridge --- typescript/test/data/redemption.ts | 7 ++-- typescript/test/services/maintenance.test.ts | 2 +- typescript/test/services/redemptions.test.ts | 13 +++---- typescript/test/utils/mock-bridge.ts | 38 ++++++++++---------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/typescript/test/data/redemption.ts b/typescript/test/data/redemption.ts index 7b0d6ef8a..deeea11a3 100644 --- a/typescript/test/data/redemption.ts +++ b/typescript/test/data/redemption.ts @@ -551,7 +551,7 @@ export interface RedemptionProofTestData { redemptionTx: BitcoinRawTxVectors redemptionProof: BitcoinSpvProof mainUtxo: BitcoinUtxo - walletPublicKey: string + walletPublicKey: Hex } } @@ -720,8 +720,9 @@ export const redemptionProof: RedemptionProofTestData = { outputIndex: 1, value: BigNumber.from(1429580), }, - walletPublicKey: - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9", + walletPublicKey: Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ), }, } diff --git a/typescript/test/services/maintenance.test.ts b/typescript/test/services/maintenance.test.ts index cbca52a78..8b0f3d7bd 100644 --- a/typescript/test/services/maintenance.test.ts +++ b/typescript/test/services/maintenance.test.ts @@ -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( diff --git a/typescript/test/services/redemptions.test.ts b/typescript/test/services/redemptions.test.ts index c8dbd7344..2d429696f 100644 --- a/typescript/test/services/redemptions.test.ts +++ b/typescript/test/services/redemptions.test.ts @@ -376,8 +376,8 @@ describe("Redemptions", () => { >() const key = MockBridge.buildRedemptionKey( - walletPublicKeyHash.toString(), - redeemerOutputScript.toString() + walletPublicKeyHash, + redeemerOutputScript ) pendingRedemptions.set( @@ -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( diff --git a/typescript/test/utils/mock-bridge.ts b/typescript/test/utils/mock-bridge.ts index 31cb72365..43b1cc8d0 100644 --- a/typescript/test/utils/mock-bridge.ts +++ b/typescript/test/utils/mock-bridge.ts @@ -36,9 +36,9 @@ interface RevealDepositLogEntry { } interface RequestRedemptionLogEntry { - walletPublicKey: string + walletPublicKey: Hex mainUtxo: BitcoinUtxo - redeemerOutputScript: string + redeemerOutputScript: Hex amount: BigNumber } @@ -46,7 +46,7 @@ interface RedemptionProofLogEntry { redemptionTx: BitcoinRawTxVectors redemptionProof: BitcoinSpvProof mainUtxo: BitcoinUtxo - walletPublicKey: string + walletPublicKey: Hex } interface NewWalletRegisteredEventsLog { @@ -55,7 +55,7 @@ interface NewWalletRegisteredEventsLog { } interface WalletLog { - walletPublicKeyHash: string + walletPublicKeyHash: Hex } /** @@ -229,7 +229,7 @@ export class MockBridge implements Bridge { redemptionTx, redemptionProof, mainUtxo, - walletPublicKey: walletPublicKey.toString(), + walletPublicKey, }) return new Promise((resolve, _) => { resolve() @@ -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((resolve, _) => { @@ -266,8 +266,8 @@ export class MockBridge implements Bridge { return new Promise((resolve, _) => { resolve( this.redemptions( - walletPublicKey.toString(), - redeemerOutputScript.toString(), + walletPublicKey, + redeemerOutputScript, this._pendingRedemptions ) ) @@ -281,8 +281,8 @@ export class MockBridge implements Bridge { return new Promise((resolve, _) => { resolve( this.redemptions( - walletPublicKey.toString(), - redeemerOutputScript.toString(), + walletPublicKey, + redeemerOutputScript, this._timedOutRedemptions ) ) @@ -290,12 +290,12 @@ export class MockBridge implements Bridge { } private redemptions( - walletPublicKey: string, - redeemerOutputScript: string, + walletPublicKey: Hex, + redeemerOutputScript: Hex, redemptionsMap: Map ): RedemptionRequest { const redemptionKey = MockBridge.buildRedemptionKey( - BitcoinHashUtils.computeHash160(Hex.from(walletPublicKey)).toString(), + BitcoinHashUtils.computeHash160(walletPublicKey), redeemerOutputScript ) @@ -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]), @@ -353,7 +353,7 @@ export class MockBridge implements Bridge { async wallets(walletPublicKeyHash: Hex): Promise { this._walletsLog.push({ - walletPublicKeyHash: walletPublicKeyHash.toPrefixedString(), + walletPublicKeyHash, }) const wallet = this._wallets.get(walletPublicKeyHash.toPrefixedString()) return wallet!