From dc660a2d1632d9f9bb65cb865b1ed978198c02b2 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 9 Oct 2018 23:28:51 +0200 Subject: [PATCH] Add digibyte tests --- bchain/coins/digibyte/digibyteparser_test.go | 144 ++++++++++++++++++- tests/rpc/testdata/digibyte.json | 53 +++++++ tests/tests.json | 4 + 3 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 tests/rpc/testdata/digibyte.json diff --git a/bchain/coins/digibyte/digibyteparser_test.go b/bchain/coins/digibyte/digibyteparser_test.go index 894dd047..cc2ef5ba 100644 --- a/bchain/coins/digibyte/digibyteparser_test.go +++ b/bchain/coins/digibyte/digibyteparser_test.go @@ -3,8 +3,10 @@ package digibyte import ( + "blockbook/bchain" "blockbook/bchain/coins/btc" "encoding/hex" + "math/big" "os" "reflect" "testing" @@ -52,13 +54,12 @@ func TestAddressToOutputScript_Mainnet(t *testing.T) { want: "a914320d7056c33fd8d0f5bb9cf42d74133dc28d89bb87", wantErr: false, }, - // TODO - complete - // { - // name: "witness_v0_keyhash", - // args: args{address: "vtc1qd80qaputavyhtvszlz9zprueqch0qd003g520j"}, - // want: "001469de0e878beb0975b202f88a208f99062ef035ef", - // wantErr: false, - // }, + { + name: "witness_v0_keyhash", + args: args{address: "dgb1qwdzu3cxvcte7g5f8ze4dsn83wf6x8zdvw927dx"}, + want: "00147345c8e0ccc2f3e45127166ad84cf172746389ac", + wantErr: false, + }, } parser := NewDigiByteParser(GetChainParams("main"), &btc.Configuration{}) @@ -76,3 +77,132 @@ func TestAddressToOutputScript_Mainnet(t *testing.T) { }) } } + +var ( + testTx1 bchain.Tx + + testTxPacked1 = "006acfc28bb5a0fe3c01000000015952b77fedb7233936a48df90e5423d62539efcd3f61a2466501d6ca26554d5e000000006b483045022100fad176fc354e976e0250ca880085f98c7072d5ccd2978d462f981c7c14495a9102207e60e2fa7b58991909f7528aaf3efb4acc5000da299b84b5d7b065b2ef1a2ac601210322e516129a8e55c043a7ac1d01f3c8fc192b88c32f03746f558432fe6a601e05ffffffff0217930054020000001976a914d9eff329b03348487fb9688a77c6b8081794fd2288ac29a9750f0a0000001976a914ad554bde320ae4b3d755ec32e706d8b327ecdd5688acc0cf6a00" +) + +func init() { + testTx1 = bchain.Tx{ + Hex: "01000000015952b77fedb7233936a48df90e5423d62539efcd3f61a2466501d6ca26554d5e000000006b483045022100fad176fc354e976e0250ca880085f98c7072d5ccd2978d462f981c7c14495a9102207e60e2fa7b58991909f7528aaf3efb4acc5000da299b84b5d7b065b2ef1a2ac601210322e516129a8e55c043a7ac1d01f3c8fc192b88c32f03746f558432fe6a601e05ffffffff0217930054020000001976a914d9eff329b03348487fb9688a77c6b8081794fd2288ac29a9750f0a0000001976a914ad554bde320ae4b3d755ec32e706d8b327ecdd5688acc0cf6a00", + Blocktime: 1532239774, + Txid: "0dcf2530419b9ef525a69f6a15e4d699be1dc9a4ac643c9581b6c57acf25eabf", + LockTime: 7000000, + Version: 1, + Vin: []bchain.Vin{ + { + ScriptSig: bchain.ScriptSig{ + Hex: "483045022100fad176fc354e976e0250ca880085f98c7072d5ccd2978d462f981c7c14495a9102207e60e2fa7b58991909f7528aaf3efb4acc5000da299b84b5d7b065b2ef1a2ac601210322e516129a8e55c043a7ac1d01f3c8fc192b88c32f03746f558432fe6a601e05", + }, + Txid: "5e4d5526cad6016546a2613fcdef3925d623540ef98da4363923b7ed7fb75259", + Vout: 0, + Sequence: 4294967295, + }, + }, + Vout: []bchain.Vout{ + { + ValueSat: *big.NewInt(9999258391), + N: 0, + ScriptPubKey: bchain.ScriptPubKey{ + Hex: "76a914d9eff329b03348487fb9688a77c6b8081794fd2288ac", + Addresses: []string{ + "DR1Scto7rRpTCAyNY6DFhRsZgG2vZ6rxLx", + }, + }, + }, + { + ValueSat: *big.NewInt(43209042217), + N: 1, + ScriptPubKey: bchain.ScriptPubKey{ + Hex: "76a914ad554bde320ae4b3d755ec32e706d8b327ecdd5688ac", + Addresses: []string{ + "DLwbcwUY5dwsdF9ezk8Uoga9V8eMB1Kb6B", + }, + }, + }, + }, + } +} + +func Test_PackTx(t *testing.T) { + type args struct { + tx bchain.Tx + height uint32 + blockTime int64 + parser *DigiByteParser + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + { + name: "digibyte-1", + args: args{ + tx: testTx1, + height: 7000002, + blockTime: 1532239774, + parser: NewDigiByteParser(GetChainParams("main"), &btc.Configuration{}), + }, + want: testTxPacked1, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := tt.args.parser.PackTx(&tt.args.tx, tt.args.height, tt.args.blockTime) + if (err != nil) != tt.wantErr { + t.Errorf("packTx() error = %v, wantErr %v", err, tt.wantErr) + return + } + h := hex.EncodeToString(got) + if !reflect.DeepEqual(h, tt.want) { + t.Errorf("packTx() = %v, want %v", h, tt.want) + } + }) + } +} + +func Test_UnpackTx(t *testing.T) { + type args struct { + packedTx string + parser *DigiByteParser + } + tests := []struct { + name string + args args + want *bchain.Tx + want1 uint32 + wantErr bool + }{ + { + name: "digibyte-1", + args: args{ + packedTx: testTxPacked1, + parser: NewDigiByteParser(GetChainParams("main"), &btc.Configuration{}), + }, + want: &testTx1, + want1: 7000002, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b, _ := hex.DecodeString(tt.args.packedTx) + got, got1, err := tt.args.parser.UnpackTx(b) + if (err != nil) != tt.wantErr { + t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("unpackTx() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("unpackTx() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} diff --git a/tests/rpc/testdata/digibyte.json b/tests/rpc/testdata/digibyte.json new file mode 100644 index 00000000..96abd9f0 --- /dev/null +++ b/tests/rpc/testdata/digibyte.json @@ -0,0 +1,53 @@ +{ + "blockHeight": 7000000, + "blockHash": "03c6664b250c3e3b688f5779ce791384b35acaa38c4461f0458a4674bd762f63", + "blockTime": 1532239864, + "blockTxs": [ + "759433255ce45b4bbc7a961767a14b383753ffa197e8228c29c16d7cf0008766", + "d4fe2eea4e62b3705ac5fda29deeaaa4d2dea446077e4153ae84398c3d62ccb4" + ], + "txDetails": { + "d4fe2eea4e62b3705ac5fda29deeaaa4d2dea446077e4153ae84398c3d62ccb4": { + "hex": "010000000203326d7375759a5863ea2cfb324a6c4201425dfd336a508900a804c22a51e125000000006a47304402200632ff38dc836b95e81f2022d2e39222c4261e85e64d909f53969d94c0febc9c022065000e5660744b699e9fb6f28a0a46e06b3870a2fe382f80c867e1ee3606056401210392091d4341e4b15692234ead7d374c4fa5dc636c30f0042526366ea70f5dc889feffffff3e2ed13beb3d3f34b0d9593c11c7d8e74e43bfe504426aea11626a09bda0fd9d000000006b4830450221009077f18dcbe30dda597f8a503414d443cb6e8ad45948df6d320e1fda9b1fd0b40220603dac961f16b86e9c65ab8c127f696192ffb6856705a4913c0c92c2d9f5a0f201210392091d4341e4b15692234ead7d374c4fa5dc636c30f0042526366ea70f5dc889feffffff02cd67b551000000001976a914035d5bd3df669b4a50839d004d4301d0edfa793c88acb7984525230000001976a9140f165c712e18717410e5ef952529dc470e34b73b88ac8ccf6a00", + "txid": "d4fe2eea4e62b3705ac5fda29deeaaa4d2dea446077e4153ae84398c3d62ccb4", + "blocktime": 1532239864, + "time": 1532239864, + "locktime": 6999948, + "version": 1, + "vin": [ + { + "txid": "25e1512ac204a80089506a33fd5d4201426c4a32fb2cea63589a7575736d3203", + "vout": 0, + "scriptSig": { + "hex": "47304402200632ff38dc836b95e81f2022d2e39222c4261e85e64d909f53969d94c0febc9c022065000e5660744b699e9fb6f28a0a46e06b3870a2fe382f80c867e1ee3606056401210392091d4341e4b15692234ead7d374c4fa5dc636c30f0042526366ea70f5dc889" + }, + "sequence": 4294967294 + }, + { + "txid": "9dfda0bd096a6211ea6a4204e5bf434ee7d8c7113c59d9b0343f3deb3bd12e3e", + "vout": 0, + "scriptSig": { + "hex": "4830450221009077f18dcbe30dda597f8a503414d443cb6e8ad45948df6d320e1fda9b1fd0b40220603dac961f16b86e9c65ab8c127f696192ffb6856705a4913c0c92c2d9f5a0f201210392091d4341e4b15692234ead7d374c4fa5dc636c30f0042526366ea70f5dc889" + }, + "sequence": 4294967294 + } + ], + "vout": [ + { + "value": 13.70843085, + "n": 0, + "scriptPubKey": { + "hex": "76a914035d5bd3df669b4a50839d004d4301d0edfa793c88ac" + } + }, + { + "value": 1509.49173431, + "n": 1, + "scriptPubKey": { + "hex": "76a9140f165c712e18717410e5ef952529dc470e34b73b88ac" + } + } + ] + } + } +} \ No newline at end of file diff --git a/tests/tests.json b/tests/tests.json index d0b749e8..4bd08ebd 100644 --- a/tests/tests.json +++ b/tests/tests.json @@ -32,6 +32,10 @@ "EstimateSmartFee", "EstimateFee", "GetBestBlockHash", "GetBestBlockHeight", "GetBlockHeader"], "sync": ["ConnectBlocksParallel", "ConnectBlocks", "HandleFork"] }, + "digibyte": { + "rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "GetTransactionForMempool", "MempoolSync", + "EstimateSmartFee", "EstimateFee", "GetBestBlockHash", "GetBestBlockHeight", "GetBlockHeader"] + }, "dogecoin": { "rpc": ["GetBlock", "GetBlockHash", "GetTransaction", "GetTransactionForMempool", "MempoolSync"], "sync": ["ConnectBlocksParallel", "ConnectBlocks"]