Fix tests

This commit is contained in:
Martin Boehm
2023-09-01 14:10:51 +02:00
parent 7d0c424ad8
commit 8ef09d124e
11 changed files with 32 additions and 8 deletions

View File

@@ -337,10 +337,15 @@ func Test_UnpackTx(t *testing.T) {
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
}
// ignore witness unpacking
for i := range got.Vin {
got.Vin[i].Witness = nil
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
}

View File

@@ -316,6 +316,10 @@ func Test_UnpackTx(t *testing.T) {
t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr)
return
}
// ignore witness unpacking
for i := range got.Vin {
got.Vin[i].Witness = nil
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
}

View File

@@ -710,6 +710,10 @@ func TestUnpackTx(t *testing.T) {
t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr)
return
}
// ignore witness unpacking
for i := range got.Vin {
got.Vin[i].Witness = nil
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
}

View File

@@ -342,6 +342,10 @@ func Test_UnpackTx(t *testing.T) {
t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr)
return
}
// ignore witness unpacking
for i := range got.Vin {
got.Vin[i].Witness = nil
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
}

View File

@@ -294,6 +294,10 @@ func Test_UnpackTx(t *testing.T) {
t.Errorf("unpackTx() error = %v, wantErr %v", err, tt.wantErr)
return
}
// ignore witness unpacking
for i := range got.Vin {
got.Vin[i].Witness = nil
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("unpackTx() got = %v, want %v", got, tt.want)
}

View File

@@ -88,7 +88,8 @@ func TestGolombFilter(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gf, err := NewGolombFilter(tt.p, tt.filterScripts, tt.key)
// TODO add tests for useZeroedKey
gf, err := NewGolombFilter(tt.p, tt.filterScripts, tt.key, false)
if err != nil && !tt.wantError {
t.Errorf("TestGolombFilter.NewGolombFilter() got unexpected error '%v'", err)
return
@@ -105,7 +106,7 @@ func TestGolombFilter(t *testing.T) {
return
}
for _, ad := range tt.addressDescriptors {
gf.AddAddrDesc(ad)
gf.AddAddrDesc(ad, nil)
}
f := gf.Compute()
got := hex.EncodeToString(f)

View File

@@ -100,7 +100,7 @@ func (m *MempoolBitcoinType) getInputAddress(payload *chanInputPayload) *addrInd
}
func (m *MempoolBitcoinType) computeGolombFilter(mtx *MempoolTx, tx *Tx) string {
gf, _ := NewGolombFilter(m.golombFilterP, "", mtx.Txid, m.useZeroedKey)
gf, _ := NewGolombFilter(m.golombFilterP, m.filterScripts, mtx.Txid, m.useZeroedKey)
if gf == nil || !gf.Enabled {
return ""
}

View File

@@ -194,7 +194,7 @@ func TestMempoolBitcoinType_computeGolombFilter_taproot(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := m.computeGolombFilter(&tt.mtx)
got := m.computeGolombFilter(&tt.mtx, nil)
if got != tt.want {
t.Errorf("MempoolBitcoinType.computeGolombFilter() = %v, want %v", got, tt.want)
}
@@ -238,3 +238,5 @@ func TestMempoolBitcoinType_computeGolombFilter_taproot(t *testing.T) {
})
}
}
// TODO test also taproot-noordinals option

View File

@@ -57,7 +57,7 @@ type Vin struct {
ScriptSig ScriptSig `json:"scriptSig"`
Sequence uint32 `json:"sequence"`
Addresses []string `json:"addresses"`
Witness [][]byte `json:"witness"`
Witness [][]byte `json:"-"`
}
// ScriptPubKey contains data about output script

View File

@@ -1462,7 +1462,7 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) {
"scriptType": "",
},
},
want: `{"id":"41","data":{}}`,
want: `{"id":"41","data":{"P":0,"M":1,"zeroedKey":false,"entries":{}}}`,
},
{
name: "websocket getMempoolFilters invalid type",
@@ -1482,7 +1482,7 @@ func websocketTestsBitcoinType(t *testing.T, ts *httptest.Server) {
"blockHash": "abcd",
},
},
want: `{"id":"43","data":""}`,
want: `{"id":"43","data":{"P":0,"M":1,"zeroedKey":false,"blockFilter":""}}`,
},
}

View File

@@ -19,7 +19,7 @@ func NewFakeBlockChain(parser bchain.BlockChainParser) (bchain.BlockChain, error
}
func (c *fakeBlockChain) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
return bchain.NewMempoolBitcoinType(chain, 1, 1, 0, ""), nil
return bchain.NewMempoolBitcoinType(chain, 1, 1, 0, "", false), nil
}
func (c *fakeBlockChain) Initialize() error {