Fix formatting and linting issues
parent
7f63acaaff
commit
b33414cdba
|
@ -3,286 +3,286 @@
|
||||||
package monetaryunit
|
package monetaryunit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blockbook/bchain"
|
"blockbook/bchain"
|
||||||
"blockbook/bchain/coins/btc"
|
"blockbook/bchain/coins/btc"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/martinboehm/btcutil/chaincfg"
|
"github.com/martinboehm/btcutil/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
c := m.Run()
|
c := m.Run()
|
||||||
chaincfg.ResetParams()
|
chaincfg.ResetParams()
|
||||||
os.Exit(c)
|
os.Exit(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
address string
|
address string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want string
|
want string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "P2PKH1",
|
name: "P2PKH1",
|
||||||
args: args{address: "7cTAePV4rJoSpa6eLhUPSuPpGLdsLiWnXf"},
|
args: args{address: "7cTAePV4rJoSpa6eLhUPSuPpGLdsLiWnXf"},
|
||||||
want: "76a9146e2b0a8655786c8c5ea7b9ce478f03e00ecb2f5588ac",
|
want: "76a9146e2b0a8655786c8c5ea7b9ce478f03e00ecb2f5588ac",
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "P2PKH2",
|
|
||||||
args: args{address: "XdmBSxuCLajxZzQQWiY2FEk6XVjiVoqLXW"},
|
|
||||||
want: "a91421ba6a62ac1d74d2ba921bbc8c9a3ca6e1420a0087",
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "P2SH1",
|
|
||||||
args: args{address: "bc1q0v3tadxj6pm3ym9j06v9rfyw0jeh5f8squ3nvt"},
|
|
||||||
want: "00147b22beb4d2d077126cb27e9851a48e7cb37a24f0",
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "P2SH2",
|
|
||||||
args: args{address: "bc1qumpyvyxz25kfjjrvyxn3zlyc2wfc0m3l3gm5pg99c4mxylemfqhsdf5q0k"},
|
|
||||||
want: "0020e6c24610c2552c99486c21a7117c98539387ee3f8a3740a0a5c576627f3b482f",
|
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
}
|
{
|
||||||
parser := NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{})
|
name: "P2PKH2",
|
||||||
|
args: args{address: "XdmBSxuCLajxZzQQWiY2FEk6XVjiVoqLXW"},
|
||||||
|
want: "a91421ba6a62ac1d74d2ba921bbc8c9a3ca6e1420a0087",
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "P2SH1",
|
||||||
|
args: args{address: "bc1q0v3tadxj6pm3ym9j06v9rfyw0jeh5f8squ3nvt"},
|
||||||
|
want: "00147b22beb4d2d077126cb27e9851a48e7cb37a24f0",
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "P2SH2",
|
||||||
|
args: args{address: "bc1qumpyvyxz25kfjjrvyxn3zlyc2wfc0m3l3gm5pg99c4mxylemfqhsdf5q0k"},
|
||||||
|
want: "0020e6c24610c2552c99486c21a7117c98539387ee3f8a3740a0a5c576627f3b482f",
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
parser := NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{})
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := parser.GetAddrDescFromAddress(tt.args.address)
|
got, err := parser.GetAddrDescFromAddress(tt.args.address)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("GetAddrDescFromAddress() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h := hex.EncodeToString(got)
|
h := hex.EncodeToString(got)
|
||||||
if !reflect.DeepEqual(h, tt.want) {
|
if !reflect.DeepEqual(h, tt.want) {
|
||||||
t.Errorf("GetAddrDescFromAddress() = %v, want %v", h, tt.want)
|
t.Errorf("GetAddrDescFromAddress() = %v, want %v", h, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_GetAddressesFromAddrDesc(t *testing.T) {
|
func Test_GetAddressesFromAddrDesc(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
script string
|
script string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want []string
|
want []string
|
||||||
want2 bool
|
want2 bool
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "P2PKH",
|
name: "P2PKH",
|
||||||
args: args{script: "76a9146e2b0a8655786c8c5ea7b9ce478f03e00ecb2f5588ac"},
|
args: args{script: "76a9146e2b0a8655786c8c5ea7b9ce478f03e00ecb2f5588ac"},
|
||||||
want: []string{"7cTAePV4rJoSpa6eLhUPSuPpGLdsLiWnXf"},
|
want: []string{"7cTAePV4rJoSpa6eLhUPSuPpGLdsLiWnXf"},
|
||||||
want2: true,
|
want2: true,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "P2SH",
|
name: "P2SH",
|
||||||
args: args{script: "a91421ba6a62ac1d74d2ba921bbc8c9a3ca6e1420a0087"},
|
args: args{script: "a91421ba6a62ac1d74d2ba921bbc8c9a3ca6e1420a0087"},
|
||||||
want: []string{"XdmBSxuCLajxZzQQWiY2FEk6XVjiVoqLXW"},
|
want: []string{"XdmBSxuCLajxZzQQWiY2FEk6XVjiVoqLXW"},
|
||||||
want2: true,
|
want2: true,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "P2WPKH",
|
name: "P2WPKH",
|
||||||
args: args{script: "00147b22beb4d2d077126cb27e9851a48e7cb37a24f0"},
|
args: args{script: "00147b22beb4d2d077126cb27e9851a48e7cb37a24f0"},
|
||||||
want: []string{"bc1q0v3tadxj6pm3ym9j06v9rfyw0jeh5f8squ3nvt"},
|
want: []string{"bc1q0v3tadxj6pm3ym9j06v9rfyw0jeh5f8squ3nvt"},
|
||||||
want2: true,
|
want2: true,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "P2WSH",
|
name: "P2WSH",
|
||||||
args: args{script: "0020e6c24610c2552c99486c21a7117c98539387ee3f8a3740a0a5c576627f3b482f"},
|
args: args{script: "0020e6c24610c2552c99486c21a7117c98539387ee3f8a3740a0a5c576627f3b482f"},
|
||||||
want: []string{"bc1qumpyvyxz25kfjjrvyxn3zlyc2wfc0m3l3gm5pg99c4mxylemfqhsdf5q0k"},
|
want: []string{"bc1qumpyvyxz25kfjjrvyxn3zlyc2wfc0m3l3gm5pg99c4mxylemfqhsdf5q0k"},
|
||||||
want2: true,
|
want2: true,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "OP_RETURN ascii",
|
name: "OP_RETURN ascii",
|
||||||
args: args{script: "6a0461686f6a"},
|
args: args{script: "6a0461686f6a"},
|
||||||
want: []string{"OP_RETURN (ahoj)"},
|
want: []string{"OP_RETURN (ahoj)"},
|
||||||
want2: false,
|
want2: false,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "OP_RETURN hex",
|
name: "OP_RETURN hex",
|
||||||
args: args{script: "6a072020f1686f6a20"},
|
args: args{script: "6a072020f1686f6a20"},
|
||||||
want: []string{"OP_RETURN 2020f1686f6a20"},
|
want: []string{"OP_RETURN 2020f1686f6a20"},
|
||||||
want2: false,
|
want2: false,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{})
|
parser := NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{})
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
b, _ := hex.DecodeString(tt.args.script)
|
b, _ := hex.DecodeString(tt.args.script)
|
||||||
got, got2, err := parser.GetAddressesFromAddrDesc(b)
|
got, got2, err := parser.GetAddressesFromAddrDesc(b)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("outputScriptToAddresses() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("outputScriptToAddresses() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("GetAddressesFromAddrDesc() = %v, want %v", got, tt.want)
|
t.Errorf("GetAddressesFromAddrDesc() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got2, tt.want2) {
|
if !reflect.DeepEqual(got2, tt.want2) {
|
||||||
t.Errorf("GetAddressesFromAddrDesc() = %v, want %v", got2, tt.want2)
|
t.Errorf("GetAddressesFromAddrDesc() = %v, want %v", got2, tt.want2)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTx1 bchain.Tx
|
testTx1 bchain.Tx
|
||||||
|
|
||||||
testTxPacked1 = "0a20f05ba72a05c4900ff2a00a0403697750201e41267aeea8a589a7dc7bcc57076e12d30101000000010c396f3768565c707addf85ecf47e04cefb2721d95afd977e13f25904de8336a0100000049483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b01ffffffff03000000000000000000dd400def140000002321025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac00d2496b000000001976a914afe70b2e1bf4199298ed8281767bae22970b415088ac0000000018e6b092e605200028f48d1b32770a0012206a33e84d90253fe177d9af951d72b2ef4ce047cf5ef8dd7a705c5668376f390c18012249483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b0128ffffffff0f3a04100022003a520a0514ef0d40dd10011a2321025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac22223764396a4e79716835694b555a566e516a6d7a6d4541513878444b777a4536536e673a470a046b49d20010021a1976a914afe70b2e1bf4199298ed8281767bae22970b415088ac22223769536a6e57436f41556d4a347656584d6b61457561736e5658537a5a7166504c324001"
|
testTxPacked1 = "0a20f05ba72a05c4900ff2a00a0403697750201e41267aeea8a589a7dc7bcc57076e12d30101000000010c396f3768565c707addf85ecf47e04cefb2721d95afd977e13f25904de8336a0100000049483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b01ffffffff03000000000000000000dd400def140000002321025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac00d2496b000000001976a914afe70b2e1bf4199298ed8281767bae22970b415088ac0000000018e6b092e605200028f48d1b32770a0012206a33e84d90253fe177d9af951d72b2ef4ce047cf5ef8dd7a705c5668376f390c18012249483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b0128ffffffff0f3a04100022003a520a0514ef0d40dd10011a2321025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac22223764396a4e79716835694b555a566e516a6d7a6d4541513878444b777a4536536e673a470a046b49d20010021a1976a914afe70b2e1bf4199298ed8281767bae22970b415088ac22223769536a6e57436f41556d4a347656584d6b61457561736e5658537a5a7166504c324001"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
testTx1 = bchain.Tx{
|
testTx1 = bchain.Tx{
|
||||||
Hex: "01000000010c396f3768565c707addf85ecf47e04cefb2721d95afd977e13f25904de8336a0100000049483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b01ffffffff03000000000000000000dd400def140000002321025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac00d2496b000000001976a914afe70b2e1bf4199298ed8281767bae22970b415088ac00000000",
|
Hex: "01000000010c396f3768565c707addf85ecf47e04cefb2721d95afd977e13f25904de8336a0100000049483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b01ffffffff03000000000000000000dd400def140000002321025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac00d2496b000000001976a914afe70b2e1bf4199298ed8281767bae22970b415088ac00000000",
|
||||||
Blocktime: 1556387942,
|
Blocktime: 1556387942,
|
||||||
Txid: "f05ba72a05c4900ff2a00a0403697750201e41267aeea8a589a7dc7bcc57076e",
|
Txid: "f05ba72a05c4900ff2a00a0403697750201e41267aeea8a589a7dc7bcc57076e",
|
||||||
LockTime: 0,
|
LockTime: 0,
|
||||||
Time: 1556387942,
|
Time: 1556387942,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
Vin: []bchain.Vin{
|
Vin: []bchain.Vin{
|
||||||
{
|
|
||||||
ScriptSig: bchain.ScriptSig{
|
|
||||||
Hex: "483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b01",
|
|
||||||
},
|
|
||||||
Txid: "6a33e84d90253fe177d9af951d72b2ef4ce047cf5ef8dd7a705c5668376f390c",
|
|
||||||
Vout: 1,
|
|
||||||
Sequence: 4294967295,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Vout: []bchain.Vout{
|
|
||||||
{
|
{
|
||||||
ValueSat: *big.NewInt(0),
|
ScriptSig: bchain.ScriptSig{
|
||||||
N: 0,
|
Hex: "483045022100fe1b79f38ca4b9dc2fbc50eac6c9bf050ae5a3ee37da05b950918230eb0a8c7c0220477173b60ec00a8b4b28d5db9fc5d8259eea35f91bbdd60089c5ec1be7b05f3b01",
|
||||||
ScriptPubKey: bchain.ScriptPubKey{
|
},
|
||||||
Hex: "",
|
Txid: "6a33e84d90253fe177d9af951d72b2ef4ce047cf5ef8dd7a705c5668376f390c",
|
||||||
Addresses: []string{
|
Vout: 1,
|
||||||
"",
|
Sequence: 4294967295,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
Vout: []bchain.Vout{
|
||||||
{
|
{
|
||||||
ValueSat: *big.NewInt(89909969117),
|
ValueSat: *big.NewInt(0),
|
||||||
N: 1,
|
N: 0,
|
||||||
ScriptPubKey: bchain.ScriptPubKey{
|
ScriptPubKey: bchain.ScriptPubKey{
|
||||||
Hex: "21025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac",
|
Hex: "",
|
||||||
Addresses: []string{
|
Addresses: []string{
|
||||||
"7d9jNyqh5iKUZVnQjmzmEAQ8xDKwzE6Sng",
|
"",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ValueSat: *big.NewInt(1800000000),
|
ValueSat: *big.NewInt(89909969117),
|
||||||
N: 2,
|
N: 1,
|
||||||
ScriptPubKey: bchain.ScriptPubKey{
|
ScriptPubKey: bchain.ScriptPubKey{
|
||||||
Hex: "76a914afe70b2e1bf4199298ed8281767bae22970b415088ac",
|
Hex: "21025d145b77df04c40ceb88ea36828755f8275dc5fecf19d3ecccce2d8198c3407cac",
|
||||||
Addresses: []string{
|
Addresses: []string{
|
||||||
"7iSjnWCoAUmJ4vVXMkaEuasnVXSzZqfPL2",
|
"7d9jNyqh5iKUZVnQjmzmEAQ8xDKwzE6Sng",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
}
|
ValueSat: *big.NewInt(1800000000),
|
||||||
|
N: 2,
|
||||||
|
ScriptPubKey: bchain.ScriptPubKey{
|
||||||
|
Hex: "76a914afe70b2e1bf4199298ed8281767bae22970b415088ac",
|
||||||
|
Addresses: []string{
|
||||||
|
"7iSjnWCoAUmJ4vVXMkaEuasnVXSzZqfPL2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_PackTx(t *testing.T) {
|
func Test_PackTx(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
tx bchain.Tx
|
tx bchain.Tx
|
||||||
height uint32
|
height uint32
|
||||||
blockTime int64
|
blockTime int64
|
||||||
parser *MonetaryUnitParser
|
parser *MonetaryUnitParser
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want string
|
want string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "monetaryunit-1",
|
name: "monetaryunit-1",
|
||||||
args: args{
|
args: args{
|
||||||
tx: testTx1,
|
tx: testTx1,
|
||||||
height: 444148,
|
height: 444148,
|
||||||
blockTime: 1556387942,
|
blockTime: 1556387942,
|
||||||
parser: NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{}),
|
parser: NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{}),
|
||||||
},
|
},
|
||||||
want: testTxPacked1,
|
want: testTxPacked1,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := tt.args.parser.PackTx(&tt.args.tx, tt.args.height, tt.args.blockTime)
|
got, err := tt.args.parser.PackTx(&tt.args.tx, tt.args.height, tt.args.blockTime)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("packTx() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("packTx() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h := hex.EncodeToString(got)
|
h := hex.EncodeToString(got)
|
||||||
if !reflect.DeepEqual(h, tt.want) {
|
if !reflect.DeepEqual(h, tt.want) {
|
||||||
t.Errorf("packTx() = %v, want %v", h, tt.want)
|
t.Errorf("packTx() = %v, want %v", h, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_UnpackTx(t *testing.T) {
|
func Test_UnpackTx(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
packedTx string
|
packedTx string
|
||||||
parser *MonetaryUnitParser
|
parser *MonetaryUnitParser
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want *bchain.Tx
|
want *bchain.Tx
|
||||||
want1 uint32
|
want1 uint32
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "monetaryunit-1",
|
name: "monetaryunit-1",
|
||||||
args: args{
|
args: args{
|
||||||
packedTx: testTxPacked1,
|
packedTx: testTxPacked1,
|
||||||
parser: NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{}),
|
parser: NewMonetaryUnitParser(GetChainParams("main"), &btc.Configuration{}),
|
||||||
},
|
},
|
||||||
want: &testTx1,
|
want: &testTx1,
|
||||||
want1: 444148,
|
want1: 444148,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
b, _ := hex.DecodeString(tt.args.packedTx)
|
b, _ := hex.DecodeString(tt.args.packedTx)
|
||||||
got, got1, err := tt.args.parser.UnpackTx(b)
|
got, got1, err := tt.args.parser.UnpackTx(b)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
|
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
if got1 != tt.want1 {
|
if got1 != tt.want1 {
|
||||||
t.Errorf("unpackTx() got1 = %v, want %v", got1, tt.want1)
|
t.Errorf("unpackTx() got1 = %v, want %v", got1, tt.want1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,55 +58,58 @@ func (b *MonetaryUnitRPC) Initialize() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Block
|
// GetBlock gets block from backend
|
||||||
func (b *MonetaryUnitRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
func (b *MonetaryUnitRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
||||||
|
|
||||||
if height == 0 {
|
if height == 0 {
|
||||||
var err error
|
var err error
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
hash, err = b.GetBlockHash(height)
|
hash, err = b.GetBlockHash(height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !b.ParseBlocks {
|
if !b.ParseBlocks {
|
||||||
return b.GetBlockFull(hash)
|
return b.GetBlockFull(hash)
|
||||||
}
|
}
|
||||||
return b.GetBlockWithoutHeader(hash, height)
|
return b.GetBlockWithoutHeader(hash, height)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if hash == "" && height > 0 {
|
if hash == "" && height > 0 {
|
||||||
hash, err = b.GetBlockHash(height)
|
hash, err = b.GetBlockHash(height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Info("rpc: getblock (verbosity=1) ", hash)
|
glog.V(1).Info("rpc: getblock (verbosity=1) ", hash)
|
||||||
|
|
||||||
res := btc.ResGetBlockThin{}
|
res := btc.ResGetBlockThin{}
|
||||||
req := btc.CmdGetBlock{Method: "getblock"}
|
req := btc.CmdGetBlock{Method: "getblock"}
|
||||||
req.Params.BlockHash = hash
|
req.Params.BlockHash = hash
|
||||||
req.Params.Verbosity = 1
|
req.Params.Verbosity = 1
|
||||||
err = b.Call(&req, &res)
|
err = b.Call(&req, &res)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
txs := make([]bchain.Tx, 0, len(res.Result.Txids))
|
txs := make([]bchain.Tx, 0, len(res.Result.Txids))
|
||||||
for _, txid := range res.Result.Txids {
|
for _, txid := range res.Result.Txids {
|
||||||
tx, err := b.GetTransaction(txid)
|
tx, err := b.GetTransaction(txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == bchain.ErrTxNotFound {
|
if err == bchain.ErrTxNotFound {
|
||||||
glog.Errorf("rpc: getblock: skipping transanction in block %s due error: %s", hash, err)
|
glog.Errorf("rpc: getblock: skipping transanction in block %s due error: %s", hash, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
txs = append(txs, *tx)
|
txs = append(txs, *tx)
|
||||||
}
|
}
|
||||||
block := &bchain.Block{
|
block := &bchain.Block{
|
||||||
BlockHeader: res.Result.BlockHeader,
|
BlockHeader: res.Result.BlockHeader,
|
||||||
Txs: txs,
|
Txs: txs,
|
||||||
}
|
}
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func NewRavencoinRPC(config json.RawMessage, pushHandler func(bchain.Notificatio
|
||||||
|
|
||||||
// Initialize initializes RavencoinRPC instance.
|
// Initialize initializes RavencoinRPC instance.
|
||||||
func (b *RavencoinRPC) Initialize() error {
|
func (b *RavencoinRPC) Initialize() error {
|
||||||
ci, err := b.GetChainInfo()
|
ci, err := b.GetChainInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func Test_GetAddrDescFromAddress_Mainnet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testTx1 bchain.Tx
|
testTx1 bchain.Tx
|
||||||
testTxPacked1 = "004eb96d8bb3b6c6140200000001ddc431a8f5c4e74296de8a6bff796ece148b9bd6827a80ecde8671df41a51fc7000000006a47304402204f929a1e1e40bd352bbd5d3c5ae6c29740e5a8b29dd8c53a15d3eab29aecee7c02206a514e5e4561cfb9330d98f4a4fe1385af56d87eb1d3e1a379d7a50276788cfe0121034a9305644fbcb56d4fc0bc15959b917f7753ae8e581acc97f9cfe771ad1e8249feffffff0200ca9a3b000000001976a91456c7359ed52d61c1ca371d7dc136632148169c5e88acd0e8cc10000000001976a914112e29df5df4866e40ef98e0857036b275380fe088ac6ab94e00"
|
testTxPacked1 = "004eb96d8bb3b6c6140200000001ddc431a8f5c4e74296de8a6bff796ece148b9bd6827a80ecde8671df41a51fc7000000006a47304402204f929a1e1e40bd352bbd5d3c5ae6c29740e5a8b29dd8c53a15d3eab29aecee7c02206a514e5e4561cfb9330d98f4a4fe1385af56d87eb1d3e1a379d7a50276788cfe0121034a9305644fbcb56d4fc0bc15959b917f7753ae8e581acc97f9cfe771ad1e8249feffffff0200ca9a3b000000001976a91456c7359ed52d61c1ca371d7dc136632148169c5e88acd0e8cc10000000001976a914112e29df5df4866e40ef98e0857036b275380fe088ac6ab94e00"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -468,9 +468,8 @@ func (ab *AddrBalance) markUtxoAsSpent(btxID []byte, vout int32) {
|
||||||
// mark utxo as spent by setting vout=-1
|
// mark utxo as spent by setting vout=-1
|
||||||
utxo.Vout = -1
|
utxo.Vout = -1
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -665,7 +665,7 @@ func TestRocksDB_Index_BitcoinType(t *testing.T) {
|
||||||
SentSat: *dbtestdata.SatB1T2A5,
|
SentSat: *dbtestdata.SatB1T2A5,
|
||||||
BalanceSat: *dbtestdata.SatB2T3A5,
|
BalanceSat: *dbtestdata.SatB2T3A5,
|
||||||
Utxos: []Utxo{
|
Utxos: []Utxo{
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB2T3),
|
BtxID: hexToBytes(dbtestdata.TxidB2T3),
|
||||||
Vout: 0,
|
Vout: 0,
|
||||||
Height: 225494,
|
Height: 225494,
|
||||||
|
|
Loading…
Reference in New Issue