Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Oct 3, 2024
1 parent 9dbf75c commit 632587b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
3 changes: 0 additions & 3 deletions e2e/e2etests/test_extract_bitcoin_inscription_memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
zetabitcoin "github.com/zeta-chain/node/zetaclient/chains/bitcoin"
btcobserver "github.com/zeta-chain/node/zetaclient/chains/bitcoin/observer"
)

Expand Down Expand Up @@ -41,15 +40,13 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) {
r.Logger.Info("obtained reveal txn id %s", txid)

dummyCoinbaseTxn := rawtx
depositorFee := zetabitcoin.DefaultDepositorFee
events, err := btcobserver.FilterAndParseIncomingTx(
r.BtcRPCClient,
[]btcjson.TxRawResult{*dummyCoinbaseTxn, *rawtx},
0,
r.BTCTSSAddress.String(),
log.Logger,
r.BitcoinParams,
depositorFee,
)
require.NoError(r, err)

Expand Down
34 changes: 24 additions & 10 deletions zetaclient/chains/bitcoin/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,33 +609,47 @@ func TestGetBtcEvent(t *testing.T) {
// https://mempool.space/tx/847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa
txHash := "847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa"
chain := chains.BitcoinMainnet

// GetBtcEventWithoutWitness arguments
tx := testutils.LoadBTCInboundRawResult(t, TestDataDir, chain.ChainId, txHash, false)
tssAddress := testutils.TSSAddressBTCMainnet
blockNumber := uint64(835640)
net := &chaincfg.MainNetParams
// 2.992e-05, see avgFeeRate https://mempool.space/api/v1/blocks/835640
depositorFee := bitcoin.DepositorFee(22 * clientcommon.BTCOutboundGasPriceMultiplier)

// fee rate of above tx is 28 sat/vB
depositorFee := bitcoin.DepositorFee(28 * clientcommon.BTCOutboundGasPriceMultiplier)

// expected result
memo, err := hex.DecodeString(tx.Vout[1].ScriptPubKey.Hex[4:])
require.NoError(t, err)
eventExpected := &observer.BTCInboundEvent{
FromAddress: "bc1q68kxnq52ahz5vd6c8czevsawu0ux9nfrzzrh6e",
ToAddress: tssAddress,
Value: tx.Vout[0].Value - depositorFee, // 7008 sataoshis
MemoBytes: memo,
BlockNumber: blockNumber,
TxHash: tx.Txid,
FromAddress: "bc1q68kxnq52ahz5vd6c8czevsawu0ux9nfrzzrh6e",
ToAddress: tssAddress,
Value: tx.Vout[0].Value - depositorFee, // 6192 sataoshis
DepositorFee: depositorFee,
MemoBytes: memo,
BlockNumber: blockNumber,
TxHash: tx.Txid,
}

// https://mempool.space/tx/c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697
preHash := "c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697"
tx.Vin[0].Txid = preHash
tx.Vin[0].Vout = 2
eventExpected.FromAddress = "bc1q68kxnq52ahz5vd6c8czevsawu0ux9nfrzzrh6e"
// load previous raw tx so so mock rpc client can return it
rpcClient := mocks.NewBTCRPCClient(t)
rpcClient := testrpc.CreateBTCRPCAndLoadTx(t, TestDataDir, chain.ChainId, preHash)

// get BTC event
event, err := observer.GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee)
event, err := observer.GetBtcEvent(
rpcClient,
*tx,
tssAddress,
blockNumber,
log.Logger,
net,
depositorFee,
)
require.NoError(t, err)
require.Equal(t, eventExpected, event)
})
Expand Down

0 comments on commit 632587b

Please sign in to comment.