Skip to content

Commit

Permalink
add tests for bitcoin testnet4
Browse files Browse the repository at this point in the history
  • Loading branch information
wakiyamap authored and martinboehm committed Nov 25, 2024
1 parent fe676b3 commit f373a73
Show file tree
Hide file tree
Showing 5 changed files with 449 additions and 1 deletion.
19 changes: 19 additions & 0 deletions bchain/coins/btc/bitcoinparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@ import (
"encoding/json"
"math/big"

"github.com/martinboehm/btcd/wire"
"github.com/martinboehm/btcutil/chaincfg"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/common"
)

// temp params for signet(wait btcd commit)
// magic numbers
const (
Testnet4Magic wire.BitcoinNet = 0x283f161c
)

// chain parameters
var (
TestNet4Params chaincfg.Params
)

func init() {
TestNet4Params = chaincfg.TestNet3Params
TestNet4Params.Net = Testnet4Magic
}

// BitcoinParser handle
type BitcoinParser struct {
*BitcoinLikeParser
Expand All @@ -33,6 +50,8 @@ func GetChainParams(chain string) *chaincfg.Params {
switch chain {
case "test":
return &chaincfg.TestNet3Params
case "testnet4":
return &TestNet4Params
case "regtest":
return &chaincfg.RegressionNetParams
case "signet":
Expand Down
55 changes: 54 additions & 1 deletion bchain/coins/btc/bitcoinparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,12 @@ func TestGetAddressesFromAddrDescTestnet(t *testing.T) {
}

var (
testTx1, testTx2, testTx3 bchain.Tx
testTx1, testTx2, testTx3, testTx4 bchain.Tx

testTxPacked1 = "0001e2408ba8d7af5401000000017f9a22c9cbf54bd902400df746f138f37bcf5b4d93eb755820e974ba43ed5f42040000006a4730440220037f4ed5427cde81d55b9b6a2fd08c8a25090c2c2fff3a75c1a57625ca8a7118022076c702fe55969fa08137f71afd4851c48e31082dd3c40c919c92cdbc826758d30121029f6da5623c9f9b68a9baf9c1bc7511df88fa34c6c2f71f7c62f2f03ff48dca80feffffff019c9700000000000017a9146144d57c8aff48492c9dfb914e120b20bad72d6f8773d00700"
testTxPacked2 = "0007c91a899ab7da6a010000000001019d64f0c72a0d206001decbffaa722eb1044534c74eee7a5df8318e42a4323ec10000000017160014550da1f5d25a9dae2eafd6902b4194c4c6500af6ffffffff02809698000000000017a914cd668d781ece600efa4b2404dc91fd26b8b8aed8870553d7360000000017a914246655bdbd54c7e477d0ea2375e86e0db2b8f80a8702473044022076aba4ad559616905fa51d4ddd357fc1fdb428d40cb388e042cdd1da4a1b7357022011916f90c712ead9a66d5f058252efd280439ad8956a967e95d437d246710bc9012102a80a5964c5612bb769ef73147b2cf3c149bc0fd4ecb02f8097629c94ab013ffd00000000"
testTxPacked3 = "00003d818bfda9aa3e02000000000102deb1999a857ab0a13d6b12fbd95ea75b409edde5f2ff747507ce42d9986a8b9d0000000000fdffffff9fd2d3361e203b2375eba6438efbef5b3075531e7e583c7cc76b7294fe7f22980000000000fdffffff02a0860100000000001600148091746745464e7555c31e9a5afceac14a02978ae7fc1c0000000000160014565ea9ff4589d3e05ba149ae6e257752bfdc2a1e0247304402207d67d320a8e813f986b35e9791935fcb736754812b7038686f5de6cfdcda99cd02201c3bb2c178e0056016437ecfe365a7eef84aa9d293ebdc566177af82e22fcdd3012103abb30c1bbe878b07b58dc169b1d061d48c60be8107f632a59778b38bf7ceea5a02473044022044f54a478cfe086e870cb026c9dcd4e14e63778bef569a4d55a6332725cd9a9802202f0e94c04e6f328fc64ad9efe552888c299750d1b8d033324825a3ff29920e030121036fcd433428aa7dc65c4f5408fa31f208c54fe4b4c6c1ae9c39a825ed4f1ac039813d0000"
testTxPacked4 = "0000a2b98ced82b6400300000000010148f8f93ebb12407809920d2ab9cc1bf01289b314eb23028c83fdab21e5fefa690100000000fdffffff0150c3000000000000160014cb888de3c89670a3061fb6ef6590f187649cca060247304402206a9db8d7157e4b0a06a1f090b9de88cdc616028b431b80617a055117877e479a02202937d6d1658d4a8afde86b245325c3bb0e769a87cb09d802bcefaa21550065e201210374aa8f312de4ebccbef55609700a39764387aa4ff5d76f1ccb4d2382e454f05b00000000"
)

func init() {
Expand Down Expand Up @@ -595,6 +596,37 @@ func init() {
},
},
}

testTx4 = bchain.Tx{
Hex: "0300000000010148f8f93ebb12407809920d2ab9cc1bf01289b314eb23028c83fdab21e5fefa690100000000fdffffff0150c3000000000000160014cb888de3c89670a3061fb6ef6590f187649cca060247304402206a9db8d7157e4b0a06a1f090b9de88cdc616028b431b80617a055117877e479a02202937d6d1658d4a8afde86b245325c3bb0e769a87cb09d802bcefaa21550065e201210374aa8f312de4ebccbef55609700a39764387aa4ff5d76f1ccb4d2382e454f05b00000000",
Blocktime: 1724927392,
Txid: "8e3f38bf6854dd3c358be8d4f9a40a6dccc50de49616125d27af9fdbe65287eb",
LockTime: 0,
VSize: 110,
Version: 3,
Vin: []bchain.Vin{
{
ScriptSig: bchain.ScriptSig{
Hex: "",
},
Txid: "69fafee521abfd838c0223eb14b38912f01bccb92a0d9209784012bb3ef9f848",
Vout: 1,
Sequence: 4294967293,
},
},
Vout: []bchain.Vout{
{
ValueSat: *big.NewInt(50000),
N: 0,
ScriptPubKey: bchain.ScriptPubKey{
Hex: "0014cb888de3c89670a3061fb6ef6590f187649cca06",
Addresses: []string{
"tb1qewygmc7gjec2xpslkmhkty83sajfejsxqmy5dq",
},
},
},
},
}
}

func TestPackTx(t *testing.T) {
Expand Down Expand Up @@ -643,6 +675,17 @@ func TestPackTx(t *testing.T) {
want: testTxPacked3,
wantErr: false,
},
{
name: "testnet4-1",
args: args{
tx: testTx4,
height: 41657,
blockTime: 1724927392,
parser: NewBitcoinParser(GetChainParams("testnet4"), &Configuration{}),
},
want: testTxPacked4,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -701,6 +744,16 @@ func TestUnpackTx(t *testing.T) {
want1: 15745,
wantErr: false,
},
{
name: "testnet4-1",
args: args{
packedTx: testTxPacked4,
parser: NewBitcoinParser(GetChainParams("testnet4"), &Configuration{}),
},
want: &testTx4,
want1: 41657,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
105 changes: 105 additions & 0 deletions tests/rpc/testdata/bitcoin_testnet4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"blockHeight": 41500,
"blockHash": "000000000000000466119d6e5eb24802dcc14605f4050ac586f45eaa61da2719",
"blockTime": 1724848265,
"blockTxs": [
"3d40148138492c4c0b91207acc2ec1cb3942e1cb51713e6851f01450452314d1",
"38924e01871d5fb25dca1bc9d17ae8cb65155fcb12a70984fc65ec85d48efd2a",
"8b77d1e7b5d7c528a59917c13f42787fa1988db744c1e9bc58f024f15fbb2ebb",
"06a9373ca11293ec51d15c5c142118fd46ceec33c0a46a865448f9916337b2ef"
],
"txDetails": {
"38924e01871d5fb25dca1bc9d17ae8cb65155fcb12a70984fc65ec85d48efd2a": {
"hex": "0200000002a6a8a1e0e89cc206f40efc707863510b866cd0f20487446f6373c5b136ea9ab3010000006a4730440220053c7b24201514691f67154cbfd1e2ba917b3813b44b6ed81afd75bd11f16c4f022075c24b3fc21e88071148c6daa1ca4075e55da1f3f403ceb943268016744b10d1012102d1b7b25ab15f33fc693ba6c9b80b4c35fca1708008c8afac171b33f1fef4bd59fdffffffcd227a67d359ad8aaf99d9a56fdb0604a18804d40e046d21607f95a0c263e6d1000000006a473044022029297263b9b49c5652bf2179f5c94968788dc8d63d42a268980b8b9d0bda480602206c5cae1eb7b23872e02e2967eb229d8ed9cc73331dbadbd0354b82f80937a23e012103e959e8ad180e0323105e95ceea131debdbe0d77bfd54289bad77d15164942acdfdffffff03c3b0090000000000160014de4e79ce2048a42698e04e079e94c97fd6e012cf9f770e000000000017a914d9e303986df109b001b97b45f3a00d84b6c9d7278788760200000000001600144a6a08ffbb16515133284e385b0ea29812ce99251ba20000",
"txid": "38924e01871d5fb25dca1bc9d17ae8cb65155fcb12a70984fc65ec85d48efd2a",
"blocktime": 1724848265,
"time": 1724848265,
"locktime": 41499,
"vsize": 398,
"version": 2,
"vin": [
{
"txid": "b39aea36b1c573636f448704f2d06c860b51637870fc0ef406c29ce8e0a1a8a6",
"vout": 1,
"sequence": 4294967293,
"scriptSig": {
"hex": "4730440220053c7b24201514691f67154cbfd1e2ba917b3813b44b6ed81afd75bd11f16c4f022075c24b3fc21e88071148c6daa1ca4075e55da1f3f403ceb943268016744b10d1012102d1b7b25ab15f33fc693ba6c9b80b4c35fca1708008c8afac171b33f1fef4bd59"
}
},
{
"txid": "d1e663c2a0957f60216d040ed40488a10406db6fa5d999af8aad59d3677a22cd",
"vout": 0,
"sequence": 4294967293,
"scriptSig": {
"hex": "473044022029297263b9b49c5652bf2179f5c94968788dc8d63d42a268980b8b9d0bda480602206c5cae1eb7b23872e02e2967eb229d8ed9cc73331dbadbd0354b82f80937a23e012103e959e8ad180e0323105e95ceea131debdbe0d77bfd54289bad77d15164942acd"
}
}
],
"vout": [
{
"value": 0.00635075,
"n": 0,
"scriptPubKey": {
"hex": "0014de4e79ce2048a42698e04e079e94c97fd6e012cf"
}
},
{
"value": 0.00948127,
"n": 1,
"scriptPubKey": {
"hex": "a914c9e67d2b78a38857c786ea9a2fc3e64cb6e7756487"
}
},
{
"value": 0.00161416,
"n": 2,
"scriptPubKey": {
"hex": "00144a6a08ffbb16515133284e385b0ea29812ce9925"
}
}
]
},
"8b77d1e7b5d7c528a59917c13f42787fa1988db744c1e9bc58f024f15fbb2ebb": {
"hex": "0200000001cd227a67d359ad8aaf99d9a56fdb0604a18804d40e046d21607f95a0c263e6d1020000006a473044022027687d38378d1e6c991f68815217e309f1e290a8c706159455a680457ec1545002202dd0d9fc7251a5a4f7d4b76d824981b97a4c5121ec46fee4786a283debde544501210223a0cd87e2f1958998684f6c75771a95727d310cc4d30ed34ca427affe89d4c2fdffffff038876020000000000160014f6a58ba8a373263dddcb82bd6202a1157270cb4de8b00400000000001600144237fc8335d817b911332fc9df26744215266b1794d204000000000017a914e5bd951e8d6b10fab8cea5b103c71ae3a37b95bf871ba20000",
"txid": "8b77d1e7b5d7c528a59917c13f42787fa1988db744c1e9bc58f024f15fbb2ebb",
"blocktime": 1724848265,
"time": 1724848265,
"locktime": 41499,
"vsize": 251,
"version": 2,
"vin": [
{
"txid": "d1e663c2a0957f60216d040ed40488a10406db6fa5d999af8aad59d3677a22cd",
"vout": 2,
"sequence": 4294967293,
"scriptSig": {
"hex": "473044022027687d38378d1e6c991f68815217e309f1e290a8c706159455a680457ec1545002202dd0d9fc7251a5a4f7d4b76d824981b97a4c5121ec46fee4786a283debde544501210223a0cd87e2f1958998684f6c75771a95727d310cc4d30ed34ca427affe89d4c2"
}
}
],
"vout": [
{
"value": 0.00161416,
"n": 0,
"scriptPubKey": {
"hex": "0014f6a58ba8a373263dddcb82bd6202a1157270cb4d"
}
},
{
"value": 0.00307432,
"n": 1,
"scriptPubKey": {
"hex": "00144237fc8335d817b911332fc9df26744215266b17"
}
},
{
"value": 0.00316052,
"n": 2,
"scriptPubKey": {
"hex": "a914e5bd951e8d6b10fab8cea5b103c71ae3a37b95bf87"
}
}
]
}
}
}
Loading

0 comments on commit f373a73

Please sign in to comment.