diff --git a/zetaclient/bitcoin/bitcoin_client_test.go b/zetaclient/bitcoin/bitcoin_client_test.go index 1cf91c910f..21573a7cb5 100644 --- a/zetaclient/bitcoin/bitcoin_client_test.go +++ b/zetaclient/bitcoin/bitcoin_client_test.go @@ -42,13 +42,13 @@ func MockBTCClientMainnet() *BTCChainClient { } // createRPCClientAndLoadTx is a helper function to load raw tx and feed it to mock rpc client -func createRPCClientAndLoadTx(chainId int64, txHash string) *stub.MockBTCRPCClient { +func createRPCClientAndLoadTx(t *testing.T, chainId int64, txHash string) *stub.MockBTCRPCClient { // file name for the archived MsgTx nameMsgTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCMsgTx(chainId, txHash)) // load archived MsgTx var msgTx wire.MsgTx - testutils.LoadObjectFromJSONFile(&msgTx, nameMsgTx) + testutils.LoadObjectFromJSONFile(t, &msgTx, nameMsgTx) tx := btcutil.NewTx(&msgTx) // feed tx to mock rpc client @@ -96,11 +96,11 @@ func TestConfirmationThreshold(t *testing.T) { func TestAvgFeeRateBlock828440(t *testing.T) { // load archived block 828440 var blockVb btcjson.GetBlockVerboseTxResult - testutils.LoadObjectFromJSONFile(&blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json")) + testutils.LoadObjectFromJSONFile(t, &blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json")) // https://mempool.space/block/000000000000000000025ca01d2c1094b8fd3bacc5468cc3193ced6a14618c27 var blockMb testutils.MempoolBlock - testutils.LoadObjectFromJSONFile(&blockMb, path.Join("../", testutils.TestDataPathBTC, "block_mempool.space_8332_828440.json")) + testutils.LoadObjectFromJSONFile(t, &blockMb, path.Join("../", testutils.TestDataPathBTC, "block_mempool.space_8332_828440.json")) gasRate, err := CalcBlockAvgFeeRate(&blockVb, &chaincfg.MainNetParams) require.NoError(t, err) @@ -110,7 +110,7 @@ func TestAvgFeeRateBlock828440(t *testing.T) { func TestAvgFeeRateBlock828440Errors(t *testing.T) { // load archived block 828440 var blockVb btcjson.GetBlockVerboseTxResult - testutils.LoadObjectFromJSONFile(&blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json")) + testutils.LoadObjectFromJSONFile(t, &blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json")) t.Run("block has no transactions", func(t *testing.T) { emptyVb := btcjson.GetBlockVerboseTxResult{Tx: []btcjson.TxRawResult{}} @@ -196,7 +196,7 @@ func TestAvgFeeRateBlock828440Errors(t *testing.T) { func TestCalcDepositorFee828440(t *testing.T) { // load archived block 828440 var blockVb btcjson.GetBlockVerboseTxResult - testutils.LoadObjectFromJSONFile(&blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json")) + testutils.LoadObjectFromJSONFile(t, &blockVb, path.Join("../", testutils.TestDataPathBTC, "block_trimmed_8332_828440.json")) avgGasRate := float64(32.0) // #nosec G701 test - always in range gasRate := int64(avgGasRate * clientcommon.BTCOuttxGasPriceMultiplier) @@ -234,13 +234,13 @@ func TestCheckTSSVout(t *testing.T) { btcClient := MockBTCClientMainnet() t.Run("valid TSS vout should pass", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() err := btcClient.checkTSSVout(params, rawResult.Vout, chain) require.NoError(t, err) }) t.Run("should fail if vout length < 2 or > 3", func(t *testing.T) { - _, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + _, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() err := btcClient.checkTSSVout(params, []btcjson.Vout{{}}, chain) @@ -250,7 +250,7 @@ func TestCheckTSSVout(t *testing.T) { require.ErrorContains(t, err, "invalid number of vouts") }) t.Run("should fail on invalid TSS vout", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() // invalid TSS vout @@ -259,7 +259,7 @@ func TestCheckTSSVout(t *testing.T) { require.Error(t, err) }) t.Run("should fail if vout 0 is not to the TSS address", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() // not TSS address, bc1qh297vdt8xq6df5xae9z8gzd4jsu9a392mp0dus @@ -268,7 +268,7 @@ func TestCheckTSSVout(t *testing.T) { require.ErrorContains(t, err, "not match TSS address") }) t.Run("should fail if vout 0 not match nonce mark", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() // not match nonce mark @@ -277,7 +277,7 @@ func TestCheckTSSVout(t *testing.T) { require.ErrorContains(t, err, "not match nonce-mark amount") }) t.Run("should fail if vout 1 is not to the receiver address", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() // not receiver address, bc1qh297vdt8xq6df5xae9z8gzd4jsu9a392mp0dus @@ -286,7 +286,7 @@ func TestCheckTSSVout(t *testing.T) { require.ErrorContains(t, err, "not match params receiver") }) t.Run("should fail if vout 1 not match payment amount", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() // not match payment amount @@ -295,7 +295,7 @@ func TestCheckTSSVout(t *testing.T) { require.ErrorContains(t, err, "not match params amount") }) t.Run("should fail if vout 2 is not to the TSS address", func(t *testing.T) { - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() // not TSS address, bc1qh297vdt8xq6df5xae9z8gzd4jsu9a392mp0dus @@ -317,7 +317,7 @@ func TestCheckTSSVoutCancelled(t *testing.T) { t.Run("valid TSS vout should pass", func(t *testing.T) { // remove change vout to simulate cancelled tx - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) rawResult.Vout[1] = rawResult.Vout[2] rawResult.Vout = rawResult.Vout[:2] params := cctx.GetCurrentOutTxParam() @@ -326,7 +326,7 @@ func TestCheckTSSVoutCancelled(t *testing.T) { require.NoError(t, err) }) t.Run("should fail if vout length < 1 or > 2", func(t *testing.T) { - _, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + _, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) params := cctx.GetCurrentOutTxParam() err := btcClient.checkTSSVoutCancelled(params, []btcjson.Vout{}, chain) @@ -337,7 +337,7 @@ func TestCheckTSSVoutCancelled(t *testing.T) { }) t.Run("should fail if vout 0 is not to the TSS address", func(t *testing.T) { // remove change vout to simulate cancelled tx - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) rawResult.Vout[1] = rawResult.Vout[2] rawResult.Vout = rawResult.Vout[:2] params := cctx.GetCurrentOutTxParam() @@ -349,7 +349,7 @@ func TestCheckTSSVoutCancelled(t *testing.T) { }) t.Run("should fail if vout 0 not match nonce mark", func(t *testing.T) { // remove change vout to simulate cancelled tx - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) rawResult.Vout[1] = rawResult.Vout[2] rawResult.Vout = rawResult.Vout[:2] params := cctx.GetCurrentOutTxParam() @@ -361,7 +361,7 @@ func TestCheckTSSVoutCancelled(t *testing.T) { }) t.Run("should fail if vout 1 is not to the TSS address", func(t *testing.T) { // remove change vout to simulate cancelled tx - rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(chainID, nonce) + rawResult, cctx := testutils.LoadBTCTxRawResultNCctx(t, chainID, nonce) rawResult.Vout[1] = rawResult.Vout[2] rawResult.Vout = rawResult.Vout[:2] params := cctx.GetCurrentOutTxParam() @@ -381,7 +381,7 @@ func TestGetSenderAddressByVin(t *testing.T) { // vin from the archived P2TR tx // https://mempool.space/tx/3618e869f9e87863c0f1cc46dbbaa8b767b4a5d6d60b143c2c50af52b257e867 txHash := "3618e869f9e87863c0f1cc46dbbaa8b767b4a5d6d60b143c2c50af52b257e867" - rpcClient := createRPCClientAndLoadTx(chain.ChainId, txHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, txHash) // get sender address txVin := btcjson.Vin{Txid: txHash, Vout: 2} @@ -393,7 +393,7 @@ func TestGetSenderAddressByVin(t *testing.T) { // vin from the archived P2WSH tx // https://mempool.space/tx/d13de30b0cc53b5c4702b184ae0a0b0f318feaea283185c1cddb8b341c27c016 txHash := "d13de30b0cc53b5c4702b184ae0a0b0f318feaea283185c1cddb8b341c27c016" - rpcClient := createRPCClientAndLoadTx(chain.ChainId, txHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, txHash) // get sender address txVin := btcjson.Vin{Txid: txHash, Vout: 0} @@ -405,7 +405,7 @@ func TestGetSenderAddressByVin(t *testing.T) { // vin from the archived P2WPKH tx // https://mempool.space/tx/c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697 txHash := "c5d224963832fc0b9a597251c2342a17b25e481a88cc9119008e8f8296652697" - rpcClient := createRPCClientAndLoadTx(chain.ChainId, txHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, txHash) // get sender address txVin := btcjson.Vin{Txid: txHash, Vout: 2} @@ -417,7 +417,7 @@ func TestGetSenderAddressByVin(t *testing.T) { // vin from the archived P2SH tx // https://mempool.space/tx/211568441340fd5e10b1a8dcb211a18b9e853dbdf265ebb1c728f9b52813455a txHash := "211568441340fd5e10b1a8dcb211a18b9e853dbdf265ebb1c728f9b52813455a" - rpcClient := createRPCClientAndLoadTx(chain.ChainId, txHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, txHash) // get sender address txVin := btcjson.Vin{Txid: txHash, Vout: 0} @@ -429,7 +429,7 @@ func TestGetSenderAddressByVin(t *testing.T) { // vin from the archived P2PKH tx // https://mempool.space/tx/781fc8d41b476dbceca283ebff9573fda52c8fdbba5e78152aeb4432286836a7 txHash := "781fc8d41b476dbceca283ebff9573fda52c8fdbba5e78152aeb4432286836a7" - rpcClient := createRPCClientAndLoadTx(chain.ChainId, txHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, txHash) // get sender address txVin := btcjson.Vin{Txid: txHash, Vout: 1} @@ -443,7 +443,7 @@ func TestGetSenderAddressByVin(t *testing.T) { txHash := "781fc8d41b476dbceca283ebff9573fda52c8fdbba5e78152aeb4432286836a7" nameMsgTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCMsgTx(chain.ChainId, txHash)) var msgTx wire.MsgTx - testutils.LoadObjectFromJSONFile(&msgTx, nameMsgTx) + testutils.LoadObjectFromJSONFile(t, &msgTx, nameMsgTx) // modify script to unknown script msgTx.TxOut[1].PkScript = []byte{0x00, 0x01, 0x02, 0x03} // can be any invalid script bytes @@ -485,7 +485,7 @@ func TestGetSenderAddressByVinErrors(t *testing.T) { }) t.Run("should return error on invalid output index", func(t *testing.T) { // create mock rpc client with preloaded tx - rpcClient := createRPCClientAndLoadTx(chain.ChainId, txHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, txHash) // invalid output index txVin := btcjson.Vin{Txid: txHash, Vout: 3} sender, err := GetSenderAddressByVin(rpcClient, txVin, net) @@ -501,7 +501,7 @@ func TestGetBtcEvent(t *testing.T) { chain := common.BtcMainnetChain() // GetBtcEvent arguments - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tssAddress := testutils.TSSAddressBTCMainnet blockNumber := uint64(835640) net := &chaincfg.MainNetParams @@ -527,7 +527,7 @@ func TestGetBtcEvent(t *testing.T) { tx.Vin[0].Vout = 2 eventExpected.FromAddress = "bc1q68kxnq52ahz5vd6c8czevsawu0ux9nfrzzrh6e" // load previous raw tx so so mock rpc client can return it - rpcClient := createRPCClientAndLoadTx(chain.ChainId, preHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event event, err := GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) @@ -542,7 +542,7 @@ func TestGetBtcEvent(t *testing.T) { tx.Vin[0].Vout = 2 eventExpected.FromAddress = "bc1px3peqcd60hk7wqyqk36697u9hzugq0pd5lzvney93yzzrqy4fkpq6cj7m3" // load previous raw tx so so mock rpc client can return it - rpcClient := createRPCClientAndLoadTx(chain.ChainId, preHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event event, err := GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) @@ -557,7 +557,7 @@ func TestGetBtcEvent(t *testing.T) { tx.Vin[0].Vout = 0 eventExpected.FromAddress = "bc1q79kmcyc706d6nh7tpzhnn8lzp76rp0tepph3hqwrhacqfcy4lwxqft0ppq" // load previous raw tx so so mock rpc client can return it - rpcClient := createRPCClientAndLoadTx(chain.ChainId, preHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event event, err := GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) @@ -572,7 +572,7 @@ func TestGetBtcEvent(t *testing.T) { tx.Vin[0].Vout = 0 eventExpected.FromAddress = "3MqRRSP76qxdVD9K4cfFnVtSLVwaaAjm3t" // load previous raw tx so so mock rpc client can return it - rpcClient := createRPCClientAndLoadTx(chain.ChainId, preHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event event, err := GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) @@ -587,7 +587,7 @@ func TestGetBtcEvent(t *testing.T) { tx.Vin[0].Vout = 1 eventExpected.FromAddress = "1ESQp1WQi7fzSpzCNs2oBTqaUBmNjLQLoV" // load previous raw tx so so mock rpc client can return it - rpcClient := createRPCClientAndLoadTx(chain.ChainId, preHash) + rpcClient := createRPCClientAndLoadTx(t, chain.ChainId, preHash) // get BTC event event, err := GetBtcEvent(rpcClient, *tx, tssAddress, blockNumber, log.Logger, net, depositorFee) @@ -596,7 +596,7 @@ func TestGetBtcEvent(t *testing.T) { }) t.Run("should skip tx if len(tx.Vout) < 2", func(t *testing.T) { // load tx and modify the tx to have only 1 vout - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vout = tx.Vout[:1] // get BTC event @@ -608,7 +608,7 @@ func TestGetBtcEvent(t *testing.T) { t.Run("should skip tx if Vout[0] is not a P2WPKH output", func(t *testing.T) { // load tx rpcClient := stub.NewMockBTCRPCClient() - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) // modify the tx to have Vout[0] a P2SH output tx.Vout[0].ScriptPubKey.Hex = strings.Replace(tx.Vout[0].ScriptPubKey.Hex, "0014", "a914", 1) @@ -624,7 +624,7 @@ func TestGetBtcEvent(t *testing.T) { }) t.Run("should skip tx if receiver address is not TSS address", func(t *testing.T) { // load tx and modify receiver address to any non-tss address: bc1qw8wrek2m7nlqldll66ajnwr9mh64syvkt67zlu - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vout[0].ScriptPubKey.Hex = "001471dc3cd95bf4fe0fb7ffd6bb29b865ddf5581196" // get BTC event @@ -635,7 +635,7 @@ func TestGetBtcEvent(t *testing.T) { }) t.Run("should skip tx if amount is less than depositor fee", func(t *testing.T) { // load tx and modify amount to less than depositor fee - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vout[0].Value = depositorFee - 1.0/1e8 // 1 satoshi less than depositor fee // get BTC event @@ -646,7 +646,7 @@ func TestGetBtcEvent(t *testing.T) { }) t.Run("should skip tx if 2nd vout is not OP_RETURN", func(t *testing.T) { // load tx and modify memo OP_RETURN to OP_1 - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vout[1].ScriptPubKey.Hex = strings.Replace(tx.Vout[1].ScriptPubKey.Hex, "6a", "51", 1) // get BTC event @@ -657,7 +657,7 @@ func TestGetBtcEvent(t *testing.T) { }) t.Run("should skip tx if memo decoding fails", func(t *testing.T) { // load tx and modify memo length to be 1 byte less than actual - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vout[1].ScriptPubKey.Hex = strings.Replace(tx.Vout[1].ScriptPubKey.Hex, "6a14", "6a13", 1) // get BTC event @@ -680,7 +680,7 @@ func TestGetBtcEventErrors(t *testing.T) { t.Run("should return error on invalid Vout[0] script", func(t *testing.T) { // load tx and modify Vout[0] script to invalid script - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vout[0].ScriptPubKey.Hex = "0014invalid000000000000000000000000000000000" // get BTC event @@ -691,7 +691,7 @@ func TestGetBtcEventErrors(t *testing.T) { }) t.Run("should return error if len(tx.Vin) < 1", func(t *testing.T) { // load tx and remove vin - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) tx.Vin = nil // get BTC event @@ -702,7 +702,7 @@ func TestGetBtcEventErrors(t *testing.T) { }) t.Run("should return error if RPC client fails to get raw tx", func(t *testing.T) { // load tx and leave rpc client without preloaded tx - tx := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + tx := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) rpcClient := stub.NewMockBTCRPCClient() // get BTC event diff --git a/zetaclient/bitcoin/tx_script_test.go b/zetaclient/bitcoin/tx_script_test.go index bf333ede59..9961acfcaf 100644 --- a/zetaclient/bitcoin/tx_script_test.go +++ b/zetaclient/bitcoin/tx_script_test.go @@ -22,7 +22,7 @@ func TestDecodeVoutP2TR(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2TR", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) require.Len(t, rawResult.Vout, 2) // decode vout 0, P2TR @@ -40,7 +40,7 @@ func TestDecodeVoutP2TRErrors(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2TR", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) t.Run("should return error on invalid script", func(t *testing.T) { invalidVout := rawResult.Vout[0] @@ -79,7 +79,7 @@ func TestDecodeVoutP2WSH(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2WSH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) require.Len(t, rawResult.Vout, 1) // decode vout 0, P2WSH @@ -97,7 +97,7 @@ func TestDecodeVoutP2WSHErrors(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2WSH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) t.Run("should return error on invalid script", func(t *testing.T) { invalidVout := rawResult.Vout[0] @@ -136,7 +136,7 @@ func TestDecodeP2WPKHVout(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCOuttx(chain.ChainId, nonce)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) require.Len(t, rawResult.Vout, 3) // decode vout 0, nonce mark 148 @@ -164,7 +164,7 @@ func TestDecodeP2WPKHVoutErrors(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCOuttx(chain.ChainId, nonce)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) t.Run("should return error on invalid script", func(t *testing.T) { invalidVout := rawResult.Vout[0] @@ -196,7 +196,7 @@ func TestDecodeVoutP2SH(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2SH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) require.Len(t, rawResult.Vout, 2) // decode vout 0, P2SH @@ -214,7 +214,7 @@ func TestDecodeVoutP2SHErrors(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2SH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) t.Run("should return error on invalid script", func(t *testing.T) { invalidVout := rawResult.Vout[0] @@ -259,7 +259,7 @@ func TestDecodeVoutP2PKH(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2PKH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) require.Len(t, rawResult.Vout, 2) // decode vout 0, P2PKH @@ -277,7 +277,7 @@ func TestDecodeVoutP2PKHErrors(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2PKH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) t.Run("should return error on invalid script", func(t *testing.T) { invalidVout := rawResult.Vout[0] @@ -334,7 +334,7 @@ func TestDecodeOpReturnMemo(t *testing.T) { chain := common.BtcMainnetChain() txHash := "847139aa65aa4a5ee896375951cbf7417cfc8a4d6f277ec11f40cd87319f04aa" scriptHex := "6a1467ed0bcc4e1256bc2ce87d22e190d63a120114bf" - rawResult := testutils.LoadBTCIntxRawResult(chain.ChainId, txHash, false) + rawResult := testutils.LoadBTCIntxRawResult(t, chain.ChainId, txHash, false) require.True(t, len(rawResult.Vout) >= 2) require.Equal(t, scriptHex, rawResult.Vout[1].ScriptPubKey.Hex) @@ -410,7 +410,7 @@ func TestDecodeTSSVout(t *testing.T) { txHash := "259fc21e63e138136c8f19270a0f7ca10039a66a474f91d23a17896f46e677a7" nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2TR", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) receiverExpected := "bc1p4scddlkkuw9486579autxumxmkvuphm5pz4jvf7f6pdh50p2uzqstawjt9" receiver, amount, err := DecodeTSSVout(rawResult.Vout[0], receiverExpected, chain) @@ -423,7 +423,7 @@ func TestDecodeTSSVout(t *testing.T) { txHash := "791bb9d16f7ab05f70a116d18eaf3552faf77b9d5688699a480261424b4f7e53" nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2WSH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) receiverExpected := "bc1qqv6pwn470vu0tssdfha4zdk89v3c8ch5lsnyy855k9hcrcv3evequdmjmc" receiver, amount, err := DecodeTSSVout(rawResult.Vout[0], receiverExpected, chain) @@ -436,7 +436,7 @@ func TestDecodeTSSVout(t *testing.T) { txHash := "5d09d232bfe41c7cb831bf53fc2e4029ab33a99087fd5328a2331b52ff2ebe5b" nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2WPKH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) receiverExpected := "bc1qaxf82vyzy8y80v000e7t64gpten7gawewzu42y" receiver, amount, err := DecodeTSSVout(rawResult.Vout[0], receiverExpected, chain) @@ -449,7 +449,7 @@ func TestDecodeTSSVout(t *testing.T) { txHash := "fd68c8b4478686ca6f5ae4c28eaab055490650dbdaa6c2c8e380a7e075958a21" nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2SH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) receiverExpected := "327z4GyFM8Y8DiYfasGKQWhRK4MvyMSEgE" receiver, amount, err := DecodeTSSVout(rawResult.Vout[0], receiverExpected, chain) @@ -462,7 +462,7 @@ func TestDecodeTSSVout(t *testing.T) { txHash := "9c741de6e17382b7a9113fc811e3558981a35a360e3d1262a6675892c91322ca" nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2PKH", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) receiverExpected := "1FueivsE338W2LgifJ25HhTcVJ7CRT8kte" receiver, amount, err := DecodeTSSVout(rawResult.Vout[0], receiverExpected, chain) @@ -480,7 +480,7 @@ func TestDecodeTSSVoutErrors(t *testing.T) { nameTx := path.Join("../", testutils.TestDataPathBTC, testutils.FileNameBTCTxByType(chain.ChainId, "P2TR", txHash)) var rawResult btcjson.TxRawResult - testutils.LoadObjectFromJSONFile(&rawResult, nameTx) + testutils.LoadObjectFromJSONFile(t, &rawResult, nameTx) receiverExpected := "bc1p4scddlkkuw9486579autxumxmkvuphm5pz4jvf7f6pdh50p2uzqstawjt9" t.Run("should return error on invalid amount", func(t *testing.T) { diff --git a/zetaclient/compliance/compliance_test.go b/zetaclient/compliance/compliance_test.go index 93ce21f785..001e5d9e0d 100644 --- a/zetaclient/compliance/compliance_test.go +++ b/zetaclient/compliance/compliance_test.go @@ -14,7 +14,7 @@ import ( func TestCctxRestricted(t *testing.T) { // load archived cctx var cctx crosschaintypes.CrossChainTx - testutils.LoadObjectFromJSONFile(&cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_1_6270.json")) + testutils.LoadObjectFromJSONFile(t, &cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_1_6270.json")) // create config cfg := config.Config{ diff --git a/zetaclient/evm/evm_client_test.go b/zetaclient/evm/evm_client_test.go index d00b4ffcfb..6f4cb677ed 100644 --- a/zetaclient/evm/evm_client_test.go +++ b/zetaclient/evm/evm_client_test.go @@ -52,7 +52,7 @@ func TestEVM_CheckTxInclusion(t *testing.T) { // load archived evm block // https://etherscan.io/block/19363323 blockNumber := receipt.BlockNumber.Uint64() - block := testutils.LoadEVMBlock(chainID, blockNumber, true) + block := testutils.LoadEVMBlock(t, chainID, blockNumber, true) // create client blockCache, err := lru.New(1000) diff --git a/zetaclient/evm/evm_signer_test.go b/zetaclient/evm/evm_signer_test.go index c318a54de5..90676cc3d8 100644 --- a/zetaclient/evm/evm_signer_test.go +++ b/zetaclient/evm/evm_signer_test.go @@ -65,15 +65,15 @@ func getNewOutTxProcessor() *outtxprocessor.Processor { return outtxprocessor.NewOutTxProcessorManager(logger) } -func getCCTX() *crosschaintypes.CrossChainTx { +func getCCTX(t *testing.T) *crosschaintypes.CrossChainTx { var cctx crosschaintypes.CrossChainTx - testutils.LoadObjectFromJSONFile(&cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_56_68270.json")) + testutils.LoadObjectFromJSONFile(t, &cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_56_68270.json")) return &cctx } -func getInvalidCCTX() *crosschaintypes.CrossChainTx { +func getInvalidCCTX(t *testing.T) *crosschaintypes.CrossChainTx { var cctx crosschaintypes.CrossChainTx - testutils.LoadObjectFromJSONFile(&cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_56_68270_invalidChainID.json")) + testutils.LoadObjectFromJSONFile(t, &cctx, path.Join("../", testutils.TestDataPathCctx, "cctx_56_68270_invalidChainID.json")) return &cctx } @@ -104,7 +104,7 @@ func TestSigner_SetGetERC20CustodyAddress(t *testing.T) { func TestSigner_TryProcessOutTx(t *testing.T) { evmSigner, err := getNewEvmSigner() require.NoError(t, err) - cctx := getCCTX() + cctx := getCCTX(t) processorManager := getNewOutTxProcessor() mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) @@ -123,7 +123,7 @@ func TestSigner_SignOutboundTx(t *testing.T) { // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) @@ -152,7 +152,7 @@ func TestSigner_SignRevertTx(t *testing.T) { require.NoError(t, err) // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) @@ -181,7 +181,7 @@ func TestSigner_SignWithdrawTx(t *testing.T) { require.NoError(t, err) // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) @@ -210,7 +210,7 @@ func TestSigner_SignCommandTx(t *testing.T) { require.NoError(t, err) // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) @@ -257,7 +257,7 @@ func TestSigner_SignERC20WithdrawTx(t *testing.T) { require.NoError(t, err) // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) @@ -286,7 +286,7 @@ func TestSigner_BroadcastOutTx(t *testing.T) { require.NoError(t, err) // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) @@ -316,7 +316,7 @@ func TestSigner_getEVMRPC(t *testing.T) { } func TestSigner_SignerErrorMsg(t *testing.T) { - cctx := getCCTX() + cctx := getCCTX(t) msg := SignerErrorMsg(cctx) require.Contains(t, msg, "nonce 68270 chain 56") @@ -328,7 +328,7 @@ func TestSigner_SignWhitelistERC20Cmd(t *testing.T) { require.NoError(t, err) // Setup txData struct - cctx := getCCTX() + cctx := getCCTX(t) mockChainClient, err := getNewEvmChainClient() require.NoError(t, err) txData, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) diff --git a/zetaclient/evm/inbounds_test.go b/zetaclient/evm/inbounds_test.go index fdac9770a0..e382340590 100644 --- a/zetaclient/evm/inbounds_test.go +++ b/zetaclient/evm/inbounds_test.go @@ -371,7 +371,7 @@ func TestEVM_ObserveTSSReceiveInBlock(t *testing.T) { // load archived evm block // https://etherscan.io/block/19363323 blockNumber := receipt.BlockNumber.Uint64() - block := testutils.LoadEVMBlock(chainID, blockNumber, true) + block := testutils.LoadEVMBlock(t, chainID, blockNumber, true) // create mock client evmClient := stub.NewMockEvmClient() diff --git a/zetaclient/evm/outbound_transaction_data_test.go b/zetaclient/evm/outbound_transaction_data_test.go index abf9656665..8f081d9440 100644 --- a/zetaclient/evm/outbound_transaction_data_test.go +++ b/zetaclient/evm/outbound_transaction_data_test.go @@ -13,7 +13,7 @@ import ( func TestSigner_SetChainAndSender(t *testing.T) { // setup inputs - cctx := getCCTX() + cctx := getCCTX(t) txData := &OutBoundTransactionData{} logger := zerolog.Logger{} @@ -43,7 +43,7 @@ func TestSigner_SetChainAndSender(t *testing.T) { } func TestSigner_SetupGas(t *testing.T) { - cctx := getCCTX() + cctx := getCCTX(t) evmSigner, err := getNewEvmSigner() require.NoError(t, err) @@ -73,14 +73,14 @@ func TestSigner_NewOutBoundTransactionData(t *testing.T) { require.NoError(t, err) t.Run("NewOutBoundTransactionData success", func(t *testing.T) { - cctx := getCCTX() + cctx := getCCTX(t) _, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) require.False(t, skip) require.NoError(t, err) }) t.Run("NewOutBoundTransactionData skip", func(t *testing.T) { - cctx := getCCTX() + cctx := getCCTX(t) cctx.CctxStatus.Status = types.CctxStatus_Aborted _, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) require.NoError(t, err) @@ -88,7 +88,7 @@ func TestSigner_NewOutBoundTransactionData(t *testing.T) { }) t.Run("NewOutBoundTransactionData unknown chain", func(t *testing.T) { - cctx := getInvalidCCTX() + cctx := getInvalidCCTX(t) require.NoError(t, err) _, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) require.ErrorContains(t, err, "unknown chain") @@ -96,7 +96,7 @@ func TestSigner_NewOutBoundTransactionData(t *testing.T) { }) t.Run("NewOutBoundTransactionData setup gas error", func(t *testing.T) { - cctx := getCCTX() + cctx := getCCTX(t) require.NoError(t, err) cctx.GetCurrentOutTxParam().OutboundTxGasPrice = "invalidGasPrice" _, skip, err := NewOutBoundTransactionData(cctx, mockChainClient, evmSigner.EvmClient(), zerolog.Logger{}, 123) diff --git a/zetaclient/testutils/testdata.go b/zetaclient/testutils/testdata.go index 79311fdf52..caf9324958 100644 --- a/zetaclient/testutils/testdata.go +++ b/zetaclient/testutils/testdata.go @@ -10,6 +10,7 @@ import ( "github.com/btcsuite/btcd/btcjson" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/onrik/ethrpc" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" "github.com/zeta-chain/zetacore/zetaclient/config" @@ -37,19 +38,15 @@ func SaveObjectToJSONFile(obj interface{}, filename string) error { } // LoadObjectFromJSONFile loads an object from a file in JSON format -func LoadObjectFromJSONFile(obj interface{}, filename string) { +func LoadObjectFromJSONFile(t *testing.T, obj interface{}, filename string) { file, err := os.Open(filepath.Clean(filename)) - if err != nil { - panic(err) - } + require.NoError(t, err) defer file.Close() // read the struct from the file decoder := json.NewDecoder(file) err = decoder.Decode(&obj) - if err != nil { - panic(err) - } + require.NoError(t, err) } func ComplianceConfigTest() config.ComplianceConfig { @@ -80,82 +77,82 @@ func SaveBTCBlockTrimTx(blockVb *btcjson.GetBlockVerboseTxResult, filename strin } // LoadEVMBlock loads archived evm block from file -func LoadEVMBlock(chainID int64, blockNumber uint64, trimmed bool) *ethrpc.Block { +func LoadEVMBlock(t *testing.T, chainID int64, blockNumber uint64, trimmed bool) *ethrpc.Block { name := path.Join("../", TestDataPathEVM, FileNameEVMBlock(chainID, blockNumber, trimmed)) block := ðrpc.Block{} - LoadObjectFromJSONFile(block, name) + LoadObjectFromJSONFile(t, block, name) return block } // LoadBTCIntxRawResult loads archived Bitcoin intx raw result from file -func LoadBTCIntxRawResult(chainID int64, txHash string, donation bool) *btcjson.TxRawResult { +func LoadBTCIntxRawResult(t *testing.T, chainID int64, txHash string, donation bool) *btcjson.TxRawResult { name := path.Join("../", TestDataPathBTC, FileNameBTCIntx(chainID, txHash, donation)) rawResult := &btcjson.TxRawResult{} - LoadObjectFromJSONFile(rawResult, name) + LoadObjectFromJSONFile(t, rawResult, name) return rawResult } // LoadBTCTxRawResultNCctx loads archived Bitcoin outtx raw result and corresponding cctx -func LoadBTCTxRawResultNCctx(chainID int64, nonce uint64) (*btcjson.TxRawResult, *crosschaintypes.CrossChainTx) { +func LoadBTCTxRawResultNCctx(t *testing.T, chainID int64, nonce uint64) (*btcjson.TxRawResult, *crosschaintypes.CrossChainTx) { //nameTx := FileNameBTCOuttx(chainID, nonce) nameTx := path.Join("../", TestDataPathBTC, FileNameBTCOuttx(chainID, nonce)) rawResult := &btcjson.TxRawResult{} - LoadObjectFromJSONFile(rawResult, nameTx) + LoadObjectFromJSONFile(t, rawResult, nameTx) nameCctx := path.Join("../", TestDataPathCctx, FileNameCctxByNonce(chainID, nonce)) cctx := &crosschaintypes.CrossChainTx{} - LoadObjectFromJSONFile(cctx, nameCctx) + LoadObjectFromJSONFile(t, cctx, nameCctx) return rawResult, cctx } // LoadEVMIntx loads archived intx from file func LoadEVMIntx( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *ethrpc.Transaction { nameTx := path.Join("../", TestDataPathEVM, FileNameEVMIntx(chainID, intxHash, coinType, false)) tx := ðrpc.Transaction{} - LoadObjectFromJSONFile(&tx, nameTx) + LoadObjectFromJSONFile(t, &tx, nameTx) return tx } // LoadEVMIntxReceipt loads archived intx receipt from file func LoadEVMIntxReceipt( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *ethtypes.Receipt { nameReceipt := path.Join("../", TestDataPathEVM, FileNameEVMIntxReceipt(chainID, intxHash, coinType, false)) receipt := ðtypes.Receipt{} - LoadObjectFromJSONFile(&receipt, nameReceipt) + LoadObjectFromJSONFile(t, &receipt, nameReceipt) return receipt } // LoadEVMIntxCctx loads archived intx cctx from file func LoadEVMIntxCctx( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *crosschaintypes.CrossChainTx { nameCctx := path.Join("../", TestDataPathCctx, FileNameEVMIntxCctx(chainID, intxHash, coinType)) cctx := &crosschaintypes.CrossChainTx{} - LoadObjectFromJSONFile(&cctx, nameCctx) + LoadObjectFromJSONFile(t, &cctx, nameCctx) return cctx } // LoadCctxByNonce loads archived cctx by nonce from file func LoadCctxByNonce( - _ *testing.T, + t *testing.T, chainID int64, nonce uint64) *crosschaintypes.CrossChainTx { nameCctx := path.Join("../", TestDataPathCctx, FileNameCctxByNonce(chainID, nonce)) cctx := &crosschaintypes.CrossChainTx{} - LoadObjectFromJSONFile(&cctx, nameCctx) + LoadObjectFromJSONFile(t, &cctx, nameCctx) return cctx } @@ -174,27 +171,27 @@ func LoadEVMIntxNReceipt( // LoadEVMIntxDonation loads archived donation intx from file func LoadEVMIntxDonation( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *ethrpc.Transaction { nameTx := path.Join("../", TestDataPathEVM, FileNameEVMIntx(chainID, intxHash, coinType, true)) tx := ðrpc.Transaction{} - LoadObjectFromJSONFile(&tx, nameTx) + LoadObjectFromJSONFile(t, &tx, nameTx) return tx } // LoadEVMIntxReceiptDonation loads archived donation intx receipt from file func LoadEVMIntxReceiptDonation( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *ethtypes.Receipt { nameReceipt := path.Join("../", TestDataPathEVM, FileNameEVMIntxReceipt(chainID, intxHash, coinType, true)) receipt := ðtypes.Receipt{} - LoadObjectFromJSONFile(&receipt, nameReceipt) + LoadObjectFromJSONFile(t, &receipt, nameReceipt) return receipt } @@ -227,27 +224,27 @@ func LoadEVMIntxNReceiptNCctx( // LoadEVMOuttx loads archived evm outtx from file func LoadEVMOuttx( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *ethtypes.Transaction { nameTx := path.Join("../", TestDataPathEVM, FileNameEVMOuttx(chainID, intxHash, coinType)) tx := ðtypes.Transaction{} - LoadObjectFromJSONFile(&tx, nameTx) + LoadObjectFromJSONFile(t, &tx, nameTx) return tx } // LoadEVMOuttxReceipt loads archived evm outtx receipt from file func LoadEVMOuttxReceipt( - _ *testing.T, + t *testing.T, chainID int64, intxHash string, coinType common.CoinType) *ethtypes.Receipt { nameReceipt := path.Join("../", TestDataPathEVM, FileNameEVMOuttxReceipt(chainID, intxHash, coinType)) receipt := ðtypes.Receipt{} - LoadObjectFromJSONFile(&receipt, nameReceipt) + LoadObjectFromJSONFile(t, &receipt, nameReceipt) return receipt }